]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
gl_textures: Totally disable the partial update codepath until it can be done correctly.
[xonotic/darkplaces.git] / gl_textures.c
index 890714cd7db7b6af3810198ee6c2dc06b15812e7..0bb0a2939f12d194d9d44a63c25a41d5995a9e0f 100644 (file)
@@ -6,7 +6,7 @@
 #include "intoverflow.h"
 
 cvar_t gl_max_size = {CF_CLIENT | CF_ARCHIVE, "gl_max_size", "2048", "maximum allowed texture size, can be used to reduce video memory usage, limited by hardware capabilities (typically 2048, 4096, or 8192)"};
-cvar_t gl_max_lightmapsize = {CF_CLIENT | CF_ARCHIVE, "gl_max_lightmapsize", "1024", "maximum allowed texture size for lightmap textures, use larger values to improve rendering speed, as long as there is enough video memory available (setting it too high for the hardware will cause very bad performance)"};
+cvar_t gl_max_lightmapsize = {CF_CLIENT | CF_ARCHIVE, "gl_max_lightmapsize", "512", "maximum allowed texture size for lightmap textures, use larger values to improve rendering speed, as long as there is enough video memory available (setting it too high for the hardware will cause very bad performance)"};
 cvar_t gl_picmip = {CF_CLIENT | CF_ARCHIVE, "gl_picmip", "0", "reduces resolution of textures by powers of 2, for example 1 will halve width/height, reducing texture memory usage by 75%"};
 cvar_t gl_picmip_world = {CF_CLIENT | CF_ARCHIVE, "gl_picmip_world", "0", "extra picmip level for world textures (may be negative, which will then reduce gl_picmip for these)"};
 cvar_t r_picmipworld = {CF_CLIENT | CF_ARCHIVE, "r_picmipworld", "1", "whether gl_picmip shall apply to world textures too (setting this to 0 is a shorthand for gl_picmip_world -9999999)"};
@@ -174,6 +174,9 @@ typedef struct gltexture_s
 
        // stores backup copy of texture for deferred texture updates (gl_nopartialtextureupdates cvar)
        unsigned char *bufferpixels;
+       unsigned char *modifiedpixels;
+       int modified_width, modified_height, modified_depth;
+       int modified_offset_x, modified_offset_y, modified_offset_z;
        qbool buffermodified;
 
        // pointer to texturepool (check this to see if the texture is allocated)
@@ -1313,9 +1316,12 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
        }
 
        R_UploadFullTexture(glt, data);
-       if ((glt->flags & TEXF_ALLOWUPDATES) && gl_nopartialtextureupdates.integer)
+       if (glt->flags & TEXF_ALLOWUPDATES)
                glt->bufferpixels = (unsigned char *)Mem_Alloc(texturemempool, glt->tilewidth*glt->tileheight*glt->tiledepth*glt->sides*glt->bytesperpixel);
 
+       glt->modifiedpixels = NULL;     
+       glt->modified_width = glt->modified_height = glt->modified_depth = glt->modified_offset_x = glt->modified_offset_y = glt->modified_offset_z = 0;
+
        // free any temporary processing buffer we allocated...
        if (temppixels)
                Mem_Free(temppixels);
@@ -2271,7 +2277,7 @@ void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, in
                return;
        }
        // update part of the texture
-       if (glt->bufferpixels)
+       if (glt->bufferpixels || (glt->bufferpixels && (x || y || z || width != glt->inputwidth || height != glt->inputheight || depth != glt->inputdepth)))
        {
                int j;
                int bpp = glt->bytesperpixel;
@@ -2299,14 +2305,45 @@ void R_UpdateTexture(rtexture_t *rt, const unsigned char *data, int x, int y, in
                        height = glt->tileheight - y;
                if (width < 1 || height < 1)
                        return;
-               glt->dirty = true;
-               glt->buffermodified = true;
+
                output += y*outputskip + x*bpp;
+               /* Cloudwalk FIXME: Broken shit, disabled for now.
+               // TODO: Optimize this further.
+               if(!gl_nopartialtextureupdates.integer)
+               {
+                       // Calculate the modified region, and resize it as it gets bigger.
+                       if(!glt->buffermodified)
+                       {
+                               glt->modified_offset_x = x;
+                               glt->modified_offset_y = y;
+                               glt->modified_offset_z = z;
+
+                               glt->modified_width = width;
+                               glt->modified_height = height;
+                               glt->modified_depth = depth;
+                       }
+                       else
+                       {
+                               if(x < glt->modified_offset_x) glt->modified_offset_x = x;
+                               if(y < glt->modified_offset_y) glt->modified_offset_y = y;
+                               if(z < glt->modified_offset_z) glt->modified_offset_z = z;
+
+                               if(width + x > glt->modified_width) glt->modified_width = width + x;
+                               if(height + y > glt->modified_height) glt->modified_height = height + y;
+                               if(depth + z > glt->modified_depth) glt->modified_depth = depth + z;
+                       }
+
+                       if(!&glt->modifiedpixels || &output < &glt->modifiedpixels)
+                               glt->modifiedpixels = output;
+               }
+               */
+
                for (j = 0;j < height;j++, output += outputskip, input += inputskip)
                        memcpy(output, input, width*bpp);
+
+               glt->dirty = true;
+               glt->buffermodified = true;
        }
-       else if (x || y || z || width != glt->inputwidth || height != glt->inputheight || depth != glt->inputdepth)
-               R_UploadPartialTexture(glt, data, x, y, z, width, height, depth);
        else
                R_UploadFullTexture(glt, data);
 }
@@ -2322,8 +2359,13 @@ int R_RealGetTexture(rtexture_t *rt)
                if (glt->buffermodified && glt->bufferpixels)
                {
                        glt->buffermodified = false;
-                       R_UploadFullTexture(glt, glt->bufferpixels);
+                       if(!glt->modifiedpixels)
+                               R_UploadFullTexture(glt, glt->bufferpixels);
+                       else
+                               R_UploadPartialTexture(glt, glt->modifiedpixels, glt->modified_offset_x, glt->modified_offset_y, glt->modified_offset_z, glt->modified_width, glt->modified_height, glt->modified_depth);
                }
+               glt->modified_offset_x = glt->modified_offset_y = glt->modified_offset_z = glt->modified_width = glt->modified_height = glt->modified_depth = 0;
+               glt->modifiedpixels = NULL;
                glt->dirty = false;
                return glt->texnum;
        }