mesa: Pass GL context to _mesa_create_save_table
[mesa.git] / src / mesa / main / texcompress_s3tc.c
index 904aa457ecc9df210ac2bed9723596303b22169a..6476f118e64184fa1ca69df9f1af1102a0d5d994 100644 (file)
@@ -47,9 +47,6 @@
 #include "swrast/s_context.h"
 
 
-#if FEATURE_texture_s3tc
-
-
 #if defined(_WIN32) || defined(WIN32)
 #define DXTN_LIBNAME "dxtn.dll"
 #define RTLD_LAZY 0
@@ -60,7 +57,6 @@
 #define DXTN_LIBNAME "libtxc_dxtn.so"
 #endif
 
-#if FEATURE_EXT_texture_sRGB
 /**
  * Convert an 8-bit sRGB value from non-linear space to a
  * linear RGB value in [0, 1].
@@ -87,14 +83,13 @@ nonlinear_to_linear(GLubyte cs8)
    }
    return table[cs8];
 }
-#endif /* FEATURE_EXT_texture_sRGB */
 
 typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
 
-dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
-dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
-dxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
-dxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
+static dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
+static dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
+static dxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
+static dxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
 
 typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width,
                                       GLint height, const GLubyte *srcPixData,
@@ -165,15 +160,10 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
 {
    const GLubyte *pixels;
    GLubyte *dst;
-   const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
    const GLubyte *tempImage = NULL;
 
    ASSERT(dstFormat == MESA_FORMAT_RGB_DXT1 ||
           dstFormat == MESA_FORMAT_SRGB_DXT1);
-   ASSERT(dstXoffset % 4 == 0);
-   ASSERT(dstYoffset % 4 == 0);
-   ASSERT(dstZoffset % 4 == 0);
-   (void) dstZoffset;
 
    if (srcFormat != GL_RGB ||
        srcType != GL_UNSIGNED_BYTE ||
@@ -197,9 +187,7 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
                                      srcFormat, srcType, 0, 0);
    }
 
-   dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat,
-                                        texWidth, dstSlices[0]);
+   dst = dstSlices[0];
 
    if (ext_tx_compress_dxtn) {
       (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels,
@@ -210,8 +198,7 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
       _mesa_warning(ctx, "external dxt library not available: texstore_rgb_dxt1");
    }
 
-   if (tempImage)
-      free((void *) tempImage);
+   free((void *) tempImage);
 
    return GL_TRUE;
 }
@@ -225,15 +212,10 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
 {
    const GLubyte *pixels;
    GLubyte *dst;
-   const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
    const GLubyte *tempImage = NULL;
 
    ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1 ||
           dstFormat == MESA_FORMAT_SRGBA_DXT1);
-   ASSERT(dstXoffset % 4 == 0);
-   ASSERT(dstYoffset % 4 == 0);
-   ASSERT(dstZoffset % 4 == 0);
-   (void) dstZoffset;
 
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
@@ -257,9 +239,8 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
                                      srcFormat, srcType, 0, 0);
    }
 
-   dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat,
-                                        texWidth, dstSlices[0]);
+   dst = dstSlices[0];
+
    if (ext_tx_compress_dxtn) {
       (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
                               GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
@@ -269,8 +250,7 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
       _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt1");
    }
 
-   if (tempImage)
-      free((void*) tempImage);
+   free((void*) tempImage);
 
    return GL_TRUE;
 }
@@ -284,15 +264,10 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
 {
    const GLubyte *pixels;
    GLubyte *dst;
-   const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
    const GLubyte *tempImage = NULL;
 
    ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT3 ||
           dstFormat == MESA_FORMAT_SRGBA_DXT3);
-   ASSERT(dstXoffset % 4 == 0);
-   ASSERT(dstYoffset % 4 == 0);
-   ASSERT(dstZoffset % 4 == 0);
-   (void) dstZoffset;
 
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
@@ -315,9 +290,8 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
                                      srcFormat, srcType, 0, 0);
    }
 
-   dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat,
-                                        texWidth, dstSlices[0]);
+   dst = dstSlices[0];
+
    if (ext_tx_compress_dxtn) {
       (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
                               GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
@@ -327,8 +301,7 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
       _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt3");
    }
 
-   if (tempImage)
-      free((void *) tempImage);
+   free((void *) tempImage);
 
    return GL_TRUE;
 }
@@ -342,15 +315,10 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
 {
    const GLubyte *pixels;
    GLubyte *dst;
-   const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
    const GLubyte *tempImage = NULL;
 
    ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT5 ||
           dstFormat == MESA_FORMAT_SRGBA_DXT5);
