summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorNanley Chery <[email protected]>2015-07-31 10:26:36 -0700
committerNanley Chery <[email protected]>2015-08-25 15:45:17 -0700
commit26c549e69d12e44e2e36c09764ce2cceab262a1b (patch)
tree69e2747d06eec40a982d0c91d83b44e9f61b5911 /src/mesa/main
parent8e581747d2342950ff44488064eef53768b3ae82 (diff)
mesa/formats: remove compressed formats from matching function
All compressed formats return GL_FALSE and there isn't any evidence to support that this behaviour would change. Remove all switch cases for compressed formats. v2. Since the exhaustive switch is removed, add a gtest to ensure all formats are handled. v3. Ensure that GL_NO_ERROR is set before returning. v4. Fix an arg to _mesa_uncompressed_format_to_type_and_comps(); fix formatting and misc improvements (Chad). Reviewed-by: Chad Versace <[email protected]> Signed-off-by: Nanley Chery <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/formats.c58
-rw-r--r--src/mesa/main/formats.h2
-rw-r--r--src/mesa/main/readpix.c2
-rw-r--r--src/mesa/main/tests/mesa_formats.cpp9
-rw-r--r--src/mesa/main/texgetimage.c2
-rw-r--r--src/mesa/main/texstore.c2
6 files changed, 23 insertions, 52 deletions
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 54d87c73b73..8dd07d88f40 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1420,20 +1420,26 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
* \param format the user-specified image format
* \param type the user-specified image datatype
* \param swapBytes typically the current pixel pack/unpack byteswap state
+ * \param[out] error GL_NO_ERROR if format is an expected input.
+ * GL_INVALID_ENUM if format is an unexpected input.
* \return GL_TRUE if the formats match, GL_FALSE otherwise.
*/
GLboolean
_mesa_format_matches_format_and_type(mesa_format mesa_format,
GLenum format, GLenum type,
- GLboolean swapBytes)
+ GLboolean swapBytes, GLenum *error)
{
const GLboolean littleEndian = _mesa_little_endian();
+ if (error)
+ *error = GL_NO_ERROR;
/* Note: When reading a GL format/type combination, the format lists channel
* assignments from most significant channel in the type to least
* significant. A type with _REV indicates that the assignments are
* swapped, so they are listed from least significant to most significant.
*
+ * Compressed formats will fall through and return GL_FALSE.
+ *
* For sanity, please keep this switch statement ordered the same as the
* enums in formats.h.
*/
@@ -1694,26 +1700,6 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
case MESA_FORMAT_S_UINT8:
return format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_SRGB_DXT1:
- case MESA_FORMAT_SRGBA_DXT1:
- case MESA_FORMAT_SRGBA_DXT3:
- case MESA_FORMAT_SRGBA_DXT5:
- return GL_FALSE;
-
- case MESA_FORMAT_RGB_FXT1:
- case MESA_FORMAT_RGBA_FXT1:
- case MESA_FORMAT_RGB_DXT1:
- case MESA_FORMAT_RGBA_DXT1:
- case MESA_FORMAT_RGBA_DXT3:
- case MESA_FORMAT_RGBA_DXT5:
- return GL_FALSE;
-
- case MESA_FORMAT_BPTC_RGBA_UNORM:
- case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
- case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
- case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
- return GL_FALSE;
-
case MESA_FORMAT_RGBA_FLOAT32:
return format == GL_RGBA && type == GL_FLOAT && !swapBytes;
case MESA_FORMAT_RGBA_FLOAT16:
@@ -1910,31 +1896,6 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return format == GL_RGBA && type == GL_UNSIGNED_SHORT &&
!swapBytes;
- case MESA_FORMAT_R_RGTC1_UNORM:
- case MESA_FORMAT_R_RGTC1_SNORM:
- case MESA_FORMAT_RG_RGTC2_UNORM:
- case MESA_FORMAT_RG_RGTC2_SNORM:
- return GL_FALSE;
-
- case MESA_FORMAT_L_LATC1_UNORM:
- case MESA_FORMAT_L_LATC1_SNORM:
- case MESA_FORMAT_LA_LATC2_UNORM:
- case MESA_FORMAT_LA_LATC2_SNORM:
- return GL_FALSE;
-
- case MESA_FORMAT_ETC1_RGB8:
- case MESA_FORMAT_ETC2_RGB8:
- case MESA_FORMAT_ETC2_SRGB8:
- case MESA_FORMAT_ETC2_RGBA8_EAC:
- case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
- case MESA_FORMAT_ETC2_R11_EAC:
- case MESA_FORMAT_ETC2_RG11_EAC:
- case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
- case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
- case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
- case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
- return GL_FALSE;
-
case MESA_FORMAT_A_SNORM8:
return format == GL_ALPHA && type == GL_BYTE;
case MESA_FORMAT_L_SNORM8:
@@ -2017,8 +1978,11 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
case MESA_FORMAT_B8G8R8X8_SRGB:
case MESA_FORMAT_X8R8G8B8_SRGB:
return GL_FALSE;
+ default:
+ assert(_mesa_is_format_compressed(format));
+ if (error)
+ *error = GL_INVALID_ENUM;
}
-
return GL_FALSE;
}
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 48b3fbd2cde..4936fa0d482 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -686,7 +686,7 @@ _mesa_format_has_color_component(mesa_format format, int component);
GLboolean
_mesa_format_matches_format_and_type(mesa_format mesa_format,
GLenum format, GLenum type,
- GLboolean swapBytes);
+ GLboolean swapBytes, GLenum *error);
#ifdef __cplusplus
}
diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index d826ecfc3d5..12779446c6d 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -201,7 +201,7 @@ readpixels_can_use_memcpy(const struct gl_context *ctx, GLenum format, GLenum ty
/* The Mesa format must match the input format and type. */
if (!_mesa_format_matches_format_and_type(rb->Format, format, type,
- packing->SwapBytes)) {
+ packing->SwapBytes, NULL)) {
return GL_FALSE;
}
diff --git a/src/mesa/main/tests/mesa_formats.cpp b/src/mesa/main/tests/mesa_formats.cpp
index bb59c5c6fb7..5356cd919a8 100644
--- a/src/mesa/main/tests/mesa_formats.cpp
+++ b/src/mesa/main/tests/mesa_formats.cpp
@@ -50,11 +50,18 @@ TEST(MesaFormatsTest, FormatTypeAndComps)
*/
if (!_mesa_is_format_compressed(f)) {
GLenum datatype = 0;
+ GLenum error = 0;
GLuint comps = 0;
- _mesa_uncompressed_format_to_type_and_comps(f, &datatype, &comps);
/* If the datatype is zero, the format was not handled */
+ _mesa_uncompressed_format_to_type_and_comps(f, &datatype, &comps);
EXPECT_NE(datatype, (GLenum)0);
+
+ /* If the error isn't NO_ERROR, the format was not handled.
+ * Use an arbitrary GLenum format. */
+ _mesa_format_matches_format_and_type(f, GL_RG, datatype,
+ GL_FALSE, &error);
+ EXPECT_EQ((GLenum)GL_NO_ERROR, error);
}
}
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
index c0ccce3d50e..3c1e166ffa1 100644
--- a/src/mesa/main/texgetimage.c
+++ b/src/mesa/main/texgetimage.c
@@ -651,7 +651,7 @@ get_tex_memcpy(struct gl_context *ctx,
texBaseFormat == texImage->_BaseFormat) {
memCopy = _mesa_format_matches_format_and_type(texImage->TexFormat,
format, type,
- ctx->Pack.SwapBytes);
+ ctx->Pack.SwapBytes, NULL);
}
if (depth > 1) {
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 37c05690091..fc83310d4e3 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -863,7 +863,7 @@ _mesa_texstore_can_use_memcpy(struct gl_context *ctx,
/* The Mesa format must match the input format and type. */
if (!_mesa_format_matches_format_and_type(dstFormat, srcFormat, srcType,
- srcPacking->SwapBytes)) {
+ srcPacking->SwapBytes, NULL)) {
return GL_FALSE;
}