Skip to content

Commit eca94e6

Browse files
committed
xrRender: Add various OpenGL implementations.
1 parent e809f75 commit eca94e6

15 files changed

+176
-58
lines changed

src/Layers/xrRender/DetailManager_VS.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "xrEngine/Environment.h"
1010
#endif
1111
#include "Layers/xrRenderDX10/dx10BufferUtils.h"
12+
#include "Layers/xrRenderGL/glBufferUtils.h"
1213

1314
const int quant = 16384;
1415
const int c_hdr = 10;
@@ -60,7 +61,7 @@ void CDetailManager::hw_Load_Geom()
6061
u32 vSize = sizeof(vertHW);
6162
Msg("* [DETAILS] %d v(%d), %d p",dwVerts,vSize,dwIndices/3);
6263

63-
#if !defined(USE_DX10) && !defined(USE_DX11)
64+
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
6465
// Determine POOL & USAGE
6566
u32 dwUsage = D3DUSAGE_WRITEONLY;
6667

@@ -76,7 +77,7 @@ void CDetailManager::hw_Load_Geom()
7677
// Fill VB
7778
{
7879
vertHW* pV;
79-
#if defined(USE_DX10) || defined(USE_DX11)
80+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
8081
vertHW* pVOriginal;
8182
pVOriginal = xr_alloc<vertHW>(dwVerts);
8283
pV = pVOriginal;
@@ -103,7 +104,10 @@ void CDetailManager::hw_Load_Geom()
103104
}
104105
}
105106
}
106-
#if defined(USE_DX10) || defined(USE_DX11)
107+
#if defined(USE_OGL)
108+
glBufferUtils::CreateVertexBuffer(&hw_VB, pVOriginal, dwVerts*vSize);
109+
xr_free(pVOriginal);
110+
#elif defined(USE_DX10) || defined(USE_DX11)
107111
R_CHK(dx10BufferUtils::CreateVertexBuffer(&hw_VB, pVOriginal, dwVerts*vSize));
108112
HW.stats_manager.increment_stats_vb ( hw_VB);
109113
xr_free(pVOriginal);
@@ -115,7 +119,7 @@ void CDetailManager::hw_Load_Geom()
115119
// Fill IB
116120
{
117121
u16* pI;
118-
#if defined(USE_DX10) || defined(USE_DX11)
122+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
119123
u16* pIOriginal;
120124
pIOriginal = xr_alloc<u16>(dwIndices);
121125
pI = pIOriginal;
@@ -133,7 +137,10 @@ void CDetailManager::hw_Load_Geom()
133137
offset = u16(offset+u16(D.number_vertices));
134138
}
135139
}
136-
#if defined(USE_DX10) || defined(USE_DX11)
140+
#if defined(USE_OGL)
141+
glBufferUtils::CreateIndexBuffer(&hw_IB, pIOriginal, dwIndices * 2);
142+
xr_free(pIOriginal);
143+
#elif defined(USE_DX10) || defined(USE_DX11)
137144
R_CHK(dx10BufferUtils::CreateIndexBuffer(&hw_IB, pIOriginal, dwIndices*2));
138145
HW.stats_manager.increment_stats_ib (hw_IB);
139146
xr_free(pIOriginal);
@@ -150,13 +157,18 @@ void CDetailManager::hw_Unload()
150157
{
151158
// Destroy VS/VB/IB
152159
hw_Geom.destroy ();
153-
HW.stats_manager.decrement_stats_vb ( hw_VB);
154-
HW.stats_manager.decrement_stats_ib ( hw_IB);
160+
#ifdef USE_OGL
161+
GLuint buffers[] = { hw_IB, hw_VB };
162+
glDeleteBuffers(2, buffers);
163+
#else
164+
HW.stats_manager.decrement_stats_vb(hw_VB);
165+
HW.stats_manager.decrement_stats_ib(hw_IB);
155166
_RELEASE (hw_IB);
156167
_RELEASE (hw_VB);
168+
#endif // USE_OGL
157169
}
158170

159-
#if !defined(USE_DX10) && !defined(USE_DX11)
171+
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
160172
void CDetailManager::hw_Load_Shaders()
161173
{
162174
// Create shader to access constant storage

src/Layers/xrRender/FSkinned.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void CSkeletonX_PM::Load(const char* N, IReader *data, u32 dwFlags)
376376
void* _verts_ = data->pointer ();
377377
inherited1::Load (N,data,dwFlags|VLOAD_NOVERTICES);
378378
GlobalEnv.Render->shader_option_skinning(-1);
379-
#if defined(USE_DX10) || defined(USE_DX11)
379+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
380380
_DuplicateIndices(N, data);
381381
#endif // USE_DX10
382382
vBase = 0;
@@ -388,14 +388,14 @@ void CSkeletonX_ST::Load(const char* N, IReader *data, u32 dwFlags)
388388
void* _verts_ = data->pointer ();
389389
inherited1::Load (N,data,dwFlags|VLOAD_NOVERTICES);
390390
GlobalEnv.Render->shader_option_skinning(-1);
391-
#if defined(USE_DX10) || defined(USE_DX11)
391+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
392392
_DuplicateIndices(N, data);
393393
#endif // USE_DX10
394394
vBase = 0;
395395
_Load_hw (*this,_verts_);
396396
}
397397

