summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/teximage.c
diff options
context:
space:
mode:
authorNeil Roberts <[email protected]>2014-06-13 17:28:48 +0100
committerNeil Roberts <[email protected]>2014-07-23 11:50:38 +0100
commit2e63f91e60376d297d883fd769713fbb5c93aadc (patch)
treef8f444b27995b9f671a0b7273caea54a2dc96f72 /src/mesa/main/teximage.c
parentc4067acd908322d79a4e08b9f4fffdd453c518ee (diff)
teximage: Add utility func for format/internalFormat compatibility check
In texture_error_check() there was a snippet of code to check whether the given format and internal format are basically compatible. This has been split out into its own static helper function so that it can be used by an implementation of glClearTexImage too.
Diffstat (limited to 'src/mesa/main/teximage.c')
-rw-r--r--src/mesa/main/teximage.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 3fba6f1b2d5..b972cc187ad 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -2010,6 +2010,43 @@ _mesa_legal_texture_base_format_for_target(struct gl_context *ctx,
return true;
}
+static bool
+texture_formats_agree(GLenum internalFormat,
+ GLenum format)
+{
+ GLboolean colorFormat;
+ GLboolean is_format_depth_or_depthstencil;
+ GLboolean is_internalFormat_depth_or_depthstencil;
+
+ /* Even though there are no color-index textures, we still have to support
+ * uploading color-index data and remapping it to RGB via the
+ * GL_PIXEL_MAP_I_TO_[RGBA] tables.
+ */
+ const GLboolean indexFormat = (format == GL_COLOR_INDEX);
+
+ is_internalFormat_depth_or_depthstencil =
+ _mesa_is_depth_format(internalFormat) ||
+ _mesa_is_depthstencil_format(internalFormat);
+
+ is_format_depth_or_depthstencil =
+ _mesa_is_depth_format(format) ||
+ _mesa_is_depthstencil_format(format);
+
+ colorFormat = _mesa_is_color_format(format);
+
+ if (_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat)
+ return false;
+
+ if (is_internalFormat_depth_or_depthstencil !=
+ is_format_depth_or_depthstencil)
+ return false;
+
+ if (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format))
+ return false;
+
+ return true;
+}
+
/**
* Test the glTexImage[123]D() parameters for errors.
*
@@ -2043,17 +2080,8 @@ texture_error_check( struct gl_context *ctx,
GLint width, GLint height,
GLint depth, GLint border )
{
- GLboolean colorFormat;
- GLboolean is_format_depth_or_depthstencil;
- GLboolean is_internalFormat_depth_or_depthstencil;
GLenum err;
- /* Even though there are no color-index textures, we still have to support
- * uploading color-index data and remapping it to RGB via the
- * GL_PIXEL_MAP_I_TO_[RGBA] tables.
- */
- const GLboolean indexFormat = (format == GL_COLOR_INDEX);
-
/* Note: for proxy textures, some error conditions immediately generate
* a GL error in the usual way. But others do not generate a GL error.
* Instead, they cause the width, height, depth, format fields of the
@@ -2136,18 +2164,7 @@ texture_error_check( struct gl_context *ctx,
}
/* make sure internal format and format basically agree */
- is_internalFormat_depth_or_depthstencil =
- _mesa_is_depth_format(internalFormat) ||
- _mesa_is_depthstencil_format(internalFormat);
-
- is_format_depth_or_depthstencil =
- _mesa_is_depth_format(format) ||
- _mesa_is_depthstencil_format(format);
-
- colorFormat = _mesa_is_color_format(format);
- if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
- (is_internalFormat_depth_or_depthstencil != is_format_depth_or_depthstencil) ||
- (_mesa_is_ycbcr_format(internalFormat) != _mesa_is_ycbcr_format(format))) {
+ if (!texture_formats_agree(internalFormat, format)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glTexImage%dD(incompatible internalFormat = %s, format = %s)",
dimensions, _mesa_lookup_enum_by_nr(internalFormat),