mesa: Allow setting GL_TEXTURE_MAX_LEVEL to 0 with GL_TEXTURE_RECTANGLE.
[mesa.git] / src / mesa / main / texcompress_etc.c
index c8bf6eab44fed33cb066f5b940db901f7360f556..cbda689409e2fd5f31ddd84d46ff79de34956416 100644 (file)
  */
 
 #include <stdbool.h>
-#include "mfeatures.h"
 #include "texcompress.h"
 #include "texcompress_etc.h"
 #include "texstore.h"
 #include "macros.h"
-#include "swrast/s_context.h"
 #include "format_unpack.h"
 
+
 struct etc2_block {
    int distance;
    uint64_t pixel_indices[2];
@@ -113,25 +112,6 @@ _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS)
    return GL_FALSE;
 }
 
-void
-_mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc1_block block;
-   GLubyte dst[3];
-   const GLubyte *src;
-
-   src = (const GLubyte *) texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc1_parse_block(&block, src);
-   etc1_fetch_texel(&block, i % 4, j % 4, dst);
-
-   texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]);
-   texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]);
-   texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]);
-   texel[ACOMP] = 1.0f;
-}
 
 /**
  * Decode texture data in format `MESA_FORMAT_ETC1_RGB8` to
@@ -231,7 +211,7 @@ etc2_base_color1_h_mode(const uint8_t *in, GLuint index)
       break;
    }
    return ((x << 4) | (x & 0xf));
- }
+}
 
 static uint8_t
 etc2_base_color2_h_mode(const uint8_t *in, GLuint index)
@@ -253,7 +233,7 @@ etc2_base_color2_h_mode(const uint8_t *in, GLuint index)
       break;
    }
    return ((x << 4) | (x & 0xf));
- }
+}
 
 static uint8_t
 etc2_base_color_o_planar(const uint8_t *in, GLuint index)
@@ -449,8 +429,7 @@ etc2_rgb8_parse_block(struct etc2_block *block,
       block->is_planar_mode = true;
 
       /* opaque bit must be set in planar mode */
