7 cvar_t gl_max_size = {CVAR_SAVE, "gl_max_size", "2048", "maximum allowed texture size, can be used to reduce video memory usage, note: this is automatically reduced to match video card capabilities (such as 256 on 3Dfx cards before Voodoo4/5)"};
8 cvar_t gl_picmip = {CVAR_SAVE, "gl_picmip", "0", "reduces resolution of textures by powers of 2, for example 1 will halve width/height, reducing texture memory usage by 75%"};
9 cvar_t r_lerpimages = {CVAR_SAVE, "r_lerpimages", "1", "bilinear filters images when scaling them up to power of 2 size (mode 1), looks better than glquake (mode 0)"};
10 cvar_t r_precachetextures = {CVAR_SAVE, "r_precachetextures", "1", "0 = never upload textures until used, 1 = upload most textures before use (exceptions: rarely used skin colormap layers), 2 = upload all textures before use (can increase texture memory usage significantly)"};
11 cvar_t gl_texture_anisotropy = {CVAR_SAVE, "gl_texture_anisotropy", "1", "anisotropic filtering quality (if supported by hardware), 1 sample (no anisotropy) and 8 sample (8 tap anisotropy) are recommended values"};
12 cvar_t gl_texturecompression = {CVAR_SAVE, "gl_texturecompression", "0", "whether to compress textures, a value of 0 disables compression (even if the individual cvars are 1), 1 enables fast (low quality) compression at startup, 2 enables slow (high quality) compression at startup"};
13 cvar_t gl_texturecompression_color = {CVAR_SAVE, "gl_texturecompression_color", "1", "whether to compress colormap (diffuse) textures"};
14 cvar_t gl_texturecompression_normal = {CVAR_SAVE, "gl_texturecompression_normal", "0", "whether to compress normalmap (normalmap) textures"};
15 cvar_t gl_texturecompression_gloss = {CVAR_SAVE, "gl_texturecompression_gloss", "1", "whether to compress glossmap (specular) textures"};
16 cvar_t gl_texturecompression_glow = {CVAR_SAVE, "gl_texturecompression_glow", "1", "whether to compress glowmap (luma) textures"};
17 cvar_t gl_texturecompression_2d = {CVAR_SAVE, "gl_texturecompression_2d", "0", "whether to compress 2d (hud/menu) textures other than the font"};
18 cvar_t gl_texturecompression_q3bsplightmaps = {CVAR_SAVE, "gl_texturecompression_q3bsplightmaps", "0", "whether to compress lightmaps in q3bsp format levels"};
19 cvar_t gl_texturecompression_q3bspdeluxemaps = {CVAR_SAVE, "gl_texturecompression_q3bspdeluxemaps", "0", "whether to compress deluxemaps in q3bsp format levels (only levels compiled with q3map2 -deluxe have these)"};
20 cvar_t gl_texturecompression_sky = {CVAR_SAVE, "gl_texturecompression_sky", "0", "whether to compress sky textures"};
21 cvar_t gl_texturecompression_lightcubemaps = {CVAR_SAVE, "gl_texturecompression_lightcubemaps", "1", "whether to compress light cubemaps (spotlights and other light projection images)"};
23 int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
24 int gl_filter_mag = GL_LINEAR;
27 static mempool_t *texturemempool;
29 // note: this must not conflict with TEXF_ flags in r_textures.h
30 // cleared when a texture is uploaded
31 #define GLTEXF_UPLOAD 0x00010000
32 // bitmask for mismatch checking
33 #define GLTEXF_IMPORTANTBITS (0)
34 // set when image is uploaded and freed
35 #define GLTEXF_DESTROYED 0x00040000
36 // dynamic texture (treat texnum == 0 differently)
37 #define GLTEXF_DYNAMIC 0x00080000
39 typedef struct textypeinfo_s
42 int inputbytesperpixel;
43 int internalbytesperpixel;
44 float glinternalbytesperpixel;
51 static textypeinfo_t textype_palette = {TEXTYPE_PALETTE, 1, 4, 4.0f, GL_BGRA , 3, GL_UNSIGNED_BYTE};
52 static textypeinfo_t textype_palette_alpha = {TEXTYPE_PALETTE, 1, 4, 4.0f, GL_BGRA , 4, GL_UNSIGNED_BYTE};
53 static textypeinfo_t textype_palette_compress = {TEXTYPE_PALETTE, 1, 4, 0.5f, GL_BGRA , GL_COMPRESSED_RGB_ARB, GL_UNSIGNED_BYTE};
54 static textypeinfo_t textype_palette_alpha_compress = {TEXTYPE_PALETTE, 1, 4, 1.0f, GL_BGRA , GL_COMPRESSED_RGBA_ARB, GL_UNSIGNED_BYTE};
55 static textypeinfo_t textype_rgba = {TEXTYPE_RGBA , 4, 4, 4.0f, GL_RGBA , 3, GL_UNSIGNED_BYTE};
56 static textypeinfo_t textype_rgba_alpha = {TEXTYPE_RGBA , 4, 4, 4.0f, GL_RGBA , 4, GL_UNSIGNED_BYTE};
57 static textypeinfo_t textype_rgba_compress = {TEXTYPE_RGBA , 4, 4, 0.5f, GL_RGBA , GL_COMPRESSED_RGB_ARB, GL_UNSIGNED_BYTE};
58 static textypeinfo_t textype_rgba_alpha_compress = {TEXTYPE_RGBA , 4, 4, 1.0f, GL_RGBA , GL_COMPRESSED_RGBA_ARB, GL_UNSIGNED_BYTE};
59 static textypeinfo_t textype_bgra = {TEXTYPE_BGRA , 4, 4, 4.0f, GL_BGRA , 3, GL_UNSIGNED_BYTE};
60 static textypeinfo_t textype_bgra_alpha = {TEXTYPE_BGRA , 4, 4, 4.0f, GL_BGRA , 4, GL_UNSIGNED_BYTE};
61 static textypeinfo_t textype_bgra_compress = {TEXTYPE_BGRA , 4, 4, 0.5f, GL_BGRA , GL_COMPRESSED_RGB_ARB, GL_UNSIGNED_BYTE};
62 static textypeinfo_t textype_bgra_alpha_compress = {TEXTYPE_BGRA , 4, 4, 1.0f, GL_BGRA , GL_COMPRESSED_RGBA_ARB, GL_UNSIGNED_BYTE};
63 static textypeinfo_t textype_shadowmap16 = {TEXTYPE_SHADOWMAP,2,2, 2.0f, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT16_ARB, GL_UNSIGNED_SHORT};
64 static textypeinfo_t textype_shadowmap24 = {TEXTYPE_SHADOWMAP,4,4, 4.0f, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT24_ARB, GL_UNSIGNED_INT};
66 typedef enum gltexturetype_e
71 GLTEXTURETYPE_CUBEMAP,
72 GLTEXTURETYPE_RECTANGLE,
77 static int gltexturetypeenums[GLTEXTURETYPE_TOTAL] = {GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_RECTANGLE_ARB};
78 static int gltexturetypebindingenums[GLTEXTURETYPE_TOTAL] = {GL_TEXTURE_BINDING_1D, GL_TEXTURE_BINDING_2D, GL_TEXTURE_BINDING_3D, GL_TEXTURE_BINDING_CUBE_MAP_ARB, GL_TEXTURE_BINDING_RECTANGLE_ARB};
79 static int gltexturetypedimensions[GLTEXTURETYPE_TOTAL] = {1, 2, 3, 2, 2};
80 static int cubemapside[6] =
82 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
83 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
84 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
85 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
86 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
87 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
90 typedef struct gltexture_s
92 // this field is exposed to the R_GetTexture macro, for speed reasons
93 // (must be identical in rtexture_t)
94 int texnum; // GL texture slot number
96 // dynamic texture stuff [11/22/2007 Black]
97 // used to hold the texture number of dirty textures
99 updatecallback_t updatecallback;
100 void *updatacallback_data;
101 // --- [11/22/2007 Black]
103 // pointer to texturepool (check this to see if the texture is allocated)
104 struct gltexturepool_s *pool;
105 // pointer to next texture in texturepool chain
106 struct gltexture_s *chain;
107 // name of the texture (this might be removed someday), no duplicates
108 char identifier[MAX_QPATH + 32];
109 // original data size in *inputtexels
110 int inputwidth, inputheight, inputdepth;
111 // copy of the original texture(s) supplied to the upload function, for
112 // delayed uploads (non-precached)
113 unsigned char *inputtexels;
114 // original data size in *inputtexels
116 // flags supplied to the LoadTexture function
117 // (might be altered to remove TEXF_ALPHA), and GLTEXF_ private flags
119 // pointer to one of the textype_ structs
120 textypeinfo_t *textype;
121 // one of the GLTEXTURETYPE_ values
123 // palette if the texture is TEXTYPE_PALETTE
124 const unsigned int *palette;
125 // actual stored texture size after gl_picmip and gl_max_size are applied
126 // (power of 2 if gl_support_arb_texture_non_power_of_two is not supported)
127 int tilewidth, tileheight, tiledepth;
128 // 1 or 6 depending on texturetype
132 // GL_RGB or GL_RGBA or GL_DEPTH_COMPONENT
135 int glinternalformat;
136 // GL_UNSIGNED_BYTE or GL_UNSIGNED_INT or GL_UNSIGNED_SHORT or GL_FLOAT
141 #define TEXTUREPOOL_SENTINEL 0xC0DEDBAD
143 typedef struct gltexturepool_s
145 unsigned int sentinel;
146 struct gltexture_s *gltchain;
147 struct gltexturepool_s *next;
151 static gltexturepool_t *gltexturepoolchain = NULL;
153 static unsigned char *resizebuffer = NULL, *colorconvertbuffer;
154 static int resizebuffersize = 0;
155 static const unsigned char *texturebuffer;
156 static int texturebuffersize = 0;
158 static textypeinfo_t *R_GetTexTypeInfo(textype_t textype, int flags)
160 if ((flags & TEXF_COMPRESS) && gl_texturecompression.integer >= 1 && gl_support_texture_compression)
162 if (flags & TEXF_ALPHA)
166 case TEXTYPE_PALETTE:
167 return &textype_palette_alpha_compress;
169 return &textype_rgba_alpha_compress;
171 return &textype_bgra_alpha_compress;
173 Host_Error("R_GetTexTypeInfo: unknown texture format");
181 case TEXTYPE_PALETTE:
182 return &textype_palette_compress;
184 return &textype_rgba_compress;
186 return &textype_bgra_compress;
188 Host_Error("R_GetTexTypeInfo: unknown texture format");
195 if (flags & TEXF_ALPHA)
199 case TEXTYPE_PALETTE:
200 return &textype_palette_alpha;
202 return &textype_rgba_alpha;
204 return &textype_bgra_alpha;
206 Host_Error("R_GetTexTypeInfo: unknown texture format");
214 case TEXTYPE_PALETTE:
215 return &textype_palette;
217 return &textype_rgba;
219 return &textype_bgra;
220 case TEXTYPE_SHADOWMAP:
221 return (flags & TEXF_LOWPRECISION) ? &textype_shadowmap16 : &textype_shadowmap24;
223 Host_Error("R_GetTexTypeInfo: unknown texture format");
228 return NULL; // this line only to hush compiler warnings
231 // dynamic texture code [11/22/2007 Black]
232 void R_MarkDirtyTexture(rtexture_t *rt) {
233 gltexture_t *glt = (gltexture_t*) rt;
238 // dont do anything if the texture is already dirty (and make sure this *is* a dynamic texture after all!)
239 if( !glt->dirtytexnum && glt->flags & GLTEXF_DYNAMIC ) {
240 glt->dirtytexnum = glt->texnum;
241 // mark it as dirty, so R_RealGetTexture gets called
246 void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void *data) {
247 gltexture_t *glt = (gltexture_t*) rt;
252 glt->flags |= GLTEXF_DYNAMIC;
253 glt->updatecallback = updatecallback;
254 glt->updatacallback_data = data;
255 glt->dirtytexnum = 0;
258 static void R_UpdateDynamicTexture(gltexture_t *glt) {
259 glt->texnum = glt->dirtytexnum;
260 // reset dirtytexnum again (not dirty anymore)
261 glt->dirtytexnum = 0;
262 // TODO: now assert that t->texnum != 0 ?
263 if( glt->updatecallback ) {
264 glt->updatecallback( (rtexture_t*) glt, glt->updatacallback_data );
268 void R_PurgeTexture(rtexture_t *rt)
270 if(rt && !(((gltexture_t*) rt)->flags & TEXF_PERSISTENT)) {
275 void R_FreeTexture(rtexture_t *rt)
277 gltexture_t *glt, **gltpointer;
279 glt = (gltexture_t *)rt;
281 Host_Error("R_FreeTexture: texture == NULL");
283 for (gltpointer = &glt->pool->gltchain;*gltpointer && *gltpointer != glt;gltpointer = &(*gltpointer)->chain);
284 if (*gltpointer == glt)
285 *gltpointer = glt->chain;
287 Host_Error("R_FreeTexture: texture \"%s\" not linked in pool", glt->identifier);
289 if (!(glt->flags & GLTEXF_UPLOAD))
292 qglDeleteTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
295 if (glt->inputtexels)
296 Mem_Free(glt->inputtexels);
300 rtexturepool_t *R_AllocTexturePool(void)
302 gltexturepool_t *pool;
303 if (texturemempool == NULL)
305 pool = (gltexturepool_t *)Mem_Alloc(texturemempool, sizeof(gltexturepool_t));
308 pool->next = gltexturepoolchain;
309 gltexturepoolchain = pool;
310 pool->sentinel = TEXTUREPOOL_SENTINEL;
311 return (rtexturepool_t *)pool;
314 void R_FreeTexturePool(rtexturepool_t **rtexturepool)
316 gltexturepool_t *pool, **poolpointer;
317 if (rtexturepool == NULL)
319 if (*rtexturepool == NULL)
321 pool = (gltexturepool_t *)(*rtexturepool);
322 *rtexturepool = NULL;
323 if (pool->sentinel != TEXTUREPOOL_SENTINEL)
324 Host_Error("R_FreeTexturePool: pool already freed");
325 for (poolpointer = &gltexturepoolchain;*poolpointer && *poolpointer != pool;poolpointer = &(*poolpointer)->next);
326 if (*poolpointer == pool)
327 *poolpointer = pool->next;
329 Host_Error("R_FreeTexturePool: pool not linked");
330 while (pool->gltchain)
331 R_FreeTexture((rtexture_t *)pool->gltchain);
336 typedef struct glmode_s
339 int minification, magnification;
343 static glmode_t modes[6] =
345 {"GL_NEAREST", GL_NEAREST, GL_NEAREST},
346 {"GL_LINEAR", GL_LINEAR, GL_LINEAR},
347 {"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
348 {"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
349 {"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
350 {"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
353 static void GL_TextureMode_f (void)
358 gltexturepool_t *pool;
362 for (i = 0;i < 6;i++)
364 if (gl_filter_min == modes[i].minification)
366 Con_Printf("%s\n", modes[i].name);
370 Con_Print("current filter is unknown???\n");
374 for (i = 0;i < 6;i++)
375 if (!strcasecmp (modes[i].name, Cmd_Argv(1) ) )
379 Con_Print("bad filter name\n");
383 gl_filter_min = modes[i].minification;
384 gl_filter_mag = modes[i].magnification;
386 // change all the existing mipmap texture objects
387 // FIXME: force renderer(/client/something?) restart instead?
389 for (pool = gltexturepoolchain;pool;pool = pool->next)
391 for (glt = pool->gltchain;glt;glt = glt->chain)
393 // only update already uploaded images
394 if (!(glt->flags & (GLTEXF_UPLOAD | TEXF_FORCENEAREST | TEXF_FORCELINEAR)))
396 qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
397 qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
398 if (glt->flags & TEXF_MIPMAP)
400 qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_min);CHECKGLERROR
404 qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_mag);CHECKGLERROR
406 qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MAG_FILTER, gl_filter_mag);CHECKGLERROR
407 qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
413 static void GL_Texture_CalcImageSize(int texturetype, int flags, int inwidth, int inheight, int indepth, int *outwidth, int *outheight, int *outdepth)
415 int picmip = 0, maxsize = 0, width2 = 1, height2 = 1, depth2 = 1;
417 if (gl_max_size.integer > gl_max_texture_size)
418 Cvar_SetValue("gl_max_size", gl_max_texture_size);
423 case GLTEXTURETYPE_1D:
424 case GLTEXTURETYPE_2D:
425 maxsize = gl_max_texture_size;
427 case GLTEXTURETYPE_3D:
428 maxsize = gl_max_3d_texture_size;
430 case GLTEXTURETYPE_CUBEMAP:
431 maxsize = gl_max_cube_map_texture_size;
435 if (flags & TEXF_PICMIP)
437 maxsize = min(maxsize, gl_max_size.integer);
438 picmip = gl_picmip.integer;
443 if (gl_support_arb_texture_non_power_of_two)
444 width2 = min(inwidth >> picmip, maxsize);
447 for (width2 = 1;width2 < inwidth;width2 <<= 1);
448 for (width2 >>= picmip;width2 > maxsize;width2 >>= 1);
450 *outwidth = max(1, width2);
454 if (gl_support_arb_texture_non_power_of_two)
455 height2 = min(inheight >> picmip, maxsize);
458 for (height2 = 1;height2 < inheight;height2 <<= 1);
459 for (height2 >>= picmip;height2 > maxsize;height2 >>= 1);
461 *outheight = max(1, height2);
465 if (gl_support_arb_texture_non_power_of_two)
466 depth2 = min(indepth >> picmip, maxsize);
469 for (depth2 = 1;depth2 < indepth;depth2 <<= 1);
470 for (depth2 >>= picmip;depth2 > maxsize;depth2 >>= 1);
472 *outdepth = max(1, depth2);
477 static int R_CalcTexelDataSize (gltexture_t *glt)
479 int width2, height2, depth2, size;
481 GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->inputwidth, glt->inputheight, glt->inputdepth, &width2, &height2, &depth2);
483 size = width2 * height2 * depth2;
485 if (glt->flags & TEXF_MIPMAP)
487 while (width2 > 1 || height2 > 1 || depth2 > 1)
495 size += width2 * height2 * depth2;
499 return (int)(size * glt->textype->glinternalbytesperpixel) * glt->sides;
502 void R_TextureStats_Print(qboolean printeach, qboolean printpool, qboolean printtotal)
506 int pooltotal = 0, pooltotalt = 0, pooltotalp = 0, poolloaded = 0, poolloadedt = 0, poolloadedp = 0;
507 int sumtotal = 0, sumtotalt = 0, sumtotalp = 0, sumloaded = 0, sumloadedt = 0, sumloadedp = 0;
509 gltexturepool_t *pool;
511 Con_Print("glsize input loaded mip alpha name\n");
512 for (pool = gltexturepoolchain;pool;pool = pool->next)
520 for (glt = pool->gltchain;glt;glt = glt->chain)
522 glsize = R_CalcTexelDataSize(glt);
523 isloaded = !(glt->flags & GLTEXF_UPLOAD);
525 pooltotalt += glsize;
526 pooltotalp += glt->inputdatasize;
530 poolloadedt += glsize;
531 poolloadedp += glt->inputdatasize;
534 Con_Printf("%c%4i%c%c%4i%c %s %s %s %s\n", isloaded ? '[' : ' ', (glsize + 1023) / 1024, isloaded ? ']' : ' ', glt->inputtexels ? '[' : ' ', (glt->inputdatasize + 1023) / 1024, glt->inputtexels ? ']' : ' ', isloaded ? "loaded" : " ", (glt->flags & TEXF_MIPMAP) ? "mip" : " ", (glt->flags & TEXF_ALPHA) ? "alpha" : " ", glt->identifier);
537 Con_Printf("texturepool %10p total: %i (%.3fMB, %.3fMB original), uploaded %i (%.3fMB, %.3fMB original), upload on demand %i (%.3fMB, %.3fMB original)\n", (void *)pool, pooltotal, pooltotalt / 1048576.0, pooltotalp / 1048576.0, poolloaded, poolloadedt / 1048576.0, poolloadedp / 1048576.0, pooltotal - poolloaded, (pooltotalt - poolloadedt) / 1048576.0, (pooltotalp - poolloadedp) / 1048576.0);
538 sumtotal += pooltotal;
539 sumtotalt += pooltotalt;
540 sumtotalp += pooltotalp;
541 sumloaded += poolloaded;
542 sumloadedt += poolloadedt;
543 sumloadedp += poolloadedp;
546 Con_Printf("textures total: %i (%.3fMB, %.3fMB original), uploaded %i (%.3fMB, %.3fMB original), upload on demand %i (%.3fMB, %.3fMB original)\n", sumtotal, sumtotalt / 1048576.0, sumtotalp / 1048576.0, sumloaded, sumloadedt / 1048576.0, sumloadedp / 1048576.0, sumtotal - sumloaded, (sumtotalt - sumloadedt) / 1048576.0, (sumtotalp - sumloadedp) / 1048576.0);
549 static void R_TextureStats_f(void)
551 R_TextureStats_Print(true, true, true);
554 static void r_textures_start(void)
556 // LordHavoc: allow any alignment
558 qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);CHECKGLERROR
559 qglPixelStorei(GL_PACK_ALIGNMENT, 1);CHECKGLERROR
561 texturemempool = Mem_AllocPool("texture management", 0, NULL);
563 // Disable JPEG screenshots if the DLL isn't loaded
564 if (! JPEG_OpenLibrary ())
565 Cvar_SetValueQuick (&scr_screenshot_jpeg, 0);
566 // TODO: support png screenshots?
570 static void r_textures_shutdown(void)
572 rtexturepool_t *temp;
574 JPEG_CloseLibrary ();
576 while(gltexturepoolchain)
578 temp = (rtexturepool_t *) gltexturepoolchain;
579 R_FreeTexturePool(&temp);
582 resizebuffersize = 0;
583 texturebuffersize = 0;
585 colorconvertbuffer = NULL;
586 texturebuffer = NULL;
587 Mem_FreePool(&texturemempool);
590 static void r_textures_newmap(void)
594 void R_Textures_Init (void)
596 Cmd_AddCommand("gl_texturemode", &GL_TextureMode_f, "set texture filtering mode (GL_NEAREST, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, etc)");
597 Cmd_AddCommand("r_texturestats", R_TextureStats_f, "print information about all loaded textures and some statistics");
598 Cvar_RegisterVariable (&gl_max_size);
599 Cvar_RegisterVariable (&gl_picmip);
600 Cvar_RegisterVariable (&r_lerpimages);
601 Cvar_RegisterVariable (&r_precachetextures);
602 Cvar_RegisterVariable (&gl_texture_anisotropy);
603 Cvar_RegisterVariable (&gl_texturecompression);
604 Cvar_RegisterVariable (&gl_texturecompression_color);
605 Cvar_RegisterVariable (&gl_texturecompression_normal);
606 Cvar_RegisterVariable (&gl_texturecompression_gloss);
607 Cvar_RegisterVariable (&gl_texturecompression_glow);
608 Cvar_RegisterVariable (&gl_texturecompression_2d);
609 Cvar_RegisterVariable (&gl_texturecompression_q3bsplightmaps);
610 Cvar_RegisterVariable (&gl_texturecompression_q3bspdeluxemaps);
611 Cvar_RegisterVariable (&gl_texturecompression_sky);
612 Cvar_RegisterVariable (&gl_texturecompression_lightcubemaps);
614 R_RegisterModule("R_Textures", r_textures_start, r_textures_shutdown, r_textures_newmap);
617 void R_Textures_Frame (void)
619 static int old_aniso = 0;
621 // could do procedural texture animation here, if we keep track of which
622 // textures were accessed this frame...
624 // free the resize buffers
625 resizebuffersize = 0;
628 Mem_Free(resizebuffer);
631 if (colorconvertbuffer)
633 Mem_Free(colorconvertbuffer);
634 colorconvertbuffer = NULL;
637 if (old_aniso != gl_texture_anisotropy.integer)
640 gltexturepool_t *pool;
643 old_aniso = bound(1, gl_texture_anisotropy.integer, gl_max_anisotropy);
645 Cvar_SetValueQuick(&gl_texture_anisotropy, old_aniso);
648 for (pool = gltexturepoolchain;pool;pool = pool->next)
650 for (glt = pool->gltchain;glt;glt = glt->chain)
652 // only update already uploaded images
653 if ((glt->flags & (GLTEXF_UPLOAD | TEXF_MIPMAP)) == TEXF_MIPMAP)
655 qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
657 qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
658 qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MAX_ANISOTROPY_EXT, old_aniso);CHECKGLERROR
660 qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
667 void R_MakeResizeBufferBigger(int size)
669 if (resizebuffersize < size)
671 resizebuffersize = size;
673 Mem_Free(resizebuffer);
674 if (colorconvertbuffer)
675 Mem_Free(colorconvertbuffer);
676 resizebuffer = (unsigned char *)Mem_Alloc(texturemempool, resizebuffersize);
677 colorconvertbuffer = (unsigned char *)Mem_Alloc(texturemempool, resizebuffersize);
678 if (!resizebuffer || !colorconvertbuffer)
679 Host_Error("R_Upload: out of memory");
683 static void GL_SetupTextureParameters(int flags, textype_t textype, int texturetype)
685 int textureenum = gltexturetypeenums[texturetype];
686 int wrapmode = ((flags & TEXF_CLAMP) && gl_support_clamptoedge) ? GL_CLAMP_TO_EDGE : GL_REPEAT;
690 if (gl_support_anisotropy && (flags & TEXF_MIPMAP))
692 int aniso = bound(1, gl_texture_anisotropy.integer, gl_max_anisotropy);
693 if (gl_texture_anisotropy.integer != aniso)
694 Cvar_SetValueQuick(&gl_texture_anisotropy, aniso);
695 qglTexParameteri(textureenum, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);CHECKGLERROR
697 qglTexParameteri(textureenum, GL_TEXTURE_WRAP_S, wrapmode);CHECKGLERROR
698 qglTexParameteri(textureenum, GL_TEXTURE_WRAP_T, wrapmode);CHECKGLERROR
699 if (gltexturetypedimensions[texturetype] >= 3)
701 qglTexParameteri(textureenum, GL_TEXTURE_WRAP_R, wrapmode);CHECKGLERROR
705 if (flags & TEXF_FORCENEAREST)
707 if (flags & TEXF_MIPMAP)
709 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);CHECKGLERROR
713 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, GL_NEAREST);CHECKGLERROR
715 qglTexParameteri(textureenum, GL_TEXTURE_MAG_FILTER, GL_NEAREST);CHECKGLERROR
717 else if (flags & TEXF_FORCELINEAR)
719 if (flags & TEXF_MIPMAP)
721 if (gl_filter_min == GL_NEAREST_MIPMAP_LINEAR || gl_filter_min == GL_LINEAR_MIPMAP_LINEAR)
723 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);CHECKGLERROR
727 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);CHECKGLERROR
732 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, GL_LINEAR);CHECKGLERROR
734 qglTexParameteri(textureenum, GL_TEXTURE_MAG_FILTER, GL_LINEAR);CHECKGLERROR
738 if (flags & TEXF_MIPMAP)
740 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, gl_filter_min);CHECKGLERROR
744 qglTexParameteri(textureenum, GL_TEXTURE_MIN_FILTER, gl_filter_mag);CHECKGLERROR
746 qglTexParameteri(textureenum, GL_TEXTURE_MAG_FILTER, gl_filter_mag);CHECKGLERROR
749 if (textype == TEXTYPE_SHADOWMAP)
751 if (gl_support_arb_shadow)
753 if (flags & TEXF_COMPARE)
755 qglTexParameteri(textureenum, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);CHECKGLERROR
759 qglTexParameteri(textureenum, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);CHECKGLERROR
761 qglTexParameteri(textureenum, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);CHECKGLERROR
763 qglTexParameteri(textureenum, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);CHECKGLERROR
769 static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int fragy, int fragz, int fragwidth, int fragheight, int fragdepth)
771 int i, mip, width, height, depth;
773 const unsigned char *prevbuffer;
778 // we need to restore the texture binding after finishing the upload
779 qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
780 qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
782 // these are rounded up versions of the size to do better resampling
783 if (gl_support_arb_texture_non_power_of_two || glt->texturetype == GLTEXTURETYPE_RECTANGLE)
785 width = glt->inputwidth;
786 height = glt->inputheight;
787 depth = glt->inputdepth;
791 for (width = 1;width < glt->inputwidth ;width <<= 1);
792 for (height = 1;height < glt->inputheight;height <<= 1);
793 for (depth = 1;depth < glt->inputdepth ;depth <<= 1);
796 R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
797 R_MakeResizeBufferBigger(fragwidth * fragheight * fragdepth * glt->sides * glt->bytesperpixel);
799 if (prevbuffer == NULL)
801 memset(resizebuffer, 0, fragwidth * fragheight * fragdepth * glt->bytesperpixel);
802 prevbuffer = resizebuffer;
804 else if (glt->textype->textype == TEXTYPE_PALETTE)
806 // promote paletted to BGRA, so we only have to worry about BGRA in the rest of this code
807 Image_Copy8bitBGRA(prevbuffer, colorconvertbuffer, fragwidth * fragheight * fragdepth * glt->sides, glt->palette);
808 prevbuffer = colorconvertbuffer;
811 if ((glt->flags & (TEXF_MIPMAP | TEXF_PICMIP | GLTEXF_UPLOAD)) == 0 && glt->inputwidth == glt->tilewidth && glt->inputheight == glt->tileheight && glt->inputdepth == glt->tiledepth)
813 // update a portion of the image
814 switch(glt->texturetype)
816 case GLTEXTURETYPE_1D:
817 qglTexSubImage1D(GL_TEXTURE_1D, 0, fragx, fragwidth, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
819 case GLTEXTURETYPE_2D:
820 qglTexSubImage2D(GL_TEXTURE_2D, 0, fragx, fragy, fragwidth, fragheight, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
822 case GLTEXTURETYPE_3D:
823 qglTexSubImage3D(GL_TEXTURE_3D, 0, fragx, fragy, fragz, fragwidth, fragheight, fragdepth, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
826 Host_Error("R_Upload: partial update of type other than 1D, 2D, or 3D");
832 if (fragx || fragy || fragz || glt->inputwidth != fragwidth || glt->inputheight != fragheight || glt->inputdepth != fragdepth)
833 Host_Error("R_Upload: partial update not allowed on initial upload or in combination with PICMIP or MIPMAP\n");
835 // upload the image for the first time
836 glt->flags &= ~GLTEXF_UPLOAD;
838 // cubemaps contain multiple images and thus get processed a bit differently
839 if (glt->texturetype != GLTEXTURETYPE_CUBEMAP)
841 if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
843 Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
844 prevbuffer = resizebuffer;
847 while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
849 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
850 prevbuffer = resizebuffer;
854 if (gl_support_texture_compression)
856 if (gl_texturecompression.integer >= 2)
857 qglHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST);
859 qglHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_FASTEST);
862 switch(glt->texturetype)
864 case GLTEXTURETYPE_1D:
865 qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
866 if (glt->flags & TEXF_MIPMAP)
868 while (width > 1 || height > 1 || depth > 1)
870 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
871 prevbuffer = resizebuffer;
872 qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
876 case GLTEXTURETYPE_2D:
877 qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
878 if (glt->flags & TEXF_MIPMAP)
880 while (width > 1 || height > 1 || depth > 1)
882 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
883 prevbuffer = resizebuffer;
884 qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
888 case GLTEXTURETYPE_3D:
889 qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
890 if (glt->flags & TEXF_MIPMAP)
892 while (width > 1 || height > 1 || depth > 1)
894 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
895 prevbuffer = resizebuffer;
896 qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
900 case GLTEXTURETYPE_CUBEMAP:
901 // convert and upload each side in turn,
902 // from a continuous block of input texels
903 texturebuffer = (unsigned char *)prevbuffer;
904 for (i = 0;i < 6;i++)
906 prevbuffer = texturebuffer;
907 texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel;
908 if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
910 Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer);
911 prevbuffer = resizebuffer;
914 while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth)
916 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth);
917 prevbuffer = resizebuffer;
920 qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
921 if (glt->flags & TEXF_MIPMAP)
923 while (width > 1 || height > 1 || depth > 1)
925 Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
926 prevbuffer = resizebuffer;
927 qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR
932 case GLTEXTURETYPE_RECTANGLE:
933 qglTexImage2D(GL_TEXTURE_RECTANGLE_ARB, mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, NULL);CHECKGLERROR
936 GL_SetupTextureParameters(glt->flags, glt->textype->textype, glt->texturetype);
938 qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
941 int R_RealGetTexture(rtexture_t *rt)
946 glt = (gltexture_t *)rt;
947 if (glt->flags & GLTEXF_DYNAMIC)
948 R_UpdateDynamicTexture(glt);
949 if (glt->flags & GLTEXF_UPLOAD)
952 qglGenTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
953 R_Upload(glt, glt->inputtexels, 0, 0, 0, glt->inputwidth, glt->inputheight, glt->inputdepth);
954 if (glt->inputtexels)
956 Mem_Free(glt->inputtexels);
957 glt->inputtexels = NULL;
958 glt->flags |= GLTEXF_DESTROYED;
960 else if (glt->flags & GLTEXF_DESTROYED)
961 Con_Printf("R_GetTexture: Texture %s already uploaded and destroyed. Can not upload original image again. Uploaded blank texture.\n", glt->identifier);
970 static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int depth, int sides, int flags, textype_t textype, int texturetype, const unsigned char *data, const unsigned int *palette)
974 gltexturepool_t *pool = (gltexturepool_t *)rtexturepool;
975 textypeinfo_t *texinfo;
978 if (cls.state == ca_dedicated)
981 if (texturetype == GLTEXTURETYPE_RECTANGLE && !gl_texturerectangle)
983 Con_Printf ("R_LoadTexture: rectangle texture not supported by driver\n");
986 if (texturetype == GLTEXTURETYPE_CUBEMAP && !gl_texturecubemap)
988 Con_Printf ("R_LoadTexture: cubemap texture not supported by driver\n");
991 if (texturetype == GLTEXTURETYPE_3D && !gl_texture3d)
993 Con_Printf ("R_LoadTexture: 3d texture not supported by driver\n");
997 texinfo = R_GetTexTypeInfo(textype, flags);
998 size = width * height * depth * sides * texinfo->inputbytesperpixel;
1001 Con_Printf ("R_LoadTexture: bogus texture size (%dx%dx%dx%dbppx%dsides = %d bytes)\n", width, height, depth, texinfo->inputbytesperpixel * 8, sides, size);
1005 // clear the alpha flag if the texture has no transparent pixels
1008 case TEXTYPE_PALETTE:
1009 if (flags & TEXF_ALPHA)
1011 flags &= ~TEXF_ALPHA;
1014 for (i = 0;i < size;i++)
1016 if (((unsigned char *)&palette[data[i]])[3] < 255)
1018 flags |= TEXF_ALPHA;
1027 if (flags & TEXF_ALPHA)
1029 flags &= ~TEXF_ALPHA;
1032 for (i = 3;i < size;i += 4)
1036 flags |= TEXF_ALPHA;
1043 case TEXTYPE_SHADOWMAP:
1046 Host_Error("R_LoadTexture: unknown texture type");
1049 glt = (gltexture_t *)Mem_Alloc(texturemempool, sizeof(gltexture_t));
1051 strlcpy (glt->identifier, identifier, sizeof(glt->identifier));
1053 glt->chain = pool->gltchain;
1054 pool->gltchain = glt;
1055 glt->inputwidth = width;
1056 glt->inputheight = height;
1057 glt->inputdepth = depth;
1058 glt->flags = flags | GLTEXF_UPLOAD;
1059 glt->textype = texinfo;
1060 glt->texturetype = texturetype;
1061 glt->inputdatasize = size;
1062 glt->palette = palette;
1063 glt->glinternalformat = texinfo->glinternalformat;
1064 glt->glformat = texinfo->glformat;
1065 glt->gltype = texinfo->gltype;
1066 glt->bytesperpixel = texinfo->internalbytesperpixel;
1067 glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1;
1069 // init the dynamic texture attributes, too [11/22/2007 Black]
1070 glt->dirtytexnum = 0;
1071 glt->updatecallback = NULL;
1072 glt->updatacallback_data = NULL;
1074 GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->inputwidth, glt->inputheight, glt->inputdepth, &glt->tilewidth, &glt->tileheight, &glt->tiledepth);
1077 if (glt->flags & TEXF_ALWAYSPRECACHE)
1079 else if (r_precachetextures.integer >= 2)
1081 else if (r_precachetextures.integer >= 1)
1082 if (glt->flags & TEXF_PRECACHE)
1087 // immediate upload (most common case)
1088 // data may be NULL (blank texture for dynamic rendering)
1090 qglGenTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
1091 R_Upload(glt, data, 0, 0, 0, glt->inputwidth, glt->inputheight, glt->inputdepth);
1095 // deferred texture upload (menu graphics)
1096 // optimize first if possible
1097 if ((textype == TEXTYPE_BGRA || textype == TEXTYPE_RGBA) && glt->inputwidth * glt->inputheight * glt->inputdepth > glt->tilewidth * glt->tileheight * glt->tiledepth)
1099 glt->inputtexels = (unsigned char *)Mem_Alloc(texturemempool, glt->tilewidth*glt->tileheight*glt->tiledepth*glt->sides*glt->bytesperpixel);
1100 Image_Resample32(data, glt->inputwidth, glt->inputheight, glt->inputdepth, glt->inputtexels, glt->tilewidth, glt->tileheight, glt->tiledepth, r_lerpimages.integer);
1101 // change texture size accordingly
1102 glt->inputwidth = glt->tilewidth;
1103 glt->inputheight = glt->tileheight;
1104 glt->inputdepth = glt->tiledepth;
1105 GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->inputwidth, glt->inputheight, glt->inputdepth, &glt->tilewidth, &glt->tileheight, &glt->tiledepth);
1109 glt->inputtexels = (unsigned char *)Mem_Alloc(texturemempool, size);
1110 memcpy(glt->inputtexels, data, size);
1114 // texture converting and uploading can take a while, so make sure we're sending keepalives
1115 CL_KeepaliveMessage(false);
1117 return (rtexture_t *)glt;
1120 rtexture_t *R_LoadTexture1D(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette)
1122 return R_SetupTexture(rtexturepool, identifier, width, 1, 1, 1, flags, textype, GLTEXTURETYPE_1D, data, palette);
1125 rtexture_t *R_LoadTexture2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette)
1127 return R_SetupTexture(rtexturepool, identifier, width, height, 1, 1, flags, textype, GLTEXTURETYPE_2D, data, palette);
1130 rtexture_t *R_LoadTexture3D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int depth, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette)
1132 return R_SetupTexture(rtexturepool, identifier, width, height, depth, 1, flags, textype, GLTEXTURETYPE_3D, data, palette);
1135 rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *identifier, int width, const unsigned char *data, textype_t textype, int flags, const unsigned int *palette)
1137 return R_SetupTexture(rtexturepool, identifier, width, width, 1, 6, flags, textype, GLTEXTURETYPE_CUBEMAP, data, palette);
1140 static int R_ShadowMapTextureFlags(int precision, qboolean filter)
1142 int flags = TEXF_ALWAYSPRECACHE | TEXF_CLAMP;
1144 flags |= TEXF_FORCELINEAR | TEXF_COMPARE;
1146 flags |= TEXF_FORCENEAREST;
1147 if (precision <= 16)
1148 flags |= TEXF_LOWPRECISION;
1152 rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter)
1154 return R_SetupTexture(rtexturepool, identifier, width, height, 1, 1, R_ShadowMapTextureFlags(precision, filter), TEXTYPE_SHADOWMAP, GLTEXTURETYPE_RECTANGLE, NULL, NULL);
1157 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int precision, qboolean filter)
1159 return R_SetupTexture(rtexturepool, identifier, width, height, 1, 1, R_ShadowMapTextureFlags(precision, filter), TEXTYPE_SHADOWMAP, GLTEXTURETYPE_2D, NULL, NULL);
1162 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width, int precision, qboolean filter)
1164 return R_SetupTexture(rtexturepool, identifier, width, width, 1, 6, R_ShadowMapTextureFlags(precision, filter), TEXTYPE_SHADOWMAP, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
1167 int R_TextureHasAlpha(rtexture_t *rt)
1169 return rt ? (((gltexture_t *)rt)->flags & TEXF_ALPHA) != 0 : false;
1172 int R_TextureWidth(rtexture_t *rt)
1174 return rt ? ((gltexture_t *)rt)->inputwidth : 0;
1177 int R_TextureHeight(rtexture_t *rt)
1179 return rt ? ((gltexture_t *)rt)->inputheight : 0;
1182 void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, int width, int height)
1186 Host_Error("R_UpdateTexture: no texture supplied");
1188 Host_Error("R_UpdateTexture: no data supplied");
1190 // we need it to be uploaded before we can update a part of it
1191 R_RealGetTexture(rt);
1193 // update part of the texture
1194 glt = (gltexture_t *)rt;
1195 R_Upload(glt, data, x, y, 0, width, height, 1);
1198 void R_ClearTexture (rtexture_t *rt)
1200 gltexture_t *glt = (gltexture_t *)rt;
1202 R_Upload( glt, NULL, 0, 0, 0, glt->tilewidth, glt->tileheight, glt->tiledepth );