Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a4d710d
feat(ww3d2): add IRenderBackend abstract interface
bobtista Apr 10, 2026
e4a8981
feat(ww3d2): add DX8Backend adapter forwarding to DX8Wrapper statics
bobtista Apr 10, 2026
b6dc7bd
feat(ww3d2): add global g_renderBackend pointer and lifecycle wiring
bobtista Apr 10, 2026
3d80c67
fix(ww3d2): Update copyright headers to TheSuperHackers for new files
bobtista Apr 18, 2026
9db0eb6
refactor(ww3d2): trim redundant comments from render backend interface
bobtista May 31, 2026
294ce4f
refactor(ww3d2): move backend implementations into Backend subfolder
bobtista May 31, 2026
b157428
feat(ww3d2): add IRenderBackend Initialize and Shutdown lifecycle hooks
bobtista May 31, 2026
3568db1
build(ww3d2): sort Backend render sources alphabetically in CMakeLists
bobtista Jun 4, 2026
0644f79
fix(ww3d2): guard against null render backend in device dependent shu…
bobtista Jul 19, 2026
89ba40d
refactor(ww3d2): decouple TransformKind values from D3D transform sta…
bobtista Jul 19, 2026
97a6034
refactor(ww3d2): add override specifiers to DX8Backend declarations
bobtista Jul 19, 2026
2422827
chore(ww3d2): use qualified include paths in render backend files
bobtista Jul 19, 2026
4d2aeeb
fix(ww3d2): Use a fixed width type for render backend shader ids
bobtista Aug 7, 2026
8acd5f0
refactor(ww3d2): Widen render backend draw and index ranges to unsign…
bobtista Aug 7, 2026
bdd6d93
refactor(ww3d2): Remove the SurfaceClass back buffer accessor from th…
bobtista Aug 7, 2026
2bbc25f
refactor(ww3d2): Separate render backend object lifetime from device …
bobtista Aug 7, 2026
c03cc18
refactor(ww3d2): Select render backend through factory
bobtista Aug 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 328 additions & 0 deletions Core/Libraries/Source/WWVegas/WW3D2/Backend/DX8Backend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2026 TheSuperHackers
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// TheSuperHackers @refactor bobtista 10/04/2026 DX8Backend forwarding adapter.
// Every method in this file is a one-line trampoline to the existing
// DX8Wrapper static API. Keep it that way — if behavior needs to change it
// should change in DX8Wrapper, not here.

#include "DX8Backend.h"
#include "RenderBackend.h"

#include "WW3D2/dx8wrapper.h"
#include "WWMath/vector3.h"
#include "WWMath/matrix4.h"
#include "WWMath/matrix3d.h"
#include "WW3D2/light.h"
#include "WW3D2/lightenvironment.h"

DX8Backend::DX8Backend()
{
}

DX8Backend::~DX8Backend()
{
}

IRenderBackend *Create_Render_Backend()
{
return new DX8Backend();
}

bool DX8Backend::Is_Device_Lost() const
{
return DX8Wrapper::Is_Device_Lost();
}

bool DX8Backend::Has_Stencil()
{
return DX8Wrapper::Has_Stencil();
}

WW3DFormat DX8Backend::Get_Back_Buffer_Format()
{
return DX8Wrapper::getBackBufferFormat();
}

void DX8Backend::Set_Gamma(float gamma, float bright, float contrast, bool calibrate, bool uselimit)
{
DX8Wrapper::Set_Gamma(gamma, bright, contrast, calibrate, uselimit);
}

void DX8Backend::Begin_Scene()
{
DX8Wrapper::Begin_Scene();
}

void DX8Backend::End_Scene(bool flip_frame)
{
DX8Wrapper::End_Scene(flip_frame);
}

void DX8Backend::Flip_To_Primary()
{
DX8Wrapper::Flip_To_Primary();
}