398-
#if defined(USE_DX10) || defined(USE_DX11)
398+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
399399

400400
void CSkeletonX_ext::_Load_hw (Fvisual& V, void * _verts_)
401401
{

src/Layers/xrRender/FVisual.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ Fvisual::Fvisual() : dxRender_Visual()
2020

2121
Fvisual::~Fvisual()
2222
{
23+
#ifndef USE_OGL
2324
HW.stats_manager.decrement_stats_vb (p_rm_Vertices);
2425
HW.stats_manager.decrement_stats_ib (p_rm_Indices);
26+
#endif // !USE_OGL
2527
xr_delete (m_fast);
2628
}
2729

src/Layers/xrRender/ModelPool.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,22 @@ void CModelPool::memory_stats ( u32& vb_mem_video, u32& vb_mem_system, u32& ib_
460460

461461
if( vis_ptr == NULL )
462462
continue;
463-
#if !defined(USE_DX10) && !defined(USE_DX11)
463+
#if defined(USE_OGL)
464+
GLint IB_size;
465+
GLint VB_size;
466+
467+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vis_ptr->m_fast->p_rm_Indices);
468+
CHK_GL(glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &IB_size));
469+
470+
ib_mem_video += IB_size;
471+
ib_mem_system += IB_size;
472+
473+
glBindBuffer(GL_ARRAY_BUFFER, vis_ptr->m_fast->p_rm_Vertices);
474+
CHK_GL(glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &VB_size));
475+
476+
vb_mem_video += VB_size;
477+
vb_mem_system += VB_size;
478+
#elif !defined(USE_DX10) && !defined(USE_DX11)
464479
D3DINDEXBUFFER_DESC IB_desc;
465480
D3DVERTEXBUFFER_DESC VB_desc;
466481

@@ -497,14 +512,7 @@ void CModelPool::memory_stats ( u32& vb_mem_video, u32& vb_mem_system, u32& ib_
497512

498513
vb_mem_video += IB_desc.ByteWidth;
499514
vb_mem_system += IB_desc.ByteWidth;
500-
501515
#endif
502-
503-
504-
505-
506-
507-
508516
}
509517
}
510518

src/Layers/xrRender/R_Backend.cpp

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,42 @@
66
CBackend RCache;
77

88
// Create Quad-IB
9-
#if defined(USE_DX10) || defined(USE_DX11)
9+
#if defined(USE_OGL)
10+
11+
// Igor: is used to test bug with rain, particles corruption
12+
void CBackend::RestoreQuadIBData()
13+
{
14+
}
15+
16+
void CBackend::CreateQuadIB()
17+
{
18+
const u32 dwTriCount = 4 * 1024;
19+
const u32 dwIdxCount = dwTriCount * 2 * 3;
20+
u16 IndexBuffer[dwIdxCount];
21+
u16 *Indices = IndexBuffer;
22+
GLenum dwUsage = GL_STATIC_DRAW;
23+
24+
int Cnt = 0;
25+
int ICnt = 0;
26+
for (int i = 0; i<dwTriCount; i++)
27+
{
28+
Indices[ICnt++] = u16(Cnt + 0);
29+
Indices[ICnt++] = u16(Cnt + 1);
30+
Indices[ICnt++] = u16(Cnt + 2);
31+
32+
Indices[ICnt++] = u16(Cnt + 3);
33+
Indices[ICnt++] = u16(Cnt + 2);
34+
Indices[ICnt++] = u16(Cnt + 1);
35+
36+
Cnt += 4;
37+
}
38+
39+
glGenBuffers(1, &QuadIB);
40+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, QuadIB);
41+
CHK_GL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, dwIdxCount * 2, Indices, dwUsage));
42+
}
43+
44+
#elif defined(USE_DX10) || defined(USE_DX11)
1045

1146
// Igor: is used to test bug with rain, particles corruption
1247
void CBackend::RestoreQuadIBData()
@@ -126,6 +161,10 @@ void CBackend::OnDeviceCreate ()
126161
#if defined(USE_DX10) || defined(USE_DX11)
127162
//CreateConstantBuffers();
128163
#endif // USE_DX10
164+
#ifdef USE_OGL
165+
// Create the program pipeline used for rendering with shaders
166+
glGenProgramPipelines(1, &pp);
167+
#endif // USE_OGL
129168

