Skip to content

Commit 7bea5f7

Browse files
committed
Refactor renderer loading mechanism
Cleanup for GEnv. In future, this will allow us to load renderer libs without hardcoded names just through iterating files with name starting from xrRender_ Layers/xrRender/HW.cpp: sanity
1 parent 8a4962c commit 7bea5f7

File tree

9 files changed

+165
-265
lines changed

9 files changed

+165
-265
lines changed

src/Include/xrAPI/xrAPI.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ class UICore;
1515

1616
class XRAPI_API EngineGlobalEnvironment
1717
{
18-
using SupportCheck = bool(*)();
19-
using SetupEnv = void(*)();
20-
2118
public:
2219
IRender* Render;
2320
IDebugRender* DRender;
@@ -34,16 +31,6 @@ class XRAPI_API EngineGlobalEnvironment
3431
bool isDedicatedServer;
3532

3633
int CurrentRenderer;
37-
SupportCheck CheckR2;
38-
SupportCheck CheckR3;
39-
SupportCheck CheckR4;
40-
SupportCheck CheckRGL;
41-
SetupEnv SetupR1;
42-
SetupEnv SetupR2;
43-
SetupEnv SetupR3;
44-
SetupEnv SetupR4;
45-
SetupEnv SetupRGL;
46-
SetupEnv SetupCurrentRenderer;
4734
};
4835

4936
extern XRAPI_API EngineGlobalEnvironment GEnv;

src/Layers/xrRender/HW.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void CHW::DestroyD3D()
2929
{
3030
_SHOW_REF("refCount:pD3D", pD3D);
3131
_RELEASE(pD3D);
32+
hD3D = nullptr;
3233
}
3334

3435
void CHW::CreateDevice(SDL_Window* m_sdlWnd)
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// xrRender_GL.cpp : Defines the entry point for the DLL application.
2-
//
31
#include "stdafx.h"
42
#include "Layers/xrRender/dxRenderFactory.h"
53
#include "Layers/xrRender/dxUIRender.h"
64
#include "Layers/xrRender/dxDebugRender.h"
75

8-
void SetupEnvRGL()
6+
extern "C"
7+
{
8+
XR_EXPORT void SetupEnv()
99
{
1010
GEnv.Render = &RImplementation;
1111
GEnv.RenderFactory = &RenderFactoryImpl;
@@ -17,25 +17,14 @@ void SetupEnvRGL()
1717
xrRender_initconsole();
1818
}
1919

20-
bool SupportsOpenGLRendering()
20+
XR_EXPORT pcstr GetModeName()
2121
{
22-
// XXX: do a real check
23-
return true;
22+
return "renderer_gl";
2423
}
2524

26-
// This must not be optimized by compiler
27-
static const volatile class GEnvHelper
25+
XR_EXPORT bool CheckRendererSupport()
2826
{
29-
public:
30-
GEnvHelper()
31-
{
32-
GEnv.CheckRGL = SupportsOpenGLRendering;
33-
GEnv.SetupRGL = SetupEnvRGL;
34-
}
35-
36-
~GEnvHelper()
37-
{
38-
GEnv.SetupRGL = nullptr;
39-
GEnv.SetupRGL = nullptr;
40-
}
41-
} helper;
27+
// XXX: do a real check
28+
return true;
29+
}
30+
}

src/Layers/xrRenderPC_R1/xrRender_R1.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "Layers/xrRender/dxUIRender.h"
44
#include "Layers/xrRender/dxDebugRender.h"
55

6-
void SetupEnvR1()
6+
extern "C"
7+
{
8+
XR_EXPORT void SetupEnv()
79
{
810
GEnv.Render = &RImplementation;
911
GEnv.RenderFactory = &RenderFactoryImpl;
@@ -15,16 +17,17 @@ void SetupEnvR1()
1517
xrRender_initconsole();
1618
}
1719

18-
// This must not be optimized by compiler
19-
static const volatile class GEnvHelper
20+
XR_EXPORT pcstr GetModeName()
21+
{
22+
return "renderer_r1";
23+
}
24+
25+
XR_EXPORT bool CheckRendererSupport()
2026
{
21-
public:
22-
GEnvHelper()
23-
{
24-
GEnv.SetupR1 = SetupEnvR1;
25-
}
26-
~GEnvHelper()
27-
{
28-
GEnv.SetupR1 = nullptr;
29-
}
30-
} helper;
27+
CHW _HW;
28+
_HW.CreateD3D();
29+
if (_HW.pD3D)
30+
return true;
31+
return false;
32+
}
33+
}

src/Layers/xrRenderPC_R2/xrRender_R2.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "Layers/xrRender/dxUIRender.h"
44
#include "Layers/xrRender/dxDebugRender.h"
55

