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
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)
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;
}
qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_mag);
CHECKGLERROR
}
+ glt->texnum = glt->image->texnum;
}
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;
// 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;
// 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);