mesa: Add decoding functions for GL_COMPRESSED_RG11_EAC
authorAnuj Phogat <anuj.phogat@gmail.com>
Tue, 13 Nov 2012 00:32:08 +0000 (16:32 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Sat, 8 Dec 2012 00:29:48 +0000 (16:29 -0800)
Data in GL_COMPRESSED_RG11_EAC format is decoded and stored in
MESA_FORMAT_RG1616.

Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/main/texcompress.c
src/mesa/main/texcompress_etc.c
src/mesa/main/texcompress_etc.h
src/mesa/main/texstore.c
src/mesa/swrast/s_texfetch.c

index 3d34d9b808b3c4b3e551a6e0236a12561b725f41..f9148d4260fbcb0d36b9d37cba2eeb5b0e55e91a 100644 (file)
@@ -623,7 +623,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
       fetch = _mesa_fetch_texel_2d_f_etc2_r11_eac;
       break;
    case MESA_FORMAT_ETC2_RG11_EAC:
-      /* fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac; -- not implemented yet */
+      fetch = _mesa_fetch_texel_2d_f_etc2_rg11_eac;
       break;
    case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
       /* fetch = _mesa_fetch_texel_2d_f_etc2_signed_r11_eac; -- not implemented yet */
index 7137eca909d68b5b74276795f582ffdf53e470c5..78af13a27c83d47b11d6bfbe5191de796ac83d2a 100644 (file)
@@ -30,6 +30,7 @@
  * GL_COMPRESSED_RGBA8_ETC2_EAC
  * GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
  * GL_COMPRESSED_R11_EAC
+ * GL_COMPRESSED_RG11_EAC
  */
 
 #include <stdbool.h>
@@ -763,6 +764,54 @@ etc2_unpack_r11(uint8_t *dst_row,
     }
 }
 
+static void
+etc2_unpack_rg11(uint8_t *dst_row,
+                 unsigned dst_stride,
+                 const uint8_t *src_row,
+                 unsigned src_stride,
+                 unsigned width,
+                 unsigned height)
+{
+   /* If internalformat is COMPRESSED_RG11_EAC, each 4 × 4 block of
+      RG color information is compressed to 128 bits.
+   */
+   const unsigned bw = 4, bh = 4, bs = 16, comps = 2, comp_size = 2;
+   struct etc2_block block;
+   unsigned x, y, i, j;
+
+   for (y = 0; y < height; y += bh) {
+      const uint8_t *src = src_row;
+
+      for (x = 0; x < width; x+= bw) {
+         /* red component */
+         etc2_r11_parse_block(&block, src);
+
+         for (j = 0; j < bh; j++) {
+            uint8_t *dst = dst_row + (y + j) * dst_stride +
+                           x * comps * comp_size;
+            for (i = 0; i < bw; i++) {
+               etc2_r11_fetch_texel(&block, i, j, dst);
+               dst += comps * comp_size;
+            }
+         }
+         /* green component */
+         etc2_r11_parse_block(&block, src + 8);
+
+         for (j = 0; j < bh; j++) {
+            uint8_t *dst = dst_row + (y + j) * dst_stride +
+                           x * comps * comp_size;
+            for (i = 0; i < bw; i++) {
+               etc2_r11_fetch_texel(&block, i, j, dst + comp_size);
+               dst += comps * comp_size;
+            }
+         }
+         src += bs;
+       }
+
+      src_row += src_stride;
+    }
+}
+
 /* ETC2 texture formats are valid in glCompressedTexImage2D and
  * glCompressedTexSubImage2D functions */
 GLboolean
@@ -805,6 +854,14 @@ _mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS)
    return GL_FALSE;
 }
 
+GLboolean
+_mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS)
+{
+   ASSERT(0);
+
+   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)
@@ -907,6 +964,33 @@ _mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
    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;
+}
+
 /**
  * Decode texture data in any one of following formats:
  * `MESA_FORMAT_ETC2_RGB8`
@@ -914,6 +998,7 @@ _mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
  * `MESA_FORMAT_ETC2_RGBA8_EAC`
  * `MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC`
  * `MESA_FORMAT_ETC2_R11_EAC`
+ * `MESA_FORMAT_ETC2_RG11_EAC`
  *
  * The size of the source data must be a multiple of the ETC2 block size
  * even if the texture image's dimensions are not aligned to 4.
@@ -952,4 +1037,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
       etc2_unpack_r11(dst_row, dst_stride,
                       src_row, src_stride,
                       src_width, src_height);
+   else if (format == MESA_FORMAT_ETC2_RG11_EAC)
+      etc2_unpack_rg11(dst_row, dst_stride,
+                       src_row, src_stride,
+                       src_width, src_height);
 }
index 85c474c0186de78ed3861ee9ccc2c2742e6eada9..36070a828af08dac4470ece966ae7401831881a4 100644 (file)
@@ -49,6 +49,9 @@ _mesa_texstore_etc2_srgb8_alpha8_eac(TEXSTORE_PARAMS);
 GLboolean
 _mesa_texstore_etc2_r11_eac(TEXSTORE_PARAMS);
 
+GLboolean
+_mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS);
+
 void
 _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel);
@@ -70,7 +73,9 @@ _mesa_fetch_texel_2d_f_etc2_srgb8_alpha8_eac(const struct
 void
 _mesa_fetch_texel_2d_f_etc2_r11_eac(const struct swrast_texture_image *texImage,
                                     GLint i, GLint j, GLint k, GLfloat *texel);
-
+void
+_mesa_fetch_texel_2d_f_etc2_rg11_eac(const struct swrast_texture_image *texImage,
+                                     GLint i, GLint j, GLint k, GLfloat *texel);
 void
 _mesa_etc1_unpack_rgba8888(uint8_t *dst_row,
                            unsigned dst_stride,
index 6da9473d699ffce28c750ffe6e8e8c6974b8daa2..4e6003013d5b2fe8f8b2add745cf322fa12a65ae 100644 (file)
@@ -4129,7 +4129,7 @@ _mesa_get_texstore_func(gl_format format)
       table[MESA_FORMAT_ETC2_RGBA8_EAC] = _mesa_texstore_etc2_rgba8_eac;
       table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = _mesa_texstore_etc2_srgb8_alpha8_eac;
       table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac;
-      /* table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac; -- not implemented yet */
+      table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac;
       /* table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = _mesa_texstore_etc2_signed_r11_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = _mesa_texstore_etc2_signed_rg11_eac; -- not implemented yet */
       /* table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
index 2d29b67ea372e13c5e64cdac1b7bb49479fd71e7..4536513fa40a8fc8f4801fb92b85f37e0b7c7ccd 100644 (file)
@@ -1061,7 +1061,7 @@ texfetch_funcs[] =
    {
       MESA_FORMAT_ETC2_RG11_EAC,
       NULL,
-      NULL /* _mesa_fetch_texel_2d_f_etc2_rg11_eac -- not implemented yet */,
+      _mesa_fetch_texel_2d_f_etc2_rg11_eac,
       NULL
    },
    {