]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
added con_notify cvar, which controls how many console notify lines are displayed...
[xonotic/darkplaces.git] / gl_textures.c
index a502f81a84e00773f8f057e535f4d0e2de93804d..710d2164010a733a7e9d56cdc0d9eed96b0e9c0e 100644 (file)
@@ -1,6 +1,7 @@
 
 #include "quakedef.h"
 #include "image.h"
+#include "jpeg.h"
 
 cvar_t r_max_size = {CVAR_SAVE, "r_max_size", "2048"};
 cvar_t r_max_scrapsize = {CVAR_SAVE, "r_max_scrapsize", "256"};
@@ -120,7 +121,7 @@ gltexture_t;
 
 typedef struct gltexturepool_s
 {
-       int sentinel;
+       unsigned int sentinel;
        struct gltextureimage_s *imagechain;
        struct gltexture_s *gltchain;
        struct gltexturepool_s *next;
@@ -222,20 +223,23 @@ void R_FreeTexture(rtexture_t *rt)
        // note: if freeing a fragment texture, this will not make the claimed
        // space available for new textures unless all other fragments in the
        // image are also freed
-       image = glt->image;
-       image->texturecount--;
-       if (image->texturecount < 1)
+       if (glt->image)
        {
-               for (gltimagepointer = &glt->pool->imagechain;*gltimagepointer && *gltimagepointer != image;gltimagepointer = &(*gltimagepointer)->imagechain);
-               if (*gltimagepointer == image)
-                       *gltimagepointer = image->imagechain;
-               else
-                       Host_Error("R_FreeTexture: image not linked in pool\n");
-               if (image->texnum)
-                       qglDeleteTextures(1, &image->texnum);
-               if (image->blockallocation)
-                       Mem_Free(image->blockallocation);
-               Mem_Free(image);
+               image = glt->image;
+               image->texturecount--;
+               if (image->texturecount < 1)
+               {
+                       for (gltimagepointer = &glt->pool->imagechain;*gltimagepointer && *gltimagepointer != image;gltimagepointer = &(*gltimagepointer)->imagechain);
+                       if (*gltimagepointer == image)
+                               *gltimagepointer = image->imagechain;
+                       else
+                               Host_Error("R_FreeTexture: image not linked in pool\n");
+                       if (image->texnum)
+                               qglDeleteTextures(1, &image->texnum);
+                       if (image->blockallocation)
+                               Mem_Free(image->blockallocation);
+                       Mem_Free(image);
+               }
        }
 
        if (glt->identifier)
@@ -473,11 +477,16 @@ static void r_textures_start(void)
        texturemempool = Mem_AllocPool("Texture Info");
        texturedatamempool = Mem_AllocPool("Texture Storage (not yet uploaded)");
        textureprocessingmempool = Mem_AllocPool("Texture Processing Buffers");
+
+       JPEG_OpenLibrary ();
 }
 
 static void r_textures_shutdown(void)
 {
        rtexturepool_t *temp;
+
+       JPEG_CloseLibrary ();
+
        while(gltexturepoolchain)
        {
                temp = (rtexturepool_t *) gltexturepoolchain;
@@ -554,8 +563,7 @@ static void GL_SetupTextureParameters(int flags, int texturetype)
        CHECKGLERROR
 
        qglTexParameteri(textureenum, GL_TEXTURE_WRAP_S, wrapmode);
-       if (gltexturetypedimensions[texturetype] >= 2)
-               qglTexParameteri(textureenum, GL_TEXTURE_WRAP_T, wrapmode);
+       qglTexParameteri(textureenum, GL_TEXTURE_WRAP_T, wrapmode);
        if (gltexturetypedimensions[texturetype] >= 3)
                qglTexParameteri(textureenum, GL_TEXTURE_WRAP_R, wrapmode);
 
@@ -621,7 +629,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->depth * glt->image->bytesperpixel);
+                       R_MakeResizeBufferBigger(glt->image->width * glt->image->height * glt->image->depth * glt->image->sides * glt->image->bytesperpixel);
                        Image_Copy8bitRGBA(prevbuffer, colorconvertbuffer, glt->width * glt->height * glt->depth, glt->palette);
                        prevbuffer = colorconvertbuffer;
                }
