From 745fa7ecce41c219009f2987cb422b1e2fcbacc2 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 30 Aug 2014 03:22:26 +0000 Subject: [PATCH] Simple use of vertex arrays in R_DrawTextureChains_Multitexture. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The glBegin(GL_POLYGON), for() loop with GL_MTexCoord2fFunc()/glVertex3fv() calls, and glEnd () per polygon is replaced by a memcpy() and a glDrawArrays() call per poly. My guess is this only saves function call overhead, but it gives a decent ~20% speedup (36 -> 42fps) on my machine on orl’s map. Note: glDrawArrays() is in OpenGL 1.1, but the glClientActiveTextureARB function is part of the GL_ARB_multitexture extension but not GL_SGIS_multitexture. Instead of splitting into two code paths, I just dropped support for GL_SGIS_multitexture. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@981 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/gl_vidsdl.c | 20 +++---------------- Quake/glquake.h | 1 + Quake/r_world.c | 49 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Quake/gl_vidsdl.c b/Quake/gl_vidsdl.c index efc09962..1b3675ff 100644 --- a/Quake/gl_vidsdl.c +++ b/Quake/gl_vidsdl.c @@ -86,6 +86,7 @@ qboolean gl_texture_NPOT = false; //ericw PFNGLMULTITEXCOORD2FARBPROC GL_MTexCoord2fFunc = NULL; //johnfitz PFNGLACTIVETEXTUREARBPROC GL_SelectTextureFunc = NULL; //johnfitz +PFNGLCLIENTACTIVETEXTUREARBPROC GL_ClientActiveTextureFunc = NULL; //ericw //==================================== @@ -561,7 +562,8 @@ static void GL_CheckExtensions (void) { GL_MTexCoord2fFunc = (PFNGLMULTITEXCOORD2FARBPROC) SDL_GL_GetProcAddress("glMultiTexCoord2fARB"); GL_SelectTextureFunc = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB"); - if (GL_MTexCoord2fFunc && GL_SelectTextureFunc) + GL_ClientActiveTextureFunc = (PFNGLCLIENTACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glClientActiveTextureARB"); + if (GL_MTexCoord2fFunc && GL_SelectTextureFunc && GL_ClientActiveTextureFunc) { Con_Printf("FOUND: ARB_multitexture\n"); TEXTURE0 = GL_TEXTURE0_ARB; @@ -573,22 +575,6 @@ static void GL_CheckExtensions (void) Con_Warning ("Couldn't link to multitexture functions\n"); } } - else if (GL_ParseExtensionList(gl_extensions, "GL_SGIS_multitexture")) - { - GL_MTexCoord2fFunc = (PFNGLMULTITEXCOORD2FARBPROC) SDL_GL_GetProcAddress("glMTexCoord2fSGIS"); - GL_SelectTextureFunc = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glSelectTextureSGIS"); - if (GL_MTexCoord2fFunc && GL_SelectTextureFunc) - { - Con_Printf("FOUND: SGIS_multitexture\n"); - TEXTURE0 = TEXTURE0_SGIS; - TEXTURE1 = TEXTURE1_SGIS; - gl_mtexable = true; - } - else - { - Con_Warning ("Couldn't link to multitexture functions\n"); - } - } else { Con_Warning ("multitexture not supported (extension not found)\n"); diff --git a/Quake/glquake.h b/Quake/glquake.h index 66e8d898..0202346f 100644 --- a/Quake/glquake.h +++ b/Quake/glquake.h @@ -157,6 +157,7 @@ extern qboolean gl_mtexable; //johnfitz -- modified multitexture support extern PFNGLMULTITEXCOORD2FARBPROC GL_MTexCoord2fFunc; extern PFNGLACTIVETEXTUREARBPROC GL_SelectTextureFunc; +extern PFNGLCLIENTACTIVETEXTUREARBPROC GL_ClientActiveTextureFunc; extern GLenum TEXTURE0, TEXTURE1; //johnfitz diff --git a/Quake/r_world.c b/Quake/r_world.c index 29e16c1a..215702ec 100644 --- a/Quake/r_world.c +++ b/Quake/r_world.c @@ -31,6 +31,39 @@ byte *SV_FatPVS (vec3_t org, qmodel_t *worldmodel); extern byte mod_novis[MAX_MAP_LEAFS/8]; int vis_changed; //if true, force pvs to be refreshed +//============================================================================== +// +// VERTEX ARRAY SUPPORT +// +//============================================================================== + +#define VERTEXBYTES (VERTEXSIZE * sizeof (float)) + +// qbsp guarantees no more than 64 verts per surf +#define MAX_VERTS_PER_SURF 64 + +static float r_surfvertexarray[MAX_VERTS_PER_SURF * VERTEXSIZE]; + +void R_VertexArrayMultitexturedSetup (void) +{ + glVertexPointer(3, GL_FLOAT, VERTEXBYTES, &r_surfvertexarray[0]); + glEnableClientState(GL_VERTEX_ARRAY); + + GL_ClientActiveTextureFunc(TEXTURE0); + glTexCoordPointer(2, GL_FLOAT, VERTEXBYTES, &r_surfvertexarray[3]); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + GL_ClientActiveTextureFunc(TEXTURE1); + glTexCoordPointer(2, GL_FLOAT, VERTEXBYTES, &r_surfvertexarray[5]); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); +} + +void R_VertexArrayMultitexturedDrawGLPoly (glpoly_t *p) +{ + memcpy(r_surfvertexarray, p->verts, p->numverts * VERTEXBYTES); + glDrawArrays(GL_POLYGON, 0, p->numverts); +} + //============================================================================== // // SETUP CHAINS @@ -410,12 +443,13 @@ R_DrawTextureChains_Multitexture -- johnfitz */ void R_DrawTextureChains_Multitexture (qmodel_t *model, entity_t *ent, texchain_t chain) { - int i, j; + int i; msurface_t *s; texture_t *t; - float *v; qboolean bound; + R_VertexArrayMultitexturedSetup (); + for (i=0 ; inumtextures ; i++) { t = model->textures[i]; @@ -439,15 +473,8 @@ void R_DrawTextureChains_Multitexture (qmodel_t *model, entity_t *ent, texchain_ } R_RenderDynamicLightmaps (s); GL_Bind (lightmap_textures[s->lightmaptexturenum]); - glBegin(GL_POLYGON); - v = s->polys->verts[0]; - for (j=0 ; jpolys->numverts ; j++, v+= VERTEXSIZE) - { - GL_MTexCoord2fFunc (TEXTURE0, v[3], v[4]); - GL_MTexCoord2fFunc (TEXTURE1, v[5], v[6]); - glVertex3fv (v); - } - glEnd (); + R_VertexArrayMultitexturedDrawGLPoly (s->polys); + rs_brushpasses++; } GL_DisableMultitexture(); // selects TEXTURE0