@@ -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
4046void _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
192217void _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 ();
0 commit comments