summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorAnuj Phogat <[email protected]>2012-10-10 13:46:20 -0700
committerIan Romanick <[email protected]>2012-12-07 16:29:48 -0800
commit75211f4367cab6477890111211d3437bf469670b (patch)
tree305fa1cdbcef5c7a741cf43d92fe005c0cff9c08 /src/mesa/main
parent7697f25667d13031a46d1c373ea53919c06c9df5 (diff)
mesa: Add decoding functions for GL_COMPRESSED_SIGNED_RG11_EAC
Data in GL_COMPRESSED_SIGNED_RG11_EAC format is decoded and stored in MESA_FORMAT_SIGNED_GR1616. Signed-off-by: Anuj Phogat <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/texcompress.c2
-rw-r--r--src/mesa/main/texcompress_etc.c87
-rw-r--r--src/mesa/main/texcompress_etc.h8
-rw-r--r--src/mesa/main/texstore.c2
4 files changed, 97 insertions, 2 deletions
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 38d31804487..b3fdfd76779 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -629,7 +629,7 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
fetch = _mesa_fetch_texel_2d_f_etc2_signed_r11_eac;
break;
case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
- /* fetch = _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac; -- not implemented yet */
+ fetch = _mesa_fetch_texel_2d_f_etc2_signed_rg11_eac;
break;
case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
/* fetch = _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1; -- not implemented yet */
diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
index 2ac140ec34f..d5a623a464a 100644
--- a/src/mesa/main/texcompress_etc.c
+++ b/src/mesa/main/texcompress_etc.c
@@ -32,6 +32,7 @@
* GL_COMPRESSED_R11_EAC
* GL_COMPRESSED_RG11_EAC
* GL_COMPRESSED_SIGNED_R11_EAC
+ * GL_COMPRESSED_SIGNED_RG11_EAC
*/
#include <stdbool.h>
@@ -894,6 +895,54 @@ etc2_unpack_signed_r11(uint8_t *dst_row,
}
}
+static void
+etc2_unpack_signed_rg11(uint8_t *dst_row,
+ unsigned dst_stride,
+ const uint8_t *src_row,
+ unsigned src_stride,
+ unsigned width,
+ unsigned height)
+{
+ /* If internalformat is COMPRESSED_SIGNED_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_signed_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_signed_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
@@ -952,6 +1001,14 @@ _mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS)
return GL_FALSE;
}
+GLboolean
+_mesa_texstore_etc2_signed_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)
@@ -1101,6 +1158,31 @@ _mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct swrast_texture_image *te
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;
+}
+
/**
* Decode texture data in any one of following formats:
* `MESA_FORMAT_ETC2_RGB8`
@@ -1110,6 +1192,7 @@ _mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct swrast_texture_image *te
* `MESA_FORMAT_ETC2_R11_EAC`
* `MESA_FORMAT_ETC2_RG11_EAC`
* `MESA_FORMAT_ETC2_SIGNED_R11_EAC`
+ * `MESA_FORMAT_ETC2_SIGNED_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.
@@ -1156,4 +1239,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
etc2_unpack_signed_r11(dst_row, dst_stride,
src_row, src_stride,
src_width, src_height);
+ else if (format == MESA_FORMAT_ETC2_SIGNED_RG11_EAC)
+ etc2_unpack_signed_rg11(dst_row, dst_stride,
+ src_row, src_stride,
+ src_width, src_height);
}
diff --git a/src/mesa/main/texcompress_etc.h b/src/mesa/main/texcompress_etc.h
index a67df2feba7..23ec1e3409d 100644
--- a/src/mesa/main/texcompress_etc.h
+++ b/src/mesa/main/texcompress_etc.h
@@ -55,6 +55,9 @@ _mesa_texstore_etc2_rg11_eac(TEXSTORE_PARAMS);
GLboolean
_mesa_texstore_etc2_signed_r11_eac(TEXSTORE_PARAMS);
+GLboolean
+_mesa_texstore_etc2_signed_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);
@@ -85,6 +88,11 @@ _mesa_fetch_texel_2d_f_etc2_signed_r11_eac(const struct
GLint i, GLint j,
GLint k, GLfloat *texel);
void
+_mesa_fetch_texel_2d_f_etc2_signed_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,
const uint8_t *src_row,
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 0d89c6aae04..9d63994111f 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4131,7 +4131,7 @@ _mesa_get_texstore_func(gl_format format)
table[MESA_FORMAT_ETC2_R11_EAC] = _mesa_texstore_etc2_r11_eac;
table[MESA_FORMAT_ETC2_RG11_EAC] = _mesa_texstore_etc2_rg11_eac;
table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = _mesa_texstore_etc2_signed_r11_eac;
- /* table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = _mesa_texstore_etc2_signed_rg11_eac; -- not implemented yet */
+ table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = _mesa_texstore_etc2_signed_rg11_eac;
/* table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
_mesa_texstore_etc2_rgb8_punchthrough_alpha1; -- not implemented yet */
/* table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =