[Mesa-dev] [PATCH 2/5] mesa: Make validate_texbuffer_format function available externally

Pi Tabred servuswiegehtz at yahoo.de
Tue Dec 10 05:13:03 PST 2013


 - change storage class from static to extern
 - rename validate_texbuffer_format to _mesa_validate_texbuffer_format
---
 src/mesa/main/teximage.c | 398 ++++++++++++++++++++++++-----------------------
 src/mesa/main/teximage.h |   4 +
 2 files changed, 206 insertions(+), 196 deletions(-)

diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 7ec3e20..6e04ba5 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1519,6 +1519,207 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
 }
 
 
+static gl_format
+get_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
+{
+   switch (internalFormat) {
+   case GL_ALPHA8:
+      return MESA_FORMAT_A8;
+   case GL_ALPHA16:
+      return MESA_FORMAT_A16;
+   case GL_ALPHA16F_ARB:
+      return MESA_FORMAT_ALPHA_FLOAT16;
+   case GL_ALPHA32F_ARB:
+      return MESA_FORMAT_ALPHA_FLOAT32;
+   case GL_ALPHA8I_EXT:
+      return MESA_FORMAT_ALPHA_INT8;
+   case GL_ALPHA16I_EXT:
+      return MESA_FORMAT_ALPHA_INT16;
+   case GL_ALPHA32I_EXT:
+      return MESA_FORMAT_ALPHA_INT32;
+   case GL_ALPHA8UI_EXT:
+      return MESA_FORMAT_ALPHA_UINT8;
+   case GL_ALPHA16UI_EXT:
+      return MESA_FORMAT_ALPHA_UINT16;
+   case GL_ALPHA32UI_EXT:
+      return MESA_FORMAT_ALPHA_UINT32;
+   case GL_LUMINANCE8:
+      return MESA_FORMAT_L8;
+   case GL_LUMINANCE16:
+      return MESA_FORMAT_L16;
+   case GL_LUMINANCE16F_ARB:
+      return MESA_FORMAT_LUMINANCE_FLOAT16;
+   case GL_LUMINANCE32F_ARB:
+      return MESA_FORMAT_LUMINANCE_FLOAT32;
+   case GL_LUMINANCE8I_EXT:
+      return MESA_FORMAT_LUMINANCE_INT8;
+   case GL_LUMINANCE16I_EXT:
+      return MESA_FORMAT_LUMINANCE_INT16;
+   case GL_LUMINANCE32I_EXT:
+      return MESA_FORMAT_LUMINANCE_INT32;
+   case GL_LUMINANCE8UI_EXT:
+      return MESA_FORMAT_LUMINANCE_UINT8;
+   case GL_LUMINANCE16UI_EXT:
+      return MESA_FORMAT_LUMINANCE_UINT16;
+   case GL_LUMINANCE32UI_EXT:
+      return MESA_FORMAT_LUMINANCE_UINT32;
+   case GL_LUMINANCE8_ALPHA8:
+      return MESA_FORMAT_AL88;
+   case GL_LUMINANCE16_ALPHA16:
+      return MESA_FORMAT_AL1616;
+   case GL_LUMINANCE_ALPHA16F_ARB:
+      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
+   case GL_LUMINANCE_ALPHA32F_ARB:
+      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
+   case GL_LUMINANCE_ALPHA8I_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_INT8;
+   case GL_LUMINANCE_ALPHA16I_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_INT8;
+   case GL_LUMINANCE_ALPHA32I_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_INT16;
+   case GL_LUMINANCE_ALPHA8UI_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_UINT8;
+   case GL_LUMINANCE_ALPHA16UI_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_UINT16;
+   case GL_LUMINANCE_ALPHA32UI_EXT:
+      return MESA_FORMAT_LUMINANCE_ALPHA_UINT32;
+   case GL_INTENSITY8:
+      return MESA_FORMAT_I8;
+   case GL_INTENSITY16:
+      return MESA_FORMAT_I16;
+   case GL_INTENSITY16F_ARB:
+      return MESA_FORMAT_INTENSITY_FLOAT16;
+   case GL_INTENSITY32F_ARB:
+      return MESA_FORMAT_INTENSITY_FLOAT32;
+   case GL_INTENSITY8I_EXT:
+      return MESA_FORMAT_INTENSITY_INT8;
+   case GL_INTENSITY16I_EXT:
+      return MESA_FORMAT_INTENSITY_INT16;
+   case GL_INTENSITY32I_EXT:
+      return MESA_FORMAT_INTENSITY_INT32;
+   case GL_INTENSITY8UI_EXT:
+      return MESA_FORMAT_INTENSITY_UINT8;
+   case GL_INTENSITY16UI_EXT:
+      return MESA_FORMAT_INTENSITY_UINT16;
+   case GL_INTENSITY32UI_EXT:
+      return MESA_FORMAT_INTENSITY_UINT32;
+   case GL_RGBA8:
+      return MESA_FORMAT_RGBA8888_REV;
+   case GL_RGBA16:
+      return MESA_FORMAT_RGBA_16;
+   case GL_RGBA16F_ARB:
+      return MESA_FORMAT_RGBA_FLOAT16;
+   case GL_RGBA32F_ARB:
+      return MESA_FORMAT_RGBA_FLOAT32;
+   case GL_RGBA8I_EXT:
+      return MESA_FORMAT_RGBA_INT8;
+   case GL_RGBA16I_EXT:
+      return MESA_FORMAT_RGBA_INT16;
+   case GL_RGBA32I_EXT:
+      return MESA_FORMAT_RGBA_INT32;
+   case GL_RGBA8UI_EXT:
+      return MESA_FORMAT_RGBA_UINT8;
+   case GL_RGBA16UI_EXT:
+      return MESA_FORMAT_RGBA_UINT16;
+   case GL_RGBA32UI_EXT:
+      return MESA_FORMAT_RGBA_UINT32;
+
+   case GL_RG8:
+      return MESA_FORMAT_GR88;
+   case GL_RG16:
+      return MESA_FORMAT_GR1616;
+   case GL_RG16F:
+      return MESA_FORMAT_RG_FLOAT16;
+   case GL_RG32F:
+      return MESA_FORMAT_RG_FLOAT32;
+   case GL_RG8I:
+      return MESA_FORMAT_RG_INT8;
+   case GL_RG16I:
+      return MESA_FORMAT_RG_INT16;
+   case GL_RG32I:
+      return MESA_FORMAT_RG_INT32;
+   case GL_RG8UI:
+      return MESA_FORMAT_RG_UINT8;
+   case GL_RG16UI:
+      return MESA_FORMAT_RG_UINT16;
+   case GL_RG32UI:
+      return MESA_FORMAT_RG_UINT32;
+
+   case GL_R8:
+      return MESA_FORMAT_R8;
+   case GL_R16:
+      return MESA_FORMAT_R16;
+   case GL_R16F:
+      return MESA_FORMAT_R_FLOAT16;
+   case GL_R32F:
+      return MESA_FORMAT_R_FLOAT32;
+   case GL_R8I:
+      return MESA_FORMAT_R_INT8;
+   case GL_R16I:
+      return MESA_FORMAT_R_INT16;
+   case GL_R32I:
+      return MESA_FORMAT_R_INT32;
+   case GL_R8UI:
+      return MESA_FORMAT_R_UINT8;
+   case GL_R16UI:
+      return MESA_FORMAT_R_UINT16;
+   case GL_R32UI:
+      return MESA_FORMAT_R_UINT32;
+
+   case GL_RGB32F:
+      return MESA_FORMAT_RGB_FLOAT32;
+   case GL_RGB32UI:
+      return MESA_FORMAT_RGB_UINT32;
+   case GL_RGB32I:
+      return MESA_FORMAT_RGB_INT32;
+
+   default:
+      return MESA_FORMAT_NONE;
+   }
+}
+
+
+/**
+ * Check if the chosen internalformat is supported.
+ * The target and level parameters will have already been validated.
+ * \return the corresponding gl_format if yes, MESA_FORMAT_NONE otherwise.
+ */
+gl_format
+_mesa_validate_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
+{
+   gl_format format = get_texbuffer_format(ctx, internalFormat);
+   GLenum datatype;
+
+   if (format == MESA_FORMAT_NONE)
+      return MESA_FORMAT_NONE;
+
+   datatype = _mesa_get_format_datatype(format);
+   if (datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float)
+      return MESA_FORMAT_NONE;
+
+   if (datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel)
+      return MESA_FORMAT_NONE;
+
+   /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
+    * any mention of R/RG formats, but they appear in the GL 3.1 core
+    * specification.
+    */
+   if (ctx->Version <= 30) {
+      GLenum base_format = _mesa_get_format_base_format(format);
+
+      if (base_format == GL_R || base_format == GL_RG)
+	 return MESA_FORMAT_NONE;
+   }
+
+   if (!ctx->Extensions.ARB_texture_buffer_object_rgb32) {
+      GLenum base_format = _mesa_get_format_base_format(format);
+      if (base_format == GL_RGB)
+         return MESA_FORMAT_NONE;
+   }
+   return format;
+}
+
+
 /**
  * Do error checking of xoffset, yoffset, zoffset, width, height and depth
  * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
@@ -3876,201 +4077,6 @@ _mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
                             width, height, depth, format, imageSize, data);
 }
 
-static gl_format
-get_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
-{
-   switch (internalFormat) {
-   case GL_ALPHA8:
-      return MESA_FORMAT_A8;
-   case GL_ALPHA16:
-      return MESA_FORMAT_A16;
-   case GL_ALPHA16F_ARB:
-      return MESA_FORMAT_ALPHA_FLOAT16;
-   case GL_ALPHA32F_ARB:
-      return MESA_FORMAT_ALPHA_FLOAT32;
-   case GL_ALPHA8I_EXT:
-      return MESA_FORMAT_ALPHA_INT8;
-   case GL_ALPHA16I_EXT:
-      return MESA_FORMAT_ALPHA_INT16;
-   case GL_ALPHA32I_EXT:
-      return MESA_FORMAT_ALPHA_INT32;
-   case GL_ALPHA8UI_EXT:
-      return MESA_FORMAT_ALPHA_UINT8;
-   case GL_ALPHA16UI_EXT:
-      return MESA_FORMAT_ALPHA_UINT16;
-   case GL_ALPHA32UI_EXT:
-      return MESA_FORMAT_ALPHA_UINT32;
-   case GL_LUMINANCE8:
-      return MESA_FORMAT_L8;
-   case GL_LUMINANCE16:
-      return MESA_FORMAT_L16;
-   case GL_LUMINANCE16F_ARB:
-      return MESA_FORMAT_LUMINANCE_FLOAT16;
-   case GL_LUMINANCE32F_ARB:
-      return MESA_FORMAT_LUMINANCE_FLOAT32;
-   case GL_LUMINANCE8I_EXT:
-      return MESA_FORMAT_LUMINANCE_INT8;
-   case GL_LUMINANCE16I_EXT:
-      return MESA_FORMAT_LUMINANCE_INT16;
-   case GL_LUMINANCE32I_EXT:
-      return MESA_FORMAT_LUMINANCE_INT32;
-   case GL_LUMINANCE8UI_EXT:
-      return MESA_FORMAT_LUMINANCE_UINT8;
-   case GL_LUMINANCE16UI_EXT:
-      return MESA_FORMAT_LUMINANCE_UINT16;
-   case GL_LUMINANCE32UI_EXT:
-      return MESA_FORMAT_LUMINANCE_UINT32;
-   case GL_LUMINANCE8_ALPHA8:
-      return MESA_FORMAT_AL88;
-   case GL_LUMINANCE16_ALPHA16:
-      return MESA_FORMAT_AL1616;
-   case GL_LUMINANCE_ALPHA16F_ARB:
-      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16;
-   case GL_LUMINANCE_ALPHA32F_ARB:
-      return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32;
-   case GL_LUMINANCE_ALPHA8I_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_INT8;
-   case GL_LUMINANCE_ALPHA16I_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_INT8;
-   case GL_LUMINANCE_ALPHA32I_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_INT16;
-   case GL_LUMINANCE_ALPHA8UI_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_UINT8;
-   case GL_LUMINANCE_ALPHA16UI_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_UINT16;
-   case GL_LUMINANCE_ALPHA32UI_EXT:
-      return MESA_FORMAT_LUMINANCE_ALPHA_UINT32;
-   case GL_INTENSITY8:
-      return MESA_FORMAT_I8;
-   case GL_INTENSITY16:
-      return MESA_FORMAT_I16;
-   case GL_INTENSITY16F_ARB:
-      return MESA_FORMAT_INTENSITY_FLOAT16;
-   case GL_INTENSITY32F_ARB:
-      return MESA_FORMAT_INTENSITY_FLOAT32;
-   case GL_INTENSITY8I_EXT:
-      return MESA_FORMAT_INTENSITY_INT8;
-   case GL_INTENSITY16I_EXT:
-      return MESA_FORMAT_INTENSITY_INT16;
-   case GL_INTENSITY32I_EXT:
-      return MESA_FORMAT_INTENSITY_INT32;
-   case GL_INTENSITY8UI_EXT:
-      return MESA_FORMAT_INTENSITY_UINT8;
-   case GL_INTENSITY16UI_EXT:
-      return MESA_FORMAT_INTENSITY_UINT16;
-   case GL_INTENSITY32UI_EXT:
-      return MESA_FORMAT_INTENSITY_UINT32;
-   case GL_RGBA8:
-      return MESA_FORMAT_RGBA8888_REV;
-   case GL_RGBA16:
-      return MESA_FORMAT_RGBA_16;
-   case GL_RGBA16F_ARB:
-      return MESA_FORMAT_RGBA_FLOAT16;
-   case GL_RGBA32F_ARB:
-      return MESA_FORMAT_RGBA_FLOAT32;
-   case GL_RGBA8I_EXT:
-      return MESA_FORMAT_RGBA_INT8;
-   case GL_RGBA16I_EXT:
-      return MESA_FORMAT_RGBA_INT16;
-   case GL_RGBA32I_EXT:
-      return MESA_FORMAT_RGBA_INT32;
-   case GL_RGBA8UI_EXT:
-      return MESA_FORMAT_RGBA_UINT8;
-   case GL_RGBA16UI_EXT:
-      return MESA_FORMAT_RGBA_UINT16;
-   case GL_RGBA32UI_EXT:
-      return MESA_FORMAT_RGBA_UINT32;
-
-   case GL_RG8:
-      return MESA_FORMAT_GR88;
-   case GL_RG16:
-      return MESA_FORMAT_GR1616;
-   case GL_RG16F:
-      return MESA_FORMAT_RG_FLOAT16;
-   case GL_RG32F:
-      return MESA_FORMAT_RG_FLOAT32;
-   case GL_RG8I:
-      return MESA_FORMAT_RG_INT8;
-   case GL_RG16I:
-      return MESA_FORMAT_RG_INT16;
-   case GL_RG32I:
-      return MESA_FORMAT_RG_INT32;
-   case GL_RG8UI:
-      return MESA_FORMAT_RG_UINT8;
-   case GL_RG16UI:
-      return MESA_FORMAT_RG_UINT16;
-   case GL_RG32UI:
-      return MESA_FORMAT_RG_UINT32;
-
-   case GL_R8:
-      return MESA_FORMAT_R8;
-   case GL_R16:
-      return MESA_FORMAT_R16;
-   case GL_R16F:
-      return MESA_FORMAT_R_FLOAT16;
-   case GL_R32F:
-      return MESA_FORMAT_R_FLOAT32;
-   case GL_R8I:
-      return MESA_FORMAT_R_INT8;
-   case GL_R16I:
-      return MESA_FORMAT_R_INT16;
-   case GL_R32I:
-      return MESA_FORMAT_R_INT32;
-   case GL_R8UI:
-      return MESA_FORMAT_R_UINT8;
-   case GL_R16UI:
-      return MESA_FORMAT_R_UINT16;
-   case GL_R32UI:
-      return MESA_FORMAT_R_UINT32;
-
-   case GL_RGB32F:
-      return MESA_FORMAT_RGB_FLOAT32;
-   case GL_RGB32UI:
-      return MESA_FORMAT_RGB_UINT32;
-   case GL_RGB32I:
-      return MESA_FORMAT_RGB_INT32;
-
-   default:
-      return MESA_FORMAT_NONE;
-   }
-}
-
-
-static gl_format
-validate_texbuffer_format(const struct gl_context *ctx, GLenum internalFormat)
-{
-   gl_format format = get_texbuffer_format(ctx, internalFormat);
-   GLenum datatype;
-
-   if (format == MESA_FORMAT_NONE)
-      return MESA_FORMAT_NONE;
-
-   datatype = _mesa_get_format_datatype(format);
-   if (datatype == GL_FLOAT && !ctx->Extensions.ARB_texture_float)
-      return MESA_FORMAT_NONE;
-
-   if (datatype == GL_HALF_FLOAT && !ctx->Extensions.ARB_half_float_pixel)
-      return MESA_FORMAT_NONE;
-
-   /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
-    * any mention of R/RG formats, but they appear in the GL 3.1 core
-    * specification.
-    */
-   if (ctx->Version <= 30) {
-      GLenum base_format = _mesa_get_format_base_format(format);
-
-      if (base_format == GL_R || base_format == GL_RG)
-	 return MESA_FORMAT_NONE;
-   }
-
-   if (!ctx->Extensions.ARB_texture_buffer_object_rgb32) {
-      GLenum base_format = _mesa_get_format_base_format(format);
-      if (base_format == GL_RGB)
-         return MESA_FORMAT_NONE;
-   }
-   return format;
-}
-
 
 static void
 texbufferrange(struct gl_context *ctx, GLenum target, GLenum internalFormat,
@@ -4087,7 +4093,7 @@ texbufferrange(struct gl_context *ctx, GLenum target, GLenum internalFormat,
       return;
    }
 
-   format = validate_texbuffer_format(ctx, internalFormat);
+   format = _mesa_validate_texbuffer_format(ctx, internalFormat);
    if (format == MESA_FORMAT_NONE) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glTexBuffer(internalFormat 0x%x)",
                   internalFormat);
diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
index 792383d..0fa8649 100644
--- a/src/mesa/main/teximage.h
+++ b/src/mesa/main/teximage.h
@@ -147,6 +147,10 @@ _mesa_legal_texture_dimensions(struct gl_context *ctx, GLenum target,
                                GLint level, GLint width, GLint height,
                                GLint depth, GLint border);
 
+extern gl_format
+_mesa_validate_texbuffer_format(const struct gl_context *ctx, 
+                                GLenum internalFormat);
+
 /**
  * Lock a texture for updating.  See also _mesa_lock_context_textures().
  */
-- 
1.8.3.1



More information about the mesa-dev mailing list