Skip to content

Commit d21e34a

Browse files
committed
RGL: preparations to use ShaderRecourceTraits
Allowed Hull, Domain and Compute shaders for OpenGL Renderer
1 parent 33cf655 commit d21e34a

File tree

5 files changed

+95
-70
lines changed

5 files changed

+95
-70
lines changed

src/Layers/xrRender/ResourceManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ECORE_API CResourceManager
4242
using map_GS = xr_map<const char*, SGS*, str_pred>;
4343
#endif
4444

45-
#if defined(USE_DX11)
45+
#if defined(USE_DX11) || defined(USE_OGL)
4646
using map_HS = xr_map<const char*, SHS*, str_pred>;
4747
using map_DS = xr_map<const char*, SDS*, str_pred>;
4848
using map_CS = xr_map<const char*, SCS*, str_pred>;
@@ -66,7 +66,7 @@ class ECORE_API CResourceManager
6666
map_GS m_gs;
6767
#endif
6868

69-
#if defined(USE_DX11)
69+
#if defined(USE_DX11) || defined(USE_OGL)
7070
map_DS m_ds;
7171
map_HS m_hs;
7272
map_CS m_cs;
@@ -164,7 +164,7 @@ class ECORE_API CResourceManager
164164
void _DeleteGS(const SGS* GS);
165165
#endif // USE_DX10
166166

167-
#if defined(USE_DX11)
167+
#if defined(USE_DX11) || defined(USE_OGL)
168168
SHS* _CreateHS(LPCSTR Name);
169169
void _DeleteHS(const SHS* HS);
170170

src/Layers/xrRender/SH_Atomic.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ struct ECORE_API SGS : public xr_resource_named
6868
typedef resptr_core<SGS, resptr_base<SGS>> ref_gs;
6969
#endif // USE_DX10
7070

71-
#if defined(USE_DX11)
72-
71+
#if defined(USE_DX11) || defined(USE_OGL)
7372
struct ECORE_API SHS : public xr_resource_named
7473
{
7574
#ifdef USE_OGL

src/Layers/xrRender/ShaderResourceTraits.h

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ template <>
99
struct ShaderTypeTraits<SVS>
1010
{
1111
typedef CResourceManager::map_VS MapType;
12-
typedef ID3DVertexShader DXIface;
12+
13+
#ifdef USE_OGL
14+
using HWShaderType = GLuint;
15+
#else
16+
using HWShaderType = ID3DVertexShader*;
17+
#endif
1318

1419
static inline const char* GetShaderExt() { return ".vs"; }
1520
static inline const char* GetCompilationTarget()
@@ -37,10 +42,12 @@ struct ShaderTypeTraits<SVS>
3742
}
3843
}
3944

40-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
45+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
4146
{
42-
DXIface* vs = 0;
43-
#ifdef USE_DX11
47+
HWShaderType vs = 0;
48+
#ifdef USE_OGL
49+
vs = glCreateShader(GL_VERTEX_SHADER);
50+
#elif defined(USE_DX11)
4451
R_CHK(HW.pDevice->CreateVertexShader(buffer, size, 0, &vs));
4552
#elif defined(USE_DX10)
4653
R_CHK(HW.pDevice->CreateVertexShader(buffer, size, &vs));
@@ -57,7 +64,12 @@ template <>
5764
struct ShaderTypeTraits<SPS>
5865
{
5966
typedef CResourceManager::map_PS MapType;
60-
typedef ID3DPixelShader DXIface;
67+
68+
#ifdef USE_OGL
69+
using HWShaderType = GLuint;
70+
#else
71+
using HWShaderType = ID3DPixelShader*;
72+
#endif
6173

6274
static inline const char* GetShaderExt() { return ".ps"; }
6375
static inline const char* GetCompilationTarget()
@@ -94,10 +106,12 @@ struct ShaderTypeTraits<SPS>
94106
}
95107
}
96108

97-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
109+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
98110
{
99-
DXIface* ps = 0;
100-
#ifdef USE_DX11
111+
HWShaderType ps = 0;
112+
#ifdef USE_OGL
113+
ps = glCreateShader(GL_FRAGMENT_SHADER);
114+
#elif defined(USE_DX11)
101115
R_CHK(HW.pDevice->CreatePixelShader(buffer, size, 0, &ps));
102116
#elif defined(USE_DX10)
103117
R_CHK(HW.pDevice->CreatePixelShader(buffer, size, &ps));
@@ -110,18 +124,24 @@ struct ShaderTypeTraits<SPS>
110124
static inline u32 GetShaderDest() { return RC_dest_pixel; }
111125
};
112126

