@@ -36,7 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636#include " common/Common.h"
3737
3838#include " GeometryCache.h"
39-
39+ # include " GLMemory.h "
4040#include " tr_local.h"
4141
4242GeometryCache geometryCache;
@@ -61,12 +61,6 @@ void GeometryCache::FreeGLBuffers() {
6161 VAO.DelVAO ();
6262}
6363
64- void GeometryCache::AllocBuffers () {
65- VBO.BufferData ( mapVerticesNumber * 8 , nullptr , GL_STATIC_DRAW );
66-
67- IBO.BufferData ( mapIndicesNumber, nullptr , GL_STATIC_DRAW );
68- }
69-
7064void GeometryCache::AddMapGeometry ( const uint32_t verticesNumber, const uint32_t indicesNumber,
7165 const vertexAttributeSpec_t* attrBegin, const vertexAttributeSpec_t* attrEnd,
7266 const glIndex_t* indices ) {
@@ -75,28 +69,28 @@ void GeometryCache::AddMapGeometry( const uint32_t verticesNumber, const uint32_
7569
7670 VAO.Bind ();
7771
78- AllocBuffers ();
79-
8072 VAO.SetAttrs ( attrBegin, attrEnd );
8173
8274 VAO.SetVertexBuffer ( VBO, 0 );
8375 VAO.SetIndexBuffer ( IBO );
8476
8577 VBO.BufferStorage ( mapVerticesNumber * 8 , 1 , nullptr );
86- VBO.MapAll ();
87- uint32_t * VBOVerts = VBO.GetData ();
78+ uint32_t * VBOVerts = stagingBuffer.MapBuffer ( mapVerticesNumber * 8 );
8879 for ( const vertexAttributeSpec_t* spec = attrBegin; spec < attrEnd; spec++ ) {
8980 vboAttributeLayout_t& attr = VAO.attrs [spec->attrIndex ];
9081
9182 R_CopyVertexAttribute ( attr, *spec, mapVerticesNumber, ( byte* ) VBOVerts );
9283 }
93- VBO.UnmapBuffer ();
84+
85+ stagingBuffer.QueueStagingCopy ( &VBO, 0 );
9486
9587 IBO.BufferStorage ( mapIndicesNumber, 1 , nullptr );
96- IBO.MapAll ();
97- uint32_t * IBOIndices = IBO.GetData ();
88+ uint32_t * IBOIndices = stagingBuffer.MapBuffer ( mapIndicesNumber );
9889 memcpy ( IBOIndices, indices, mapIndicesNumber * sizeof ( uint32_t ) );
99- IBO.UnmapBuffer ();
90+
91+ stagingBuffer.QueueStagingCopy ( &IBO, 0 );
92+
93+ stagingBuffer.FlushAll ();
10094
10195 glBindVertexArray ( backEnd.currentVAO );
10296}
0 commit comments