From 1aea459957c5a3df90ca6b93c73b99c30b8b985c Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 5 Aug 2002 12:16:44 +0000 Subject: [PATCH] R_GetTexture is now named R_RealGetTexture, R_GetTexture is a macro which hardly ever calls R_RealGetTexture - this is a nice speed gain, cutting out about 2.3 million calls during timedemo bigass1 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2202 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_textures.c | 27 ++++++++++++++++++++------- r_textures.h | 8 +++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/gl_textures.c b/gl_textures.c index e987acb1..10cba22d 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -73,6 +73,10 @@ gltextureimage_t; typedef struct gltexture_s { + // this field is exposed to the R_GetTexture macro, for speed reasons + // (must be identical in rtexture_t) + int texnum; // GL texture slot number + // pointer to texturepool (check this to see if the texture is allocated) struct gltexturepool_s *pool; // pointer to next texture in texturepool chain @@ -168,15 +172,19 @@ static void R_PrecacheTexture(gltexture_t *glt) R_UploadTexture(glt); } -int R_GetTexture(rtexture_t *rt) +int R_RealGetTexture(rtexture_t *rt) { - gltexture_t *glt; - if (!rt) + if (rt) + { + gltexture_t *glt; + glt = (gltexture_t *)rt; + if (glt->flags & GLTEXF_UPLOAD) + R_UploadTexture(glt); + glt->texnum = glt->image->texnum; + return glt->image->texnum; + } + else return 0; - glt = (gltexture_t *)rt; - if (glt->flags & GLTEXF_UPLOAD) - R_UploadTexture(glt); - return glt->image->texnum; } void R_FreeTexture(rtexture_t *rt) @@ -542,6 +550,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data) qglTexSubImage2D(GL_TEXTURE_2D, 0, glt->x, glt->y, glt->width, glt->height, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer); CHECKGLERROR + glt->texnum = glt->image->texnum; return; } @@ -626,6 +635,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data) qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_mag); CHECKGLERROR } + glt->texnum = glt->image->texnum; } static void R_FindImageForTexture(gltexture_t *glt) @@ -637,6 +647,9 @@ static void R_FindImageForTexture(gltexture_t *glt) texinfo = glt->textype; pool = glt->pool; + // remains -1 until uploaded + glt->texnum = -1; + x = 0; y = 0; w = glt->width; diff --git a/r_textures.h b/r_textures.h index 4b52c76d..ebcd8893 100644 --- a/r_textures.h +++ b/r_textures.h @@ -23,10 +23,11 @@ // 32bit RGBA #define TEXTYPE_RGBA 3 -// contents of this structure are private to gl_textures.c +// contents of this structure are mostly private to gl_textures.c typedef struct { - int useless; + // this is exposed (rather than private) for speed reasons only + int texnum; } rtexture_t; @@ -64,7 +65,8 @@ void R_FragmentLocation(rtexture_t *rt, int *x, int *y, float *fx1, float *fy1, // returns the renderer dependent texture slot number (call this before each // use, as a texture might not have been precached) -int R_GetTexture (rtexture_t *rt); +#define R_GetTexture(rt) ((rt) ? ((rt)->texnum >= 0 ? (rt)->texnum : R_RealGetTexture(rt)) : 0) +int R_RealGetTexture (rtexture_t *rt); // returns true if the texture is transparent (useful for rendering code) int R_TextureHasAlpha(rtexture_t *rt); -- 2.39.2