void DX8Backend::Clear(bool clear_color, bool clear_z_stencil,
const Vector3 & color,
float dest_alpha, float z, unsigned int stencil)
{
DX8Wrapper::Clear(clear_color, clear_z_stencil, color, dest_alpha, z, stencil);
}

void DX8Backend::Set_Viewport(const RenderBackendViewport & viewport)
{
D3DVIEWPORT8 vp;
vp.X = viewport.x;
vp.Y = viewport.y;
vp.Width = viewport.width;
vp.Height = viewport.height;
vp.MinZ = viewport.min_z;
vp.MaxZ = viewport.max_z;
DX8Wrapper::Set_Viewport(&vp);
}

void DX8Backend::Set_Vertex_Buffer(const VertexBufferClass * vb, unsigned int stream)
{
DX8Wrapper::Set_Vertex_Buffer(vb, stream);
}

void DX8Backend::Set_Vertex_Buffer(const DynamicVBAccessClass & vba)
{
DX8Wrapper::Set_Vertex_Buffer(vba);
}

void DX8Backend::Set_Index_Buffer(const IndexBufferClass * ib, unsigned int index_base_offset)
{
DX8Wrapper::Set_Index_Buffer(ib, static_cast<unsigned short>(index_base_offset));
}

void DX8Backend::Set_Index_Buffer(const DynamicIBAccessClass & iba, unsigned int index_base_offset)
{
DX8Wrapper::Set_Index_Buffer(iba, static_cast<unsigned short>(index_base_offset));
}

void DX8Backend::Set_Index_Buffer_Index_Offset(unsigned int offset)
{
DX8Wrapper::Set_Index_Buffer_Index_Offset(offset);
}

void DX8Backend::Set_Shader(const ShaderClass & shader)
{
DX8Wrapper::Set_Shader(shader);
}

void DX8Backend::Get_Shader(ShaderClass & shader)
{
DX8Wrapper::Get_Shader(shader);
}

void DX8Backend::Set_Material(const VertexMaterialClass * material)
{
DX8Wrapper::Set_Material(material);
}

void DX8Backend::Set_Texture(unsigned int stage, TextureBaseClass * texture)
{
DX8Wrapper::Set_Texture(stage, texture);
}

void DX8Backend::Apply_Render_State_Changes()
{
DX8Wrapper::Apply_Render_State_Changes();
}

void DX8Backend::Apply_Default_State()
{
DX8Wrapper::Apply_Default_State();
}

void DX8Backend::Invalidate_Cached_Render_States()
{
DX8Wrapper::Invalidate_Cached_Render_States();
}

static D3DTRANSFORMSTATETYPE To_D3D_Transform(TransformKind transform)
{
switch (transform)
{
case RB_TRANSFORM_VIEW:
return D3DTS_VIEW;
case RB_TRANSFORM_PROJECTION:
return D3DTS_PROJECTION;
case RB_TRANSFORM_WORLD:
default:
return D3DTS_WORLD;
}
}

void DX8Backend::Set_Transform(TransformKind transform, const Matrix4x4 & m)
{
DX8Wrapper::Set_Transform(To_D3D_Transform(transform), m);
}

void DX8Backend::Set_Transform(TransformKind transform, const Matrix3D & m)
{
DX8Wrapper::Set_Transform(To_D3D_Transform(transform), m);
}

void DX8Backend::Get_Transform(TransformKind transform, Matrix4x4 & m)
{
DX8Wrapper::Get_Transform(To_D3D_Transform(transform), m);
}

void DX8Backend::Set_World_Identity()
{
DX8Wrapper::Set_World_Identity();
}

void DX8Backend::Set_View_Identity()
{
DX8Wrapper::Set_View_Identity();
}

bool DX8Backend::Is_World_Identity()
{
return DX8Wrapper::Is_World_Identity();
}

bool DX8Backend::Is_View_Identity()
{
return DX8Wrapper::Is_View_Identity();
}

void DX8Backend::Set_Projection_Transform_With_Z_Bias(const Matrix4x4 & matrix, float znear, float zfar)
{
DX8Wrapper::Set_Projection_Transform_With_Z_Bias(matrix, znear, zfar);
}

