aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2011-11-29 00:10:37 +0800
committerChia-I Wu <[email protected]>2011-12-02 08:43:46 +0800
commit5c31eb78e5fa4c4cfcc82df3c9a2c34fcd4b402c (patch)
tree3b4b9ec72057762ab379b2a836173972edce8d2a
parentd4a38e86d4b4d66cca20ee63222f940cb73fa709 (diff)
gallium: add PIPE_FORMAT_ETC1_RGB8
The format is defined by GL_OES_compressed_ETC1_RGB8_texture. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Jose Fonseca <[email protected]>
-rw-r--r--src/gallium/auxiliary/Makefile.sources1
-rw-r--r--src/gallium/auxiliary/util/u_format.csv3
-rw-r--r--src/gallium/auxiliary/util/u_format.h7
-rw-r--r--src/gallium/auxiliary/util/u_format_etc.c104
-rw-r--r--src/gallium/auxiliary/util/u_format_etc.h46
-rw-r--r--src/gallium/auxiliary/util/u_format_pack.py2
-rwxr-xr-xsrc/gallium/auxiliary/util/u_format_table.py1
-rw-r--r--src/gallium/include/pipe/p_format.h3
8 files changed, 165 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
index 5c65533308c..d40b95451f0 100644
--- a/src/gallium/auxiliary/Makefile.sources
+++ b/src/gallium/auxiliary/Makefile.sources
@@ -103,6 +103,7 @@ C_SOURCES := \
util/u_format_latc.c \
util/u_format_s3tc.c \
util/u_format_rgtc.c \
+ util/u_format_etc.c \
util/u_format_tests.c \
util/u_format_yuv.c \
util/u_format_zs.c \
diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv
index 4b6fc75361d..345cc9d47c4 100644
--- a/src/gallium/auxiliary/util/u_format.csv
+++ b/src/gallium/auxiliary/util/u_format.csv
@@ -158,6 +158,7 @@ PIPE_FORMAT_R8G8Bx_SNORM , other, 1, 1, sn8 , sn8 , , , x
# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt
# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt
# - http://www.opengl.org/registry/specs/EXT/texture_compression_latc.txt
+# - http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
# - http://msdn.microsoft.com/en-us/library/bb694531.aspx
PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb
PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb
@@ -178,6 +179,8 @@ PIPE_FORMAT_LATC1_SNORM , rgtc, 4, 4, x64, , , , xxx1, rg
PIPE_FORMAT_LATC2_UNORM , rgtc, 4, 4, x128, , , , xxxy, rgb
PIPE_FORMAT_LATC2_SNORM , rgtc, 4, 4, x128, , , , xxxy, rgb
+PIPE_FORMAT_ETC1_RGB8 , etc, 4, 4, x64, , , , xyz1, rgb
+
# Straightforward D3D10-like formats (also used for
# vertex buffer element description)
#
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 99ee6767e83..9694c9034d2 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -70,9 +70,14 @@ enum util_format_layout {
UTIL_FORMAT_LAYOUT_RGTC = 5,
/**
+ * Ericsson Texture Compression
+ */
+ UTIL_FORMAT_LAYOUT_ETC = 6,
+
+ /**
* Everything else that doesn't fit in any of the above layouts.
*/
- UTIL_FORMAT_LAYOUT_OTHER = 6
+ UTIL_FORMAT_LAYOUT_OTHER = 7
};
diff --git a/src/gallium/auxiliary/util/u_format_etc.c b/src/gallium/auxiliary/util/u_format_etc.c
new file mode 100644
index 00000000000..7500e1ed650
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_format_etc.c
@@ -0,0 +1,104 @@
+#include "pipe/p_compiler.h"
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "u_format_etc.h"
+
+/* define etc1_parse_block and etc. */
+#define UINT8_TYPE uint8_t
+#define TAG(x) x
+#include "../../../mesa/main/texcompress_etc_tmp.h"
+#undef TAG
+#undef UINT8_TYPE
+
+void
+util_format_etc1_rgb8_unpack_rgba_8unorm(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 etc1_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) {
+ etc1_parse_block(&block, src);
+
+ for (j = 0; j < bh; j++) {
+ uint8_t *dst = dst_row + (y + j) * dst_stride + x * comps;
+ for (i = 0; i < bw; i++) {
+ etc1_fetch_texel(&block, i, j, dst);
+ dst[3] = 255;
+ dst += comps;
+ }
+ }
+
+ src += bs;
+ }
+
+ src_row += src_stride;
+ }
+}
+
+void
+util_format_etc1_rgb8_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
+{
+ assert(0);
+}
+
+void
+util_format_etc1_rgb8_unpack_rgba_float(float *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 etc1_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) {
+ etc1_parse_block(&block, src);
+
+ for (j = 0; j < bh; j++) {
+ float *dst = dst_row + (y + j) * dst_stride / sizeof(*dst_row) + x * comps;
+ uint8_t tmp[3];
+
+ for (i = 0; i < bw; i++) {
+ etc1_fetch_texel(&block, i, j, tmp);
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = 1.0f;
+ dst += comps;
+ }
+ }
+
+ src += bs;
+ }
+
+ src_row += src_stride;
+ }
+}
+
+void
+util_format_etc1_rgb8_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
+{
+ assert(0);
+}
+
+void
+util_format_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
+{
+ const unsigned bw = 4, bh = 4;
+ struct etc1_block block;
+ uint8_t tmp[3];
+
+ assert(i < bw && j < bh);
+
+ etc1_parse_block(&block, src);
+ etc1_fetch_texel(&block, i, j, tmp);
+
+ dst[0] = ubyte_to_float(tmp[0]);
+ dst[1] = ubyte_to_float(tmp[1]);
+ dst[2] = ubyte_to_float(tmp[2]);
+ dst[3] = 1.0f;
+}
diff --git a/src/gallium/auxiliary/util/u_format_etc.h b/src/gallium/auxiliary/util/u_format_etc.h
new file mode 100644
index 00000000000..30c3dcb920d
--- /dev/null
+++ b/src/gallium/auxiliary/util/u_format_etc.h
@@ -0,0 +1,46 @@
+/**************************************************************************
+ *
+ * Copyright 2011 LunarG, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ **************************************************************************/
+
+#ifndef U_FORMAT_ETC1_H_
+#define U_FORMAT_ETC1_H_
+
+void
+util_format_etc1_rgb8_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_unpack_rgba_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height);
+
+void
+util_format_etc1_rgb8_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j);
+
+#endif /* U_FORMAT_ETC1_H_ */
diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py
index 14a5049449a..fff409fb75d 100644
--- a/src/gallium/auxiliary/util/u_format_pack.py
+++ b/src/gallium/auxiliary/util/u_format_pack.py
@@ -658,7 +658,7 @@ def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix):
def is_format_hand_written(format):
- return format.layout in ('s3tc', 'rgtc', 'subsampled', 'other') or format.colorspace == ZS
+ return format.layout in ('s3tc', 'rgtc', 'etc', 'subsampled', 'other') or format.colorspace == ZS
def generate(formats):
diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py
index 703d99959f5..07beb38723b 100755
--- a/src/gallium/auxiliary/util/u_format_table.py
+++ b/src/gallium/auxiliary/util/u_format_table.py
@@ -89,6 +89,7 @@ def write_format_table(formats):
print '#include "u_format_s3tc.h"'
print '#include "u_format_rgtc.h"'
print '#include "u_format_latc.h"'
+ print '#include "u_format_etc.h"'
print
u_format_pack.generate(formats)
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index f229a5ad545..c05629b616e 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -312,6 +312,9 @@ enum pipe_format {
PIPE_FORMAT_L32A32_SINT = 224,
PIPE_FORMAT_B10G10R10A2_UINT = 225,
+
+ PIPE_FORMAT_ETC1_RGB8 = 226,
+
PIPE_FORMAT_COUNT
};