X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=gl_textures.c;h=14685e7949e1fe87a5b4fec166c3749f26bf6812;hb=3e3f3dacdc0d4594a847bf6d77bb0b145a187708;hp=4617d0d6ea987f4333367a76791861fb5ad0ee64;hpb=d090340b054029faddb432e2c66085e6e91abcf7;p=xonotic%2Fdarkplaces.git diff --git a/gl_textures.c b/gl_textures.c index 4617d0d6..14685e79 100644 --- a/gl_textures.c +++ b/gl_textures.c @@ -96,8 +96,8 @@ static textypeinfo_t textype_depth16 = {"depth16", static textypeinfo_t textype_depth24 = {"depth24", TEXTYPE_DEPTHBUFFER24 , 2, 2, 2.0f, GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; static textypeinfo_t textype_depth24stencil8 = {"depth24stencil8", TEXTYPE_DEPTHBUFFER24STENCIL8, 2, 2, 2.0f, GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT}; static textypeinfo_t textype_colorbuffer = {"colorbuffer", TEXTYPE_COLORBUFFER , 2, 2, 2.0f, GL_RGB565 , GL_RGBA , GL_UNSIGNED_SHORT_5_6_5}; -static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 2, 2, 2.0f, GL_RGB565 , GL_RGBA , GL_UNSIGNED_SHORT_5_6_5}; -static textypeinfo_t textype_colorbuffer32f = {"colorbuffer32f", TEXTYPE_COLORBUFFER32F , 2, 2, 2.0f, GL_RGB565 , GL_RGBA , GL_UNSIGNED_SHORT_5_6_5}; +static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 2, 2, 2.0f, GL_RGBA16F , GL_RGBA , GL_HALF_FLOAT_ARB}; +static textypeinfo_t textype_colorbuffer32f = {"colorbuffer32f", TEXTYPE_COLORBUFFER32F , 2, 2, 2.0f, GL_RGBA32F , GL_RGBA , GL_FLOAT}; // image formats: static textypeinfo_t textype_alpha = {"alpha", TEXTYPE_ALPHA , 1, 4, 4.0f, GL_ALPHA , GL_ALPHA , GL_UNSIGNED_BYTE }; @@ -120,7 +120,7 @@ static textypeinfo_t textype_depth16 = {"depth16", static textypeinfo_t textype_depth24 = {"depth24", TEXTYPE_DEPTHBUFFER24 , 4, 4, 4.0f, GL_DEPTH_COMPONENT24_ARB , GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }; static textypeinfo_t textype_depth24stencil8 = {"depth24stencil8", TEXTYPE_DEPTHBUFFER24STENCIL8, 4, 4, 4.0f, GL_DEPTH24_STENCIL8_EXT , GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT}; static textypeinfo_t textype_colorbuffer = {"colorbuffer", TEXTYPE_COLORBUFFER , 4, 4, 4.0f, GL_RGBA , GL_BGRA , GL_UNSIGNED_BYTE }; -static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 8, 8, 8.0f, GL_RGBA16F_ARB , GL_RGBA , GL_FLOAT }; +static textypeinfo_t textype_colorbuffer16f = {"colorbuffer16f", TEXTYPE_COLORBUFFER16F , 8, 8, 8.0f, GL_RGBA16F_ARB , GL_RGBA , GL_HALF_FLOAT_ARB}; static textypeinfo_t textype_colorbuffer32f = {"colorbuffer32f", TEXTYPE_COLORBUFFER32F , 16, 16, 16.0f, GL_RGBA32F_ARB , GL_RGBA , GL_FLOAT }; // image formats: @@ -209,7 +209,7 @@ typedef struct gltexture_s // dynamic texture stuff [11/22/2007 Black] updatecallback_t updatecallback; - void *updatacallback_data; + void *updatecallback_data; // --- [11/22/2007 Black] // stores backup copy of texture for deferred texture updates (gl_nopartialtextureupdates cvar) @@ -353,13 +353,13 @@ void R_MakeTextureDynamic(rtexture_t *rt, updatecallback_t updatecallback, void glt->flags |= GLTEXF_DYNAMIC; glt->updatecallback = updatecallback; - glt->updatacallback_data = data; + glt->updatecallback_data = data; } static void R_UpdateDynamicTexture(gltexture_t *glt) { glt->dirty = false; if( glt->updatecallback ) { - glt->updatecallback( (rtexture_t*) glt, glt->updatacallback_data ); + glt->updatecallback( (rtexture_t*) glt, glt->updatecallback_data ); } } @@ -1256,13 +1256,13 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) for (width = glt->tilewidth;width < glt->inputwidth ;width <<= 1); for (height = glt->tileheight;height < glt->inputheight;height <<= 1); for (depth = glt->tiledepth;depth < glt->inputdepth ;depth <<= 1); - R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); if (prevbuffer == NULL) { width = glt->tilewidth; height = glt->tileheight; depth = glt->tiledepth; +// R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); // memset(resizebuffer, 0, width * height * depth * glt->sides * glt->bytesperpixel); // prevbuffer = resizebuffer; } @@ -1271,6 +1271,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) if (glt->textype->textype == TEXTYPE_PALETTE) { // promote paletted to BGRA, so we only have to worry about BGRA in the rest of this code + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_Copy8bitBGRA(prevbuffer, colorconvertbuffer, glt->inputwidth * glt->inputheight * glt->inputdepth * glt->sides, glt->palette); prevbuffer = colorconvertbuffer; } @@ -1278,6 +1279,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { // multiply RGB channels by A channel before uploading int alpha; + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); for (i = 0;i < glt->inputwidth*glt->inputheight*glt->inputdepth*4;i += 4) { alpha = prevbuffer[i+3]; @@ -1291,12 +1293,14 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) // scale up to a power of 2 size (if appropriate) if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_Resample32(prevbuffer, glt->inputwidth, glt->inputheight, glt->inputdepth, resizebuffer, width, height, depth, r_lerpimages.integer); prevbuffer = resizebuffer; } // apply mipmap reduction algorithm to get down to picmip/max_size while (width > glt->tilewidth || height > glt->tileheight || depth > glt->tiledepth) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); prevbuffer = resizebuffer; } @@ -1339,6 +1343,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); prevbuffer = resizebuffer; qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR @@ -1352,6 +1357,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); 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, glt->gltype, prevbuffer);CHECKGLERROR @@ -1369,12 +1375,14 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel; if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); 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) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); prevbuffer = resizebuffer; } @@ -1384,6 +1392,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); prevbuffer = resizebuffer; qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, glt->gltype, prevbuffer);CHECKGLERROR @@ -1418,6 +1427,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); prevbuffer = resizebuffer; if (IDirect3DTexture9_LockRect((IDirect3DTexture9*)glt->d3dtexture, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits) @@ -1441,6 +1451,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); prevbuffer = resizebuffer; if (IDirect3DVolumeTexture9_LockBox((IDirect3DVolumeTexture9*)glt->d3dtexture, mip, &d3dlockedbox, NULL, 0) == D3D_OK && d3dlockedbox.pBits) @@ -1463,12 +1474,14 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel; if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); 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) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); prevbuffer = resizebuffer; } @@ -1483,6 +1496,7 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) { while (width > 1 || height > 1 || depth > 1) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1); prevbuffer = resizebuffer; if (IDirect3DCubeTexture9_LockRect((IDirect3DCubeTexture9*)glt->d3dtexture, (D3DCUBEMAP_FACES)i, mip, &d3dlockedrect, NULL, 0) == D3D_OK && d3dlockedrect.pBits) @@ -1570,12 +1584,14 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data) texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel; if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); 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) { + R_MakeResizeBufferBigger(width * height * depth * glt->sides * glt->bytesperpixel); Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, glt->tilewidth, glt->tileheight, glt->tiledepth); prevbuffer = resizebuffer; } @@ -1803,7 +1819,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden glt->gltexturetypeenum = gltexturetypeenums[glt->texturetype]; // init the dynamic texture attributes, too [11/22/2007 Black] glt->updatecallback = NULL; - glt->updatacallback_data = NULL; + glt->updatecallback_data = NULL; GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->miplevel, glt->inputwidth, glt->inputheight, glt->inputdepth, &glt->tilewidth, &glt->tileheight, &glt->tiledepth, &glt->miplevels); @@ -1971,11 +1987,11 @@ rtexture_t *R_LoadTextureRenderBuffer(rtexturepool_t *rtexturepool, const char * glt->sides = glt->texturetype == GLTEXTURETYPE_CUBEMAP ? 6 : 1; glt->texnum = 0; glt->dirty = false; - glt->glisdepthstencil = glt->texturetype == TEXTYPE_DEPTHBUFFER24STENCIL8; - glt->gltexturetypeenum = gltexturetypeenums[glt->texturetype]; + glt->glisdepthstencil = textype == TEXTYPE_DEPTHBUFFER24STENCIL8; + glt->gltexturetypeenum = GL_TEXTURE_2D; // init the dynamic texture attributes, too [11/22/2007 Black] glt->updatecallback = NULL; - glt->updatacallback_data = NULL; + glt->updatecallback_data = NULL; GL_Texture_CalcImageSize(glt->texturetype, glt->flags, glt->miplevel, glt->inputwidth, glt->inputheight, glt->inputdepth, &glt->tilewidth, &glt->tileheight, &glt->tiledepth, &glt->miplevels);