mesa: move gl_texture_image::FetchTexel fields to swrast
[mesa.git] / src / mesa / main / texcompress_s3tc.c
index 12c2e903eb508c7a07d3e653d88ff3e24ac2e012..36a56447ea0819e24365485d1c9defcfe7998fb4 100644 (file)
 #include "glheader.h"
 #include "imports.h"
 #include "colormac.h"
-#include "context.h"
-#include "convolve.h"
 #include "dlopen.h"
 #include "image.h"
+#include "macros.h"
+#include "mfeatures.h"
+#include "mtypes.h"
 #include "texcompress.h"
 #include "texcompress_s3tc.h"
 #include "texstore.h"
+#include "swrast/s_context.h"
 
 
 #if FEATURE_texture_s3tc
@@ -78,7 +80,7 @@ nonlinear_to_linear(GLubyte cs8)
             table[i] = cs / 12.92f;
          }
          else {
-            table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
+            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
          }
       }
       tableReady = GL_TRUE;
@@ -105,7 +107,7 @@ static void *dxtlibhandle = NULL;
 
 
 void
-_mesa_init_texture_s3tc( GLcontext *ctx )
+_mesa_init_texture_s3tc( struct gl_context *ctx )
 {
    /* called during context initialization */
    ctx->Mesa_DXTn = GL_FALSE;
@@ -149,7 +151,6 @@ _mesa_init_texture_s3tc( GLcontext *ctx )
    }
    if (dxtlibhandle) {
       ctx->Mesa_DXTn = GL_TRUE;
-      _mesa_warning(ctx, "software DXTn compression/decompression available");
    }
 #else
    (void) ctx;
@@ -163,12 +164,12 @@ GLboolean
 _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
-   GLint srcRowStride;
    GLubyte *dst;
    const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == MESA_FORMAT_RGB_DXT1);
+   ASSERT(dstFormat == MESA_FORMAT_RGB_DXT1 ||
+          dstFormat == MESA_FORMAT_SRGB_DXT1);
    ASSERT(dstXoffset % 4 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset % 4 == 0);
@@ -188,15 +189,11 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
                                              srcPacking);
       if (!tempImage)
          return GL_FALSE; /* out of memory */
-      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
       pixels = tempImage;
-      srcRowStride = 3 * srcWidth;
       srcFormat = GL_RGB;
    }
    else {
       pixels = (const GLchan *) srcAddr;
-      srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
-                                            srcType) / sizeof(GLchan);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -226,12 +223,12 @@ GLboolean
 _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
-   GLint srcRowStride;
    GLubyte *dst;
    const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1);
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1 ||
+          dstFormat == MESA_FORMAT_SRGBA_DXT1);
    ASSERT(dstXoffset % 4 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset % 4 == 0);
@@ -251,15 +248,11 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
                                              srcPacking);
       if (!tempImage)
          return GL_FALSE; /* out of memory */
-      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
       pixels = tempImage;
-      srcRowStride = 4 * srcWidth;
       srcFormat = GL_RGBA;
    }
    else {
       pixels = (const GLchan *) srcAddr;
-      srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
-                                            srcType) / sizeof(GLchan);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -288,12 +281,12 @@ GLboolean
 _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
-   GLint srcRowStride;
    GLubyte *dst;
    const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT3);
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT3 ||
+          dstFormat == MESA_FORMAT_SRGBA_DXT3);
    ASSERT(dstXoffset % 4 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset % 4 == 0);
@@ -313,14 +306,10 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
                                              srcPacking);
       if (!tempImage)
          return GL_FALSE; /* out of memory */
-      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
       pixels = tempImage;
-      srcRowStride = 4 * srcWidth;
    }
    else {
       pixels = (const GLchan *) srcAddr;
-      srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
-                                            srcType) / sizeof(GLchan);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -349,12 +338,12 @@ GLboolean
 _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
-   GLint srcRowStride;
    GLubyte *dst;
    const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT5);
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT5 ||
+          dstFormat == MESA_FORMAT_SRGBA_DXT5);
    ASSERT(dstXoffset % 4 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset % 4 == 0);
@@ -374,14 +363,10 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
                                              srcPacking);
       if (!tempImage)
          return GL_FALSE; /* out of memory */
-      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
       pixels = tempImage;
