summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Piñeiro <apinheiro@igalia.com>2018-05-06 11:42:55 +0200
committerAlejandro Piñeiro <apinheiro@igalia.com>2018-05-09 09:05:19 +0200
commit24a92424105372d67eff10ea1361902b32667da8 (patch)
treef77d2096ccc5a98df745dedf0948838b3c84cfd9
parentdd20daa579c816498f61e08c819117ad6eb4b4a5 (diff)
arb_internalformat_query2: use CompressedTexImage*D for specific compressed formats
Until right now we were using glTexImage*D for any compressed internalformat. That would only work always if the driver supports online compression for specific compressed internalformats. As it is not really easy to check which internalformats the driver supports online compression for, it is safer to use glCompressedTexImage*D for any specific internalformat, keeping glTexImage*D for the generic ones. v2: specific compressed internalformat GL_COMPRESSED_RED_RGTC1 was missing, minor tweaks (Antia) Reviewed-by: Antia Puentes <apuentes@igalia.com>
-rw-r--r--tests/spec/arb_internalformat_query2/common.c127
1 files changed, 118 insertions, 9 deletions
diff --git a/tests/spec/arb_internalformat_query2/common.c b/tests/spec/arb_internalformat_query2/common.c
index 68f33a4a0..13e2a9118 100644
--- a/tests/spec/arb_internalformat_query2/common.c
+++ b/tests/spec/arb_internalformat_query2/common.c
@@ -186,6 +186,48 @@ test_data_check_supported(const test_data *data,
return result;
}
+
+/*
+ * Spec 4.6, Table 8.14
+ */
+static const GLenum specific_compressed_internalformats[] = {
+ GL_COMPRESSED_RED_RGTC1,
+ GL_COMPRESSED_SIGNED_RED_RGTC1,
+ GL_COMPRESSED_RG_RGTC2,
+ GL_COMPRESSED_SIGNED_RG_RGTC2,
+ GL_COMPRESSED_RGBA_BPTC_UNORM,
+ GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM,
+ GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT,
+ GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,
+ GL_COMPRESSED_RGB8_ETC2,
+ GL_COMPRESSED_SRGB8_ETC2,
+ GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+ GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+ GL_COMPRESSED_RGBA8_ETC2_EAC,
+ GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
+ GL_COMPRESSED_R11_EAC,
+ GL_COMPRESSED_SIGNED_R11_EAC,
+ GL_COMPRESSED_RG11_EAC,
+ GL_COMPRESSED_SIGNED_RG11_EAC,
+};
+
+/*
+ * Returns if @internalformat is a specific compressed internalformat.
+ *
+ * This is needed because specific compressed internalformats that
+ * doesn't support online compression can't be used with glTexImage*D,
+ * and glCompressedTexImage*D should be used instead. In general, for
+ * specific compressed internalformats, it is better to use
+ * glCompressedTexImage*D
+ */
+static bool
+internalformat_is_specific_compressed(const GLenum internalformat)
+{
+ return value_on_set((const GLint*) specific_compressed_internalformats,
+ ARRAY_SIZE(specific_compressed_internalformats),
+ (GLint) internalformat);
+}
+
/* Returns if @value is one of the values among @set */
bool
value_on_set(const GLint *set,
@@ -336,8 +378,8 @@ try_basic(const GLenum *targets, unsigned num_targets,
}
/* Returns a valid format for @internalformat, so it would be possible
- * to create a texture using glTexImageXD with that
- * format/internalformat combination */
+ * to create a texture using glTexImageXD/glCompressedTexImageXD with
+ * that format/internalformat combination */
static GLenum
format_for_internalformat(const GLenum internalformat)
{
@@ -432,6 +474,51 @@ create_texture(const GLenum target,
int width = 16;
int depth = 16;
unsigned i;
+ bool is_specific_compressed = internalformat_is_specific_compressed(internalformat);
+ int image_size = 0;
+
+ /*
+ * From OpenGL 4.6 spec, Section 8.5, Texture Image
+ * Specification:
+ *
+ * "An INVALID_ENUM error is generated by
+ * CompressedTexImage1D if internalformat is one of the
+ * specific compressed formats. OpenGL defines no specific
+ * one-dimensional compressed formats, but such formats
+ * may be provided by extensions."
+ *
+ * From OpenGL 4.6 spec, Section 8.7, Compressed Texture
+ * Images:
+ *
+ * "An INVALID_ENUM error is generated if the target
+ * parameter to any of the CompressedTexImagenD commands
+ * is TEXTURE_RECTANGLE or PROXY_TEXTURE_RECTANGLE ."
+ */
+ if (is_specific_compressed &&
+ (target == GL_TEXTURE_1D || target == GL_TEXTURE_RECTANGLE))
+ return false;
+
+ /*
+ * From ARB_texture_multisample:
+ *
+ * "(2) What commands may be used on multisample textures?
+ *
+ * RESOLVED: Multisample textures can be bound for
+ * rendering and texturing, but they cannot be loaded/read
+ * with SubImage commands (TexSubImage, CopyTexSubImage,
+ * GetTexImage), they don't support compressed formats, and
+ * they don't need TexParameters since they can only be
+ * fetched with texelFetchMultisample."
+ */
+ if (is_specific_compressed &&
+ (target == GL_TEXTURE_2D_MULTISAMPLE ||
+ target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {
+ return false;
+ }
+
+ if (is_specific_compressed) {
+ image_size = piglit_compressed_image_size(internalformat, width, height);
+ }
glGenTextures(1, &tex);
glBindTexture(target, tex);
@@ -444,14 +531,29 @@ create_texture(const GLenum target,
case GL_TEXTURE_1D_ARRAY:
case GL_TEXTURE_2D:
case GL_TEXTURE_RECTANGLE:
- glTexImage2D(target, 0, internalformat, width, height, 0,
- format, type, NULL);
+ if (is_specific_compressed) {
+ glCompressedTexImage2D(target, 0, internalformat,
+ width, height, 0,
+ image_size, NULL);
+ } else {
+ glTexImage2D(target, 0, internalformat,
+ width, height, 0,
+ format, type, NULL);
+ }
break;
case GL_TEXTURE_CUBE_MAP:
for (i = 0; i < 6; i++) {
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
- internalformat, width, height, 0, format, type,
- NULL);
+ if (is_specific_compressed) {
+ glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+ internalformat,
+ width, height, 0,
+ image_size, NULL);
+ } else {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+ internalformat,
+ width, height, 0,
+ format, type, NULL);
+ }
}
break;
@@ -462,8 +564,15 @@ create_texture(const GLenum target,
/* fall through */
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_3D:
- glTexImage3D(target, 0, internalformat, width, height, depth, 0,
- format, type, NULL);
+ image_size = image_size * depth;
+ if (is_specific_compressed) {
+ glCompressedTexImage3D(target, 0, internalformat,
+ width, height, depth, 0,
+ image_size, NULL);
+ } else {
+ glTexImage3D(target, 0, internalformat, width, height, depth, 0,
+ format, type, NULL);
+ }
break;
case GL_TEXTURE_2D_MULTISAMPLE:
glTexImage2DMultisample(target, 1, internalformat, width, height,