Skip to content

Commit d7a5034

Browse files
committed
R_DStreams: Merge OpenGL implementation.
1 parent d1678e9 commit d7a5034

File tree

4 files changed

+49
-207
lines changed

4 files changed

+49
-207
lines changed

src/Layers/xrRender/R_DStreams.cpp

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ void _VertexStream::Create ()
1414
RImplementation.Resources->Evict();
1515

1616
mSize = rsDVB_Size*1024;
17-
#if defined(USE_DX10) || defined(USE_DX11)
17+
#if defined (USE_OGL)
18+
glGenBuffers(1, &pVB);
19+
R_ASSERT(pVB);
20+
21+
glBindBuffer(GL_ARRAY_BUFFER, pVB);
22+
CHK_GL(glBufferData(GL_ARRAY_BUFFER, mSize, nullptr, GL_DYNAMIC_DRAW));
23+
#elif defined(USE_DX10) || defined(USE_DX11)
1824
D3D_BUFFER_DESC bufferDesc;
1925
bufferDesc.ByteWidth = mSize;
2026
bufferDesc.Usage = D3D_USAGE_DYNAMIC;
@@ -39,8 +45,12 @@ void _VertexStream::Create ()
3945

4046
void _VertexStream::Destroy ()
4147
{
42-
HW.stats_manager.decrement_stats_vb (pVB);
43-
_RELEASE (pVB);
48+
#ifdef USE_OGL
49+
glDeleteBuffers(1, &pVB);
50+
#else
51+
HW.stats_manager.decrement_stats_vb(pVB);
52+
_RELEASE(pVB);
53+
#endif // USE_OGL
4454
_clear ();
4555
}
4656

@@ -66,14 +76,19 @@ void* _VertexStream::Lock ( u32 vl_Count, u32 Stride, u32& vOffset )
6676

6777
// Check if there is need to flush and perform lock
6878
BYTE* pData = 0;
79+
#ifdef USE_OGL
80+
glBindBuffer(GL_ARRAY_BUFFER, pVB);
81+
#endif // USE_OGL
6982
if ((vl_Count+vl_mPosition) >= vl_mSize)
7083
{
7184
// FLUSH-LOCK
7285
mPosition = 0;
7386
vOffset = 0;
7487
mDiscardID ++;
7588

76-
#if defined(USE_DX11)
89+
#if defined (USE_OGL)
90+
CHK_GL(pData = glMapBufferRange(GL_ARRAY_BUFFER, mPosition, bytes_need, LOCKFLAGS_FLUSH));
91+
#elif defined(USE_DX11)
7792
HW.pContext->Map(pVB, 0, D3D_MAP_WRITE_DISCARD, 0, &MappedSubRes);
7893
pData=(BYTE*)MappedSubRes.pData;
7994
pData += vOffset;
@@ -92,7 +107,9 @@ void* _VertexStream::Lock ( u32 vl_Count, u32 Stride, u32& vOffset )
92107
mPosition = vl_mPosition*Stride;
93108
vOffset = vl_mPosition;
94109

95-
#if defined(USE_DX11)
110+
#if defined(USE_OGL)
111+
CHK_GL(pData = glMapBufferRange(GL_ARRAY_BUFFER, mPosition, bytes_need, LOCKFLAGS_APPEND));
112+
#elif defined(USE_DX11)
96113
HW.pContext->Map(pVB, 0, D3D_MAP_WRITE_NO_OVERWRITE, 0, &MappedSubRes);
97114
pData=(BYTE*)MappedSubRes.pData;
98115
pData += vOffset*Stride;
@@ -123,7 +140,9 @@ void _VertexStream::Unlock ( u32 Count, u32 Stride)
123140

124141
VERIFY (pVB);
125142

126-
#if defined(USE_DX11)
143+
#if defined(USE_OGL)
144+
CHK_GL(glUnmapBuffer(GL_ARRAY_BUFFER));
145+
#elif defined(USE_DX11)
127146
HW.pContext->Unmap(pVB, 0);
128147
#elif defined(USE_DX10)
129148
pVB->Unmap();
@@ -167,7 +186,13 @@ void _IndexStream::Create ()
167186

168187
mSize = rsDIB_Size*1024;
169188

170-
#if defined(USE_DX10) || defined(USE_DX11)
189+
#if defined(USE_OGL)
190+
glGenBuffers(1, &pIB);
191+
R_ASSERT(pIB);
192+
193+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pIB);
194+
CHK_GL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, mSize, nullptr, GL_DYNAMIC_DRAW));
195+
#elif defined(USE_DX10) || defined(USE_DX11)
171196
D3D_BUFFER_DESC bufferDesc;
172197
bufferDesc.ByteWidth = mSize;
173198
bufferDesc.Usage = D3D_USAGE_DYNAMIC;
@@ -191,8 +216,12 @@ void _IndexStream::Create ()
191216