130169
CreateQuadIB ();
131170

@@ -144,12 +183,19 @@ void CBackend::OnDeviceDestroy()
144183
Vertex.Destroy ();
145184

146185
// Quad
147-
HW.stats_manager.decrement_stats_ib (QuadIB);
148-
_RELEASE (QuadIB);
186+
#ifdef USE_OGL
187+
glDeleteBuffers(1, &QuadIB);
188+
#else
189+
HW.stats_manager.decrement_stats_ib(QuadIB);
190+
_RELEASE(QuadIB);
191+
#endif
149192

150193
#if defined(USE_DX10) || defined(USE_DX11)
151194
//DestroyConstantBuffers();
152195
#endif // USE_DX10
196+
#ifdef USE_OGL
197+
glDeleteProgramPipelines(1, &pp);
198+
#endif // USE_OGL
153199
}
154200

155201
#if defined(USE_DX10) || defined(USE_DX11)

src/Layers/xrRender/R_Backend.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ class ECORE_API CBackend
237237
#if defined(USE_DX10) || defined(USE_DX11)
238238
IC void get_ConstantDirect (shared_str& n, u32 DataSize, void** pVData, void** pGData, void** pPData);
239239
#else //USE_DX10
240+
#ifndef USE_OGL
240241
IC R_constant_array& get_ConstantCache_Vertex () { return constants.a_vertex; }
241242
IC R_constant_array& get_ConstantCache_Pixel () { return constants.a_pixel; }
243+
#endif // USE_OGL
242244
#endif // USE_DX10
243245

