]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
svs.clients is now allocated dynamically according to svs.maxclients, and there is...
[xonotic/darkplaces.git] / gl_textures.c
index 10cba22dd64283763d771ab38a33bf646648671e..8aa0457f31984dc5ad961b4e1026d3f58bbb4415 100644 (file)
@@ -494,6 +494,41 @@ void R_Textures_Init (void)
        R_RegisterModule("R_Textures", r_textures_start, r_textures_shutdown, r_textures_newmap);
 }
 
+void R_Textures_Frame (void)
+{
+       // could do procedural texture animation here, if we keep track of which
+       // textures were accessed this frame...
+
+       // free the resize buffers
+       resizebuffersize = 0;
+       if (resizebuffer)
+       {
+               Mem_Free(resizebuffer);
+               resizebuffer = NULL;
+       }
+       if (colorconvertbuffer)
+       {
+               Mem_Free(colorconvertbuffer);
+               colorconvertbuffer = NULL;
+       }
+}
+
+void R_MakeResizeBufferBigger(int size)
+{
+       if (resizebuffersize < size)
+       {
+               resizebuffersize = size;
+               if (resizebuffer)
+                       Mem_Free(resizebuffer);
+               if (colorconvertbuffer)
+                       Mem_Free(colorconvertbuffer);
+               resizebuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
+               colorconvertbuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
+               if (!resizebuffer || !colorconvertbuffer)
+                       Host_Error("R_Upload: out of memory\n");
+       }
+}
+
 static void R_Upload(gltexture_t *glt, qbyte *data)
 {
        int mip, width, height, internalformat;
@@ -509,22 +544,10 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
 
        if (glt->flags & TEXF_FRAGMENT)
        {
-               if (resizebuffersize < glt->image->width * glt->image->height * glt->image->bytesperpixel)
-               {
-                       resizebuffersize = glt->image->width * glt->image->height * glt->image->bytesperpixel;
-                       if (resizebuffer)
-                               Mem_Free(resizebuffer);
-                       if (colorconvertbuffer)
-                               Mem_Free(colorconvertbuffer);
-                       resizebuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
-                       colorconvertbuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
-                       if (!resizebuffer || !colorconvertbuffer)
-                               Host_Error("R_Upload: out of memory\n");
-               }
-
                if (glt->image->flags & GLTEXF_UPLOAD)
                {
                        Con_DPrintf("uploaded new fragments image\n");
+                       R_MakeResizeBufferBigger(glt->image->width * glt->image->height * glt->image->bytesperpixel);
                        glt->image->flags &= ~GLTEXF_UPLOAD;
                        memset(resizebuffer, 255, glt->image->width * glt->image->height * glt->image->bytesperpixel);
                        qglTexImage2D (GL_TEXTURE_2D, 0, glt->image->glinternalformat, glt->image->width, glt->image->height, 0, glt->image->glformat, GL_UNSIGNED_BYTE, resizebuffer);
@@ -537,6 +560,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
 
                if (prevbuffer == NULL)
                {
+                       R_MakeResizeBufferBigger(glt->image->width * glt->image->height * glt->image->bytesperpixel);
                        memset(resizebuffer, 255, glt->width * glt->height * glt->image->bytesperpixel);
                        prevbuffer = resizebuffer;
                }
@@ -544,6 +568,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                {
                        // promote paletted to RGBA, so we only have to worry about RGB and
                        // RGBA in the rest of this code
+                       R_MakeResizeBufferBigger(glt->image->width * glt->image->height * glt->image->bytesperpixel);
                        Image_Copy8bitRGBA(prevbuffer, colorconvertbuffer, glt->width * glt->height, d_8to24table);
                        prevbuffer = colorconvertbuffer;
                }
@@ -560,18 +585,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
        for (width = 1;width < glt->width;width <<= 1);
        for (height = 1;height < glt->height;height <<= 1);
 
-       if (resizebuffersize < width * height * glt->image->bytesperpixel)
-       {
-               resizebuffersize = width * height * glt->image->bytesperpixel;
-               if (resizebuffer)
-                       Mem_Free(resizebuffer);
-               if (colorconvertbuffer)
-                       Mem_Free(colorconvertbuffer);
-               resizebuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
-               colorconvertbuffer = Mem_Alloc(textureprocessingmempool, resizebuffersize);
-               if (!resizebuffer || !colorconvertbuffer)
-                       Host_Error("R_Upload: out of memory\n");
-       }
+       R_MakeResizeBufferBigger(width * height * glt->image->bytesperpixel);
 
        if (prevbuffer == NULL)
        {