From: havoc Date: Tue, 16 Mar 2004 09:49:16 +0000 (+0000) Subject: optimized away most texmatrix comparisons (now checks unit->texmatrixenabled which... X-Git-Tag: xonotic-v0.1.0preview~5980 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=024933f06a5f9a4a5bd852a8732b1c9790266104;p=xonotic%2Fdarkplaces.git optimized away most texmatrix comparisons (now checks unit->texmatrixenabled which just dodges the comparisons) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4035 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_backend.c b/gl_backend.c index 8dd6b5c5..2a8be5a4 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -335,6 +335,8 @@ typedef struct gltextureunit_s float rgbscale, alphascale; int combinergb, combinealpha; // FIXME: add more combine stuff + // texmatrixenabled exists only to avoid unnecessary texmatrix compares + int texmatrixenabled; matrix4x4_t matrix; } gltextureunit_t; @@ -382,7 +384,11 @@ void GL_SetupTextureState(void) unit->alphascale = 1; unit->combinergb = GL_MODULATE; unit->combinealpha = GL_MODULATE; + unit->texmatrixenabled = false; unit->matrix = r_identitymatrix; + qglMatrixMode(GL_TEXTURE); + qglLoadIdentity(); + qglMatrixMode(GL_MODELVIEW); qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), NULL);CHECKGLERROR qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR @@ -863,7 +869,6 @@ void R_Mesh_State(const rmeshstate_t *m) { int i, combinergb, combinealpha, scale; gltextureunit_t *unit; - const matrix4x4_t *texmatrix; matrix4x4_t tempmatrix; BACKENDACTIVECHECK @@ -1082,19 +1087,31 @@ void R_Mesh_State(const rmeshstate_t *m) } } // update texmatrix - // if texmatrix is not set (3,3 should always be 1 in a texture matrix) just compare to the identity matrix if (m->texmatrix[i].m[3][3]) - texmatrix = &m->texmatrix[i]; + { + // texmatrix specified, check if it is different + if (!unit->texmatrixenabled || memcmp(&unit->matrix, &m->texmatrix[i], sizeof(matrix4x4_t))) + { + unit->texmatrixenabled = true; + unit->matrix = m->texmatrix[i]; + Matrix4x4_Transpose(&tempmatrix, &unit->matrix); + qglMatrixMode(GL_TEXTURE); + GL_ActiveTexture(i); + qglLoadMatrixf(&tempmatrix.m[0][0]); + qglMatrixMode(GL_MODELVIEW); + } + } else - texmatrix = &r_identitymatrix; - if (memcmp(&unit->matrix, texmatrix, sizeof(matrix4x4_t))) { - unit->matrix = *texmatrix; - Matrix4x4_Transpose(&tempmatrix, &unit->matrix); - qglMatrixMode(GL_TEXTURE); - GL_ActiveTexture(i); - qglLoadMatrixf(&tempmatrix.m[0][0]); - qglMatrixMode(GL_MODELVIEW); + // no texmatrix specified, revert to identity + if (unit->texmatrixenabled) + { + unit->texmatrixenabled = false; + qglMatrixMode(GL_TEXTURE); + GL_ActiveTexture(i); + qglLoadIdentity(); + qglMatrixMode(GL_MODELVIEW); + } } } else