mesa: Add the infrastructure for KHR_texture_compression_astc_sliced_3d
[mesa.git] / src / mesa / main / glformats.c
index 6f862d7848fc96c5f14c0c2352170c05c6c4ea60..0c2210a42d9f0bdf36df6a7d169312fa0a5b03e7 100644 (file)
@@ -823,10 +823,10 @@ _mesa_is_enum_format_signed_int(GLenum format)
 }
 
 /**
- * Test if the given format is an ASTC format.
+ * Test if the given format is an ASTC 2D format.
  */
-GLboolean
-_mesa_is_astc_format(GLenum internalFormat)
+static bool
+is_astc_2d_format(GLenum internalFormat)
 {
    switch (internalFormat) {
    case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
@@ -896,6 +896,39 @@ is_astc_3d_format(GLenum internalFormat)
    }
 }
 
+/**
+ * Test if the given format is an ASTC format.
+ */
+GLboolean
+_mesa_is_astc_format(GLenum internalFormat)
+{
+   return is_astc_2d_format(internalFormat) ||
+          is_astc_3d_format(internalFormat);
+}
+
+/**
+ * Test if the given format is an ETC2 format.
+ */
+GLboolean
+_mesa_is_etc2_format(GLenum internalFormat)
+{
+   switch (internalFormat) {
+   case GL_COMPRESSED_RGB8_ETC2:
+   case GL_COMPRESSED_SRGB8_ETC2:
+   case GL_COMPRESSED_RGBA8_ETC2_EAC:
+   case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
+   case GL_COMPRESSED_R11_EAC:
+   case GL_COMPRESSED_RG11_EAC:
+   case GL_COMPRESSED_SIGNED_R11_EAC:
+   case GL_COMPRESSED_SIGNED_RG11_EAC:
+   case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+   case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
+      return true;
+   default:
+      return false;
+   }
+}
+
 /**
  * Test if the given format is an integer (non-normalized) format.
  */
@@ -2378,8 +2411,10 @@ _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
             return base_compressed;
    }
 
-   if (ctx->Extensions.KHR_texture_compression_astc_ldr &&
-      _mesa_is_astc_format(internalFormat))
+   if ((ctx->Extensions.KHR_texture_compression_astc_ldr &&
+        is_astc_2d_format(internalFormat)) ||
+       (ctx->Extensions.OES_texture_compression_astc &&
+        is_astc_3d_format(internalFormat)))
         return GL_RGBA;
 
    if (ctx->Extensions.MESA_ycbcr_texture) {
@@ -3644,7 +3679,8 @@ _mesa_is_es3_color_renderable(GLenum internal_format)
  * is marked "Texture Filterable" in Table 8.10 of the ES 3.2 specification.
  */
 bool
-_mesa_is_es3_texture_filterable(GLenum internal_format)
+_mesa_is_es3_texture_filterable(const struct gl_context *ctx,
+                                GLenum internal_format)
 {
    switch (internal_format) {
    case GL_R8:
@@ -3668,6 +3704,20 @@ _mesa_is_es3_texture_filterable(GLenum internal_format)
    case GL_R11F_G11F_B10F:
    case GL_RGB9_E5:
       return true;
+   case GL_R32F:
+   case GL_RG32F:
+   case GL_RGB32F:
+   case GL_RGBA32F:
+      /* The OES_texture_float_linear spec says:
+       *
+       *    "When implemented against OpenGL ES 3.0 or later versions, sized
+       *     32-bit floating-point formats become texture-filterable. This
+       *     should be noted by, for example, checking the ``TF'' column of
+       *     table 8.13 in the ES 3.1 Specification (``Correspondence of sized
+       *     internal formats to base internal formats ... and use cases ...'')
+       *     for the R32F, RG32F, RGB32F, and RGBA32F formats."
+       */
+      return ctx->Extensions.OES_texture_float_linear;
    default:
       return false;
    }