GL3_BindVBO(vbo) wrapping glBindBuffer(GL_ARRAY_BUFFER, vbo)

avoids calling glBindBuffer() if the vbo is already bound, similar
to GL3_Bind(), GL3_BindVAO(), GL3_UseProgram() etc
This commit is contained in:
Daniel Gibson 2017-02-20 02:01:48 +01:00
parent 30026f2025
commit 098890805f
5 changed files with 21 additions and 10 deletions

View file

@ -44,7 +44,7 @@ GL3_Draw_InitLocal(void)
glBindVertexArray(vao2D);
glGenBuffers(1, &vbo2D);
glBindBuffer(GL_ARRAY_BUFFER, vbo2D);
GL3_BindVBO(vbo2D);
GL3_UseProgram(gl3state.si2D.shaderProgram);
@ -61,7 +61,7 @@ GL3_Draw_InitLocal(void)
glGenVertexArrays(1, &vao2Dcolor);
glBindVertexArray(vao2Dcolor);
glBindBuffer(GL_ARRAY_BUFFER, vbo2D); // yes, both VAOs share the same VBO
GL3_BindVBO(vbo2D); // yes, both VAOs share the same VBO
GL3_UseProgram(gl3state.si2Dcolor.shaderProgram);
@ -109,7 +109,7 @@ drawTexturedRectangle(float x, float y, float w, float h,
// Note: while vao2D "remembers" its vbo for drawing, binding the vao does *not*
// implicitly bind the vbo, so I need to explicitly bind it before glBufferData()
glBindBuffer(GL_ARRAY_BUFFER, vbo2D);
GL3_BindVBO(vbo2D);
glBufferData(GL_ARRAY_BUFFER, sizeof(vBuf), vBuf, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@ -284,7 +284,7 @@ GL3_Draw_Fill(int x, int y, int w, int h, int c)
GL3_UseProgram(gl3state.si2Dcolor.shaderProgram);
GL3_BindVAO(vao2Dcolor);
glBindBuffer(GL_ARRAY_BUFFER, vbo2D);
GL3_BindVBO(vbo2D);
glBufferData(GL_ARRAY_BUFFER, sizeof(vBuf), vBuf, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@ -313,7 +313,7 @@ GL3_Draw_FadeScreen(void)
GL3_BindVAO(vao2Dcolor);
glBindBuffer(GL_ARRAY_BUFFER, vbo2D);
GL3_BindVBO(vbo2D);
glBufferData(GL_ARRAY_BUFFER, sizeof(vBuf), vBuf, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

View file

@ -290,6 +290,7 @@ GL3_Register(void)
gl_round_down = ri.Cvar_Get("gl_round_down", "1", 0);
gl_picmip = ri.Cvar_Get("gl_picmip", "0", 0);
gl_showtris = ri.Cvar_Get("gl_showtris", "0", 0);
gl_showbbox = Cvar_Get("gl_showbbox", "0", 0);
//gl_ztrick = ri.Cvar_Get("gl_ztrick", "0", 0); NOTE: dump this.
//gl_zfix = ri.Cvar_Get("gl_zfix", "0", 0);
//gl_finish = ri.Cvar_Get("gl_finish", "0", CVAR_ARCHIVE);

View file

@ -49,7 +49,7 @@ void GL3_SurfInit(void)
GL3_BindVAO(gl3state.vao3D);
glGenBuffers(1, &gl3state.vbo3D);
glBindBuffer(GL_ARRAY_BUFFER, gl3state.vbo3D);
GL3_BindVBO(gl3state.vbo3D);
glEnableVertexAttribArray(GL3_ATTRIB_POSITION);
qglVertexAttribPointer(GL3_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, VERTEXSIZE*sizeof(GLfloat), 0);
@ -125,8 +125,7 @@ GL3_DrawGLPoly(glpoly_t *p)
GL3_UseProgram(gl3state.si3D.shaderProgram); // TODO: needed each time?! maybe call this once in DrawTextureChains()?
GL3_BindVAO(gl3state.vao3D);
glBindBuffer(GL_ARRAY_BUFFER, gl3state.vbo3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, VERTEXSIZE*sizeof(GLfloat)*p->numverts, v, GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);
@ -158,7 +157,7 @@ GL3_DrawGLFlowingPoly(msurface_t *fa)
GL3_UseProgram(gl3state.si3Dflow.shaderProgram);
GL3_BindVAO(gl3state.vao3D);
glBindBuffer(GL_ARRAY_BUFFER, gl3state.vbo3D);
GL3_BindVBO(gl3state.vbo3D);
glBufferData(GL_ARRAY_BUFFER, VERTEXSIZE*sizeof(GLfloat)*p->numverts, p->verts[0], GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLE_FAN, 0, p->numverts);

View file

@ -244,7 +244,7 @@ GL3_EmitWaterPolys(msurface_t *fa)
GL3_UseProgram(gl3state.si3Dturb.shaderProgram);
GL3_BindVAO(gl3state.vao3D);
glBindBuffer(GL_ARRAY_BUFFER, gl3state.vbo3D);
GL3_BindVBO(gl3state.vbo3D);
for (bp = fa->polys; bp != NULL; bp = bp->next)
{

View file

@ -164,6 +164,7 @@ typedef struct
//qboolean hwgamma;
GLuint currentVAO;
GLuint currentVBO;
GLuint currentShaderProgram;
gl3ShaderInfo_t si2D; // shader for rendering 2D with textures
gl3ShaderInfo_t si2Dcolor; // shader for rendering 2D with flat colors
@ -284,6 +285,16 @@ GL3_BindVAO(GLuint vao)
}
}
static inline void
GL3_BindVBO(GLuint vbo)
{
if(vbo != gl3state.currentVBO)
{
gl3state.currentVBO = vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
}
}
extern qboolean GL3_CullBox(vec3_t mins, vec3_t maxs);
extern void GL3_RotateForEntity(entity_t *e);