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)"};
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)"};
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"};
+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"};
+cvar_t gl_texturecompression_color = {CVAR_SAVE, "gl_texturecompression_color", "1", "whether to compress colormap (diffuse) textures"};
+cvar_t gl_texturecompression_normal = {CVAR_SAVE, "gl_texturecompression_normal", "1", "whether to compress normalmap (normalmap) textures"};
+cvar_t gl_texturecompression_gloss = {CVAR_SAVE, "gl_texturecompression_gloss", "1", "whether to compress glossmap (specular) textures"};
+cvar_t gl_texturecompression_glow = {CVAR_SAVE, "gl_texturecompression_glow", "1", "whether to compress glowmap (luma) textures"};
+cvar_t gl_texturecompression_2d = {CVAR_SAVE, "gl_texturecompression_2d", "1", "whether to compress 2d (hud/menu) textures other than the font"};
+cvar_t gl_texturecompression_q3bsplightmaps = {CVAR_SAVE, "gl_texturecompression_q3bsplightmaps", "1", "whether to compress lightmaps in q3bsp format levels"};
+cvar_t gl_texturecompression_q3bspdeluxemaps = {CVAR_SAVE, "gl_texturecompression_q3bspdeluxemaps", "1", "whether to compress deluxemaps in q3bsp format levels (only levels compiled with q3map2 -deluxe have these)"};
+cvar_t gl_texturecompression_sky = {CVAR_SAVE, "gl_texturecompression_sky", "0", "whether to compress sky textures"};
+cvar_t gl_texturecompression_lightcubemaps = {CVAR_SAVE, "gl_texturecompression_lightcubemaps", "1", "whether to compress light cubemaps (spotlights and other light projection images)"};
int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
int gl_filter_mag = GL_LINEAR;
int internalbytesperpixel;
int glformat;
int glinternalformat;
+ int glcompressedinternalformat;
}
textypeinfo_t;
-static textypeinfo_t textype_palette = {TEXTYPE_PALETTE, 1, 4, GL_RGBA , 3};
-static textypeinfo_t textype_rgb = {TEXTYPE_RGB , 3, 3, GL_RGB , 3};
-static textypeinfo_t textype_rgba = {TEXTYPE_RGBA , 4, 4, GL_RGBA , 3};
-static textypeinfo_t textype_palette_alpha = {TEXTYPE_PALETTE, 1, 4, GL_RGBA , 4};
-static textypeinfo_t textype_rgba_alpha = {TEXTYPE_RGBA , 4, 4, GL_RGBA , 4};
+static textypeinfo_t textype_palette = {TEXTYPE_PALETTE, 1, 4, GL_RGBA , 3, GL_COMPRESSED_RGB_ARB};
+static textypeinfo_t textype_rgb = {TEXTYPE_RGB , 3, 3, GL_RGB , 3, GL_COMPRESSED_RGB_ARB};
+static textypeinfo_t textype_rgba = {TEXTYPE_RGBA , 4, 4, GL_RGBA , 3, GL_COMPRESSED_RGB_ARB};
+static textypeinfo_t textype_palette_alpha = {TEXTYPE_PALETTE, 1, 4, GL_RGBA , 4, GL_COMPRESSED_RGBA_ARB};
+static textypeinfo_t textype_rgba_alpha = {TEXTYPE_RGBA , 4, 4, GL_RGBA , 4, GL_COMPRESSED_RGBA_ARB};
#define GLTEXTURETYPE_1D 0
#define GLTEXTURETYPE_2D 1
// pointer to next texture in texturepool chain
struct gltexture_s *chain;
// name of the texture (this might be removed someday), no duplicates
- char identifier[32];
+ char identifier[MAX_QPATH + 32];
// original data size in *inputtexels
int inputwidth, inputheight, inputdepth;
// copy of the original texture(s) supplied to the upload function, for
int texturetype;
// palette if the texture is TEXTYPE_PALETTE
const unsigned int *palette;
- // power of 2 size, after gl_picmip and gl_max_size are applied
+ // actual stored texture size after gl_picmip and gl_max_size are applied
+ // (power of 2 if gl_support_arb_texture_non_power_of_two is not supported)
int tilewidth, tileheight, tiledepth;
// 1 or 6 depending on texturetype
int sides;
Host_Error("R_FreeTexture: texture \"%s\" not linked in pool", glt->identifier);
if (glt->texnum)
- qglDeleteTextures(1, (GLuint *)&glt->texnum);
+ {
+ CHECKGLERROR
+ qglDeleteTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
+ }
if (glt->inputtexels)
Mem_Free(glt->inputtexels);
// change all the existing mipmap texture objects
// FIXME: force renderer(/client/something?) restart instead?
+ CHECKGLERROR
for (pool = gltexturepoolchain;pool;pool = pool->next)
{
for (glt = pool->gltchain;glt;glt = glt->chain)
// only update already uploaded images
if (!(glt->flags & (GLTEXF_UPLOAD | TEXF_FORCENEAREST | TEXF_FORCELINEAR)))
{
- qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);
- qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);
+ qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
+ qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
if (glt->flags & TEXF_MIPMAP)
- qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_min);
+ {
+ qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_min);CHECKGLERROR
+ }
else
- qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_mag);
- qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MAG_FILTER, gl_filter_mag);
- qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);
+ {
+ qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MIN_FILTER, gl_filter_mag);CHECKGLERROR
+ }
+ qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MAG_FILTER, gl_filter_mag);CHECKGLERROR
+ qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
}
}
}
if (outwidth)
{
- for (width2 = 1;width2 < inwidth;width2 <<= 1);
- for (width2 >>= picmip;width2 > maxsize;width2 >>= 1);
+ if (gl_support_arb_texture_non_power_of_two)
+ width2 = min(inwidth >> picmip, maxsize);
+ else
+ {
+ for (width2 = 1;width2 < inwidth;width2 <<= 1);
+ for (width2 >>= picmip;width2 > maxsize;width2 >>= 1);
+ }
*outwidth = max(1, width2);
}
if (outheight)
{
- for (height2 = 1;height2 < inheight;height2 <<= 1);
- for (height2 >>= picmip;height2 > maxsize;height2 >>= 1);
+ if (gl_support_arb_texture_non_power_of_two)
+ height2 = min(inheight >> picmip, maxsize);
+ else
+ {
+ for (height2 = 1;height2 < inheight;height2 <<= 1);
+ for (height2 >>= picmip;height2 > maxsize;height2 >>= 1);
+ }
*outheight = max(1, height2);
}
if (outdepth)
{
- for (depth2 = 1;depth2 < indepth;depth2 <<= 1);
- for (depth2 >>= picmip;depth2 > maxsize;depth2 >>= 1);
+ if (gl_support_arb_texture_non_power_of_two)
+ depth2 = min(indepth >> picmip, maxsize);
+ else
+ {
+ for (depth2 = 1;depth2 < indepth;depth2 <<= 1);
+ for (depth2 >>= picmip;depth2 > maxsize;depth2 >>= 1);
+ }
*outdepth = max(1, depth2);
}
}
static void r_textures_start(void)
{
// LordHavoc: allow any alignment
- qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
CHECKGLERROR
+ qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);CHECKGLERROR
+ qglPixelStorei(GL_PACK_ALIGNMENT, 1);CHECKGLERROR
texturemempool = Mem_AllocPool("texture management", 0, NULL);
Cvar_RegisterVariable (&r_lerpimages);
Cvar_RegisterVariable (&r_precachetextures);
Cvar_RegisterVariable (&gl_texture_anisotropy);
+ Cvar_RegisterVariable (&gl_texturecompression);
+ Cvar_RegisterVariable (&gl_texturecompression_color);
+ Cvar_RegisterVariable (&gl_texturecompression_normal);
+ Cvar_RegisterVariable (&gl_texturecompression_gloss);
+ Cvar_RegisterVariable (&gl_texturecompression_glow);
+ Cvar_RegisterVariable (&gl_texturecompression_2d);
+ Cvar_RegisterVariable (&gl_texturecompression_q3bsplightmaps);
+ Cvar_RegisterVariable (&gl_texturecompression_q3bspdeluxemaps);
+ Cvar_RegisterVariable (&gl_texturecompression_sky);
+ Cvar_RegisterVariable (&gl_texturecompression_lightcubemaps);
R_RegisterModule("R_Textures", r_textures_start, r_textures_shutdown, r_textures_newmap);
}
Cvar_SetValueQuick(&gl_texture_anisotropy, old_aniso);
+ CHECKGLERROR
for (pool = gltexturepoolchain;pool;pool = pool->next)
{
for (glt = pool->gltchain;glt;glt = glt->chain)
// only update already uploaded images
if ((glt->flags & (GLTEXF_UPLOAD | TEXF_MIPMAP)) == TEXF_MIPMAP)
{
- qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);
+ qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
- qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);
+ qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
qglTexParameteri(gltexturetypeenums[glt->texturetype], GL_TEXTURE_MAX_ANISOTROPY_EXT, old_aniso);CHECKGLERROR
- qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);
+ qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
}
}
}
CHECKGLERROR
// we need to restore the texture binding after finishing the upload
- qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);
- qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);
- CHECKGLERROR
+ qglGetIntegerv(gltexturetypebindingenums[glt->texturetype], &oldbindtexnum);CHECKGLERROR
+ qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR
+
+ // these are rounded up versions of the size to do better resampling
+ if (gl_support_arb_texture_non_power_of_two)
+ {
+ width = glt->inputwidth;
+ height = glt->inputheight;
+ depth = glt->inputdepth;
+ }
+ else
+ {
+ for (width = 1;width < glt->inputwidth ;width <<= 1);
+ for (height = 1;height < glt->inputheight;height <<= 1);
+ for (depth = 1;depth < glt->inputdepth ;depth <<= 1);
+ }
+ R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
R_MakeResizeBufferBigger(fragwidth * fragheight * fragdepth * glt->sides * glt->bytesperpixel);
if (prevbuffer == NULL)
prevbuffer = colorconvertbuffer;
}
- // these are rounded up versions of the size to do better resampling
- for (width = 1;width < glt->inputwidth ;width <<= 1);
- for (height = 1;height < glt->inputheight;height <<= 1);
- for (depth = 1;depth < glt->inputdepth ;depth <<= 1);
-
- R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel);
-
- if ((glt->flags & (TEXF_MIPMAP | TEXF_PICMIP | GLTEXF_UPLOAD)) == 0)
+ if ((glt->flags & (TEXF_MIPMAP | TEXF_PICMIP | GLTEXF_UPLOAD)) == 0 && glt->inputwidth == glt->tilewidth && glt->inputheight == glt->tileheight && glt->inputdepth == glt->tiledepth)
{
// update a portion of the image
switch(glt->texturetype)
{
case GLTEXTURETYPE_1D:
- qglTexSubImage1D(GL_TEXTURE_1D, 0, fragx, fragwidth, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexSubImage1D(GL_TEXTURE_1D, 0, fragx, fragwidth, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
break;
case GLTEXTURETYPE_2D:
- qglTexSubImage2D(GL_TEXTURE_2D, 0, fragx, fragy, fragwidth, fragheight, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexSubImage2D(GL_TEXTURE_2D, 0, fragx, fragy, fragwidth, fragheight, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
break;
case GLTEXTURETYPE_3D:
- qglTexSubImage3D(GL_TEXTURE_3D, 0, fragx, fragy, fragz, fragwidth, fragheight, fragdepth, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexSubImage3D(GL_TEXTURE_3D, 0, fragx, fragy, fragz, fragwidth, fragheight, fragdepth, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
break;
default:
Host_Error("R_Upload: partial update of type other than 1D, 2D, or 3D");
}
}
mip = 0;
+ if (gl_support_texture_compression)
+ {
+ if (gl_texturecompression.integer >= 2)
+ qglHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_NICEST);
+ else
+ qglHint(GL_TEXTURE_COMPRESSION_HINT_ARB, GL_FASTEST);
+ CHECKGLERROR
+ }
switch(glt->texturetype)
{
case GLTEXTURETYPE_1D:
- qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
if (glt->flags & TEXF_MIPMAP)
{
while (width > 1 || height > 1 || depth > 1)
{
Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
prevbuffer = resizebuffer;
- qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
}
break;
case GLTEXTURETYPE_2D:
- qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
if (glt->flags & TEXF_MIPMAP)
{
while (width > 1 || height > 1 || depth > 1)
{
Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
prevbuffer = resizebuffer;
- qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
}
break;
case GLTEXTURETYPE_3D:
- qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
if (glt->flags & TEXF_MIPMAP)
{
while (width > 1 || height > 1 || depth > 1)
{
Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
prevbuffer = resizebuffer;
- qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
}
break;
prevbuffer = resizebuffer;
}
mip = 0;
- qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
if (glt->flags & TEXF_MIPMAP)
{
while (width > 1 || height > 1 || depth > 1)
{
Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1, glt->bytesperpixel);
prevbuffer = resizebuffer;
- qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);
- CHECKGLERROR
+ qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
}
}
}
}
GL_SetupTextureParameters(glt->flags, glt->texturetype);
}
- qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);
+ qglBindTexture(gltexturetypeenums[glt->texturetype], oldbindtexnum);CHECKGLERROR
}
static void R_UploadTexture (gltexture_t *glt)
if (!(glt->flags & GLTEXF_UPLOAD))
return;
- qglGenTextures(1, (GLuint *)&glt->texnum);
+ CHECKGLERROR
+ qglGenTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR
R_Upload(glt, glt->inputtexels, 0, 0, 0, glt->inputwidth, glt->inputheight, glt->inputdepth);
if (glt->inputtexels)
{
size = width * height * depth * sides * texinfo->inputbytesperpixel;
if (size < 1)
{
- Con_Printf ("R_LoadTexture: bogus texture size (%dx%dx%dx%dbppx%dsides = %d bytes)\n", width, height, depth, texinfo->inputbytesperpixel * 8, sides);
+ Con_Printf ("R_LoadTexture: bogus texture size (%dx%dx%dx%dbppx%dsides = %d bytes)\n", width, height, depth, texinfo->inputbytesperpixel * 8, sides, size);
return NULL;
}
glt->texturetype = texturetype;
glt->inputdatasize = size;
glt->palette = palette;
- glt->glinternalformat = texinfo->glinternalformat;
+ glt->glinternalformat = ((flags & TEXF_COMPRESS) && gl_texturecompression.integer >= 1 && gl_support_texture_compression) ? texinfo->glcompressedinternalformat : texinfo->glinternalformat;
glt->glformat = texinfo->glformat;
glt->bytesperpixel = texinfo->internalbytesperpixel;
glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1;