mesa: add fallthrough comments to glformats.c
[mesa.git] / src / mesa / main / glformats.c
index f2af50cd855e4f6eb45df312e5eb11391d76b3f3..252599340aa05f70072f1de109888c356464fa10 100644 (file)
@@ -1886,6 +1886,7 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
       case GL_RED:
          if (_mesa_has_rg_textures(ctx))
             return GL_NO_ERROR;
+         /* fallthrough */
       default:
          return GL_INVALID_OPERATION;
       }
@@ -2391,7 +2392,7 @@ _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
         is_astc_3d_format(internalFormat)))
         return GL_RGBA;
 
-   if (!_mesa_has_MESA_ycbcr_texture(ctx)) {
+   if (_mesa_has_MESA_ycbcr_texture(ctx)) {
       if (internalFormat == GL_YCBCR_MESA)
          return GL_YCBCR_MESA;
    }
@@ -2927,6 +2928,7 @@ _mesa_gles_error_check_format_and_type(const struct gl_context *ctx,
          case GL_RGBA:
             if (_mesa_has_OES_texture_float(ctx) && internalFormat == format)
                break;
+         /* fallthrough */
          default:
             return GL_INVALID_OPERATION;
          }
@@ -2935,6 +2937,7 @@ _mesa_gles_error_check_format_and_type(const struct gl_context *ctx,
       case GL_HALF_FLOAT_OES:
          if (_mesa_has_OES_texture_half_float(ctx) && internalFormat == format)
             break;
+         /* fallthrough */
       default:
          return GL_INVALID_OPERATION;
       }
@@ -3059,14 +3062,15 @@ _mesa_gles_error_check_format_and_type(const struct gl_context *ctx,
             if (ctx->Version <= 20)
                return GL_INVALID_OPERATION;
             break;
-         case GL_RGB:
-            if (_mesa_has_OES_texture_float(ctx) && internalFormat == format)
-               break;
          case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
          case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
             if (!_mesa_has_EXT_texture_compression_bptc(ctx))
                return GL_INVALID_OPERATION;
             break;
+         case GL_RGB:
+            if (_mesa_has_OES_texture_float(ctx) && internalFormat == format)
+               break;
+            /* fallthrough */
          default:
             return GL_INVALID_OPERATION;
          }
@@ -3501,7 +3505,43 @@ get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
    case GL_INTENSITY:
       set_swizzle(swizzle, 0, 0, 0, 0);
       return true;
+   case GL_DEPTH_COMPONENT:
+      set_swizzle(swizzle, 0, 6, 6, 6);
+      return true;
+   case GL_STENCIL_INDEX:
+      set_swizzle(swizzle, 6, 0, 6, 6);
+      return true;
+   default:
+      return false;
+   }
+}
+
+bool
+_mesa_swap_bytes_in_type_enum(GLenum *type)
+{
+   switch (*type) {
+   case GL_UNSIGNED_INT_8_8_8_8:
+      *type = GL_UNSIGNED_INT_8_8_8_8_REV;
+      return true;
+   case GL_UNSIGNED_INT_8_8_8_8_REV:
+      *type = GL_UNSIGNED_INT_8_8_8_8;
+      return true;
+   case GL_UNSIGNED_SHORT_8_8_MESA:
+      *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
+      return true;
+   case GL_UNSIGNED_SHORT_8_8_REV_MESA:
+      *type = GL_UNSIGNED_SHORT_8_8_MESA;
+      return true;
+   case GL_BYTE:
+   case GL_UNSIGNED_BYTE:
+      /* format/types that are arrays of 8-bit values are unaffected by
+       * swapBytes.
+       */
+      return true;
    default:
+      /* swapping bytes on 4444, 1555, or >8 bit per channel types etc. will
+       * never match a Mesa format.
+       */
       return false;
    }
 }
@@ -3530,6 +3570,9 @@ _mesa_format_from_format_and_type(GLenum format, GLenum type)
    bool normalized = false, is_float = false, is_signed = false;
    int num_channels = 0, type_size = 0;
 
+   if (format == GL_COLOR_INDEX)
+      return MESA_FORMAT_NONE;
+
    /* Extract array format type information from the OpenGL data type */
    switch (type) {
    case GL_UNSIGNED_BYTE:
@@ -3577,10 +3620,24 @@ _mesa_format_from_format_and_type(GLenum format, GLenum type)
     * create the array format
     */
    if (is_array_format) {
-      normalized = !_mesa_is_enum_format_integer(format);
+      enum mesa_array_format_base_format bf;
+      switch (format) {
+      case GL_DEPTH_COMPONENT:
+         bf = MESA_ARRAY_FORMAT_BASE_FORMAT_DEPTH;
+         break;
+      case GL_STENCIL_INDEX:
+         bf = MESA_ARRAY_FORMAT_BASE_FORMAT_STENCIL;
+         break;
+      default:
+         bf = MESA_ARRAY_FORMAT_BASE_FORMAT_RGBA_VARIANTS;
+         break;
+      }
+
+      normalized = !(_mesa_is_enum_format_integer(format) ||
+                     format == GL_STENCIL_INDEX);
       num_channels = _mesa_components_in_format(format);
 
-      return MESA_ARRAY_FORMAT(type_size, is_signed, is_float,
+      return MESA_ARRAY_FORMAT(bf, type_size, is_signed, is_float,
                                normalized, num_channels,
                                swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
    }