+ if (glt->bufferpixels)
+ {
+ int j;
+ int bpp = glt->bytesperpixel;
+ int inputskip = width*bpp;
+ int outputskip = glt->tilewidth*bpp;
+ const unsigned char *input = data;
+ unsigned char *output = glt->bufferpixels;
+ if (x < 0)
+ {
+ width += x;
+ input -= x*bpp;
+ x = 0;
+ }
+ if (y < 0)
+ {
+ height += y;
+ input -= y*inputskip;
+ y = 0;
+ }
+ if (width > glt->tilewidth - x)
+ width = glt->tilewidth - x;
+ if (height > glt->tileheight - y)
+ height = glt->tileheight - y;
+ if (width < 1 || height < 1)
+ return;
+ glt->buffermodified = true;
+ output += y*outputskip + x*bpp;
+ for (j = 0;j < height;j++, output += outputskip, input += inputskip)
+ memcpy(output, input, width*bpp);
+ if (!(glt->flags & TEXF_MANUALFLUSHUPDATES))
+ R_FlushTexture(rt);
+ }
+ else
+ R_Upload(glt, data, x, y, 0, width, height, 1);
+}
+
+void R_FlushTexture(rtexture_t *rt)
+{
+ gltexture_t *glt;
+ if (rt == NULL)
+ Host_Error("R_FlushTexture: no texture supplied");
+
+ // update part of the texture
+ glt = (gltexture_t *)rt;
+
+ if (!glt->buffermodified || !glt->bufferpixels)
+ return;
+ glt->buffermodified = false;
+ R_Upload(glt, glt->bufferpixels, 0, 0, 0, glt->tilewidth, glt->tileheight, glt->tiledepth);