]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_textures.c
very basic softrast support in vid_glx.c. VERY SLOW, as it doesn't use an Xtension...
[xonotic/darkplaces.git] / gl_textures.c
index 0f08b5f9ea3df9047df57644a6861c286cb30425..d7729d55fcf0e626d1376b51f85feafc703b8bcf 100644 (file)
@@ -93,6 +93,8 @@ static textypeinfo_t textype_dxt1a                  = {TEXTYPE_DXT1A      , 4, 0
 static textypeinfo_t textype_dxt3                   = {TEXTYPE_DXT3       , 4, 0, 1.0f, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0                 , 0                };
 static textypeinfo_t textype_dxt5                   = {TEXTYPE_DXT5       , 4, 0, 1.0f, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0                 , 0                };
 static textypeinfo_t textype_colorbuffer            = {TEXTYPE_COLORBUFFER, 4, 4, 4.0f, GL_RGBA                         , GL_BGRA           , GL_UNSIGNED_BYTE };
+static textypeinfo_t textype_colorbuffer16f         = {TEXTYPE_COLORBUFFER16F,8,8,8.0f, GL_RGBA16F_ARB                  , GL_RGBA           , GL_FLOAT         };
+static textypeinfo_t textype_colorbuffer32f         = {TEXTYPE_COLORBUFFER32F,16,16,16.0f,GL_RGBA32F_ARB                , GL_RGBA           , GL_FLOAT         };
 
 
 typedef enum gltexturetype_e
@@ -236,6 +238,10 @@ static textypeinfo_t *R_GetTexTypeInfo(textype_t textype, int flags)
                return (flags & TEXF_LOWPRECISION) ? &textype_shadowmap16 : &textype_shadowmap24;
        case TEXTYPE_COLORBUFFER:
                return &textype_colorbuffer;
+       case TEXTYPE_COLORBUFFER16F:
+               return &textype_colorbuffer16f;
+       case TEXTYPE_COLORBUFFER32F:
+               return &textype_colorbuffer32f;
        default:
                Host_Error("R_GetTexTypeInfo: unknown texture format");
                break;
@@ -297,6 +303,8 @@ void R_FreeTexture(rtexture_t *rt)
        else
                Host_Error("R_FreeTexture: texture \"%s\" not linked in pool", glt->identifier);
 
+       R_Mesh_ClearBindingsForTexture(glt->texnum);
+
        switch(vid.renderpath)
        {
        case RENDERPATH_GL11:
@@ -1142,42 +1150,43 @@ static void R_UploadFullTexture(gltexture_t *glt, const unsigned char *data)
                width = glt->tilewidth;
                height = glt->tileheight;
                depth = glt->tiledepth;
-               memset(resizebuffer, 0, width * height * depth * glt->sides * glt->bytesperpixel);
-               prevbuffer = resizebuffer;
-       }
-       else 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, glt->inputwidth * glt->inputheight * glt->inputdepth * glt->sides, glt->palette);
-               prevbuffer = colorconvertbuffer;
+//             memset(resizebuffer, 0, width * height * depth * glt->sides * glt->bytesperpixel);
+//             prevbuffer = resizebuffer;
        }