113-
#if defined(USE_DX10) || defined(USE_DX11)
127+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
114128
template <>
115129
struct ShaderTypeTraits<SGS>
116130
{
117131
typedef CResourceManager::map_GS MapType;
118-
typedef ID3DGeometryShader DXIface;
132+
133+
#ifdef USE_OGL
134+
using HWShaderType = GLuint;
135+
#else
136+
using HWShaderType = ID3DGeometryShader*;
137+
#endif
138+
119139

120140
static inline const char* GetShaderExt() { return ".gs"; }
121141
static inline const char* GetCompilationTarget()
122142
{
123143
#ifdef USE_DX10
124-
if (HW.pDevice1 == 0)
144+
if (HW.pDevice1 == nullptr)
125145
return D3D10GetGeometryShaderProfile(HW.pDevice);
126146
else
127147
return "gs_4_1";
@@ -144,27 +164,34 @@ struct ShaderTypeTraits<SGS>
144164
entry = "main";
145165
}
146166

147-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
167+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
148168
{
149-
DXIface* gs = 0;
150-
#ifdef USE_DX11
169+
HWShaderType gs = 0;
170+
#ifdef USE_OGL
171+
gs = glCreateShader(GL_GEOMETRY_SHADER);
172+
#elif defined(USE_DX11)
151173
R_CHK(HW.pDevice->CreateGeometryShader(buffer, size, 0, &gs));
152174
#else
153175
R_CHK(HW.pDevice->CreateGeometryShader(buffer, size, &gs));
154-
#endif
176+
#endif
155177
return gs;
156178
}
157179

158180
static inline u32 GetShaderDest() { return RC_dest_geometry; }
159181
};
160182
#endif
161183

162-
#ifdef USE_DX11
184+
#if defined(USE_DX11) || defined(USE_OGL)
163185
template <>
164186
struct ShaderTypeTraits<SHS>
165187
{
166188
typedef CResourceManager::map_HS MapType;
167-
typedef ID3D11HullShader DXIface;
189+
190+
#ifdef USE_OGL
191+
using HWShaderType = GLuint;
192+
#else
193+
using HWShaderType = ID3D11HullShader*;
194+
#endif
168195

169196
static inline const char* GetShaderExt() { return ".hs"; }
170197
static inline const char* GetCompilationTarget() { return "hs_5_0"; }
@@ -175,10 +202,14 @@ struct ShaderTypeTraits<SHS>
175202
entry = "main";
176203
}
177204

178-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
205+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
179206
{
180-
DXIface* hs = 0;
207+
HWShaderType hs = 0;
208+
#ifdef USE_OGL
209+
hs = glCreateShader(GL_TESS_CONTROL_SHADER);
210+
#else
181211
R_CHK(HW.pDevice->CreateHullShader(buffer, size, NULL, &hs));
212+
#endif
182213
return hs;
183214
}
184215

@@ -189,7 +220,12 @@ template <>
189220
struct ShaderTypeTraits<SDS>
190221
{
191222
typedef CResourceManager::map_DS MapType;
192-
typedef ID3D11DomainShader DXIface;
223+
224+
#ifdef USE_OGL
225+
using HWShaderType = GLuint;
226+
#else
227+
using HWShaderType = ID3D11DomainShader*;
228+
#endif
193229

194230
static inline const char* GetShaderExt() { return ".ds"; }
195231
static inline const char* GetCompilationTarget() { return "ds_5_0"; }
@@ -200,10 +236,14 @@ struct ShaderTypeTraits<SDS>
200236
entry = "main";
201237
}
202238

203-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
239+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
204240
{
205-
DXIface* hs = 0;
241+
HWShaderType hs = 0;
242+
#ifdef USE_OGL
243+
hs = glCreateShader(GL_TESS_EVALUATION_SHADER);
244+
#else
206245
R_CHK(HW.pDevice->CreateDomainShader(buffer, size, NULL, &hs));
246+
#endif
207247
return hs;
208248
}
209249

@@ -214,7 +254,12 @@ template <>
214254
struct ShaderTypeTraits<SCS>
215255
{
216256
typedef CResourceManager::map_CS MapType;
217-
typedef ID3D11ComputeShader DXIface;
257+
258+
#ifdef USE_OGL
259+
using HWShaderType = GLuint;
260+
#else
261+
using HWShaderType = ID3D11ComputeShader*;
262+
#endif
218263

219264
static inline const char* GetShaderExt() { return ".cs"; }
220265
static inline const char* GetCompilationTarget() { return "cs_5_0"; }
@@ -225,10 +270,15 @@ struct ShaderTypeTraits<SCS>
225270
entry = "main";
226271
}
227272

228-
static inline DXIface* CreateHWShader(DWORD const* buffer, size_t size)
273+
static inline HWShaderType CreateHWShader(DWORD const* buffer, size_t size)
229274
{
230-
DXIface* cs = 0;
275+
HWShaderType cs = 0;
276+
277+
#ifdef USE_OGL
278+
cs = glCreateShader(GL_COMPUTE_SHADER);
279+
#else
231280
R_CHK(HW.pDevice->CreateComputeShader(buffer, size, NULL, &cs));
281+
#endif
232282
return cs;
233283
}
234284

