mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / glformats.c
index 02709a17cf0a9c07ee948d81cf09898ad45a77bb..9bb341cc0e95997e3455631a999755fc609b02c3 100644 (file)
@@ -1136,76 +1136,60 @@ GLenum
 _mesa_get_nongeneric_internalformat(GLenum format)
 {
    switch (format) {
-      /* GL 1.1 formats. */
-      case 4:
-      case GL_RGBA:
-         return GL_RGBA8;
-
-      case 3:
-      case GL_RGB:
-         return GL_RGB8;
-
-      case 2:
-      case GL_LUMINANCE_ALPHA:
-         return GL_LUMINANCE8_ALPHA8;
-
-      case 1:
-      case GL_LUMINANCE:
-         return GL_LUMINANCE8;
-
-      case GL_ALPHA:
-         return GL_ALPHA8;
-
-      case GL_INTENSITY:
-         return GL_INTENSITY8;
-
-      /* GL_ARB_texture_rg */
-      case GL_RED:
-         return GL_R8;
-
-      case GL_RG:
-         return GL_RG8;
-
-      /* GL_EXT_texture_sRGB */
-      case GL_SRGB:
-         return GL_SRGB8;
-
-      case GL_SRGB_ALPHA:
-         return GL_SRGB8_ALPHA8;
-
-      case GL_SLUMINANCE:
-         return GL_SLUMINANCE8;
-
-      case GL_SLUMINANCE_ALPHA:
-         return GL_SLUMINANCE8_ALPHA8;
-
-      /* GL_EXT_texture_snorm */
-      case GL_RGBA_SNORM:
-         return GL_RGBA8_SNORM;
-
-      case GL_RGB_SNORM:
-         return GL_RGB8_SNORM;
-
-      case GL_RG_SNORM:
-         return GL_RG8_SNORM;
-
-      case GL_RED_SNORM:
-         return GL_R8_SNORM;
-
-      case GL_LUMINANCE_ALPHA_SNORM:
-         return GL_LUMINANCE8_ALPHA8_SNORM;
-
-      case GL_LUMINANCE_SNORM:
-         return GL_LUMINANCE8_SNORM;
+   /* GL 1.1 formats. */
+   case 4:
+   case GL_RGBA:
+      return GL_RGBA8;
+   case 3:
+   case GL_RGB:
+      return GL_RGB8;
+   case 2:
+   case GL_LUMINANCE_ALPHA:
+      return GL_LUMINANCE8_ALPHA8;
+   case 1:
+   case GL_LUMINANCE:
+      return GL_LUMINANCE8;
+   case GL_ALPHA:
+      return GL_ALPHA8;
+   case GL_INTENSITY:
+      return GL_INTENSITY8;
 
-      case GL_ALPHA_SNORM:
-         return GL_ALPHA8_SNORM;
+   /* GL_ARB_texture_rg */
+   case GL_RED:
+      return GL_R8;
+   case GL_RG:
+      return GL_RG8;
 
-      case GL_INTENSITY_SNORM:
-         return GL_INTENSITY8_SNORM;
+   /* GL_EXT_texture_sRGB */
+   case GL_SRGB:
+      return GL_SRGB8;
+   case GL_SRGB_ALPHA:
+      return GL_SRGB8_ALPHA8;
+   case GL_SLUMINANCE:
+      return GL_SLUMINANCE8;
+   case GL_SLUMINANCE_ALPHA:
+      return GL_SLUMINANCE8_ALPHA8;
+
+   /* GL_EXT_texture_snorm */
+   case GL_RGBA_SNORM:
+      return GL_RGBA8_SNORM;
+   case GL_RGB_SNORM:
+      return GL_RGB8_SNORM;
+   case GL_RG_SNORM:
+      return GL_RG8_SNORM;
+   case GL_RED_SNORM:
+      return GL_R8_SNORM;
+   case GL_LUMINANCE_ALPHA_SNORM:
+      return GL_LUMINANCE8_ALPHA8_SNORM;
+   case GL_LUMINANCE_SNORM:
+      return GL_LUMINANCE8_SNORM;
+   case GL_ALPHA_SNORM:
+      return GL_ALPHA8_SNORM;
+   case GL_INTENSITY_SNORM:
+      return GL_INTENSITY8_SNORM;
 
-      default:
-         return format;
+   default:
+      return format;
    }
 }
 