@@ -655,7 +663,7 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
        for (height = 1;height < glt->height;height <<= 1);
        for (depth  = 1;depth  < glt->depth ;depth  <<= 1);
 
-       R_MakeResizeBufferBigger(width * height * depth * glt->image->bytesperpixel);
+       R_MakeResizeBufferBigger(width * height * depth * glt->image->sides * glt->image->bytesperpixel);
 
        if (prevbuffer == NULL)
        {
@@ -671,29 +679,31 @@ 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
-                       Image_Copy8bitRGBA(prevbuffer, colorconvertbuffer, glt->width * glt->height * glt->depth, glt->palette);
+                       Image_Copy8bitRGBA(prevbuffer, colorconvertbuffer, glt->width * glt->height * glt->depth * glt->image->sides, glt->palette);
                        prevbuffer = colorconvertbuffer;
                }
+       }
+
+       // 3 and 4 are converted by the driver to it's preferred format for the current display mode
+       internalformat = 3;
+       if (glt->flags & TEXF_ALPHA)
+               internalformat = 4;
 
+       // cubemaps contain multiple images and thus get processed a bit differently
+       if (glt->image->texturetype != GLTEXTURETYPE_CUBEMAP)
+       {
                if (glt->width != width || glt->height != height || glt->depth != depth)
                {
                        Image_Resample(prevbuffer, glt->width, glt->height, glt->depth, resizebuffer, width, height, depth, glt->image->bytesperpixel, r_lerpimages.integer);
                        prevbuffer = resizebuffer;
                }
-
-               // apply picmip/max_size limitations
+               // picmip/max_size
                while (width > glt->image->width || height > glt->image->height || depth > glt->image->depth)
                {
                        Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, glt->image->width, glt->image->height, glt->image->depth, glt->image->bytesperpixel);
                        prevbuffer = resizebuffer;
                }
        }
-
-       // 3 and 4 are converted by the driver to it's preferred format for the current display mode
-       internalformat = 3;
-       if (glt->flags & TEXF_ALPHA)
-               internalformat = 4;
-
        mip = 0;
        switch(glt->image->texturetype)
        {
@@ -747,6 +757,18 @@ static void R_Upload(gltexture_t *glt, qbyte *data)
                {
                        prevbuffer = texturebuffer;
                        texturebuffer += width * height * depth * glt->textype->inputbytesperpixel;
+                       if (glt->width != width || glt->height != height || glt->depth != depth)
+                       {
+                               Image_Resample(prevbuffer, glt->width, glt->height, glt->depth, resizebuffer, width, height, depth, glt->image->bytesperpixel, r_lerpimages.integer);
+                               prevbuffer = resizebuffer;
+                       }
+                       // picmip/max_size
+                       while (width > glt->image->width || height > glt->image->height || depth > glt->image->depth)
+                       {
+                               Image_MipReduce(prevbuffer, resizebuffer, &width, &height, &depth, glt->image->width, glt->image->height, glt->image->depth, glt->image->bytesperpixel);
+                               prevbuffer = resizebuffer;
+                       }
+                       mip = 0;
                        qglTexImage2D(cubemapside[i], mip++, internalformat, width, height, 0, glt->image->glformat, GL_UNSIGNED_BYTE, prevbuffer);
                        CHECKGLERROR
                        if (glt->flags & TEXF_MIPMAP)
@@ -937,6 +959,8 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
 
        texinfo = R_GetTexTypeInfo(textype, flags);
        size = width * height * depth * sides * texinfo->inputbytesperpixel;
+       if (size < 1)
+               Sys_Error("R_LoadTexture: bogus texture size (%dx%dx%dx%dbppx%dsides = %d bytes)\n", width, height, depth, texinfo->inputbytesperpixel * 8, sides);
 
        // clear the alpha flag if the texture has no transparent pixels
        switch(textype)
@@ -1007,7 +1031,7 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
        {
                glt->inputtexels = Mem_Alloc(texturedatamempool, size);
                if (glt->inputtexels == NULL)
-                       Sys_Error("R_SetupTexture: out of memory\n");
+                       Sys_Error("R_LoadTexture: out of memory\n");
                memcpy(glt->inputtexels, data, size);
        }
        else