X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=gl_textures.c;h=8ac8d6cad73cc6a8521ddf252a9621d287591ce4;hb=b3f5f964484b851ef9eb6b714780210693462b4c;hp=97e0aa948fd964b351b73f348d0126fea77cdfac;hpb=7af88bb6e88c6b799be6d2e99f0c0f8515c502ac;p=xonotic%2Fdarkplaces.git diff --git a/gl_textures.c b/gl_textures.c index 97e0aa94..8ac8d6ca 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -86,7 +86,8 @@ typedef struct gltexture_s 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; @@ -351,20 +352,35 @@ static void GL_Texture_CalcImageSize(int texturetype, int flags, int inwidth, in 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); } } @@ -452,6 +468,7 @@ static void r_textures_start(void) // LordHavoc: allow any alignment CHECKGLERROR qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);CHECKGLERROR + qglPixelStorei(GL_PACK_ALIGNMENT, 1);CHECKGLERROR texturemempool = Mem_AllocPool("texture management", 0, NULL); @@ -648,9 +665,18 @@ static void R_Upload(gltexture_t *glt, unsigned char *data, int fragx, int fragy qglBindTexture(gltexturetypeenums[glt->texturetype], glt->texnum);CHECKGLERROR // 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); + 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); @@ -830,7 +856,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden 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; }