-   ASSERT(dstXoffset % 4 == 0);
-   ASSERT(dstYoffset % 4 == 0);
-   ASSERT(dstZoffset % 4 == 0);
-   (void) dstZoffset;
 
    if (srcFormat != GL_RGBA ||
        srcType != GL_UNSIGNED_BYTE ||
@@ -373,9 +341,8 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
                                      srcFormat, srcType, 0, 0);
    }
 
-   dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat,
-                                        texWidth, dstSlices[0]);
+   dst = dstSlices[0];
+
    if (ext_tx_compress_dxtn) {
       (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
                               GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
@@ -385,21 +352,21 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
       _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt5");
    }
 
-   if (tempImage)
-      free((void *) tempImage);
+   free((void *) tempImage);
 
    return GL_TRUE;
 }
 
 
 static void
-fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
-                         GLint i, GLint j, GLint k, GLubyte *texel )
+fetch_texel_2d_rgb_dxt1(const struct swrast_texture_image *texImage,
+                        GLint i, GLint j, GLint k, GLubyte *texel)
 {
    (void) k;
    if (fetch_ext_rgb_dxt1) {
-      fetch_ext_rgb_dxt1(texImage->Base.RowStride,
-                         (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0;
+      fetch_ext_rgb_dxt1(texImage->RowStride,
+                         texImage->Map + sliceOffset, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -407,8 +374,8 @@ fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgb_dxt1(const struct swrast_texture_image *texImage,
-                                GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_rgb_dxt1(const struct swrast_texture_image *texImage,
+                           GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -421,13 +388,14 @@ _mesa_fetch_texel_2d_f_rgb_dxt1(const struct swrast_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
-                          GLint i, GLint j, GLint k, GLubyte *texel )
+fetch_texel_2d_rgba_dxt1(const struct swrast_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLubyte *texel)
 {
    (void) k;
    if (fetch_ext_rgba_dxt1) {
-      fetch_ext_rgba_dxt1(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0;
+      fetch_ext_rgba_dxt1(texImage->RowStride,
+                          texImage->Map + sliceOffset, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -435,8 +403,8 @@ fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt1(const struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_rgba_dxt1(const struct swrast_texture_image *texImage,
+                            GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -449,14 +417,14 @@ _mesa_fetch_texel_2d_f_rgba_dxt1(const struct swrast_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
-                          GLint i, GLint j, GLint k, GLubyte *texel )
+fetch_texel_2d_rgba_dxt3(const struct swrast_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLubyte *texel)
 {
    (void) k;
    if (fetch_ext_rgba_dxt3) {
-      fetch_ext_rgba_dxt3(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0;
+      fetch_ext_rgba_dxt3(texImage->RowStride,
+                          texImage->Map + sliceOffset, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
@@ -464,8 +432,8 @@ fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt3(const struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_rgba_dxt3(const struct swrast_texture_image *texImage,
+                            GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -478,14 +446,14 @@ _mesa_fetch_texel_2d_f_rgba_dxt3(const struct swrast_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
-                          GLint i, GLint j, GLint k, GLubyte *texel )
+fetch_texel_2d_rgba_dxt5(const struct swrast_texture_image *texImage,
+                         GLint i, GLint j, GLint k, GLubyte *texel)
 {
    (void) k;
    if (fetch_ext_rgba_dxt5) {
-      fetch_ext_rgba_dxt5(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0;
+      fetch_ext_rgba_dxt5(texImage->RowStride,
+                          texImage->Map + sliceOffset, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
@@ -493,8 +461,8 @@ fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt5(const struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_rgba_dxt5(const struct swrast_texture_image *texImage,
+                            GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -505,10 +473,9 @@ _mesa_fetch_texel_2d_f_rgba_dxt5(const struct swrast_texture_image *texImage,
    texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
 }
 
-#if FEATURE_EXT_texture_sRGB
 void
-_mesa_fetch_texel_2d_f_srgb_dxt1( const struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, GLfloat *texel )
+_mesa_fetch_texel_srgb_dxt1(const struct swrast_texture_image *texImage,
+                            GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -520,8 +487,8 @@ _mesa_fetch_texel_2d_f_srgb_dxt1( const struct swrast_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt1(const struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_srgba_dxt1(const struct swrast_texture_image *texImage,
+                             GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -533,8 +500,8 @@ _mesa_fetch_texel_2d_f_srgba_dxt1(const struct swrast_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt3(const struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_srgba_dxt3(const struct swrast_texture_image *texImage,
+                             GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -546,8 +513,8 @@ _mesa_fetch_texel_2d_f_srgba_dxt3(const struct swrast_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt5(const struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, GLfloat *texel)
+_mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage,
+                             GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
@@ -557,7 +524,3 @@ _mesa_fetch_texel_2d_f_srgba_dxt5(const struct swrast_texture_image *texImage,
    texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
    texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
 }
-#endif /* FEATURE_EXT_texture_sRGB */
-
-
-#endif /* FEATURE_texture_s3tc */