192217
void _IndexStream::Destroy()
193218
{
194-
HW.stats_manager.decrement_stats_ib (pIB);
195-
_RELEASE (pIB);
219+
#ifdef USE_OGL
220+
glDeleteBuffers(1, &pIB);
221+
#else
222+
HW.stats_manager.decrement_stats_ib(pIB);
223+
_RELEASE(pIB);
224+
#endif // USE_OGL
196225
_clear ();
197226
}
198227

@@ -218,7 +247,10 @@ u16* _IndexStream::Lock ( u32 Count, u32& vOffset )
218247
dwFlags = LOCKFLAGS_FLUSH; // discard it's contens
219248
mDiscardID ++;
220249
}
221-
#if defined(USE_DX11)
250+
#if defined(USE_OGL)
251+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pIB);
252+
CHK_GL(pLockedData = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, mPosition * 2, Count * 2, flags));
253+
#elif defined(USE_DX11)
222254
D3D_MAP MapMode = (dwFlags==LOCKFLAGS_APPEND) ?
223255
D3D_MAP_WRITE_NO_OVERWRITE : D3D_MAP_WRITE_DISCARD;
224256
HW.pContext->Map(pIB, 0, MapMode, 0, &MappedSubRes);
@@ -245,7 +277,9 @@ void _IndexStream::Unlock(u32 RealCount)
245277
PGO (Msg("PGO:IB_UNLOCK:%d",RealCount));
246278
mPosition += RealCount;
247279
VERIFY (pIB);
248-
#if defined(USE_DX11)
280+
#if defined(USE_OGL)
281+
CHK_GL(glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER));
282+
#elif defined(USE_DX11)
249283
HW.pContext->Unmap(pIB, 0);
250284
#elif defined(USE_DX10)
251285
pIB->Unmap();

src/Layers/xrRenderPC_GL/GL_DStreams.cpp

Lines changed: 0 additions & 192 deletions
This file was deleted.

src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
<ClCompile Include="..\xrRender\Light_Render_Direct.cpp" />
250250
<ClCompile Include="..\xrRender\Light_Render_Direct_ComputeXFS.cpp" />
251251
<ClCompile Include="..\xrRender\ModelPool.cpp" />
252+
<ClCompile Include="..\xrRender\R_DStreams.cpp" />
252253
<ClCompile Include="..\xrRender\Shader.cpp" />
253254
<ClCompile Include="blender_bloom_build.cpp" />
254255
<ClCompile Include="blender_combine.cpp" />
@@ -357,7 +358,6 @@
357358
<ClCompile Include="glResourceManager_Scripting.cpp" />
358359
<ClCompile Include="glr_constants.cpp" />
359360
<ClCompile Include="glTexture.cpp" />
360-
<ClCompile Include="GL_DStreams.cpp" />
361361
<ClCompile Include="gl_R_render.cpp" />
362362
<ClCompile Include="r2_R_calculate.cpp" />
363363
<ClCompile Include="gl_rendertarget.cpp" />

src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@
201201
<ClCompile Include="..\xrRender\ParticleGroup.cpp">
202202
<Filter>Models\Visuals</Filter>
203203
</ClCompile>
204-
<ClCompile Include="GL_DStreams.cpp">
205-
<Filter>Refactored\Backend</Filter>
206-
</ClCompile>
207204
<ClCompile Include="..\xrRender\ResourceManager.cpp">
208205
<Filter>Refactored\Execution &amp; 3D\Shaders\ShaderManager</Filter>
209206
</ClCompile>
@@ -639,6 +636,9 @@
639636
<ClCompile Include="..\xrRender\D3DUtils.cpp">
640637
<Filter>Refactored\Execution &amp; 3D\DebugDraw</Filter>
641638
</ClCompile>
639+
<ClCompile Include="..\xrRender\R_DStreams.cpp">
640+
<Filter>Refactored\Backend</Filter>
641+
</ClCompile>
642642
</ItemGroup>
643643
<ItemGroup>
644644
<ClInclude Include="stdafx.h">

0 commit comments

Comments
 (0)