mesa: Allow GL_DEPTH_COMPONENT and GL_DEPTH_STENCIL combinations in glTexImage{123}D()
[mesa.git] / src / mesa / main / format_unpack.c
index a2e3445cee4c8a6a546dca1fb6db07775e52320c..276ba556a15cff6b7584d1aee6be96f4cd462424 100644 (file)
@@ -234,6 +234,9 @@ unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
 static void
 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
 {
+   /* Warning: this function does not match the current Mesa definition
+    * of MESA_FORMAT_R5G6B5_UNORM.
+    */
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
    for (i = 0; i < n; i++) {
@@ -300,6 +303,9 @@ unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
 static void
 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
 {
+   /* Warning: this function does not match the current Mesa definition
+    * of MESA_FORMAT_A1R5G5B5_UNORM.
+    */
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
    for (i = 0; i < n; i++) {
@@ -2360,9 +2366,9 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_ARGB2101010_UINT;
       table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_ABGR2101010_UINT;
       table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_Z24_S8;
-      table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_S8_Z24;
+      table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_S8_Z24;
       table[MESA_FORMAT_Z_UNORM16] = unpack_Z16;
-      table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_X8_Z24;
+      table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_X8_Z24;
       table[MESA_FORMAT_X8Z24_UNORM] = unpack_Z24_X8;
       table[MESA_FORMAT_Z_UNORM32] = unpack_Z32;
       table[MESA_FORMAT_S_UINT8] = unpack_S8;
@@ -2699,6 +2705,9 @@ unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
 static void
 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
 {
+   /* Warning: this function does not match the current Mesa definition
+    * of MESA_FORMAT_R5G6B5_UNORM.
+    */
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
    for (i = 0; i < n; i++) {
@@ -2765,6 +2774,9 @@ unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
 static void
 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
 {
+   /* Warning: this function does not match the current Mesa definition
+    * of MESA_FORMAT_A1R5G5B5_UNORM.
+    */
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
    for (i = 0; i < n; i++) {
@@ -3974,8 +3986,8 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
    case MESA_FORMAT_X8Z24_UNORM:
       unpack = unpack_float_z_Z24_X8;
       break;
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
+   case MESA_FORMAT_Z24_UNORM_X8_UINT:
       unpack = unpack_float_z_X8_Z24;
       break;
    case MESA_FORMAT_Z_UNORM16:
@@ -4079,8 +4091,8 @@ _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
    case MESA_FORMAT_X8Z24_UNORM:
       unpack = unpack_uint_z_Z24_X8;
       break;
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
+   case MESA_FORMAT_Z24_UNORM_X8_UINT:
       unpack = unpack_uint_z_X8_Z24;
       break;
    case MESA_FORMAT_Z_UNORM16:
@@ -4152,7 +4164,7 @@ _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
       unpack_ubyte_s_Z24_S8(src, dst, n);
       break;
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
+   case MESA_FORMAT_Z24_UNORM_S8_UINT:
       unpack_ubyte_s_S8_Z24(src, dst, n);
       break;
    case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
@@ -4176,12 +4188,31 @@ unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
    }
 }
 
+static void
+unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
+                                         GLuint *dst, GLuint n)
+{
+   GLuint i;
+
+   for (i = 0; i < n; i++) {
+      /* 8 bytes per pixel (float + uint32) */
+      GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
+      GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
+      GLuint s = src[i * 2 + 1] & 0xff;
+      dst[i] = (z24 << 8) | s;
+   }
+}
+
 static void
 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
 {
    memcpy(dst, src, n * 4);
 }
 
+/**
+ * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
+ * \param format  the source data format
+ */
 void
 _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
                                         const void *src, GLuint *dst)
@@ -4190,9 +4221,12 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
       unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
       break;
-   case MESA_FORMAT_Z24_UNORM_X8_UINT:
+   case MESA_FORMAT_Z24_UNORM_S8_UINT:
       unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
       break;
+   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+      unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
+      break;
    default:
       _mesa_problem(NULL,
                     "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",