@@ -248,15 +298,15 @@ inline CResourceManager::map_VS& CResourceManager::GetShaderMap()
248298
return m_vs;
249299
}
250300

251-
#if defined(USE_DX10) || defined(USE_DX11)
301+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
252302
template <>
253303
inline CResourceManager::map_GS& CResourceManager::GetShaderMap()
254304
{
255305
return m_gs;
256306
}
257307
#endif
258308

259-
#if defined(USE_DX11)
309+
#if defined(USE_DX11) || defined(USE_OGL)
260310
template <>
261311
inline CResourceManager::map_DS& CResourceManager::GetShaderMap()
262312
{

src/Layers/xrRenderPC_GL/glResourceManager_Resources.cpp

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "../xrRender/tss.h"
1010
#include "../xrRender/blenders/blender.h"
1111
#include "../xrRender/blenders/blender_recorder.h"
12-
1312
#include "../xrRenderGL/glBufferUtils.h"
13+
#include "Layers/xrRender/ShaderResourceTraits.h"
1414

1515
void fix_texture_name(LPSTR fn);
1616

@@ -242,19 +242,7 @@ SVS* CResourceManager::_CreateVS(LPCSTR _name)
242242
return _vs;
243243
}
244244

245-
void CResourceManager::_DeleteVS(const SVS* vs)
246-
{
247-
if (0 == (vs->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
248-
LPSTR N = LPSTR(*vs->cName);
249-
map_VS::iterator I = m_vs.find(N);
250-
if (I != m_vs.end())
251-
{
252-
m_vs.erase(I);
253-
return;
254-
}
255-
Msg("! ERROR: Failed to find compiled vertex-shader '%s'", *vs->cName);
256-
}
257-
245+
void CResourceManager::_DeleteVS(const SVS* vs) { DestroyShader(vs); }
258246
//--------------------------------------------------------------------------------------------------------------
259247
SPS* CResourceManager::_CreatePS(LPCSTR _name)
260248
{
@@ -337,18 +325,7 @@ SPS* CResourceManager::_CreatePS(LPCSTR _name)
337325
return _ps;
338326
}
339327

340-
void CResourceManager::_DeletePS(const SPS* ps)
341-
{
342-
if (0 == (ps->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
343-
LPSTR N = LPSTR(*ps->cName);
344-
map_PS::iterator I = m_ps.find(N);
345-
if (I != m_ps.end())
346-
{
347-
m_ps.erase(I);
348-
return;
349-
}
350-
Msg("! ERROR: Failed to find compiled pixel-shader '%s'", *ps->cName);
351-
}
328+
void CResourceManager::_DeletePS(const SPS* ps) { DestroyShader(ps); }
352329

353330
//--------------------------------------------------------------------------------------------------------------
354331
SGS* CResourceManager::_CreateGS(LPCSTR name)
@@ -418,18 +395,16 @@ SGS* CResourceManager::_CreateGS(LPCSTR name)
418395
return _gs;
419396
}
420397

421-
void CResourceManager::_DeleteGS(const SGS* gs)
422-
{
423-
if (0 == (gs->dwFlags & xr_resource_flagged::RF_REGISTERED)) return;
424-
LPSTR N = LPSTR(*gs->cName);
425-
map_GS::iterator I = m_gs.find(N);
426-
if (I != m_gs.end())
427-
{
428-
m_gs.erase(I);
429-
return;
430-
}
431-
Msg("! ERROR: Failed to find compiled geometry shader '%s'", *gs->cName);
432-
}
398+
void CResourceManager::_DeleteGS(const SGS* gs) { DestroyShader(gs); }
399+
400+
SHS* CResourceManager::_CreateHS(LPCSTR Name) { return CreateShader<SHS>(Name); }
401+
void CResourceManager::_DeleteHS(const SHS* HS) { DestroyShader(HS); }
402+
403+
SDS* CResourceManager::_CreateDS(LPCSTR Name) { return CreateShader<SDS>(Name); }
404+
void CResourceManager::_DeleteDS(const SDS* DS) { DestroyShader(DS); }
405+
406+
SCS* CResourceManager::_CreateCS(LPCSTR Name) { return CreateShader<SCS>(Name); }
407+
void CResourceManager::_DeleteCS(const SCS* CS) { DestroyShader(CS); }
433408

434409
R_constant_table* CResourceManager::_CreateConstantTable(R_constant_table& C)
435410
{

src/Layers/xrRenderPC_GL/rgl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Layers/xrRender/LightTrack.h"
1515
#include "Layers/xrRender/dxWallMarkArray.h"
1616
#include "Layers/xrRender/dxUIShader.h"
17+
#include "Layers/xrRender/ShaderResourceTraits.h"
1718

1819
CRender RImplementation;
1920

0 commit comments

Comments
 (0)