Skip to content

Commit e648a3e

Browse files
committed
feat(ww3d2): add global g_renderBackend pointer and lifecycle wiring
1 parent 97a23e4 commit e648a3e

4 files changed

Lines changed: 103 additions & 0 deletions

File tree

Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ set(WW3D2_SRC
158158
proto.h
159159
proxy.h
160160
rddesc.h
161+
RenderBackend.cpp
162+
RenderBackend.h
161163
#render2d.cpp
162164
#render2d.h
163165
render2dsentence.cpp
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 Electronic Arts Inc.
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
// TheSuperHackers @refactor bobtista 10/04/2026 Render backend global
20+
// owner. Holds the single g_renderBackend pointer and constructs/destroys
21+
// the concrete backend instance. See RENDER_BACKEND.md.
22+
23+
#include "RenderBackend.h"
24+
#include "DX8Backend.h"
25+
26+
IRenderBackend * g_renderBackend = nullptr;
27+
28+
void Init_Render_Backend()
29+
{
30+
if (g_renderBackend != nullptr)
31+
{
32+
return;
33+
}
34+
35+
// Phase 1: the DX8 backend is the only option. Phase 2 will introduce
36+
// a compile-time flag to pick between DX8, bgfx, and Diligent.
37+
g_renderBackend = new DX8Backend();
38+
}
39+
40+
void Shutdown_Render_Backend()
41+
{
42+
if (g_renderBackend == nullptr)
43+
{
44+
return;
45+
}
46+
delete g_renderBackend;
47+
g_renderBackend = nullptr;
48+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 Electronic Arts Inc.
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
// TheSuperHackers @refactor bobtista 10/04/2026 Backend-agnostic access point
20+
// for the global IRenderBackend instance. Engine-side code should include
21+
// this header (not IRenderBackend.h or DX8Backend.h directly) to use the
22+
// render backend. See RENDER_BACKEND.md.
23+
24+
#pragma once
25+
26+
#include "IRenderBackend.h"
27+
28+
// The active rendering backend. Set by Init_Render_Backend() during
29+
// WW3D device initialization and cleared by Shutdown_Render_Backend()
30+
// during device teardown. Never null between those two calls.
31+
extern IRenderBackend * g_renderBackend;
32+
33+
// Create the render backend. Called by DX8Wrapper::Do_Onetime_Device_Dependent_Inits
34+
// after the D3D device has been successfully created.
35+
//
36+
// Phase 1 always creates a DX8Backend. Phase 2 will add a compile-time
37+
// option to select between DX8Backend, BgfxBackend, and DiligentBackend.
38+
void Init_Render_Backend();
39+
40+
// Destroy the render backend. Called by DX8Wrapper::Do_Onetime_Device_Dependent_Shutdowns
41+
// before the D3D device is released.
42+
void Shutdown_Render_Backend();

Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "dx8vertexbuffer.h"
5757
#include "dx8indexbuffer.h"
5858
#include "dx8renderer.h"
59+
#include "RenderBackend.h"
5960
#include "ww3d.h"
6061
#include "camera.h"
6162
#include "wwstring.h"
@@ -387,6 +388,11 @@ void DX8Wrapper::Do_Onetime_Device_Dependent_Inits()
387388
TextureLoader::Init();
388389

389390
Set_Default_Global_Render_States();
391+
392+
// TheSuperHackers @refactor bobtista 10/04/2026 Construct the global
393+
// IRenderBackend instance now that the D3D device is ready. See
394+
// Core/Libraries/Source/WWVegas/WW3D2/RENDER_BACKEND.md.
395+
Init_Render_Backend();
390396
}
391397

392398
inline DWORD F2DW(float f) { return *((unsigned*)&f); }
@@ -447,6 +453,11 @@ void DX8Wrapper::Invalidate_Cached_Render_States()
447453

448454
void DX8Wrapper::Do_Onetime_Device_Dependent_Shutdowns()
449455
{
456+
// TheSuperHackers @refactor bobtista 10/04/2026 Tear down the render
457+
// backend before the D3D device is released so any backend-owned
458+
// resources get released first. See RENDER_BACKEND.md.
459+
Shutdown_Render_Backend();
460+
450461
/*
451462
** Shutdown ww3d systems
452463
*/

0 commit comments

Comments
 (0)