-      srcRowStride = 4 * srcWidth;
    }
    else {
       pixels = (const GLchan *) srcAddr;
-      srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
-                                            srcType) / sizeof(GLchan);
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
@@ -404,14 +389,14 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
 
 
 static void
-fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage,
+fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
                          GLint i, GLint j, GLint k, GLchan *texel )
 {
    (void) k;
    if (fetch_ext_rgb_dxt1) {
       ASSERT (sizeof(GLchan) == sizeof(GLubyte));
-      fetch_ext_rgb_dxt1(texImage->RowStride,
-                         (GLubyte *)(texImage)->Data, i, j, texel);
+      fetch_ext_rgb_dxt1(texImage->Base.RowStride,
+                         (GLubyte *)(texImage)->Base.Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -419,7 +404,7 @@ fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgb_dxt1(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_rgb_dxt1(const struct swrast_texture_image *texImage,
                                 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -433,13 +418,13 @@ _mesa_fetch_texel_2d_f_rgb_dxt1(const struct gl_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage,
+fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
                           GLint i, GLint j, GLint k, GLchan *texel )
 {
    (void) k;
    if (fetch_ext_rgba_dxt1) {
-      fetch_ext_rgba_dxt1(texImage->RowStride,
-                          (GLubyte *)(texImage)->Data, i, j, texel);
+      fetch_ext_rgba_dxt1(texImage->Base.RowStride,
+                          (GLubyte *)(texImage)->Base.Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -447,7 +432,7 @@ fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt1(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_rgba_dxt1(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -461,13 +446,14 @@ _mesa_fetch_texel_2d_f_rgba_dxt1(const struct gl_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage,
+fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
                           GLint i, GLint j, GLint k, GLchan *texel )
 {
    (void) k;
    if (fetch_ext_rgba_dxt3) {
       ASSERT (sizeof(GLchan) == sizeof(GLubyte));
-      fetch_ext_rgba_dxt3(texImage->RowStride, (GLubyte *)(texImage)->Data,
+      fetch_ext_rgba_dxt3(texImage->Base.RowStride,
+                          (GLubyte *)(texImage)->Base.Data,
                           i, j, texel);
    }
    else
@@ -476,7 +462,7 @@ fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt3(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_rgba_dxt3(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -490,12 +476,13 @@ _mesa_fetch_texel_2d_f_rgba_dxt3(const struct gl_texture_image *texImage,
 
 
 static void
-fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage,
+fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
                           GLint i, GLint j, GLint k, GLchan *texel )
 {
    (void) k;
    if (fetch_ext_rgba_dxt5) {
-      fetch_ext_rgba_dxt5(texImage->RowStride, (GLubyte *)(texImage)->Data,
+      fetch_ext_rgba_dxt5(texImage->Base.RowStride,
+                          (GLubyte *)(texImage)->Base.Data,
                           i, j, texel);
    }
    else
@@ -504,7 +491,7 @@ fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage,
 
 
 void
-_mesa_fetch_texel_2d_f_rgba_dxt5(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_rgba_dxt5(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -518,7 +505,7 @@ _mesa_fetch_texel_2d_f_rgba_dxt5(const struct gl_texture_image *texImage,
 
 #if FEATURE_EXT_texture_sRGB
 void
-_mesa_fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_srgb_dxt1( const struct swrast_texture_image *texImage,
                                   GLint i, GLint j, GLint k, GLfloat *texel )
 {
    /* just sample as GLchan and convert to float here */
@@ -531,7 +518,7 @@ _mesa_fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt1(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_srgba_dxt1(const struct swrast_texture_image *texImage,
                                   GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -544,7 +531,7 @@ _mesa_fetch_texel_2d_f_srgba_dxt1(const struct gl_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt3(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_srgba_dxt3(const struct swrast_texture_image *texImage,
                                   GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */
@@ -557,7 +544,7 @@ _mesa_fetch_texel_2d_f_srgba_dxt3(const struct gl_texture_image *texImage,
 }
 
 void
-_mesa_fetch_texel_2d_f_srgba_dxt5(const struct gl_texture_image *texImage,
+_mesa_fetch_texel_2d_f_srgba_dxt5(const struct swrast_texture_image *texImage,
                                   GLint i, GLint j, GLint k, GLfloat *texel)
 {
    /* just sample as GLchan and convert to float here */