diff options
author | Anuj Phogat <anuj.phogat@gmail.com> | 2012-10-23 12:22:20 -0700 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2012-12-07 16:29:49 -0800 |
commit | e06dcbfdc2c90b402cec257fd5e2fc843a7f708f (patch) | |
tree | 0f26df98d0305bfaf459425651d03a3ebdccd051 | |
parent | 883efbf6daa02cfe8a5ce78ed87aaa06bec7c995 (diff) |
mesa: Add decoding functions for GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
Data in GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 format is decoded and stored
in MESA_FORMAT_SARGB.
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r-- | src/mesa/main/texcompress.c | 2 | ||||
-rw-r--r-- | src/mesa/main/texcompress_etc.c | 78 | ||||
-rw-r--r-- | src/mesa/main/texcompress_etc.h | 8 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 4 | ||||
-rw-r--r-- | src/mesa/swrast/s_texfetch.c | 2 |
5 files changed, 90 insertions, 4 deletions
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c index c05b89124d2..372a483faaa 100644 --- a/src/mesa/main/texcompress.c +++ b/src/mesa/main/texcompress.c @@ -637,3 +637,3 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height, case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: - /* fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1; -- not implemented yet */ + fetch = _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1; break; diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c index 7c8287bfba7..b98ff029a2e 100644 --- a/src/mesa/main/texcompress_etc.c +++ b/src/mesa/main/texcompress_etc.c @@ -36,2 +36,3 @@ * MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1 + * MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1 */ @@ -1043,2 +1044,43 @@ etc2_unpack_rgb8_punchthrough_alpha1(uint8_t *dst_row, +static void +etc2_unpack_srgb8_punchthrough_alpha1(uint8_t *dst_row, + unsigned dst_stride, + const uint8_t *src_row, + unsigned src_stride, + unsigned width, + unsigned height) +{ + const unsigned bw = 4, bh = 4, bs = 8, comps = 4; + struct etc2_block block; + unsigned x, y, i, j; + uint8_t tmp; + + for (y = 0; y < height; y += bh) { + const uint8_t *src = src_row; + + for (x = 0; x < width; x+= bw) { + etc2_rgb8_parse_block(&block, src, + true /* punchthrough_alpha */); + for (j = 0; j < bh; j++) { + uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps; + for (i = 0; i < bw; i++) { + etc2_rgb8_fetch_texel(&block, i, j, dst, + true /* punchthrough_alpha */); + /* Convert to MESA_FORMAT_SARGB8 */ + tmp = dst[0]; + dst[0] = dst[2]; + dst[2] = tmp; + dst[3] = dst[3]; + + dst += comps; + } + } + + src += bs; + } + + src_row += src_stride; + } +} + /* ETC2 texture formats are valid in glCompressedTexImage2D and @@ -1117,2 +1159,10 @@ _mesa_texstore_etc2_rgb8_punchthrough_alpha1(TEXSTORE_PARAMS) +GLboolean +_mesa_texstore_etc2_srgb8_punchthrough_alpha1(TEXSTORE_PARAMS) +{ + ASSERT(0); + + return GL_FALSE; +} + void @@ -1318,2 +1368,25 @@ _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1( +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]); +} + /** @@ -1329,2 +1402,3 @@ _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1( * `MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1` + * `MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1` * @@ -1383,2 +1457,6 @@ _mesa_unpack_etc2_format(uint8_t *dst_row, src_width, src_height); + else if (format == MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1) + etc2_unpack_srgb8_punchthrough_alpha1(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 05934794609..5e086d4e79c 100644 --- a/src/mesa/main/texcompress_etc.h +++ b/src/mesa/main/texcompress_etc.h @@ -63,2 +63,5 @@ _mesa_texstore_etc2_rgb8_punchthrough_alpha1(TEXSTORE_PARAMS); +GLboolean +_mesa_texstore_etc2_srgb8_punchthrough_alpha1(TEXSTORE_PARAMS); + void @@ -103,2 +106,7 @@ _mesa_fetch_texel_2d_f_etc2_rgb8_punchthrough_alpha1( void +_mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1( + const struct swrast_texture_image *texImage, + GLint i, GLint j, + GLint k, GLfloat *texel); +void _mesa_etc1_unpack_rgba8888(uint8_t *dst_row, diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 80edd0008e7..26c5b670312 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -4136,4 +4136,4 @@ _mesa_get_texstore_func(gl_format format) _mesa_texstore_etc2_rgb8_punchthrough_alpha1; - /* table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] = - _mesa_texstore_etc2_srgb8_punchthrough_alpha1; -- not implemented yet */ + table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] = + _mesa_texstore_etc2_srgb8_punchthrough_alpha1; table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8; diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c index 579dd5c5fc1..86b01a0b346 100644 --- a/src/mesa/swrast/s_texfetch.c +++ b/src/mesa/swrast/s_texfetch.c @@ -1087,3 +1087,3 @@ texfetch_funcs[] = NULL, - NULL /* _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1 -- not implemented yet */, + _mesa_fetch_texel_2d_f_etc2_srgb8_punchthrough_alpha1, NULL |