Skip to content

Commit

Permalink
Refactor renderer loading mechanism
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Xottab-DUTY committed Oct 21, 2018
1 parent 8a4962c commit 7bea5f7
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 265 deletions.
13 changes: 0 additions & 13 deletions src/Include/xrAPI/xrAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class UICore;

class XRAPI_API EngineGlobalEnvironment
{
using SupportCheck = bool(*)();
using SetupEnv = void(*)();

public:
IRender* Render;
IDebugRender* DRender;
Expand All @@ -34,16 +31,6 @@ class XRAPI_API EngineGlobalEnvironment
bool isDedicatedServer;

int CurrentRenderer;
SupportCheck CheckR2;
SupportCheck CheckR3;
SupportCheck CheckR4;
SupportCheck CheckRGL;
SetupEnv SetupR1;
SetupEnv SetupR2;
SetupEnv SetupR3;
SetupEnv SetupR4;
SetupEnv SetupRGL;
SetupEnv SetupCurrentRenderer;
};

extern XRAPI_API EngineGlobalEnvironment GEnv;
1 change: 1 addition & 0 deletions src/Layers/xrRender/HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void CHW::DestroyD3D()
{
_SHOW_REF("refCount:pD3D", pD3D);
_RELEASE(pD3D);
hD3D = nullptr;
}

void CHW::CreateDevice(SDL_Window* m_sdlWnd)
Expand Down
31 changes: 10 additions & 21 deletions src/Layers/xrRenderPC_GL/xrRender_GL.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// xrRender_GL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Layers/xrRender/dxRenderFactory.h"
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"

void SetupEnvRGL()
extern "C"
{
XR_EXPORT void SetupEnv()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -17,25 +17,14 @@ void SetupEnvRGL()
xrRender_initconsole();
}

bool SupportsOpenGLRendering()
XR_EXPORT pcstr GetModeName()
{
// XXX: do a real check
return true;
return "renderer_gl";
}

// This must not be optimized by compiler
static const volatile class GEnvHelper
XR_EXPORT bool CheckRendererSupport()
{
public:
GEnvHelper()
{
GEnv.CheckRGL = SupportsOpenGLRendering;
GEnv.SetupRGL = SetupEnvRGL;
}

~GEnvHelper()
{
GEnv.SetupRGL = nullptr;
GEnv.SetupRGL = nullptr;
}
} helper;
// XXX: do a real check
return true;
}
}
29 changes: 16 additions & 13 deletions src/Layers/xrRenderPC_R1/xrRender_R1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"

void SetupEnvR1()
extern "C"
{
XR_EXPORT void SetupEnv()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -15,16 +17,17 @@ void SetupEnvR1()
xrRender_initconsole();
}

// This must not be optimized by compiler
static const volatile class GEnvHelper
XR_EXPORT pcstr GetModeName()
{
return "renderer_r1";
}

XR_EXPORT bool CheckRendererSupport()
{
public:
GEnvHelper()
{
GEnv.SetupR1 = SetupEnvR1;
}
~GEnvHelper()
{
GEnv.SetupR1 = nullptr;
}
} helper;
CHW _HW;
_HW.CreateD3D();
if (_HW.pD3D)
return true;
return false;
}
}
32 changes: 12 additions & 20 deletions src/Layers/xrRenderPC_R2/xrRender_R2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"

void SetupEnvR2()
extern "C"
{
XR_EXPORT void SetupEnv()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -15,7 +17,12 @@ void SetupEnvR2()
xrRender_initconsole();
}

bool SupportsAdvancedRendering()
XR_EXPORT pcstr GetModeName()
{
return "renderer_r2";
}

XR_EXPORT bool CheckRendererSupport()
{
D3DCAPS9 caps;
CHW _HW;
Expand All @@ -26,22 +33,7 @@ bool SupportsAdvancedRendering()

if (ps_ver_major < 3)
return false;
else
return true;
}

// This must not be optimized by compiler
static const volatile class GEnvHelper
{
public:
GEnvHelper()
{
GEnv.CheckR2 = SupportsAdvancedRendering;
GEnv.SetupR2 = SetupEnvR2;
}
~GEnvHelper()
{
GEnv.CheckR2 = nullptr;
GEnv.SetupR2 = nullptr;
}
} helper;
return true;
}
}
39 changes: 9 additions & 30 deletions src/Layers/xrRenderPC_R3/xrRender_R3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"

void SetupEnvR3()
extern "C"
{
XR_EXPORT void SetupEnv()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -15,36 +17,13 @@ void SetupEnvR3()
xrRender_initconsole();
}

bool SupportsDX10Rendering()
XR_EXPORT pcstr GetModeName()
{
return xrRender_test_hw() ? true : false;
/*
D3DCAPS9 caps;
CHW _HW;
_HW.CreateD3D ();
_HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
_HW.DestroyD3D ();
u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
if (ps_ver_major<3)
return false;
else
return true;
*/
return "renderer_r3";
}

// This must not be optimized by compiler
static const volatile class GEnvHelper
XR_EXPORT bool CheckRendererSupport()
{
public:
GEnvHelper()
{
GEnv.CheckR3 = SupportsDX10Rendering;
GEnv.SetupR3 = SetupEnvR3;
}
~GEnvHelper()
{
GEnv.CheckR3 = nullptr;
GEnv.SetupR3 = nullptr;
}
} helper;
return xrRender_test_hw() ? true : false;
}
}
40 changes: 9 additions & 31 deletions src/Layers/xrRenderPC_R4/xrRender_R4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include "Layers/xrRender/dxRenderFactory.h"
#include "Layers/xrRender/dxUIRender.h"
#include "Layers/xrRender/dxDebugRender.h"
#include "Include/xrAPI/xrAPI.h"

void SetupEnvR4()
extern "C"
{
XR_EXPORT void SetupEnv()
{
GEnv.Render = &RImplementation;
GEnv.RenderFactory = &RenderFactoryImpl;
Expand All @@ -16,36 +17,13 @@ void SetupEnvR4()
xrRender_initconsole();
}

bool SupportsDX11Rendering()
XR_EXPORT pcstr GetModeName()
{
return xrRender_test_hw() ? true : false;
/*
D3DCAPS9 caps;
CHW _HW;
_HW.CreateD3D ();
_HW.pD3D->GetDeviceCaps (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);
_HW.DestroyD3D ();
u16 ps_ver_major = u16 ( u32(u32(caps.PixelShaderVersion)&u32(0xf << 8ul))>>8 );
if (ps_ver_major<3)
return false;
else
return true;
*/
return "renderer_r4";
}

// This must not be optimized by compiler
static const volatile class GEnvHelper
XR_EXPORT bool CheckRendererSupport()
{
public:
GEnvHelper()
{
GEnv.CheckR4 = SupportsDX11Rendering;
GEnv.SetupR4 = SetupEnvR4;
}
~GEnvHelper()
{
GEnv.CheckR4 = nullptr;
GEnv.SetupR4 = nullptr;
}
} helper;
return xrRender_test_hw() ? true : false;
}
}
Loading

0 comments on commit 7bea5f7

Please sign in to comment.