Unify buffering data and drawing with gl3state.v[ab]ao3D

use GL3_BufferAndDraw3D() instead of glBufferData() and glDrawArrays()
in each place it's needed.
This by itself doesn't make anything faster, but it will make trying out
different ways to upload data easier.
This commit is contained in:
Daniel Gibson 2019-04-01 17:13:24 +02:00
parent 44e8088f7d
commit 7b4dc000ad
4 changed files with 24 additions and 19 deletions

View file

@ -583,6 +583,18 @@ GL3_Shutdown(void)
GL3_ShutdownContext();
}
// assumes gl3state.v[ab]o3D are bound
// buffers and draws gl3_3D_vtx_t vertices
// drawMode is something like GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN or whatever
void
GL3_BufferAndDraw3D(const gl3_3D_vtx_t* verts, int numVerts, GLenum drawMode)
{
// TODO: do something more efficient, maybe with glMapBufferRange() + GL_MAP_UNSYNCHRONIZED_BIT
// and glBindBufferRange()
glBufferData( GL_ARRAY_BUFFER, sizeof(gl3_3D_vtx_t)*numVerts, verts, GL_STREAM_DRAW );
glDrawArrays( drawMode, 0, numVerts );
}
static void
GL3_DrawBeam(entity_t *e)
{
@ -658,8 +670,7 @@ GL3_DrawBeam(entity_t *e)
GL3_BindVAO(gl3state.vao3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STREAM_DRAW);
glDrawArrays( GL_TRIANGLE_STRIP, 0, NUM_BEAM_SEGS*4 );
GL3_BufferAndDraw3D(verts, NUM_BEAM_SEGS*4, GL_TRIANGLE_STRIP);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
@ -734,8 +745,7 @@ GL3_DrawSpriteModel(entity_t *e)
GL3_BindVAO(gl3state.vao3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, 4*sizeof(gl3_3D_vtx_t), verts, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
GL3_BufferAndDraw3D(verts, 4, GL_TRIANGLE_FAN);
if (alpha != 1.0F)
{
@ -779,16 +789,14 @@ GL3_DrawNullModel(void)
{{16 * cos( 4 * M_PI / 2 ), 16 * sin( 4 * M_PI / 2 ), 0}, {0,0}, {0,0}}
};
glBufferData(GL_ARRAY_BUFFER, sizeof(vtxA), vtxA, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, 6);
GL3_BufferAndDraw3D(vtxA, 6, GL_TRIANGLE_FAN);
gl3_3D_vtx_t vtxB[6] = {
{{0, 0, 16}, {0,0}, {0,0}},
vtxA[5], vtxA[4], vtxA[3], vtxA[2], vtxA[1]
};
glBufferData(GL_ARRAY_BUFFER, sizeof(vtxB), vtxB, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, 6);
GL3_BufferAndDraw3D(vtxB, 6, GL_TRIANGLE_FAN);
gl3state.uni3DData.transModelMat4 = origModelMat;
GL3_UpdateUBO3D();

View file

@ -44,7 +44,7 @@ extern int numgl3textures;
void GL3_SurfInit(void)
{
// init the VAO and VBO for the standard vertexdata: 10 floats and 1 uint
// (X, Y, Z), (S, T), (LMS, LMT), (normX, normY, normZ) - last two groups for lightmap/dynlights
// (X, Y, Z), (S, T), (LMS, LMT), (normX, normY, normZ) ; lightFlags - last two groups for lightmap/dynlights
glGenVertexArrays(1, &gl3state.vao3D);
GL3_BindVAO(gl3state.vao3D);
@ -212,9 +212,8 @@ GL3_DrawGLPoly(msurface_t *fa)
GL3_BindVAO(gl3state.vao3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, sizeof(gl3_3D_vtx_t)*p->numverts, p->vertices, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
GL3_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
}
void
@ -241,8 +240,7 @@ GL3_DrawGLFlowingPoly(msurface_t *fa)
GL3_BindVAO(gl3state.vao3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, sizeof(gl3_3D_vtx_t)*p->numverts, p->vertices, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
GL3_BufferAndDraw3D(p->vertices, p->numverts, GL_TRIANGLE_FAN);
}
static void

View file

@ -255,9 +255,7 @@ GL3_EmitWaterPolys(msurface_t *fa)
for (bp = fa->polys; bp != NULL; bp = bp->next)
{
int numverts = bp->numverts;
glBufferData(GL_ARRAY_BUFFER, sizeof(gl3_3D_vtx_t)*numverts, bp->vertices, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, numverts);
GL3_BufferAndDraw3D(bp->vertices, bp->numverts, GL_TRIANGLE_FAN);
}
}
@ -726,8 +724,7 @@ GL3_DrawSkyBox(void)
MakeSkyVec( skymaxs [ 0 ] [ i ], skymaxs [ 1 ] [ i ], i, &skyVertices[2] );
MakeSkyVec( skymaxs [ 0 ] [ i ], skymins [ 1 ] [ i ], i, &skyVertices[3] );
glBufferData(GL_ARRAY_BUFFER, sizeof(skyVertices), skyVertices, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
GL3_BufferAndDraw3D(skyVertices, 4, GL_TRIANGLE_FAN);
}
// glPopMatrix();

View file

@ -225,7 +225,7 @@ typedef struct
// NOTE: make sure siParticle is always the last shaderInfo (or adapt GL3_ShutdownShaders())
gl3ShaderInfo_t siParticle; // for particles. surprising, right?
GLuint vao3D, vbo3D; // for brushes etc, using 1 floats as vertex input (x,y,z, s,t, lms,lmt, normX,normY,normZ)
GLuint vao3D, vbo3D; // for brushes etc, using 10 floats and one uint as vertex input (x,y,z, s,t, lms,lmt, normX,normY,normZ ; lightFlags)
GLuint vaoAlias, vboAlias, eboAlias; // for models, using 9 floats as (x,y,z, s,t, r,g,b,a)
GLuint vaoParticle, vboParticle; // for particles, using 9 floats (x,y,z, size,distance, r,g,b,a)
@ -350,6 +350,8 @@ GL3_BindEBO(GLuint ebo)
}
}
extern void GL3_BufferAndDraw3D(const gl3_3D_vtx_t* verts, int numVerts, GLenum drawMode);
extern qboolean GL3_CullBox(vec3_t mins, vec3_t maxs);
extern void GL3_RotateForEntity(entity_t *e);