aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-09-09 16:49:03 +0200
committermarha <marha@users.sourceforge.net>2011-09-09 16:49:03 +0200
commit05cf7dd22994a1dbfd3580b00690c01c392a5797 (patch)
treeec1c29b5f8a67c54b13b44f1eb7aa700f91fef9e /mesalib/src/mesa/main
parent0947b921a3223c14322f10d83e71618d1724b734 (diff)
parentf9cf11136d65f20aab4fb6d5fc3ec3c59185a0b4 (diff)
downloadvcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.tar.gz
vcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.tar.bz2
vcxsrv-05cf7dd22994a1dbfd3580b00690c01c392a5797.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/include/GL/internal/dri_interface.h mesalib/scons/gallium.py mesalib/src/glsl/ast_to_hir.cpp mesalib/src/glsl/glsl_parser_extras.cpp mesalib/src/glsl/ir_variable.cpp mesalib/src/glsl/linker.cpp mesalib/src/mesa/SConscript mesalib/src/mesa/drivers/common/driverfuncs.c mesalib/src/mesa/main/compiler.h mesalib/src/mesa/main/formats.c mesalib/src/mesa/main/formats.h mesalib/src/mesa/main/texcompress.c mesalib/src/mesa/main/texgetimage.c mesalib/src/mesa/sources.mak
Diffstat (limited to 'mesalib/src/mesa/main')
-rw-r--r--mesalib/src/mesa/main/compiler.h31
-rw-r--r--mesalib/src/mesa/main/format_unpack.c1494
-rw-r--r--mesalib/src/mesa/main/format_unpack.h49
-rw-r--r--mesalib/src/mesa/main/formats.c64
-rw-r--r--mesalib/src/mesa/main/formats.h7
-rw-r--r--mesalib/src/mesa/main/mipmap.c85
-rw-r--r--mesalib/src/mesa/main/texcompress.c89
-rw-r--r--mesalib/src/mesa/main/texcompress.h5
-rw-r--r--mesalib/src/mesa/main/texgetimage.c177
9 files changed, 1879 insertions, 122 deletions
diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h
index 942ac6b0a..d2caaaa79 100644
--- a/mesalib/src/mesa/main/compiler.h
+++ b/mesalib/src/mesa/main/compiler.h
@@ -114,29 +114,30 @@ extern "C" {
/**
* Function inlining
*/
-#ifndef INLINE
-# if defined(__GNUC__)
-# define INLINE __inline__
-# elif defined(__MSC__)
-# define INLINE __inline
+#ifndef inline
+# ifdef __cplusplus
+ /* C++ supports inline keyword */
+# elif defined(__GNUC__)
+# define inline __inline__
# elif defined(_MSC_VER)
-# define INLINE __inline
+# define inline __inline
# elif defined(__ICL)
-# define INLINE __inline
+# define inline __inline
# elif defined(__INTEL_COMPILER)
-# define INLINE inline
+ /* Intel compiler supports inline keyword */
# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
-# define INLINE __inline
+# define inline __inline
# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
-# define INLINE inline
-# define __inline inline
-# define __inline__ inline
-# elif (__STDC_VERSION__ >= 199901L) /* C99 */
-# define INLINE inline
+ /* C99 supports inline keyword */
+# elif (__STDC_VERSION__ >= 199901L)
+ /* C99 supports inline keyword */
# else
-# define INLINE
+# define inline
# endif
#endif
+#ifndef INLINE
+# define INLINE inline
+#endif
/**
diff --git a/mesalib/src/mesa/main/format_unpack.c b/mesalib/src/mesa/main/format_unpack.c
new file mode 100644
index 000000000..c5146f72d
--- /dev/null
+++ b/mesalib/src/mesa/main/format_unpack.c
@@ -0,0 +1,1494 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * 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, sublicense,
+ * 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 above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS 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.
+ */
+
+
+#include "colormac.h"
+#include "format_unpack.h"
+#include "macros.h"
+#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
+#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+
+
+/**
+ * Convert an 8-bit sRGB value from non-linear space to a
+ * linear RGB value in [0, 1].
+ * Implemented with a 256-entry lookup table.
+ */
+static INLINE GLfloat
+nonlinear_to_linear(GLubyte cs8)
+{
+ static GLfloat table[256];
+ static GLboolean tableReady = GL_FALSE;
+ if (!tableReady) {
+ /* compute lookup table now */
+ GLuint i;
+ for (i = 0; i < 256; i++) {
+ const GLfloat cs = UBYTE_TO_FLOAT(i);
+ if (cs <= 0.04045) {
+ table[i] = cs / 12.92f;
+ }
+ else {
+ table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
+ }
+ }
+ tableReady = GL_TRUE;
+ }
+ return table[cs8];
+}
+
+
+typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[4]);
+
+
+static void
+unpack_RGBA8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+static void
+unpack_RGBA8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+static void
+unpack_ARGB8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+}
+
+static void
+unpack_ARGB8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+}
+
+static void
+unpack_XRGB8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_XRGB8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
+ dst[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_RGB888(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = UBYTE_TO_FLOAT( s[2] );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s[1] );
+ dst[BCOMP] = UBYTE_TO_FLOAT( s[0] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_BGR888(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = UBYTE_TO_FLOAT( s[0] );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s[1] );
+ dst[BCOMP] = UBYTE_TO_FLOAT( s[2] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB565(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
+ dst[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB565_REV(const void *src, GLfloat dst[4])
+{
+ GLushort s = *((const GLushort *) src);
+ s = (s >> 8) | (s << 8); /* byte swap */
+ dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
+ dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_ARGB4444(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+ dst[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_ARGB4444_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
+ dst[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
+ dst[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_RGBA5551(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
+ dst[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = ((s ) & 0x01) * 1.0F;
+}
+
+static void
+unpack_ARGB1555(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
+ dst[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
+ dst[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
+ dst[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
+}
+
+static void
+unpack_ARGB1555_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
+ dst[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
+ dst[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
+ dst[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
+}
+
+static void
+unpack_AL44(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
+ dst[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
+}
+
+static void
+unpack_AL88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
+}
+
+static void
+unpack_AL88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
+}
+
+static void
+unpack_AL1616(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
+}
+
+static void
+unpack_AL1616_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
+}
+
+static void
+unpack_RGB332(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
+ dst[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
+ dst[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+
+static void
+unpack_A8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = UBYTE_TO_FLOAT(s);
+}
+
+static void
+unpack_A16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = USHORT_TO_FLOAT(s);
+}
+
+static void
+unpack_L8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = UBYTE_TO_FLOAT(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_L16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = USHORT_TO_FLOAT(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_I8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = UBYTE_TO_FLOAT(s);
+}
+
+static void
+unpack_I16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = USHORT_TO_FLOAT(s);
+}
+
+static void
+unpack_YCBCR(const void *src, GLfloat dst[4])
+{
+ const GLuint i = 0;
+ const GLushort *src0 = (const GLushort *) src;
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
+ const GLubyte cb = *src0 & 0xff; /* chroma U */
+ const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
+ const GLubyte cr = *src1 & 0xff; /* chroma V */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ dst[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_YCBCR_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint i = 0;
+ const GLushort *src0 = (const GLushort *) src;
+ const GLushort *src1 = src0 + 1; /* odd */
+ const GLubyte y0 = *src0 & 0xff; /* luminance */
+ const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
+ const GLubyte y1 = *src1 & 0xff; /* luminance */
+ const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
+ const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
+ GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
+ GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
+ r *= (1.0F / 255.0F);
+ g *= (1.0F / 255.0F);
+ b *= (1.0F / 255.0F);
+ dst[RCOMP] = CLAMP(r, 0.0F, 1.0F);
+ dst[GCOMP] = CLAMP(g, 0.0F, 1.0F);
+ dst[BCOMP] = CLAMP(b, 0.0F, 1.0F);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[0] = UBYTE_TO_FLOAT(s);
+ dst[1] = dst[2] = 0.0F;
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_RG88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
+ dst[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_R16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT(s);
+ dst[GCOMP] = 0.0;
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG1616(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_RG1616_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
+ dst[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
+ dst[BCOMP] = 0.0;
+ dst[ACOMP] = 1.0;
+}
+
+static void
+unpack_ARGB2101010(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
+ dst[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
+ dst[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
+ dst[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
+}
+
+
+static void
+unpack_Z24_S8(const void *src, GLfloat dst[4])
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ dst[0] = dst[1] = dst[2] = (s >> 8) * scale;
+ dst[3] = 1.0F;
+ ASSERT(dst[0] >= 0.0F);
+ ASSERT(dst[0] <= 1.0F);
+}
+
+static void
+unpack_S8_Z24(const void *src, GLfloat dst[4])
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ dst[0] = dst[1] = dst[2] = (s & 0x00ffffff) * scale;
+ dst[3] = 1.0F;
+ ASSERT(dst[0] >= 0.0F);
+ ASSERT(dst[0] <= 1.0F);
+}
+
+static void
+unpack_Z16(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[0] = dst[1] = dst[2] = s * (1.0F / 65535.0F);
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_X8_Z24(const void *src, GLfloat dst[4])
+{
+ unpack_S8_Z24(src, dst);
+}
+
+static void
+unpack_Z24_X8(const void *src, GLfloat dst[4])
+{
+ unpack_Z24_S8(src, dst);
+}
+
+static void
+unpack_Z32(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[0] = dst[1] = dst[2] = s * (1.0F / 0xffffffff);
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_Z32_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLfloat s = *((const GLfloat *) src);
+ dst[0] = dst[1] = dst[2] = s;
+ dst[3] = 1.0F;
+}
+
+static void
+unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[4])
+{
+ const GLfloat s = *((const GLfloat *) src);
+ dst[0] = dst[1] = dst[2] = s;
+ dst[3] = 1.0F;
+}
+
+
+static void
+unpack_S8(const void *src, GLfloat dst[4])
+{
+ /* should never be used */
+ dst[0] = dst[1] = dst[2] = 0.0F;
+ dst[3] = 1.0F;
+}
+
+
+static void
+unpack_SRGB8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = nonlinear_to_linear(s[2]);
+ dst[GCOMP] = nonlinear_to_linear(s[1]);
+ dst[BCOMP] = nonlinear_to_linear(s[0]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SRGBA8(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = nonlinear_to_linear( (s >> 24) );
+ dst[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ dst[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
+}
+
+static void
+unpack_SARGB8(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
+ dst[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
+ dst[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
+ dst[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
+}
+
+static void
+unpack_SL8(const void *src, GLfloat dst[4])
+{
+ const GLubyte s = *((const GLubyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = nonlinear_to_linear(s);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SLA8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = nonlinear_to_linear(s[0]);
+ dst[ACOMP] = UBYTE_TO_FLOAT(s[1]); /* linear */
+}
+
+static void
+unpack_SRGB_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT3(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_SRGBA_DXT5(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGB_FXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_FXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGB_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT1(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT3(const void *src, GLfloat dst[4])
+{
+}
+
+static void
+unpack_RGBA_DXT5(const void *src, GLfloat dst[4])
+{
+}
+
+
+static void
+unpack_RGBA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = s[2];
+ dst[ACOMP] = s[3];
+}
+
+static void
+unpack_RGBA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = _mesa_half_to_float(s[2]);
+ dst[ACOMP] = _mesa_half_to_float(s[3]);
+}
+
+static void
+unpack_RGB_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = s[2];
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RGB_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = _mesa_half_to_float(s[2]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = _mesa_half_to_float(s[0]);
+}
+
+static void
+unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = s[0];
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = _mesa_half_to_float(s[0]);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = s[0];
+ dst[ACOMP] = s[1];
+}
+
+static void
+unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = _mesa_half_to_float(s[0]);
+ dst[ACOMP] = _mesa_half_to_float(s[1]);
+}
+
+static void
+unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = s[0];
+}
+
+static void
+unpack_R_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RG_FLOAT32(const void *src, GLfloat dst[4])
+{
+ const GLfloat *s = (const GLfloat *) src;
+ dst[RCOMP] = s[0];
+ dst[GCOMP] = s[1];
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_RG_FLOAT16(const void *src, GLfloat dst[4])
+{
+ const GLhalfARB *s = (const GLhalfARB *) src;
+ dst[RCOMP] = _mesa_half_to_float(s[0]);
+ dst[GCOMP] = _mesa_half_to_float(s[1]);
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+
+static void
+unpack_RGBA_INT8(const void *src, GLfloat dst[4])
+{
+ const GLbyte *s = (const GLbyte *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_INT16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_INT32(const void *src, GLfloat dst[4])
+{
+ const GLint *s = (const GLint *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT8(const void *src, GLfloat dst[4])
+{
+ const GLubyte *s = (const GLubyte *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT16(const void *src, GLfloat dst[4])
+{
+ const GLushort *s = (const GLushort *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_RGBA_UINT32(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ dst[RCOMP] = (GLfloat) s[0];
+ dst[GCOMP] = (GLfloat) s[1];
+ dst[BCOMP] = (GLfloat) s[2];
+ dst[ACOMP] = (GLfloat) s[3];
+}
+
+static void
+unpack_DUDV8(const void *src, GLfloat dst[4])
+{
+ const GLbyte *s = (const GLbyte *) src;
+ dst[RCOMP] = BYTE_TO_FLOAT(s[0]);
+ dst[GCOMP] = BYTE_TO_FLOAT(s[1]);
+ dst[BCOMP] = 0;
+ dst[ACOMP] = 0;
+}
+
+static void
+unpack_SIGNED_R8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( s );
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLushort *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[ACOMP] = 1.0f;
+}
+
+static void
+unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+}
+
+static void
+unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[4])
+{
+ const GLuint s = *((const GLuint *) src);
+ dst[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
+ dst[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
+}
+
+static void
+unpack_SIGNED_R16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s );
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_GR1616(const void *src, GLfloat dst[4])
+{
+ /* XXX TODO */
+}
+
+static void
+unpack_SIGNED_RGB_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
+}
+
+static void
+unpack_RGBA_16(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] = USHORT_TO_FLOAT( s[0] );
+ dst[GCOMP] = USHORT_TO_FLOAT( s[1] );
+ dst[BCOMP] = USHORT_TO_FLOAT( s[2] );
+ dst[ACOMP] = USHORT_TO_FLOAT( s[3] );
+}
+
+static void
+unpack_RED_RGTC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_RG_RGTC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_L_LATC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_LA_LATC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[4])
+{
+ /* XXX to do */
+}
+
+static void
+unpack_SIGNED_A8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] = 0.0F;
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_L8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( s );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_AL88(const void *src, GLfloat dst[4])
+{
+ const GLushort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+}
+
+static void
+unpack_SIGNED_I8(const void *src, GLfloat dst[4])
+{
+ const GLbyte s = *((const GLbyte *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = BYTE_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_A16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] = 0.0F;
+ dst[GCOMP] = 0.0F;
+ dst[BCOMP] = 0.0F;
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_SIGNED_L16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s );
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_SIGNED_AL1616(const void *src, GLfloat dst[4])
+{
+ const GLshort *s = (const GLshort *) src;
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
+}
+
+static void
+unpack_SIGNED_I16(const void *src, GLfloat dst[4])
+{
+ const GLshort s = *((const GLshort *) src);
+ dst[RCOMP] =
+ dst[GCOMP] =
+ dst[BCOMP] =
+ dst[ACOMP] = SHORT_TO_FLOAT_TEX( s );
+}
+
+static void
+unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ rgb9e5_to_float3(*s, dst);
+ dst[ACOMP] = 1.0F;
+}
+
+static void
+unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[4])
+{
+ const GLuint *s = (const GLuint *) src;
+ r11g11b10f_to_float3(*s, dst);
+ dst[ACOMP] = 1.0F;
+}
+
+
+/**
+ * Return the unpacker function for the given format.
+ */
+static unpack_rgba_func
+get_unpack_rgba_function(gl_format format)
+{
+ static unpack_rgba_func table[MESA_FORMAT_COUNT];
+ static GLboolean initialized = GL_FALSE;
+
+ if (!initialized) {
+ table[MESA_FORMAT_NONE] = NULL;
+
+ table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
+ table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
+ table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
+ table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
+ table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
+ table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
+ table[MESA_FORMAT_RGB888] = unpack_RGB888;
+ table[MESA_FORMAT_BGR888] = unpack_BGR888;
+ table[MESA_FORMAT_RGB565] = unpack_RGB565;
+ table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
+ table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
+ table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
+ table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
+ table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
+ table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
+ table[MESA_FORMAT_AL44] = unpack_AL44;
+ table[MESA_FORMAT_AL88] = unpack_AL88;
+ table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
+ table[MESA_FORMAT_AL1616] = unpack_AL1616;
+ table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
+ table[MESA_FORMAT_RGB332] = unpack_RGB332;
+ table[MESA_FORMAT_A8] = unpack_A8;
+ table[MESA_FORMAT_A16] = unpack_A16;
+ table[MESA_FORMAT_L8] = unpack_L8;
+ table[MESA_FORMAT_L16] = unpack_L16;
+ table[MESA_FORMAT_I8] = unpack_I8;
+ table[MESA_FORMAT_I16] = unpack_I16;
+ table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
+ table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
+ table[MESA_FORMAT_R8] = unpack_R8;
+ table[MESA_FORMAT_RG88] = unpack_RG88;
+ table[MESA_FORMAT_RG88_REV] = unpack_RG88_REV;
+ table[MESA_FORMAT_R16] = unpack_R16;
+ table[MESA_FORMAT_RG1616] = unpack_RG1616;
+ table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
+ table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
+ table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
+ table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
+ table[MESA_FORMAT_Z16] = unpack_Z16;
+ table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
+ table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
+ table[MESA_FORMAT_Z32] = unpack_Z32;
+ table[MESA_FORMAT_S8] = unpack_S8;
+ table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
+ table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
+ table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
+ table[MESA_FORMAT_SL8] = unpack_SL8;
+ table[MESA_FORMAT_SLA8] = unpack_SLA8;
+ table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
+ table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
+ table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
+ table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
+
+ table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
+ table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
+ table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
+ table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
+ table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
+ table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
+
+ table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
+ table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
+ table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
+ table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
+ table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
+ table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
+ table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
+ table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
+ table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
+ table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
+ table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
+ table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
+ table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
+
+ table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
+ table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
+ table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
+ table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
+ table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
+ table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
+
+ table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
+ table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
+ table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
+ table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
+ table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
+ table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
+ table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
+ table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
+ table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
+ table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
+
+ table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
+ table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
+ table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
+ table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
+
+ table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
+ table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
+ table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
+ table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
+
+ table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
+ table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
+ table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
+ table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
+ table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
+ table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
+ table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
+ table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
+
+ table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
+ table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
+
+ table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
+ table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
+
+ initialized = GL_TRUE;
+ }
+
+ return table[format];
+}
+
+
+void
+_mesa_unpack_rgba_row(gl_format format, GLuint n,
+ const void *src, GLfloat dst[][4])
+{
+ unpack_rgba_func unpack = get_unpack_rgba_function(format);
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
+
+/**
+ * Unpack a 2D rect of pixels returning float RGBA colors.
+ * \param format the source image format
+ * \param src start address of the source image
+ * \param srcRowStride source image row stride in bytes
+ * \param dst start address of the dest image
+ * \param dstRowStride dest image row stride in bytes
+ * \param x source image start X pos
+ * \param y source image start Y pos
+ * \param width width of rect region to convert
+ * \param height height of rect region to convert
+ */
+void
+_mesa_unpack_rgba_block(gl_format format,
+ const void *src, GLint srcRowStride,
+ GLfloat dst[][4], GLint dstRowStride,
+ GLuint x, GLuint y, GLuint width, GLuint height)
+{
+ unpack_rgba_func unpack = get_unpack_rgba_function(format);
+ const GLuint srcPixStride = _mesa_get_format_bytes(format);
+ const GLuint dstPixStride = 4 * sizeof(GLfloat);
+ const GLubyte *srcRow, *srcPix;
+ GLubyte *dstRow;
+ GLfloat *dstPix;
+ GLuint i, j;
+
+ /* XXX needs to be fixed for compressed formats */
+
+ srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
+ dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
+
+ for (i = 0; i < height; i++) {
+ srcPix = srcRow;
+ dstPix = (GLfloat *) dstRow;
+
+ for (j = 0; j < width; j++) {
+ unpack(srcPix, dstPix);
+ srcPix += srcPixStride;
+ dstPix += dstPixStride;
+ }
+
+ dstRow += dstRowStride;
+ srcRow += srcRowStride;
+ }
+}
+
+
+
+
+typedef void (*unpack_float_z_func)(const void *src, GLfloat *dst);
+
+static void
+unpack_float_z_Z24_S8(const void *src, GLfloat *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ *dst = (s >> 8) * scale;
+ ASSERT(*dst >= 0.0F);
+ ASSERT(*dst <= 1.0F);
+}
+
+static void
+unpack_float_z_S8_Z24(const void *src, GLfloat *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
+ *dst = (s & 0x00ffffff) * scale;
+ ASSERT(*dst >= 0.0F);
+ ASSERT(*dst <= 1.0F);
+}
+
+static void
+unpack_float_z_Z16(const void *src, GLfloat *dst)
+{
+ const GLushort s = *((const GLushort *) src);
+ *dst = s * (1.0F / 65535.0F);
+}
+
+static void
+unpack_float_z_X8_Z24(const void *src, GLfloat *dst)
+{
+ unpack_float_z_S8_Z24(src, dst);
+}
+
+static void
+unpack_float_z_Z24_X8(const void *src, GLfloat *dst)
+{
+ unpack_float_z_Z24_S8(src, dst);
+}
+
+static void
+unpack_float_z_Z32(const void *src, GLfloat *dst)
+{
+ const GLuint s = *((const GLuint *) src);
+ *dst = s * (1.0F / 0xffffffff);
+}
+
+static void
+unpack_float_z_Z32X24S8(const void *src, GLfloat *dst)
+{
+ *dst = *((const GLfloat *) src);
+}
+
+
+
+void
+_mesa_unpack_float_z_row(gl_format format, GLuint n,
+ const void *src, GLfloat *dst)
+{
+ unpack_float_z_func unpack;
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ unpack = unpack_float_z_Z24_S8;
+ break;
+ case MESA_FORMAT_S8_Z24:
+ unpack = unpack_float_z_S8_Z24;
+ break;
+ case MESA_FORMAT_Z16:
+ unpack = unpack_float_z_Z16;
+ break;
+ case MESA_FORMAT_X8_Z24:
+ unpack = unpack_float_z_X8_Z24;
+ break;
+ case MESA_FORMAT_Z24_X8:
+ unpack = unpack_float_z_Z24_X8;
+ break;
+ case MESA_FORMAT_Z32:
+ unpack = unpack_float_z_Z32;
+ break;
+ case MESA_FORMAT_Z32_FLOAT_X24S8:
+ unpack = unpack_float_z_Z32X24S8;
+ break;
+ default:
+ _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, &dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
+
+typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst);
+
+static void
+unpack_uint_z_Z24_S8(const void *src, GLuint *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ *dst = (s >> 8);
+}
+
+static void
+unpack_uint_z_S8_Z24(const void *src, GLuint *dst)
+{
+ /* only return Z, not stencil data */
+ const GLuint s = *((const GLuint *) src);
+ *dst = s & 0x00ffffff;
+}
+
+static void
+unpack_uint_z_Z16(const void *src, GLuint *dst)
+{
+ *dst = *((const GLushort *) src);
+}
+
+static void
+unpack_uint_z_X8_Z24(const void *src, GLuint *dst)
+{
+ unpack_uint_z_S8_Z24(src, dst);
+}
+
+static void
+unpack_uint_z_Z24_X8(const void *src, GLuint *dst)
+{
+ unpack_uint_z_Z24_S8(src, dst);
+}
+
+static void
+unpack_uint_z_Z32(const void *src, GLuint *dst)
+{
+ *dst = *((const GLuint *) src);
+}
+
+
+void
+_mesa_unpack_uint_z_row(gl_format format, GLuint n,
+ const void *src, GLuint *dst)
+{
+ unpack_uint_z_func unpack;
+ GLuint srcStride = _mesa_get_format_bytes(format);
+ const GLubyte *srcPtr = (GLubyte *) src;
+ GLuint i;
+
+ switch (format) {
+ case MESA_FORMAT_Z24_S8:
+ unpack = unpack_uint_z_Z24_S8;
+ break;
+ case MESA_FORMAT_S8_Z24:
+ unpack = unpack_uint_z_S8_Z24;
+ break;
+ case MESA_FORMAT_Z16:
+ unpack = unpack_uint_z_Z16;
+ break;
+ case MESA_FORMAT_X8_Z24:
+ unpack = unpack_uint_z_X8_Z24;
+ break;
+ case MESA_FORMAT_Z24_X8:
+ unpack = unpack_uint_z_Z24_X8;
+ break;
+ case MESA_FORMAT_Z32:
+ unpack = unpack_uint_z_Z32;
+ break;
+ default:
+ _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
+ _mesa_get_format_name(format));
+ return;
+ }
+
+ for (i = 0; i < n; i++) {
+ unpack(srcPtr, &dst[i]);
+ srcPtr += srcStride;
+ }
+}
+
+
diff --git a/mesalib/src/mesa/main/format_unpack.h b/mesalib/src/mesa/main/format_unpack.h
new file mode 100644
index 000000000..c37727d91
--- /dev/null
+++ b/mesalib/src/mesa/main/format_unpack.h
@@ -0,0 +1,49 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * 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, sublicense,
+ * 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 above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS 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.
+ */
+
+#ifndef FORMAT_UNPACK_H
+#define FORMAT_UNPACK_H
+
+extern void
+_mesa_unpack_rgba_row(gl_format format, GLuint n,
+ const void *src, GLfloat dst[][4]);
+
+
+extern void
+_mesa_unpack_rgba_block(gl_format format,
+ const void *src, GLint srcRowStride,
+ GLfloat dst[][4], GLint dstRowStride,
+ GLuint x, GLuint y, GLuint width, GLuint height);
+
+
+extern void
+_mesa_unpack_float_z_row(gl_format format, GLuint n,
+ const void *src, GLfloat *dst);
+
+
+void
+_mesa_unpack_uint_z_row(gl_format format, GLuint n,
+ const void *src, GLuint *dst);
+
+
+#endif /* FORMAT_UNPACK_H */
diff --git a/mesalib/src/mesa/main/formats.c b/mesalib/src/mesa/main/formats.c
index fd16d98c5..47f876b76 100644
--- a/mesalib/src/mesa/main/formats.c
+++ b/mesalib/src/mesa/main/formats.c
@@ -1343,6 +1343,70 @@ _mesa_get_srgb_format_linear(gl_format format)
/**
+ * If the given format is a compressed format, return a corresponding
+ * uncompressed format.
+ */
+gl_format
+_mesa_get_uncompressed_format(gl_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_RGB_FXT1:
+ return MESA_FORMAT_RGB888;
+ case MESA_FORMAT_RGBA_FXT1:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGB_DXT1:
+ case MESA_FORMAT_SRGB_DXT1:
+ return MESA_FORMAT_RGB888;
+ case MESA_FORMAT_RGBA_DXT1:
+ case MESA_FORMAT_SRGBA_DXT1:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGBA_DXT3:
+ case MESA_FORMAT_SRGBA_DXT3:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RGBA_DXT5:
+ case MESA_FORMAT_SRGBA_DXT5:
+ return MESA_FORMAT_RGBA8888;
+ case MESA_FORMAT_RED_RGTC1:
+ return MESA_FORMAT_R8;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ return MESA_FORMAT_SIGNED_R8;
+ case MESA_FORMAT_RG_RGTC2:
+ return MESA_FORMAT_RG88;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ return MESA_FORMAT_SIGNED_RG88_REV;
+ case MESA_FORMAT_L_LATC1:
+ return MESA_FORMAT_L8;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ return MESA_FORMAT_SIGNED_L8;
+ case MESA_FORMAT_LA_LATC2:
+ return MESA_FORMAT_AL88;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ return MESA_FORMAT_SIGNED_AL88;
+ default:
+#ifdef DEBUG
+ assert(!_mesa_is_format_compressed(format));
+#endif
+ return format;
+ }
+}
+
+
+GLuint
+_mesa_format_num_components(gl_format format)
+{
+ const struct gl_format_info *info = _mesa_get_format_info(format);
+ return ((info->RedBits > 0) +
+ (info->GreenBits > 0) +
+ (info->BlueBits > 0) +
+ (info->AlphaBits > 0) +
+ (info->LuminanceBits > 0) +
+ (info->IntensityBits > 0) +
+ (info->DepthBits > 0) +
+ (info->StencilBits > 0));
+}
+
+
+/**
* Return number of bytes needed to store an image of the given size
* in the given format.
*/
diff --git a/mesalib/src/mesa/main/formats.h b/mesalib/src/mesa/main/formats.h
index 26bcbe084..b6b1b687f 100644
--- a/mesalib/src/mesa/main/formats.h
+++ b/mesalib/src/mesa/main/formats.h
@@ -266,4 +266,11 @@ _mesa_test_formats(void);
extern gl_format
_mesa_get_srgb_format_linear(gl_format format);
+extern gl_format
+_mesa_get_uncompressed_format(gl_format format);
+
+extern GLuint
+_mesa_format_num_components(gl_format format);
+
+
#endif /* FORMATS_H */
diff --git a/mesalib/src/mesa/main/mipmap.c b/mesalib/src/mesa/main/mipmap.c
index cf9d522f2..869243d1c 100644
--- a/mesalib/src/mesa/main/mipmap.c
+++ b/mesalib/src/mesa/main/mipmap.c
@@ -1985,50 +1985,45 @@ generate_mipmap_uncompressed(struct gl_context *ctx, GLenum target,
static void
generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
struct gl_texture_object *texObj,
- const struct gl_texture_image *srcImage,
+ struct gl_texture_image *srcImage,
GLuint maxLevel)
{
GLint level;
gl_format temp_format;
- GLenum datatype;
- GLuint comps;
- GLuint row;
GLint components;
GLuint temp_src_stride, temp_dst_stride; /* in bytes */
GLchan *temp_src = NULL, *temp_dst = NULL;
+ GLenum temp_datatype;
+ GLenum temp_base_format;
- /* Choose the format we will do _mesa_generate_mipmap_level() in,
- * and uncompress the firstImage into a temporary of that format.
- */
+ /* only two types of compressed textures at this time */
assert(texObj->Target == GL_TEXTURE_2D ||
texObj->Target == GL_TEXTURE_CUBE_MAP_ARB);
- if (srcImage->_BaseFormat == GL_RGB) {
- temp_format = MESA_FORMAT_RGB888;
- components = 3;
- } else if (srcImage->_BaseFormat == GL_RED) {
- temp_format = MESA_FORMAT_R8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_RG) {
- temp_format = MESA_FORMAT_RG88;
- components = 2;
- } else if (srcImage->_BaseFormat == GL_RGBA) {
- temp_format = MESA_FORMAT_RGBA8888;
- components = 4;
- } else if (srcImage->_BaseFormat == GL_LUMINANCE) {
- temp_format = MESA_FORMAT_L8;
- components = 1;
- } else if (srcImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- temp_format = MESA_FORMAT_AL88;
- components = 2;
- } else {
- _mesa_problem(ctx, "bad srcImage->_BaseFormat in _mesa_generate_mipmaps");
- return;
+ /*
+ * Choose a format for the temporary, uncompressed base image.
+ * Then, get number of components, choose temporary image datatype,
+ * and get base format.
+ */
+ temp_format = _mesa_get_uncompressed_format(srcImage->TexFormat);
+
+ components = _mesa_format_num_components(temp_format);
+
+ /* Revisit this if we get compressed formats with >8 bits per component */
+ if (_mesa_get_format_datatype(srcImage->TexFormat)
+ == GL_SIGNED_NORMALIZED) {
+ temp_datatype = GL_BYTE;
+ }
+ else {
+ temp_datatype = GL_UNSIGNED_BYTE;
}
- /* allocate storage for uncompressed GL_RGB or GL_RGBA images */
- temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
+ temp_base_format = _mesa_get_format_base_format(temp_format);
+
+
+ /* allocate storage for the temporary, uncompressed image */
/* 20 extra bytes, just be safe when calling last FetchTexel */
+ temp_src_stride = _mesa_format_row_stride(temp_format, srcImage->Width);
temp_src = (GLubyte *) malloc(temp_src_stride * srcImage->Height + 20);
if (!temp_src) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "generate mipmaps");
@@ -2036,16 +2031,20 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
}
/* decompress base image to the temporary */
- for (row = 0; row < srcImage->Height; row++) {
- GLuint col;
- GLchan *dst = (GLchan *) temp_src + temp_src_stride * row;
- for (col = 0; col < srcImage->Width; col++) {
- srcImage->FetchTexelc(srcImage, col, row, 0, dst);
- dst += components;
- }
+ {
+ /* save pixel packing mode */
+ struct gl_pixelstore_attrib save = ctx->Pack;
+ /* use default/tight packing parameters */
+ ctx->Pack = ctx->DefaultPacking;
+
+ /* Get the uncompressed image */
+ ctx->Driver.GetTexImage(ctx, target, texObj->BaseLevel,
+ temp_base_format, temp_datatype,
+ temp_src, texObj, srcImage);
+ /* restore packing mode */
+ ctx->Pack = save;
}
- _mesa_format_to_type_and_comps(temp_format, &datatype, &comps);
for (level = texObj->BaseLevel; level < maxLevel; level++) {
/* generate image[level+1] from image[level] */
@@ -2086,7 +2085,10 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
return;
}
- _mesa_generate_mipmap_level(target, datatype, comps, border,
+ /* Free old image data */
+ ctx->Driver.FreeTextureImageBuffer(ctx, dstImage);
+
+ _mesa_generate_mipmap_level(target, temp_datatype, components, border,
srcWidth, srcHeight, srcDepth,
temp_src, temp_src_stride / components,
dstWidth, dstHeight, dstDepth,
@@ -2100,8 +2102,7 @@ generate_mipmap_compressed(struct gl_context *ctx, GLenum target,
ctx->Driver.TexImage2D(ctx, target, level + 1,
srcImage->InternalFormat,
dstWidth, dstHeight, border,
- _mesa_get_format_base_format(temp_format),
- GL_UNSIGNED_BYTE,
+ temp_base_format, temp_datatype,
temp_dst, &ctx->DefaultPacking, texObj, dstImage);
/* swap src and dest pointers */
@@ -2130,7 +2131,7 @@ void
_mesa_generate_mipmap(struct gl_context *ctx, GLenum target,
struct gl_texture_object *texObj)
{
- const struct gl_texture_image *srcImage;
+ struct gl_texture_image *srcImage;
GLint maxLevel;
ASSERT(texObj);
diff --git a/mesalib/src/mesa/main/texcompress.c b/mesalib/src/mesa/main/texcompress.c
index 532f79fd5..b821dd0c0 100644
--- a/mesalib/src/mesa/main/texcompress.c
+++ b/mesalib/src/mesa/main/texcompress.c
@@ -37,6 +37,9 @@
#include "mfeatures.h"
#include "mtypes.h"
#include "texcompress.h"
+#include "texcompress_fxt1.h"
+#include "texcompress_rgtc.h"
+#include "texcompress_s3tc.h"
/**
@@ -259,7 +262,6 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
n += 4;
}
}
- return n;
#if FEATURE_ES1 || FEATURE_ES2
if (formats) {
@@ -278,6 +280,8 @@ _mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
n += 10;
}
#endif
+
+ return n;
}
@@ -437,3 +441,86 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
return (GLubyte *) image + offset;
}
+
+
+/**
+ * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
+ */
+void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest)
+{
+ void (*fetch)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel);
+ struct gl_texture_image texImage; /* dummy teximage */
+ GLuint i, j;
+
+ /* setup dummy texture image info */
+ memset(&texImage, 0, sizeof(texImage));
+ texImage.Data = (void *) src;
+ texImage.RowStride = srcRowStride;
+
+ switch (format) {
+ /* DXT formats */
+ case MESA_FORMAT_RGB_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt1;
+ break;
+ case MESA_FORMAT_RGBA_DXT3:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt3;
+ break;
+ case MESA_FORMAT_RGBA_DXT5:
+ fetch = _mesa_fetch_texel_2d_f_rgba_dxt5;
+ break;
+
+ /* FXT1 formats */
+ case MESA_FORMAT_RGB_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgb_fxt1;
+ break;
+ case MESA_FORMAT_RGBA_FXT1:
+ fetch = _mesa_fetch_texel_2d_f_rgba_fxt1;
+ break;
+
+ /* Red/RG formats */
+ case MESA_FORMAT_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_red_rgtc1;
+ break;
+ case MESA_FORMAT_SIGNED_RED_RGTC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_red_rgtc1;
+ break;
+ case MESA_FORMAT_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_rg_rgtc2;
+ break;
+ case MESA_FORMAT_SIGNED_RG_RGTC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_rg_rgtc2;
+ break;
+
+ /* L/LA formats */
+ case MESA_FORMAT_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_l_latc1;
+ break;
+ case MESA_FORMAT_SIGNED_L_LATC1:
+ fetch = _mesa_fetch_texel_2d_f_signed_l_latc1;
+ break;
+ case MESA_FORMAT_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_la_latc2;
+ break;
+ case MESA_FORMAT_SIGNED_LA_LATC2:
+ fetch = _mesa_fetch_texel_2d_f_signed_la_latc2;
+ break;
+
+ default:
+ _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
+ return;
+ }
+
+ for (j = 0; j < height; j++) {
+ for (i = 0; i < width; i++) {
+ fetch(&texImage, i, j, 0, dest);
+ dest += 4;
+ }
+ }
+}
diff --git a/mesalib/src/mesa/main/texcompress.h b/mesalib/src/mesa/main/texcompress.h
index 375cf90c8..2c357068c 100644
--- a/mesalib/src/mesa/main/texcompress.h
+++ b/mesalib/src/mesa/main/texcompress.h
@@ -50,6 +50,11 @@ _mesa_compressed_image_address(GLint col, GLint row, GLint img,
gl_format mesaFormat,
GLsizei width, const GLubyte *image);
+extern void
+_mesa_decompress_image(gl_format format, GLuint width, GLuint height,
+ const GLubyte *src, GLint srcRowStride,
+ GLfloat *dest);
+
#else /* _HAVE_FULL_GL */
/* no-op macros */
diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c
index 46e38d7bc..7e1fc3695 100644
--- a/mesalib/src/mesa/main/texgetimage.c
+++ b/mesalib/src/mesa/main/texgetimage.c
@@ -34,13 +34,14 @@
#include "enums.h"
#include "context.h"
#include "formats.h"
+#include "format_unpack.h"
#include "image.h"
#include "mfeatures.h"
#include "mtypes.h"
#include "pack.h"
#include "pbo.h"
+#include "texcompress.h"
#include "texgetimage.h"
-#include "texfetch.h"
#include "teximage.h"
@@ -75,8 +76,9 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions,
const GLint width = texImage->Width;
const GLint height = texImage->Height;
const GLint depth = texImage->Depth;
- GLint img, row, col;
+ GLint img, row;
GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat));
+ const GLint texelSize = _mesa_get_format_bytes(texImage->TexFormat);
if (!depthRow) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
@@ -88,11 +90,12 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions,
void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
width, height, format, type,
img, row, 0);
- assert(dest);
+ const GLubyte *src = (GLubyte *) texImage->Data +
+ (texImage->ImageOffsets[img] +
+ texImage->RowStride * row) * texelSize;
+
+ _mesa_unpack_float_z_row(texImage->TexFormat, width, src, depthRow);
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, depthRow + col);
- }
_mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack);
}
}
@@ -173,95 +176,141 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions,
/**
- * glGetTexImage for (s)RGBA, Luminance, etc. pixels.
- * This is the slow way since we use texture sampling.
+ * glGetTexImage for color formats (RGBA, RGB, alpha, LA, etc).
+ * Compressed textures are handled here as well.
*/
static void
get_tex_rgba(struct gl_context *ctx, GLuint dimensions,
GLenum format, GLenum type, GLvoid *pixels,
struct gl_texture_image *texImage)
{
- const GLint width = texImage->Width;
- const GLint height = texImage->Height;
- const GLint depth = texImage->Depth;
- const GLenum dataType = _mesa_get_format_datatype(texImage->TexFormat);
+ /* don't want to apply sRGB -> RGB conversion here so override the format */
+ const gl_format texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat);
+ const GLuint width = texImage->Width;
+ const GLuint height = texImage->Height;
+ const GLuint depth = texImage->Depth;
+ const GLenum dataType = _mesa_get_format_datatype(texFormat);
+ const GLenum baseFormat = _mesa_get_format_base_format(texFormat);
/* Normally, no pixel transfer ops are performed during glGetTexImage.
* The only possible exception is component clamping to [0,1].
*/
GLbitfield transferOps = 0x0;
- GLint img, row;
- GLfloat (*rgba)[4] = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
- const GLboolean is_sampler_srgb_decode =
- _mesa_get_format_color_encoding(texImage->TexFormat) == GL_SRGB &&
- texImage->TexObject->Sampler.sRGBDecode == GL_DECODE_EXT;
-
- if (!rgba) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
- return;
- }
- /* Clamping does not apply to GetTexImage (final conversion)?
- * Looks like we need clamp though when going from format
- * containing negative values to unsigned format.
+ /* In general, clamping does not apply to glGetTexImage, except when
+ * the returned type of the image can't hold negative values.
*/
- if (format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) {
- transferOps |= IMAGE_CLAMP_BIT;
- }
- else if (!type_with_negative_values(type) &&
- (dataType == GL_FLOAT ||
- dataType == GL_SIGNED_NORMALIZED)) {
- transferOps |= IMAGE_CLAMP_BIT;
+ if (!type_with_negative_values(type)) {
+ /* the returned image type can't have negative values */
+ if (dataType == GL_FLOAT ||
+ dataType == GL_SIGNED_NORMALIZED ||
+ format == GL_LUMINANCE ||
+ format == GL_LUMINANCE_ALPHA) {
+ transferOps |= IMAGE_CLAMP_BIT;
+ }
}
- /* glGetTexImage always returns sRGB data for sRGB textures. Make sure the
- * fetch functions return sRGB data without linearizing it.
- */
- if (is_sampler_srgb_decode) {
- texImage->TexObject->Sampler.sRGBDecode = GL_SKIP_DECODE_EXT;
- _mesa_set_fetch_functions(texImage, dimensions);
- }
+ if (_mesa_is_format_compressed(texFormat)) {
+ /* Decompress into temp buffer, then pack into user buffer */
+ GLfloat *tempImage, *srcRow;
+ GLuint row;
- for (img = 0; img < depth; img++) {
+ tempImage = (GLfloat *) malloc(texImage->Width * texImage->Height *
+ texImage->Depth * 4 * sizeof(GLfloat));
+ if (!tempImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+ return;
+ }
+
+ _mesa_decompress_image(texFormat, texImage->Width, texImage->Height,
+ texImage->Data, texImage->RowStride, tempImage);
+
+ if (baseFormat == GL_LUMINANCE ||
+ baseFormat == GL_LUMINANCE_ALPHA) {
+ /* Set green and blue to zero since the pack function here will
+ * compute L=R+G+B.
+ */
+ GLuint i;
+ for (i = 0; i < width * height; i++) {
+ tempImage[i * 4 + GCOMP] = tempImage[i * 4 + BCOMP] = 0.0f;
+ }
+ }
+
+ srcRow = tempImage;
for (row = 0; row < height; row++) {
void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
width, height, format, type,
- img, row, 0);
- GLint col;
+ 0, row, 0);
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow,
+ format, type, dest, &ctx->Pack, transferOps);
+ srcRow += width * 4;
+ }
+
+ free(tempImage);
+ }
+ else {
+ /* No decompression needed */
+ const GLint texelSize = _mesa_get_format_bytes(texFormat);
+ GLuint img, row;
+ GLfloat (*rgba)[4];
+
+ rgba = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
+ if (!rgba) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()");
+ return;
+ }
+
+ for (img = 0; img < depth; img++) {
+ for (row = 0; row < height; row++) {
+ void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
+ width, height, format, type,
+ img, row, 0);
+ const GLubyte *src = (const GLubyte *) texImage->Data +
+ (texImage->ImageOffsets[img] +
+ texImage->RowStride * row) * texelSize;
+
+ _mesa_unpack_rgba_row(texFormat, width, src, rgba);
- for (col = 0; col < width; col++) {
- texImage->FetchTexelf(texImage, col, row, img, rgba[col]);
if (texImage->_BaseFormat == GL_ALPHA) {
- rgba[col][RCOMP] = 0.0F;
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][RCOMP] = 0.0F;
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
}
else if (texImage->_BaseFormat == GL_LUMINANCE) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
}
else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ }
}
else if (texImage->_BaseFormat == GL_INTENSITY) {
- rgba[col][GCOMP] = 0.0F;
- rgba[col][BCOMP] = 0.0F;
- rgba[col][ACOMP] = 1.0F;
+ GLint col;
+ for (col = 0; col < width; col++) {
+ rgba[col][GCOMP] = 0.0F;
+ rgba[col][BCOMP] = 0.0F;
+ rgba[col][ACOMP] = 1.0F;
+ }
}
+
+ _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
+ format, type, dest,
+ &ctx->Pack, transferOps);
}
- _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) rgba,
- format, type, dest,
- &ctx->Pack, transferOps);
}
- }
- if (is_sampler_srgb_decode) {
- texImage->TexObject->Sampler.sRGBDecode = GL_DECODE_EXT;
- _mesa_set_fetch_functions(texImage, dimensions);
+ free(rgba);
}
-
- free(rgba);
}