-
-       if (glt->flags & TEXF_RGBMULTIPLYBYALPHA)
+       else
        {
-               // multiply RGB channels by A channel before uploading
-               int alpha;
-               for (i = 0;i < glt->inputwidth*glt->inputheight*glt->inputdepth*4;i += 4)
+               if (glt->textype->textype == TEXTYPE_PALETTE)
                {
-                       alpha = prevbuffer[i+3];
-                       colorconvertbuffer[i] = (prevbuffer[i] * alpha) >> 8;
-                       colorconvertbuffer[i+1] = (prevbuffer[i+1] * alpha) >> 8;
-                       colorconvertbuffer[i+2] = (prevbuffer[i+2] * alpha) >> 8;
-                       colorconvertbuffer[i+3] = alpha;
+                       // promote paletted to BGRA, so we only have to worry about BGRA in the rest of this code
+                       Image_Copy8bitBGRA(prevbuffer, colorconvertbuffer, glt->inputwidth * glt->inputheight * glt->inputdepth * glt->sides, glt->palette);
+                       prevbuffer = colorconvertbuffer;
+               }
+               if (glt->flags & TEXF_RGBMULTIPLYBYALPHA)
+               {
+                       // multiply RGB channels by A channel before uploading
+                       int alpha;
+                       for (i = 0;i < glt->inputwidth*glt->inputheight*glt->inputdepth*4;i += 4)
+                       {
+                               alpha = prevbuffer[i+3];
+                               colorconvertbuffer[i] = (prevbuffer[i] * alpha) >> 8;
+                               colorconvertbuffer[i+1] = (prevbuffer[i+1] * alpha) >> 8;
+                               colorconvertbuffer[i+2] = (prevbuffer[i+2] * alpha) >> 8;
+                               colorconvertbuffer[i+3] = alpha;
+                       }
+                       prevbuffer = colorconvertbuffer;
+               }
+               // scale up to a power of 2 size (if appropriate)
+               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;
+               }
+               // apply mipmap reduction algorithm to get down to 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;
                }
-               prevbuffer = colorconvertbuffer;
-       }
-
-       // scale up to a power of 2 size (if appropriate)
-       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;
-       }
-       // apply mipmap reduction algorithm to get down to 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;
        }
 
        // do the appropriate upload type...
@@ -1560,6 +1569,8 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                flags |= TEXF_ALPHA;
                break;
        case TEXTYPE_COLORBUFFER:
+       case TEXTYPE_COLORBUFFER16F:
+       case TEXTYPE_COLORBUFFER32F:
                flags |= TEXF_ALPHA;
                break;
        default:
@@ -1631,7 +1642,9 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                        case TEXTYPE_PALETTE: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
                        case TEXTYPE_RGBA: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8B8G8R8 : D3DFMT_X8B8G8R8;break;
                        case TEXTYPE_BGRA: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
-                       case TEXTYPE_COLORBUFFER: d3dformat = (flags & TEXF_ALPHA) ? D3DFMT_A8R8G8B8 : D3DFMT_X8R8G8B8;break;
+                       case TEXTYPE_COLORBUFFER: d3dformat = D3DFMT_A8R8G8B8;break;
+                       case TEXTYPE_COLORBUFFER16F: d3dformat = D3DFMT_A16B16G16R16F;break;
+                       case TEXTYPE_COLORBUFFER32F: d3dformat = D3DFMT_A32B32G32R32F;break;
                        case TEXTYPE_SHADOWMAP: d3dformat = D3DFMT_D16;d3dusage = D3DUSAGE_DEPTHSTENCIL;break; // note: can not use D3DUSAGE_RENDERTARGET here
                        case TEXTYPE_ALPHA: d3dformat = D3DFMT_A8;break;
                        default: d3dformat = D3DFMT_A8R8G8B8;Sys_Error("R_LoadTexture: unsupported texture type %i when picking D3DFMT", (int)textype);break;
@@ -1678,6 +1691,8 @@ static rtexture_t *R_SetupTexture(rtexturepool_t *rtexturepool, const char *iden
                        case TEXTYPE_RGBA: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA8;break;
                        case TEXTYPE_BGRA: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8;break;
                        case TEXTYPE_COLORBUFFER: tflags = DPSOFTRAST_TEXTURE_FORMAT_BGRA8;break;
+                       case TEXTYPE_COLORBUFFER16F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA16F;break;
+                       case TEXTYPE_COLORBUFFER32F: tflags = DPSOFTRAST_TEXTURE_FORMAT_RGBA32F;break;
                        case TEXTYPE_SHADOWMAP: tflags = DPSOFTRAST_TEXTURE_FORMAT_DEPTH;break;
                        case TEXTYPE_ALPHA: tflags = DPSOFTRAST_TEXTURE_FORMAT_ALPHA8;break;
                        default: Sys_Error("R_LoadTexture: unsupported texture type %i when picking DPSOFTRAST_TEXTURE_FLAGS", (int)textype);