]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
R_GetTexture is now named R_RealGetTexture, R_GetTexture is a macro which hardly...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Aug 2002 12:16:44 +0000 (12:16 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Aug 2002 12:16:44 +0000 (12:16 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2202 d7cf8633-e32d-0410-b094-e92efae38249

gl_textures.c
r_textures.h

index e987acb17a76250bf3c9582ce8c5d3938eb294e3..10cba22dd64283763d771ab38a33bf646648671e 100644 (file)
@@ -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;
index 4b52c76d70fa608ec25b9cb90877ad4c3b076a7a..ebcd8893e71ce1f7817104e224a343e8aeaab067 100644 (file)
 // 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);