-      if (!block->opaque)
-         block->opaque = true;
+      block->opaque = true;
 
       for (i = 0; i < 3; i++) {
          block->base_colors[0][i] = etc2_base_color_o_planar(src, i);
@@ -468,7 +447,7 @@ etc2_rgb8_parse_block(struct etc2_block *block,
           */
          block->base_colors[0][i] = etc1_base_color_diff_hi(src[i]);
          block->base_colors[1][i] = etc1_base_color_diff_lo(src[i]);
-     }
+      }
    }
 
    if (block->is_ind_mode || block->is_diff_mode) {
@@ -746,7 +725,7 @@ etc2_unpack_srgb8(uint8_t *dst_row,
             for (i = 0; i < bw; i++) {
                etc2_rgb8_fetch_texel(&block, i, j, dst,
                                      false /* punchthrough_alpha */);
-               /* Convert to MESA_FORMAT_SARGB8 */
+               /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
                tmp = dst[0];
                dst[0] = dst[2];
                dst[2] = tmp;
@@ -756,10 +735,10 @@ etc2_unpack_srgb8(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -792,10 +771,10 @@ etc2_unpack_rgba8(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -826,7 +805,7 @@ etc2_unpack_srgb8_alpha8(uint8_t *dst_row,
             for (i = 0; i < bw; i++) {
                etc2_rgba8_fetch_texel(&block, i, j, dst);
 
-               /* Convert to MESA_FORMAT_SARGB8 */
+               /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
                tmp = dst[0];
                dst[0] = dst[2];
                dst[2] = tmp;
@@ -836,10 +815,10 @@ etc2_unpack_srgb8_alpha8(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -871,10 +850,10 @@ etc2_unpack_r11(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -919,10 +898,10 @@ etc2_unpack_rg11(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -955,10 +934,10 @@ etc2_unpack_signed_r11(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -1003,10 +982,10 @@ etc2_unpack_signed_rg11(uint8_t *dst_row,
             }
          }
          src += bs;
-       }
+      }
 
       src_row += src_stride;
-    }
+   }
 }
 
 static void
@@ -1067,7 +1046,7 @@ etc2_unpack_srgb8_punchthrough_alpha1(uint8_t *dst_row,
             for (i = 0; i < bw; i++) {
                etc2_rgb8_fetch_texel(&block, i, j, dst,
                                      true /* punchthrough_alpha */);
-               /* Convert to MESA_FORMAT_SARGB8 */
+               /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
                tmp = dst[0];
                dst[0] = dst[2];
                dst[2] = tmp;
@@ -1166,229 +1145,6 @@ _mesa_texstore_etc2_srgb8_punchthrough_alpha1(TEXSTORE_PARAMS)
    return GL_FALSE;
 }
 
-void
-_mesa_fetch_texel_2d_f_etc2_rgb8(const struct swrast_texture_image *texImage,
-                                 GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[3];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_rgb8_parse_block(&block, src,
-                         false /* punchthrough_alpha */);
-   etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
-                         false /* punchthrough_alpha */);
-
-   texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]);
-   texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]);
-   texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]);
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_srgb8(const struct swrast_texture_image *texImage,
-                                  GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[3];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_rgb8_parse_block(&block, src,
-                         false /* punchthrough_alpha */);
-   etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
-                         false /* punchthrough_alpha */);
-
-   texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
-   texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
-   texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_rgba8_eac(const struct swrast_texture_image *texImage,
-                                      GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[4];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16;
-
-   etc2_rgba8_parse_block(&block, src);
-   etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst);
-
-   texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]);
-   texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]);
-   texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]);
-   texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct
-                                             swrast_texture_image *texImage,
-                                             GLint i, GLint j,
-                                             GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[4];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16;
-
-   etc2_rgba8_parse_block(&block, src);
-   etc2_rgba8_fetch_texel(&block, i % 4, j % 4, dst);
-
-   texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
-   texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
-   texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
-   texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
-                                    GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   GLushort dst;
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_r11_parse_block(&block, src);
-   etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)&dst);
-
-   texel[RCOMP] = USHORT_TO_FLOAT(dst);
-   texel[GCOMP] = 0.0f;
-   texel[BCOMP] = 0.0f;
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct
-                                     swrast_texture_image *texImage,
-                                     GLint i, GLint j,
-                                     GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   GLushort dst[2];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16;
-
-   /* red component */
-   etc2_r11_parse_block(&block, src);
-   etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)dst);
-
-   /* green component */
-   etc2_r11_parse_block(&block, src + 8);
-   etc2_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)(dst + 1));
-
-   texel[RCOMP] = USHORT_TO_FLOAT(dst[0]);
-   texel[GCOMP] = USHORT_TO_FLOAT(dst[1]);
-   texel[BCOMP] = 0.0f;
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct swrast_texture_image *texImage,
-                                           GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   GLushort dst;
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_r11_parse_block(&block, src);
-   etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)&dst);
-
-   texel[RCOMP] = SHORT_TO_FLOAT(dst);
-   texel[GCOMP] = 0.0f;
-   texel[BCOMP] = 0.0f;
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_signed_rg11_eac(const struct swrast_texture_image *texImage,
-                                            GLint i, GLint j, GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   GLushort dst[2];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 16;
-
-   /* red component */
-   etc2_r11_parse_block(&block, src);
-   etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)dst);
-
-   /* green component */
-   etc2_r11_parse_block(&block, src + 8);
-   etc2_signed_r11_fetch_texel(&block, i % 4, j % 4, (uint8_t *)(dst + 1));
-
-   texel[RCOMP] = SHORT_TO_FLOAT(dst[0]);
-   texel[GCOMP] = SHORT_TO_FLOAT(dst[1]);
-   texel[BCOMP] = 0.0f;
-   texel[ACOMP] = 1.0f;
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1(
-   const struct swrast_texture_image *texImage,
-   GLint i, GLint j,
-   GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[4];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_rgb8_parse_block(&block, src,
-                         true /* punchthrough alpha */);
-   etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
-                         true /* punchthrough alpha */);
-   texel[RCOMP] = UBYTE_TO_FLOAT(dst[0]);
-   texel[GCOMP] = UBYTE_TO_FLOAT(dst[1]);
-   texel[BCOMP] = UBYTE_TO_FLOAT(dst[2]);
-   texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
-}
-
-void
-_mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1(
-   const struct swrast_texture_image *texImage,
-   GLint i, GLint j,
-   GLint k, GLfloat *texel)
-{
-   struct etc2_block block;
-   uint8_t dst[4];
-   const uint8_t *src;
-
-   src = texImage->Map +
-      (((texImage->RowStride + 3) / 4) * (j / 4) + (i / 4)) * 8;
-
-   etc2_rgb8_parse_block(&block, src,
-                         true /* punchthrough alpha */);
-   etc2_rgb8_fetch_texel(&block, i % 4, j % 4, dst,
-                         true /* punchthrough alpha */);
-   texel[RCOMP] = _mesa_nonlinear_to_linear(dst[0]);
-   texel[GCOMP] = _mesa_nonlinear_to_linear(dst[1]);
-   texel[BCOMP] = _mesa_nonlinear_to_linear(dst[2]);
-   texel[ACOMP] = UBYTE_TO_FLOAT(dst[3]);
-}
 
 /**
  * Decode texture data in any one of following formats:
@@ -1418,7 +1174,7 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
                          unsigned src_stride,
                          unsigned src_width,
                          unsigned src_height,
-                         gl_format format)
+                         mesa_format format)
 {
    if (format == MESA_FORMAT_ETC2_RGB8)
       etc2_unpack_rgb8(dst_row, dst_stride,
@@ -1465,8 +1221,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
 
 
 static void
-fetch_etc1_rgb8(const GLubyte *map, const GLuint imageOffsets[],
-                GLint rowStride, GLint i, GLint j, GLint k,
+fetch_etc1_rgb8(const GLubyte *map,
+                GLint rowStride, GLint i, GLint j,
                 GLfloat *texel)
 {
    struct etc1_block block;
@@ -1486,9 +1242,8 @@ fetch_etc1_rgb8(const GLubyte *map, const GLuint imageOffsets[],
 
 
 static void
-fetch_etc2_rgb8(const GLubyte *map, const GLuint imageOffsets[],
-                GLint rowStride, GLint i, GLint j, GLint k,
-                GLfloat *texel)
+fetch_etc2_rgb8(const GLubyte *map,
+                GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    uint8_t dst[3];
@@ -1508,9 +1263,8 @@ fetch_etc2_rgb8(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_srgb8(const GLubyte *map, const GLuint imageOffsets[],
-                 GLint rowStride, GLint i, GLint j, GLint k,
-                 GLfloat *texel)
+fetch_etc2_srgb8(const GLubyte *map,
+                 GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    uint8_t dst[3];
@@ -1530,9 +1284,8 @@ fetch_etc2_srgb8(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_rgba8_eac(const GLubyte *map, const GLuint imageOffsets[],
-                     GLint rowStride, GLint i, GLint j, GLint k,
-                     GLfloat *texel)
+fetch_etc2_rgba8_eac(const GLubyte *map,
+                     GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    uint8_t dst[4];
@@ -1550,9 +1303,8 @@ fetch_etc2_rgba8_eac(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_srgb8_alpha8_eac(const GLubyte *map, const GLuint imageOffsets[],
-                            GLint rowStride, GLint i, GLint j, GLint k,
-                            GLfloat *texel)
+fetch_etc2_srgb8_alpha8_eac(const GLubyte *map,
+                            GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    uint8_t dst[4];
@@ -1570,9 +1322,8 @@ fetch_etc2_srgb8_alpha8_eac(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
-                   GLint rowStride, GLint i, GLint j, GLint k,
-                   GLfloat *texel)
+fetch_etc2_r11_eac(const GLubyte *map,
+                   GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    GLushort dst;
@@ -1590,9 +1341,8 @@ fetch_etc2_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
-                    GLint rowStride, GLint i, GLint j, GLint k,
-                    GLfloat *texel)
+fetch_etc2_rg11_eac(const GLubyte *map,
+                    GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    GLushort dst[2];
@@ -1615,9 +1365,8 @@ fetch_etc2_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_signed_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
-                          GLint rowStride, GLint i, GLint j, GLint k,
-                          GLfloat *texel)
+fetch_etc2_signed_r11_eac(const GLubyte *map,
+                          GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    GLushort dst;
@@ -1635,9 +1384,8 @@ fetch_etc2_signed_r11_eac(const GLubyte *map, const GLuint imageOffsets[],
 }
 
 static void
-fetch_etc2_signed_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
-                           GLint rowStride, GLint i, GLint j, GLint k,
-                           GLfloat *texel)
+fetch_etc2_signed_rg11_eac(const GLubyte *map,
+                           GLint rowStride, GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    GLushort dst[2];
@@ -1661,8 +1409,7 @@ fetch_etc2_signed_rg11_eac(const GLubyte *map, const GLuint imageOffsets[],
 
 static void
 fetch_etc2_rgb8_punchthrough_alpha1(const GLubyte *map,
-                                    const GLuint imageOffsets[],
-                                    GLint rowStride, GLint i, GLint j, GLint k,
+                                    GLint rowStride, GLint i, GLint j,
                                     GLfloat *texel)
 {
    struct etc2_block block;
@@ -1683,10 +1430,8 @@ fetch_etc2_rgb8_punchthrough_alpha1(const GLubyte *map,
 
 static void
 fetch_etc2_srgb8_punchthrough_alpha1(const GLubyte *map,
-                                     const GLuint imageOffsets[],
                                      GLint rowStride,
-                                     GLint i, GLint j, GLint k,
-                                     GLfloat *texel)
+                                     GLint i, GLint j, GLfloat *texel)
 {
    struct etc2_block block;
    uint8_t dst[4];
@@ -1706,7 +1451,7 @@ fetch_etc2_srgb8_punchthrough_alpha1(const GLubyte *map,
 
 
 compressed_fetch_func
-_mesa_get_etc_fetch_func(gl_format format)
+_mesa_get_etc_fetch_func(mesa_format format)
 {
    switch (format) {
    case MESA_FORMAT_ETC1_RGB8: