]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
todo items went from 465 to 459 by finding items that was already done or duplicates
[xonotic/darkplaces.git] / gl_textures.c
index a55660409cd4bb7b702dae60a3f3eee91d009d4d..b4649e05df094efeb75d0914f29904f677c1eb0e 100644 (file)
@@ -798,19 +798,16 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int
                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)
-       {
-               memset(resizebuffer, 0, fragwidth * fragheight * fragdepth * glt->bytesperpixel);
-               prevbuffer = resizebuffer;
-       }
-       else if (glt->textype->textype == TEXTYPE_PALETTE)
+       if (prevbuffer != NULL)
        {
-               // 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;
+               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;
+               }
        }
 
        if ((glt->flags & (TEXF_MIPMAP | TEXF_PICMIP | GLTEXF_UPLOAD)) == 0 && glt->inputwidth == glt->tilewidth && glt->inputheight == glt->tileheight && glt->inputdepth == glt->tiledepth)
@@ -841,7 +838,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 (glt->texturetype != GLTEXTURETYPE_CUBEMAP)
+               if ((prevbuffer != NULL) && (glt->texturetype != GLTEXTURETYPE_CUBEMAP))
                {
                        if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
                        {
@@ -872,8 +869,17 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int
                        {
                                while (width > 1 || height > 1 || depth > 1)
                                {
-                                       Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
-                                       prevbuffer = resizebuffer;
+                                       if (prevbuffer != NULL)
+                                       {
+                                               Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
+                                               prevbuffer = resizebuffer;
+                                       }
+                                       else
+                                       {
+                                               if (width > 1) width >>= 1;
+                                               if (height > 1) height >>= 1;
+                                               if (depth > 1) depth >>= 1;
+                                       }
                                        qglTexImage1D(GL_TEXTURE_1D, mip++, glt->glinternalformat, width, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
                                }
                        }
@@ -884,8 +890,17 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int
                        {
                                while (width > 1 || height > 1 || depth > 1)
                                {
-                                       Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
-                                       prevbuffer = resizebuffer;
+                                       if (prevbuffer != NULL)
+                                       {
+                                               Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
+                                               prevbuffer = resizebuffer;
+                                       }
+                                       else
+                                       {
+                                               if (width > 1) width >>= 1;
+                                               if (height > 1) height >>= 1;
+                                               if (depth > 1) depth >>= 1;
+                                       }
                                        qglTexImage2D(GL_TEXTURE_2D, mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
                                }
                        }
@@ -896,8 +911,17 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int
                        {
                                while (width > 1 || height > 1 || depth > 1)
                                {
-                                       Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
-                                       prevbuffer = resizebuffer;
+                                       if (prevbuffer != NULL)
+                                       {
+                                               Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
+                                               prevbuffer = resizebuffer;
+                                       }
+                                       else
+                                       {
+                                               if (width > 1) width >>= 1;
+                                               if (height > 1) height >>= 1;
+                                               if (depth > 1) depth >>= 1;
+                                       }
                                        qglTexImage3D(GL_TEXTURE_3D, mip++, glt->glinternalformat, width, height, depth, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
                                }
                        }
@@ -905,21 +929,24 @@ 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 = (unsigned char *)prevbuffer;
+                       texturebuffer = prevbuffer ? (unsigned char *)prevbuffer : NULL;
                        for (i = 0;i < 6;i++)
                        {
                                prevbuffer = texturebuffer;
-                               texturebuffer += glt->inputwidth * glt->inputheight * glt->inputdepth * glt->textype->inputbytesperpixel;
-                               if (glt->inputwidth != width || glt->inputheight != height || glt->inputdepth != depth)
+                               if (prevbuffer != NULL)
                                {
-                                       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;
+                                       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;
+                                       }
                                }
                                mip = 0;
                                qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
@@ -927,8 +954,17 @@ static void R_Upload(gltexture_t *glt, const unsigned char *data, int fragx, int
                                {
                                        while (width > 1 || height > 1 || depth > 1)
                                        {
-                                               Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
-                                               prevbuffer = resizebuffer;
+                                               if (prevbuffer != NULL)
+                                               {
+                                                       Image_MipReduce32(prevbuffer, resizebuffer, &width, &height, &depth, 1, 1, 1);
+                                                       prevbuffer = resizebuffer;
+                                               }
+                                               else
+                                               {
+                                                       if (width > 1) width >>= 1;
+                                                       if (height > 1) height >>= 1;
+                                                       if (depth > 1) depth >>= 1;
+                                               }
                                                qglTexImage2D(cubemapside[i], mip++, glt->glinternalformat, width, height, 0, glt->glformat, GL_UNSIGNED_BYTE, prevbuffer);CHECKGLERROR
                                        }
                                }
@@ -1119,3 +1155,9 @@ void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, in
        R_Upload(glt, data, x, y, 0, width, height, 1);
 }
 
+void R_ClearTexture (rtexture_t *rt)
+{
+       gltexture_t *glt = (gltexture_t *)rt;
+
+       R_Upload( glt, NULL, 0, 0, 0, glt->tilewidth, glt->tileheight, glt->tiledepth );
+}