X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=gl_textures.c;h=f86ee1f6c1a2be6f9f3a8084faea7b91f744047c;hb=e62db3c2c5912dfdae790f97bed7791487dee34c;hp=f2fac414d9669cfafa26a18034b2bab647f62f74;hpb=a6cd51357b59bc588e47d3827953340c4de33d12;p=xonotic%2Fdarkplaces.git diff --git a/gl_textures.c b/gl_textures.c index f2fac414..f86ee1f6 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -11,12 +11,12 @@ cvar_t r_precachetextures = {CVAR_SAVE, "r_precachetextures", "1", "0 = never up 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_normal = {CVAR_SAVE, "gl_texturecompression_normal", "0", "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_2d = {CVAR_SAVE, "gl_texturecompression_2d", "0", "whether to compress 2d (hud/menu) textures other than the font"}; +cvar_t gl_texturecompression_q3bsplightmaps = {CVAR_SAVE, "gl_texturecompression_q3bsplightmaps", "0", "whether to compress lightmaps in q3bsp format levels"}; +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)"}; 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)"}; @@ -226,7 +226,7 @@ void R_MarkDirtyTexture(rtexture_t *rt) { if( !glt->dirtytexnum && glt->flags & GLTEXF_DYNAMIC ) { glt->dirtytexnum = glt->texnum; // mark it as dirty, so R_RealGetTexture gets called - glt->texnum = -1; + glt->texnum = 0; } } @@ -308,7 +308,7 @@ void R_FreeTexture(rtexture_t *rt) else Host_Error("R_FreeTexture: texture \"%s\" not linked in pool", glt->identifier); - if (glt->texnum) + if (!(glt->flags & GLTEXF_UPLOAD)) { CHECKGLERROR qglDeleteTextures(1, (GLuint *)&glt->texnum);CHECKGLERROR @@ -556,7 +556,7 @@ void R_TextureStats_Print(qboolean printeach, qboolean printpool, qboolean print 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); } if (printpool) - Con_Printf("texturepool %10p total: %i (%.3fMB, %.3fMB original), uploaded %i (%.3fMB, %.3fMB original), upload on demand %i (%.3fMB, %.3fMB original)\n", 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); + 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); sumtotal += pooltotal; sumtotalt += pooltotalt; sumtotalp += pooltotalp; @@ -798,16 +798,19 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int for (depth = 1;depth < glt->inputdepth ;depth <<= 1); } - if (prevbuffer != NULL) + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); + R_MakeResizeBufferBigger(fragwidth * fragheight * fragdepth * glt->sides * glt->bytesperpixel); + + if (prevbuffer == NULL) { - R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); - R_MakeResizeBufferBigger(fragwidth * fragheight * fragdepth * glt->sides * glt->bytesperpixel); - if (glt->textype->textype == TEXTYPE_PALETTE) - { - // promote paletted to BGRA, so we only have to worry about BGRA in the rest of this code - Image_Copy8bitBGRA(prevbuffer, colorconvertbuffer, fragwidth * fragheight * fragdepth * glt->sides, glt->palette); - prevbuffer = colorconvertbuffer; - } + memset(resizebuffer, 0, fragwidth * fragheight * fragdepth * glt->bytesperpixel); + prevbuffer = resizebuffer; + } + else if (glt->textype->textype == TEXTYPE_PALETTE) + { + // promote paletted to BGRA, so we only have to worry about BGRA in the rest of this code + Image_Copy8bitBGRA(prevbuffer, colorconvertbuffer, fragwidth * fragheight * fragdepth * glt->sides, glt->palette); + prevbuffer = colorconvertbuffer; } if ((glt->flags & (TEXF_MIPMAP | TEXF_PICMIP | GLTEXF_UPLOAD)) == 0 && glt->inputwidth == glt->tilewidth && glt->inputheight == glt->tileheight && glt->inputdepth == glt->tiledepth) @@ -838,7 +841,7 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int glt->flags &= ~GLTEXF_UPLOAD; // cubemaps contain multiple images and thus get processed a bit differently - if ((prevbuffer != NULL) && (glt->texturetype != GLTEXTURETYPE_CUBEMAP)) + if (glt->texturetype != GLTEXTURETYPE_CUBEMAP) { if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { @@ -869,11 +872,8 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int { while (width > 1 || height > 1 || depth > 1) { - if (prevbuffer != NULL) - { - Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); - prevbuffer = resizebuffer; - } + Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); + prevbuffer = resizebuffer; qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR } } @@ -884,11 +884,8 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int { while (width > 1 || height > 1 || depth > 1) { - if (prevbuffer != NULL) - { - Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); - prevbuffer = resizebuffer; - } + Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); + prevbuffer = resizebuffer; qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR } } @@ -899,11 +896,8 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int { while (width > 1 || height > 1 || depth > 1) { - if (prevbuffer != NULL) - { - Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); - prevbuffer = resizebuffer; - } + Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); + prevbuffer = resizebuffer; qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR } } @@ -911,24 +905,21 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int case GLTEXTURETYPE_CUBEMAP: // convert and upload each side in turn, // from a continuous block of input texels - texturebuffer = prevbuffer ? (unsigned char *)prevbuffer : NULL; + texturebuffer = (unsigned char *)prevbuffer; for (i = 0;i < 6;i++) { prevbuffer = texturebuffer; - if (prevbuffer != NULL) + texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel; + if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { - texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel; - if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) - { - Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer); - prevbuffer = resizebuffer; - } - // picmip/max_size - while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth) - { - Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); - prevbuffer = resizebuffer; - } + Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer); + prevbuffer = resizebuffer; + } + // picmip/max_size + while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth) + { + Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); + prevbuffer = resizebuffer; } mip = 0; qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR @@ -936,11 +927,8 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int { while (width > 1 || height > 1 || depth > 1) { - if (prevbuffer != NULL) - { - Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); - prevbuffer = resizebuffer; - } + Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); + prevbuffer = resizebuffer; qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR } } @@ -1059,7 +1047,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden glt->glformat = texinfo->glformat; glt->bytesperpixel = texinfo->internalbytesperpixel; glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1; - glt->texnum = -1; + glt->texnum = 0; // init the dynamic texture attributes, too [11/22/2007 Black] glt->dirtytexnum = 0; glt->updatecallback = NULL; @@ -1076,6 +1064,9 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->inputwidth, glt->inputheight, glt->inputdepth, &glt->tilewidth, &glt->tileheight, &glt->tiledepth); R_PrecacheTexture(glt); + // texture converting and uploading can take a while, so make sure we're sending keepalives + CL_KeepaliveMessage(false); + return (rtexture_t *)glt; }