[Mesa-dev] [PATCH 02/22] glformats: Add GL_DEPTH_COMPONENT and GL_STENCIL_INDEX to array formats

Chris Wilson chris at chris-wilson.co.uk
Sat Aug 5 09:39:54 UTC 2017


GL_DEPTH_COMPONENT and GL_STENCIL_INDEX are simple array formats of the
indiciated types, but were absent from the get_swizzle_from_format()
table causing them to be neglect and triggering
unreachable("Unsupported format").

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/mesa/main/glformats.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 4f240206ff..06be3ec48d 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -3326,8 +3326,11 @@ set_swizzle(uint8_t *swizzle, int x, int y, int z, int w)
 }
 
 static bool
-get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
+get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle, bool *is_array)
 {
+   if (!*is_array)
+      return false;
+
    switch (format) {
    case GL_RGBA:
    case GL_RGBA_INTEGER_EXT:
@@ -3378,8 +3381,14 @@ get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
       return true;
    case GL_INTENSITY:
       set_swizzle(swizzle, 0, 0, 0, 0);
-      return true;
+      return false;
+   case GL_DEPTH_COMPONENT:
+   case GL_STENCIL_INDEX:
+      /* Pretend to be a single R channel when falling back to an array */
+      set_swizzle(swizzle, 0, 4, 4, 5);
+      return false;
    default:
+      *is_array = false;
       return false;
    }
 }
@@ -3447,14 +3456,10 @@ _mesa_format_from_format_and_type(GLenum format, GLenum type)
       break;
    }
 
-   /* Extract array format swizzle information from the OpenGL format */
-   if (is_array_format)
-      is_array_format = get_swizzle_from_gl_format(format, swizzle);
-
    /* If this is an array format type after checking data type and format,
     * create the array format
     */
-   if (is_array_format) {
+   if (get_swizzle_from_gl_format(format, swizzle, &is_array_format)) {
       normalized = !_mesa_is_enum_format_integer(format);
       num_channels = _mesa_components_in_format(format);
 
@@ -3625,6 +3630,18 @@ _mesa_format_from_format_and_type(GLenum format, GLenum type)
       break;
    }
 
+   /* If this is an array format type after checking data type and format,
+    * create the array format
+    */
+   if (is_array_format) {
+      normalized = !_mesa_is_enum_format_integer(format);
+      num_channels = _mesa_components_in_format(format);
+
+      return MESA_ARRAY_FORMAT(type_size, is_signed, is_float,
+                               normalized, num_channels,
+                               swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
+   }
+
    /* If we got here it means that we could not find a Mesa format that
     * matches the GL format/type provided. We may need to add a new Mesa
     * format in that case.
-- 
2.13.3



More information about the mesa-dev mailing list