@@ -1219,28 +1203,20 @@ _mesa_get_linear_internalformat(GLenum format)
    switch (format) {
    case GL_SRGB:
       return GL_RGB;
-
    case GL_SRGB_ALPHA:
       return GL_RGBA;
-
    case GL_SRGB8:
       return GL_RGB8;
-
    case GL_SRGB8_ALPHA8:
       return GL_RGBA8;
-
    case GL_SLUMINANCE8:
       return GL_LUMINANCE8;
-
    case GL_SLUMINANCE:
       return GL_LUMINANCE;
-
    case GL_SLUMINANCE_ALPHA:
       return GL_LUMINANCE_ALPHA;
-
    case GL_SLUMINANCE8_ALPHA8:
       return GL_LUMINANCE8_ALPHA8;
-
    default:
       return format;
    }
@@ -1262,6 +1238,22 @@ GLenum
 _mesa_error_check_format_and_type(const struct gl_context *ctx,
                                   GLenum format, GLenum type)
 {
+   /* From OpenGL 3.3 spec, page 220:
+    *    "If the format is DEPTH_STENCIL, then values are taken from
+    *    both the depth buffer and the stencil buffer. If there is no
+    *    depth buffer or if there is no stencil buffer, then the error
+    *    INVALID_OPERATION occurs. If the type parameter is not
+    *    UNSIGNED_INT_24_8 or FLOAT_32_UNSIGNED_INT_24_8_REV, then the
+    *    error INVALID_ENUM occurs."
+    *
+    * OpenGL ES still generates GL_INVALID_OPERATION because glReadPixels
+    * cannot be used to read depth or stencil in that API.
+    */
+   if (_mesa_is_desktop_gl(ctx) && format == GL_DEPTH_STENCIL
+       && type != GL_UNSIGNED_INT_24_8
+       && type != GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
+      return GL_INVALID_ENUM;
+
    /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
    switch (type) {
    case GL_BITMAP:
@@ -1347,10 +1339,8 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_INT:
             case GL_UNSIGNED_INT:
             case GL_FLOAT:
-               return GL_NO_ERROR;
             case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
+               return GL_NO_ERROR;
             default:
                return GL_INVALID_ENUM;
          }
@@ -1373,10 +1363,8 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_INT:
             case GL_UNSIGNED_INT:
             case GL_FLOAT:
-               return GL_NO_ERROR;
             case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
+               return GL_NO_ERROR;
             default:
                return GL_INVALID_ENUM;
          }
@@ -1392,10 +1380,8 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_INT:
             case GL_UNSIGNED_INT:
             case GL_FLOAT:
-               return GL_NO_ERROR;
             case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
+               return GL_NO_ERROR;
             default:
                return GL_INVALID_ENUM;
          }
@@ -1413,14 +1399,12 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_UNSIGNED_BYTE_2_3_3_REV:
             case GL_UNSIGNED_SHORT_5_6_5:
             case GL_UNSIGNED_SHORT_5_6_5_REV:
+            case GL_HALF_FLOAT:
                return GL_NO_ERROR;
             case GL_UNSIGNED_INT_2_10_10_10_REV:
                /* OK by GL_EXT_texture_type_2_10_10_10_REV */
                return (ctx->API == API_OPENGLES2)
                   ? GL_NO_ERROR : GL_INVALID_ENUM;
-            case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
             case GL_UNSIGNED_INT_5_9_9_9_REV:
                return ctx->Extensions.EXT_texture_shared_exponent
                   ? GL_NO_ERROR : GL_INVALID_ENUM;
@@ -1443,10 +1427,8 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_INT:
             case GL_UNSIGNED_INT:
             case GL_FLOAT:
-               return GL_NO_ERROR;
             case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
+               return GL_NO_ERROR;
             default:
                return GL_INVALID_ENUM;
          }
@@ -1470,10 +1452,8 @@ _mesa_error_check_format_and_type(const struct gl_context *ctx,
             case GL_UNSIGNED_INT_8_8_8_8_REV:
             case GL_UNSIGNED_INT_10_10_10_2:
             case GL_UNSIGNED_INT_2_10_10_10_REV:
-               return GL_NO_ERROR;
             case GL_HALF_FLOAT:
-               return ctx->Extensions.ARB_half_float_pixel
-                  ? GL_NO_ERROR : GL_INVALID_ENUM;
+               return GL_NO_ERROR;
             default:
                return GL_INVALID_ENUM;
          }