void DX8Backend::Set_Light(unsigned int index, const LightClass & light)
{
DX8Wrapper::Set_Light(index, light);
}

void DX8Backend::Set_Ambient(const Vector3 & color)
{
DX8Wrapper::Set_Ambient(color);
}

const Vector3 & DX8Backend::Get_Ambient() const
{
return DX8Wrapper::Get_Ambient();
}

void DX8Backend::Set_Fog(bool enable, const Vector3 & color, float start, float end)
{
DX8Wrapper::Set_Fog(enable, color, start, end);
}

bool DX8Backend::Get_Fog_Enable() const
{
return DX8Wrapper::Get_Fog_Enable();
}

void DX8Backend::Set_Light_Environment(LightEnvironmentClass * light_env)
{
DX8Wrapper::Set_Light_Environment(light_env);
}

LightEnvironmentClass * DX8Backend::Get_Light_Environment() const
{
return DX8Wrapper::Get_Light_Environment();
}

void DX8Backend::Draw_Triangles(unsigned int start_index,
unsigned int polygon_count,
unsigned int min_vertex_index,
unsigned int vertex_count)
{
DX8Wrapper::Draw_Triangles(static_cast<unsigned short>(start_index),
static_cast<unsigned short>(polygon_count),
static_cast<unsigned short>(min_vertex_index),
static_cast<unsigned short>(vertex_count));
}

void DX8Backend::Draw_Triangles(unsigned int buffer_type,
unsigned int start_index,
unsigned int polygon_count,
unsigned int min_vertex_index,
unsigned int vertex_count)
{
DX8Wrapper::Draw_Triangles(buffer_type,
static_cast<unsigned short>(start_index),
static_cast<unsigned short>(polygon_count),
static_cast<unsigned short>(min_vertex_index),
static_cast<unsigned short>(vertex_count));
}

void DX8Backend::Draw_Strip(unsigned int start_index,
unsigned int index_count,
unsigned int min_vertex_index,
unsigned int vertex_count)
{
DX8Wrapper::Draw_Strip(static_cast<unsigned short>(start_index),
static_cast<unsigned short>(index_count),
static_cast<unsigned short>(min_vertex_index),
static_cast<unsigned short>(vertex_count));
}

void DX8Backend::Set_Vertex_Shader(unsigned int vertex_shader)
{
DX8Wrapper::Set_Vertex_Shader(static_cast<DWORD>(vertex_shader));
}

void DX8Backend::Set_Pixel_Shader(unsigned int pixel_shader)
{
DX8Wrapper::Set_Pixel_Shader(static_cast<DWORD>(pixel_shader));
}

void DX8Backend::Set_Vertex_Shader_Constant(int reg, const void * data, int count)
{
DX8Wrapper::Set_Vertex_Shader_Constant(reg, data, count);
}

void DX8Backend::Set_Pixel_Shader_Constant(int reg, const void * data, int count)
{
DX8Wrapper::Set_Pixel_Shader_Constant(reg, data, count);
}

TextureClass * DX8Backend::Create_Render_Target(int width, int height, WW3DFormat format)
{
return DX8Wrapper::Create_Render_Target(width, height, format);
}

void DX8Backend::Set_Render_Target_With_Z(TextureClass * texture, ZTextureClass * ztexture)
{
DX8Wrapper::Set_Render_Target_With_Z(texture, ztexture);
}

bool DX8Backend::Is_Render_To_Texture()
{
return DX8Wrapper::Is_Render_To_Texture();
}

void DX8Backend::Set_Shadow_Map(int idx, ZTextureClass * ztex)
{
DX8Wrapper::Set_Shadow_Map(idx, ztex);
}

ZTextureClass * DX8Backend::Get_Shadow_Map(int idx)
{
return DX8Wrapper::Get_Shadow_Map(idx);
}
Loading
Loading