@@ -36,7 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
36
#include " common/Common.h"
37
37
38
38
#include " GeometryCache.h"
39
-
39
+ # include " GLMemory.h "
40
40
#include " tr_local.h"
41
41
42
42
GeometryCache geometryCache;
@@ -61,12 +61,6 @@ void GeometryCache::FreeGLBuffers() {
61
61
VAO.DelVAO ();
62
62
}
63
63
64
- void GeometryCache::AllocBuffers () {
65
- VBO.BufferData ( mapVerticesNumber * 8 , nullptr , GL_STATIC_DRAW );
66
-
67
- IBO.BufferData ( mapIndicesNumber, nullptr , GL_STATIC_DRAW );
68
- }
69
-
70
64
void GeometryCache::AddMapGeometry ( const uint32_t verticesNumber, const uint32_t indicesNumber,
71
65
const vertexAttributeSpec_t* attrBegin, const vertexAttributeSpec_t* attrEnd,
72
66
const glIndex_t* indices ) {
@@ -75,28 +69,28 @@ void GeometryCache::AddMapGeometry( const uint32_t verticesNumber, const uint32_
75
69
76
70
VAO.Bind ();
77
71
78
- AllocBuffers ();
79
-
80
72
VAO.SetAttrs ( attrBegin, attrEnd );
81
73
82
74
VAO.SetVertexBuffer ( VBO, 0 );
83
75
VAO.SetIndexBuffer ( IBO );
84
76
85
77
VBO.BufferStorage ( mapVerticesNumber * 8 , 1 , nullptr );
86
- VBO.MapAll ();
87
- uint32_t * VBOVerts = VBO.GetData ();
78
+ uint32_t * VBOVerts = stagingBuffer.MapBuffer ( mapVerticesNumber * 8 );
88
79
for ( const vertexAttributeSpec_t* spec = attrBegin; spec < attrEnd; spec++ ) {
89
80
vboAttributeLayout_t& attr = VAO.attrs [spec->attrIndex ];
90
81
91
82
R_CopyVertexAttribute ( attr, *spec, mapVerticesNumber, ( byte* ) VBOVerts );
92
83
}
93
- VBO.UnmapBuffer ();
84
+
85
+ stagingBuffer.QueueStagingCopy ( &VBO, 0 );
94
86
95
87
IBO.BufferStorage ( mapIndicesNumber, 1 , nullptr );
96
- IBO.MapAll ();
97
- uint32_t * IBOIndices = IBO.GetData ();
88
+ uint32_t * IBOIndices = stagingBuffer.MapBuffer ( mapIndicesNumber );
98
89
memcpy ( IBOIndices, indices, mapIndicesNumber * sizeof ( uint32_t ) );
99
- IBO.UnmapBuffer ();
90
+
91
+ stagingBuffer.QueueStagingCopy ( &IBO, 0 );
92
+
93
+ stagingBuffer.FlushAll ();
100
94
101
95
glBindVertexArray ( backEnd.currentVAO );
102
96
}
0 commit comments