[Mesa-dev] [PATCH v2 04/18] glformats: add _mesa_es3_error_check_format_and_type
Ian Romanick
idr at freedesktop.org
Mon Jan 14 15:01:49 PST 2013
On 01/12/2013 08:10 PM, Jordan Justen wrote:
> From: Matt Turner <mattst88 at gmail.com>
>
> This function checks for ES3 compatible
> format/type/internalFormat/dimension combinations.
>
> [jordan.l.justen at intel.com: additional tweaks for gles3-gtf]
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
This code looks fine, but I hate it. I wish there was a good,
performant way that this could be table driven. I'd much rather have a
list of the valid combinations than this giant, nested switch-statement
of doom. :(
> ---
> src/mesa/main/glformats.c | 439 +++++++++++++++++++++++++++++++++++++++++++++
> src/mesa/main/glformats.h | 5 +
> 2 files changed, 444 insertions(+)
>
> diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
> index 74d9242..342af6d 100644
> --- a/src/mesa/main/glformats.c
> +++ b/src/mesa/main/glformats.c
> @@ -1680,3 +1680,442 @@ _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
>
> return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
> }
> +
> +
> +/**
> + * Do error checking of format/type combinations for OpenGL ES 3
> + * glTex[Sub]Image.
> + * \return error code, or GL_NO_ERROR.
> + */
> +GLenum
> +_mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
> + GLenum internalFormat,
> + unsigned dimensions)
> +{
> + GLboolean type_valid = GL_TRUE;
> +
> + switch (format) {
> + case GL_RGBA:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + switch (internalFormat) {
> + case GL_RGBA:
> + case GL_RGBA8:
> + case GL_RGB5_A1:
> + case GL_RGBA4:
> + case GL_SRGB8_ALPHA8_EXT:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RGBA8_SNORM)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT_4_4_4_4:
> + switch (internalFormat) {
> + case GL_RGBA:
> + case GL_RGBA4:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_UNSIGNED_SHORT_5_5_5_1:
> + switch (internalFormat) {
> + case GL_RGBA:
> + case GL_RGB5_A1:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_UNSIGNED_INT_2_10_10_10_REV:
> + switch (internalFormat) {
> + case GL_RGBA: /* GL_EXT_texture_type_2_10_10_10_REV */
> + case GL_RGB10_A2:
> + case GL_RGB5_A1:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_HALF_FLOAT:
> + if (internalFormat != GL_RGBA16F)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_FLOAT:
> + switch (internalFormat) {
> + case GL_RGBA16F:
> + case GL_RGBA32F:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RGBA_INTEGER:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_RGBA8UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RGBA8I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT:
> + if (internalFormat != GL_RGBA16UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_SHORT:
> + if (internalFormat != GL_RGBA16I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT:
> + if (internalFormat != GL_RGBA32UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_INT:
> + if (internalFormat != GL_RGBA32I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT_2_10_10_10_REV:
> + if (internalFormat != GL_RGB10_A2UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RGB:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + switch (internalFormat) {
> + case GL_RGB:
> + case GL_RGB8:
> + case GL_RGB565:
> + case GL_SRGB8:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RGB8_SNORM)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT_5_6_5:
> + switch (internalFormat) {
> + case GL_RGB:
> + case GL_RGB565:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_UNSIGNED_INT_10F_11F_11F_REV:
> + if (internalFormat != GL_R11F_G11F_B10F)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT_5_9_9_9_REV:
> + if (internalFormat != GL_RGB9_E5)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_HALF_FLOAT:
> + switch (internalFormat) {
> + case GL_RGB16F:
> + case GL_R11F_G11F_B10F:
> + case GL_RGB9_E5:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_FLOAT:
> + switch (internalFormat) {
> + case GL_RGB16F:
> + case GL_RGB32F:
> + case GL_R11F_G11F_B10F:
> + case GL_RGB9_E5:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_UNSIGNED_INT_2_10_10_10_REV:
> + switch (internalFormat) {
> + case GL_RGB: /* GL_EXT_texture_type_2_10_10_10_REV */
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RGB_INTEGER:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_RGB8UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RGB8I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT:
> + if (internalFormat != GL_RGB16UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_SHORT:
> + if (internalFormat != GL_RGB16I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT:
> + if (internalFormat != GL_RGB32UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_INT:
> + if (internalFormat != GL_RGB32I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RG:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_RG8)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RG8_SNORM)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_HALF_FLOAT:
> + if (internalFormat != GL_RG16F)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_FLOAT:
> + switch (internalFormat) {
> + case GL_RG16F:
> + case GL_RG32F:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RG_INTEGER:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_RG8UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_RG8I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT:
> + if (internalFormat != GL_RG16UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_SHORT:
> + if (internalFormat != GL_RG16I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT:
> + if (internalFormat != GL_RG32UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_INT:
> + if (internalFormat != GL_RG32I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RED:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_R8)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_R8_SNORM)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_HALF_FLOAT:
> + if (internalFormat != GL_R16F)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_FLOAT:
> + switch (internalFormat) {
> + case GL_R16F:
> + case GL_R32F:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_RED_INTEGER:
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + if (internalFormat != GL_R8UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_BYTE:
> + if (internalFormat != GL_R8I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_SHORT:
> + if (internalFormat != GL_R16UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_SHORT:
> + if (internalFormat != GL_R16I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT:
> + if (internalFormat != GL_R32UI)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_INT:
> + if (internalFormat != GL_R32I)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_DEPTH_COMPONENT:
> + if (dimensions != 2) {
> + return GL_INVALID_OPERATION;
> + }
> + switch (type) {
> + case GL_UNSIGNED_SHORT:
> + if (internalFormat != GL_DEPTH_COMPONENT16)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_UNSIGNED_INT:
> + switch (internalFormat) {
> + case GL_DEPTH_COMPONENT16:
> + case GL_DEPTH_COMPONENT24:
> + break;
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_FLOAT:
> + if (internalFormat != GL_DEPTH_COMPONENT32F)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_DEPTH_STENCIL:
> + if (dimensions != 2) {
> + return GL_INVALID_OPERATION;
> + }
> + switch (type) {
> + case GL_UNSIGNED_INT_24_8:
> + if (internalFormat != GL_DEPTH24_STENCIL8)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
> + if (internalFormat != GL_DEPTH32F_STENCIL8)
> + return GL_INVALID_OPERATION;
> + break;
> +
> + default:
> + return GL_INVALID_OPERATION;
> + }
> + break;
> +
> + case GL_ALPHA:
> + case GL_LUMINANCE:
> + case GL_LUMINANCE_ALPHA:
> + if (type != GL_UNSIGNED_BYTE || format != internalFormat)
> + return GL_INVALID_OPERATION;
> + break;
> + }
> +
> + return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
> +}
> diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
> index fe604dd..4cbc82f 100644
> --- a/src/mesa/main/glformats.h
> +++ b/src/mesa/main/glformats.h
> @@ -120,6 +120,11 @@ extern GLenum
> _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
> unsigned dimensions);
>
> +extern GLenum
> +_mesa_es3_error_check_format_and_type(GLenum format, GLenum type,
> + GLenum internalFormat,
> + unsigned dimensions);
> +
>
> #ifdef __cplusplus
> }
>
More information about the mesa-dev
mailing list