6-
void SetupEnvR2()
6+
extern "C"
7+
{
8+
XR_EXPORT void SetupEnv()
79
{
810
GEnv.Render = &RImplementation;
911
GEnv.RenderFactory = &RenderFactoryImpl;
@@ -15,7 +17,12 @@ void SetupEnvR2()
1517
xrRender_initconsole();
1618
}
1719

18-
bool SupportsAdvancedRendering()
20+
XR_EXPORT pcstr GetModeName()
21+
{
22+
return "renderer_r2";
23+
}
24+
25+
XR_EXPORT bool CheckRendererSupport()
1926
{
2027
D3DCAPS9 caps;
2128
CHW _HW;
@@ -26,22 +33,7 @@ bool SupportsAdvancedRendering()
2633

2734
if (ps_ver_major < 3)
2835
return false;
29-
else
30-
return true;
31-
}
3236

33-
// This must not be optimized by compiler
34-
static const volatile class GEnvHelper
35-
{
36-
public:
37-
GEnvHelper()
38-
{
39-
GEnv.CheckR2 = SupportsAdvancedRendering;
40-
GEnv.SetupR2 = SetupEnvR2;
41-
}
42-
~GEnvHelper()
43-
{
44-
GEnv.CheckR2 = nullptr;
45-
GEnv.SetupR2 = nullptr;
46-
}
47-
} helper;
37+
return true;
38+
}
39+
}

src/Layers/xrRenderPC_R3/xrRender_R3.cpp

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "Layers/xrRender/dxUIRender.h"
44
#include "Layers/xrRender/dxDebugRender.h"
55

6-
void SetupEnvR3()
6+
extern "C"
7+
{
8+
XR_EXPORT void SetupEnv()
79
{
810
GEnv.Render = &RImplementation;
911
GEnv.RenderFactory = &RenderFactoryImpl;
@@ -15,36 +17,13 @@ void SetupEnvR3()
1517
xrRender_initconsole();
1618
}
1719

18-
bool SupportsDX10Rendering()
20+
XR_EXPORT pcstr GetModeName()
1921
{
20-
return xrRender_test_hw() ? true : false;
21-
/*
22-
D3DCAPS9 caps;
23-
CHW _HW;
24-
_HW.CreateD3D ();
25-
_HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
26-
_HW.DestroyD3D ();
27-
u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
28-
29-
if (ps_ver_major<3)
30-
return false;
31-
else
32-
return true;
33-
*/
22+
return "renderer_r3";
3423
}
3524

36-
// This must not be optimized by compiler
37-
static const volatile class GEnvHelper
25+
XR_EXPORT bool CheckRendererSupport()
3826
{
39-
public:
40-
GEnvHelper()
41-
{
42-
GEnv.CheckR3 = SupportsDX10Rendering;
43-
GEnv.SetupR3 = SetupEnvR3;
44-
}
45-
~GEnvHelper()
46-
{
47-
GEnv.CheckR3 = nullptr;
48-
GEnv.SetupR3 = nullptr;
49-
}
50-
} helper;
27+
return xrRender_test_hw() ? true : false;
28+
}
29+
}

src/Layers/xrRenderPC_R4/xrRender_R4.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#include "Layers/xrRender/dxRenderFactory.h"
33
#include "Layers/xrRender/dxUIRender.h"
44
#include "Layers/xrRender/dxDebugRender.h"
5-
#include "Include/xrAPI/xrAPI.h"
65

7-
void SetupEnvR4()
6+
extern "C"
7+
{
8+
XR_EXPORT void SetupEnv()
89
{
910
GEnv.Render = &RImplementation;
1011
GEnv.RenderFactory = &RenderFactoryImpl;
@@ -16,36 +17,13 @@ void SetupEnvR4()
1617
xrRender_initconsole();
1718
}
1819

19-
bool SupportsDX11Rendering()
20+
XR_EXPORT pcstr GetModeName()
2021
{
21-
return xrRender_test_hw() ? true : false;
22-
/*
23-
D3DCAPS9 caps;
24-
CHW _HW;
25-
_HW.CreateD3D ();
26-
_HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
27-
_HW.DestroyD3D ();
28-
u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
29-
30-
if (ps_ver_major<3)
31-
return false;
32-
else
33-
return true;
34-
*/
22+
return "renderer_r4";
3523
}
3624

37-
// This must not be optimized by compiler
38-
static const volatile class GEnvHelper
25+
XR_EXPORT bool CheckRendererSupport()
3926
{
40-
public:
41-
GEnvHelper()
42-
{
43-
GEnv.CheckR4 = SupportsDX11Rendering;
44-
GEnv.SetupR4 = SetupEnvR4;
45-
}
46-
~GEnvHelper()
47-
{
48-
GEnv.CheckR4 = nullptr;
49-
GEnv.SetupR4 = nullptr;
50-
}
51-
} helper;
27+
return xrRender_test_hw() ? true : false;
28+
}
29+
}

0 commit comments

Comments
 (0)