244246
// API
@@ -364,7 +366,7 @@ class ECORE_API CBackend
364366
ICF void set_ca (R_constant* C, u32 e, const Fmatrix& A) { if (C) constants.seta(C,e,A); }
365367
ICF void set_ca (R_constant* C, u32 e, const Fvector4& A) { if (C) constants.seta(C,e,A); }
366368
ICF void set_ca (R_constant* C, u32 e, float x, float y, float z, float w) { if (C) constants.seta(C,e,x,y,z,w); }
367-
#if defined(USE_DX10) || defined(USE_DX11)
369+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
368370
ICF void set_c (R_constant* C, float A) { if (C) constants.set(C,A); }
369371
ICF void set_c (R_constant* C, int A) { if (C) constants.set(C,A); }
370372
#endif // USE_DX10
@@ -377,7 +379,7 @@ class ECORE_API CBackend
377379
ICF void set_ca (LPCSTR n, u32 e, const Fmatrix& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
378380
ICF void set_ca (LPCSTR n, u32 e, const Fvector4& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
379381
ICF void set_ca (LPCSTR n, u32 e, float x, float y, float z, float w) { if(ctable) set_ca (&*ctable->get(n),e,x,y,z,w);}
380-
#if defined(USE_DX10) || defined(USE_DX11)
382+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
381383
ICF void set_c (LPCSTR n, float A) { if(ctable) set_c (&*ctable->get(n),A); }
382384
ICF void set_c (LPCSTR n, int A) { if(ctable) set_c (&*ctable->get(n),A); }
383385
#endif // USE_DX10
@@ -389,7 +391,7 @@ class ECORE_API CBackend
389391
ICF void set_ca (shared_str& n, u32 e, const Fmatrix& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
390392
ICF void set_ca (shared_str& n, u32 e, const Fvector4& A) { if(ctable) set_ca (&*ctable->get(n),e,A); }
391393
ICF void set_ca (shared_str& n, u32 e, float x, float y, float z, float w) { if(ctable) set_ca (&*ctable->get(n),e,x,y,z,w);}
392-
#if defined(USE_DX10) || defined(USE_DX11)
394+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
393395
ICF void set_c (shared_str& n, float A) { if(ctable) set_c (&*ctable->get(n),A); }
394396
ICF void set_c (shared_str& n, int A) { if(ctable) set_c (&*ctable->get(n),A); }
395397
#endif // USE_DX10

src/Layers/xrRender/R_Backend_DBG.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void CBackend::dbg_DIP(D3DPRIMITIVETYPE pt, ref_geom geom, u32 baseV, u32 startV
1717

1818
void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pIdx, int pcnt)
1919
{
20-
#if defined(USE_DX10) || defined(USE_DX11)
20+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
2121
// TODO: DX10: implement
2222
//VERIFY(!"CBackend::dbg_Draw not implemented.");
2323
#else // USE_DX10
@@ -31,7 +31,7 @@ void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int vcnt, u16* pI
3131
}
3232
void CBackend::dbg_Draw (D3DPRIMITIVETYPE T, FVF::L* pVerts, int pcnt)
3333
{
34-
#if defined(USE_DX10) || defined(USE_DX11)
34+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
3535
// TODO: DX10: implement
3636
//VERIFY(!"CBackend::dbg_Draw not implemented.");
3737
#else // USE_DX10
@@ -127,7 +127,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
127127
0.3536f,-0.1464f,-0.9239f, 0.3827f,0.0000f,-0.9239f, 0.3536f,0.1464f,-0.9239f,
128128
0.2706f,0.2706f,-0.9239f, 0.1464f,0.3536f,-0.9239f, 0.0000f,0.0000f,-1.0000f
129129
};
130-
#if !defined(USE_DX10) && !defined(USE_DX11)
130+
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
131131
u16 gFaces[224*3] =
132132
{
133133
0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,7, 0,7,8, 0,8,9, 0,9,10,
@@ -167,7 +167,7 @@ void CBackend::dbg_DrawEllipse(Fmatrix& T, u32 C)
167167

168168
set_xform_world (T);
169169

170-
#if defined(USE_DX10) || defined(USE_DX11)
170+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
171171
// TODO: DX10: implement
172172
//VERIFY(!"CBackend::dbg_Draw not implemented.");
173173
//dbg_Draw(D3DPT_TRIANGLELIST,verts,vcnt,gFaces,224);

src/Layers/xrRender/R_Backend_Runtime.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ void CBackend::OnFrameEnd ()
2020
if (!g_dedicated_server)
2121
#endif
2222
{
23-
#if defined(USE_DX10) || defined(USE_DX11)
23+
#if defined(USE_OGL)
24+
Invalidate ();
25+
#elif defined(USE_DX10) || defined(USE_DX11)
2426
HW.pContext->ClearState();
2527
Invalidate ();
2628
#else // USE_DX10
@@ -146,7 +148,7 @@ DX10_ONLY(gs = NULL);
146148

147149
void CBackend::set_ClipPlanes (u32 _enable, Fplane* _planes /*=NULL */, u32 count/* =0*/)
148150
{
149-
#if defined(USE_DX10) || defined(USE_DX11)
151+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
150152
// TODO: DX10: Implement in the corresponding vertex shaders
151153
// Use this to set up location, were shader setup code will get data
152154
//VERIFY(!"CBackend::set_ClipPlanes not implemented!");
@@ -184,7 +186,7 @@ void CBackend::set_ClipPlanes (u32 _enable, Fmatrix* _xform /*=NULL */, u32 fma
184186
{
185187
if (0==HW.Caps.geometry.dwClipPlanes) return;
186188
if (!_enable) {
187-
#if defined(USE_DX10) || defined(USE_DX11)
189+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
188190
// TODO: DX10: Implement in the corresponding vertex shaders
189191
// Use this to set up location, were shader setup code will get data
190192
//VERIFY(!"CBackend::set_ClipPlanes not implemented!");
@@ -371,7 +373,11 @@ void CBackend::set_Textures (STextureList* _T)
371373
continue;
372374

373375
textures_ps[_last_ps] = 0;
374-
#if defined(USE_DX10) || defined(USE_DX11)
376+
#if defined(USE_OGL)
377+
CHK_GL(glActiveTexture(GL_TEXTURE0 + _last_ps));
378+
CHK_GL(glBindTexture(GL_TEXTURE_2D, 0));
379+
CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
380+
#elif defined(USE_DX10) || defined(USE_DX11)
375381
// TODO: DX10: Optimise: set all resources at once
376382
ID3DShaderResourceView *pRes = 0;
377383
//HW.pDevice->PSSetShaderResources(_last_ps, 1, &pRes);
@@ -387,7 +393,11 @@ void CBackend::set_Textures (STextureList* _T)
387393
continue;
388394

389395
textures_vs[_last_vs] = 0;
390-
#if defined(USE_DX10) || defined(USE_DX11)
396+
#if defined(USE_OGL)
397+
CHK_GL(glActiveTexture(GL_TEXTURE0 + CTexture::rstVertex + _last_vs));
398+
CHK_GL(glBindTexture(GL_TEXTURE_2D, 0));
399+
CHK_GL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
400+
#elif defined(USE_DX10) || defined(USE_DX11)
391401
// TODO: DX10: Optimise: set all resources at once
392402
ID3DShaderResourceView *pRes = 0;
393403
//HW.pDevice->VSSetShaderResources(_last_vs, 1, &pRes);

src/Layers/xrRender/ResourceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void CResourceManager::_DumpMemoryUsage ()
417417
void CResourceManager::Evict()
418418
{
419419
// TODO: DX10: check if we really need this method
420-
#if !defined(USE_DX10) && !defined(USE_DX11)
420+
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
421421
CHK_DX (HW.pDevice->EvictManagedResources());
422422
#endif // USE_DX10
423423
}

0 commit comments

Comments
 (0)