[Mesa-dev] [PATCH 1/2] mesa: add GL_RED, GL_RG support for floating point textures

Tapani Pälli tapani.palli at intel.com
Mon Jun 8 01:14:18 PDT 2015


Mesa supports EXT_texture_rg and OES_texture_float. This patch adds
support for using unsized enums GL_RED and GL_RG for floating point
targets and writes proper checks for internalformat when format is
GL_RED or GL_RG and type is of GL_FLOAT or GL_HALF_FLOAT.

Later, internalformat will get adjusted by adjust_for_oes_float_texture
after these checks.

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90748
---
 src/mesa/main/glformats.c | 119 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 105 insertions(+), 14 deletions(-)

diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 6a77c91..edc4918 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -2029,6 +2029,41 @@ _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
 
 
 /**
+ * Checks if internalformat is invalid for OES_texture_float and EXT_texture_rg
+ */
+static bool
+invalid_rg_float_internal(GLenum internalFormat)
+{
+   switch (internalFormat) {
+   case GL_R8_SNORM:
+   case GL_R8:
+   case GL_RG8:
+   case GL_RG8_SNORM:
+   case GL_RGB:
+   case GL_RGB8:
+   case GL_RGB8_SNORM:
+   case GL_RGB565:
+   case GL_RGBA:
+   case GL_RGBA4:
+   case GL_RGBA8:
+   case GL_RGBA8_SNORM:
+   case GL_RGB5_A1:
+   case GL_RGB10_A2:
+   case GL_SRGB8:
+   case GL_SRGB8_ALPHA8:
+   case GL_ALPHA:
+   case GL_LUMINANCE:
+   case GL_LUMINANCE_ALPHA:
+   case GL_R11F_G11F_B10F:
+   case GL_RGB9_E5:
+      return true;
+   default:
+      return false;
+   };
+}
+
+
+/**
  * Do error checking of format/type combinations for OpenGL ES 3
  * glTex[Sub]Image.
  * \return error code, or GL_NO_ERROR.
@@ -2291,20 +2326,47 @@ _mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
             return GL_INVALID_OPERATION;
          break;
 
+      case GL_HALF_FLOAT_OES:
       case GL_HALF_FLOAT:
-         if (internalFormat != GL_RG16F)
+         switch (internalFormat) {
+         case GL_R16F:
+         case GL_R32F:
+         case GL_RG32F:
+         case GL_RGB16F:
+         case GL_RGB32F:
+         case GL_RGBA16F:
+         case GL_RGBA32F:
             return GL_INVALID_OPERATION;
-         break;
+         default:
+            break;
+         }
+
+         if (invalid_rg_float_internal(internalFormat))
+            return GL_INVALID_OPERATION;
+
+         if (ctx->Extensions.ARB_texture_rg &&
+             ctx->Extensions.OES_texture_half_float)
+            break;
 
       case GL_FLOAT:
          switch (internalFormat) {
-         case GL_RG16F:
-         case GL_RG32F:
-            break;
-         default:
+         case GL_R16F:
+         case GL_R32F:
+         case GL_RGB16F:
+         case GL_RGB32F:
+         case GL_RGBA16F:
+         case GL_RGBA32F:
             return GL_INVALID_OPERATION;
+         default:
+            break;
          }
-         break;
+
+         if (invalid_rg_float_internal(internalFormat))
+            return GL_INVALID_OPERATION;
+
+         if (ctx->Extensions.ARB_texture_rg &&
+             ctx->Extensions.OES_texture_float)
+            break;
 
       default:
          return GL_INVALID_OPERATION;
@@ -2361,19 +2423,48 @@ _mesa_es3_error_check_format_and_type(const struct gl_context *ctx,
          break;
 
       case GL_HALF_FLOAT:
-         if (internalFormat != GL_R16F)
-            return GL_INVALID_OPERATION;
-         break;
+      case GL_HALF_FLOAT_OES:
 
-      case GL_FLOAT:
          switch (internalFormat) {
-         case GL_R16F:
          case GL_R32F:
-            break;
+         case GL_RG16F:
+         case GL_RG32F:
+         case GL_RGB16F:
+         case GL_RGB32F:
+         case GL_RGBA16F:
+         case GL_RGBA32F:
+            return GL_INVALID_OPERATION;
          default:
+            break;
+         }
+
+         if (invalid_rg_float_internal(internalFormat))
+            return GL_INVALID_OPERATION;
+
+         if (ctx->Extensions.ARB_texture_rg &&
+             ctx->Extensions.OES_texture_half_float)
+            break;
+
+      case GL_FLOAT:
+
+         switch (internalFormat) {
+         case GL_RG16F:
+         case GL_RG32F:
+         case GL_RGB16F:
+         case GL_RGB32F:
+         case GL_RGBA16F:
+         case GL_RGBA32F:
             return GL_INVALID_OPERATION;
+         default:
+            break;
          }
-         break;
+
+         if (invalid_rg_float_internal(internalFormat))
+            return GL_INVALID_OPERATION;
+
+         if (ctx->Extensions.ARB_texture_rg &&
+             ctx->Extensions.OES_texture_float)
+            break;
 
       default:
          return GL_INVALID_OPERATION;
-- 
2.1.0



More information about the mesa-dev mailing list