[Piglit] [PATCH 1/2] gl-3.0/required-*-formats: New tests for GL3.0.
Eric Anholt
eric at anholt.net
Thu Nov 17 10:13:21 PST 2011
These should reasonably cover the "Required Texture Formats" and
"Required Framebuffer Formats" sections of GL 3.0, and be reasonably
extensible for future GL versions.
---
tests/all.tests | 1 +
tests/spec/gl-3.0/CMakeLists.gl.txt | 19 ++
.../required-renderbuffer-attachment-formats.c | 140 +++++++++
tests/spec/gl-3.0/required-sized-texture-formats.c | 220 ++++++++++++++
.../gl-3.0/required-texture-attachment-formats.c | 150 ++++++++++
tests/util/CMakeLists.gl.txt | 1 +
tests/util/sized-internalformats.c | 315 ++++++++++++++++++++
tests/util/sized-internalformats.h | 106 +++++++
8 files changed, 952 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/gl-3.0/CMakeLists.gl.txt
create mode 100644 tests/spec/gl-3.0/required-renderbuffer-attachment-formats.c
create mode 100644 tests/spec/gl-3.0/required-sized-texture-formats.c
create mode 100644 tests/spec/gl-3.0/required-texture-attachment-formats.c
create mode 100644 tests/util/sized-internalformats.c
create mode 100644 tests/util/sized-internalformats.h
diff --git a/tests/all.tests b/tests/all.tests
index 2a85b7a..267f44e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -793,6 +793,7 @@ gl30 = Group()
spec['!OpenGL 3.0'] = gl30
add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')
add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
+add_concurrent_test(gl30, 'gl-3.0-required-sized-formats')
# Group spec/glsl-1.00
spec['glsl-1.00'] = Group()
diff --git a/tests/spec/gl-3.0/CMakeLists.gl.txt b/tests/spec/gl-3.0/CMakeLists.gl.txt
new file mode 100644
index 0000000..e151a76
--- /dev/null
+++ b/tests/spec/gl-3.0/CMakeLists.gl.txt
@@ -0,0 +1,19 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+ ${GLUT_INCLUDE_DIR}
+ ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+ piglitutil
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+ ${GLUT_glut_LIBRARY}
+)
+
+add_executable (gl-3.0-required-sized-texture-formats required-sized-texture-formats.c)
+add_executable (gl-3.0-required-renderbuffer-attachment-formats required-renderbuffer-attachment-formats.c)
+add_executable (gl-3.0-required-texture-attachment-formats required-texture-attachment-formats.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/gl-3.0/required-renderbuffer-attachment-formats.c b/tests/spec/gl-3.0/required-renderbuffer-attachment-formats.c
new file mode 100644
index 0000000..aec4192
--- /dev/null
+++ b/tests/spec/gl-3.0/required-renderbuffer-attachment-formats.c
@@ -0,0 +1,140 @@
+/* Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+#include "sized-internalformats.h"
+
+/**
+ * @file required-renderbuffer-attachment-formats.c
+ *
+ * Tests that the color-and-texturing required sized internal formats
+ * for GL 3.0 are supported as renderbuffer attachments. See page 294
+ * of the GL 3.0 pdf (20080923) "Required Framebuffer Formats" and
+ * page 180 "Required Texture Formats".
+ */
+
+int piglit_width = 32;
+int piglit_height = 32;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+enum piglit_result
+piglit_display(void)
+{
+ /* UNREACHED */
+ return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ GLuint rb, fbo;
+ int i, c;
+
+ if (!GLEW_VERSION_3_0) {
+ printf("Requires GL 3.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ glGenRenderbuffers(1, &rb);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb);
+
+ for (i = 0; required_formats[i].token != GL_NONE; i++) {
+ GLenum attachment, status;
+ const struct sized_internalformat *f;
+
+ /* FINISHME: Add support for future GL versions. */
+ if (required_formats[i].version != 30)
+ continue;
+
+ if (!required_formats[i].rb_required)
+ continue;
+
+ f = get_sized_internalformat(required_formats[i].token);
+
+ if (f->token == GL_DEPTH24_STENCIL8 ||
+ f->token == GL_DEPTH32F_STENCIL8) {
+ attachment = GL_DEPTH_STENCIL_ATTACHMENT;
+ } else if (get_channel_size(f, D)) {
+ attachment = GL_DEPTH_ATTACHMENT;
+ } else {
+ attachment = GL_COLOR_ATTACHMENT0;
+ }
+
+ glRenderbufferStorage(GL_RENDERBUFFER, f->token, 1, 1);
+
+ /* We don't test the sizes of the channels, because
+ * the spec allows the implementation to choose
+ * resolution pretty much however it feels (GL 2.x
+ * texturing-style). From page 284 of the GL 3.0
+ * spec:
+ *
+ * "A GL implementation may vary its allocation of
+ * internal component resolution based on any
+ * RenderbufferStorage parameter (except target),
+ * but the allocation and chosen internal format
+ * must not be a function of any other state and
+ * cannot be changed once they are established."
+ */
+
+ if (glGetError() != 0) {
+ printf("Unexpected error creating %s texture\n",
+ f->name);
+ pass = false;
+ continue;
+ }
+
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment,
+ GL_RENDERBUFFER, rb);
+
+ if (glGetError() != 0) {
+ printf("Unexpected error binding %s texture\n",
+ f->name);
+ pass = false;
+ continue;
+ }
+
+ if (attachment == GL_COLOR_ATTACHMENT0) {
+ glDrawBuffer(GL_COLOR_ATTACHMENT0);
+ } else {
+ glDrawBuffer(GL_NONE);
+ }
+
+ status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "%s fbo incomplete (status = 0x%04x)\n",
+ f->name, status);
+ pass = false;
+ } else {
+ printf("%s: fbo complete\n", f->name);
+ }
+
+ glDeleteFramebuffers(1, &fbo);
+ }
+
+ glDeleteRenderbuffers(1, &rb);
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
diff --git a/tests/spec/gl-3.0/required-sized-texture-formats.c b/tests/spec/gl-3.0/required-sized-texture-formats.c
new file mode 100644
index 0000000..0780a46
--- /dev/null
+++ b/tests/spec/gl-3.0/required-sized-texture-formats.c
@@ -0,0 +1,220 @@
+/* Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+#include "sized-internalformats.h"
+
+/**
+ * @file required-sized-formats.c
+ *
+ * Tests that the required sized internal formats for GL 3.0 are
+ * exposed. See page 180 of the GL 3.0 pdf (20080923), "Required
+ * Texture Formats". Notably:
+ *
+ * "In addition, implementations are required to support the
+ * following sized internal formats. Requesting one of these
+ * internal formats for any texture type will allocate exactly
+ * the internal component sizes and types shown for that format
+ * in tables 3.16- 3.17:"
+ */
+
+int piglit_width = 32;
+int piglit_height = 32;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+GLenum type_queries[CHANNELS] = {
+ GL_TEXTURE_RED_TYPE,
+ GL_TEXTURE_GREEN_TYPE,
+ GL_TEXTURE_BLUE_TYPE,
+ GL_TEXTURE_ALPHA_TYPE,
+ GL_TEXTURE_LUMINANCE_TYPE,
+ GL_TEXTURE_INTENSITY_TYPE,
+ GL_TEXTURE_DEPTH_TYPE,
+ GL_NONE,
+};
+
+GLenum size_queries[CHANNELS] = {
+ GL_TEXTURE_RED_SIZE,
+ GL_TEXTURE_GREEN_SIZE,
+ GL_TEXTURE_BLUE_SIZE,
+ GL_TEXTURE_ALPHA_SIZE,
+ GL_TEXTURE_LUMINANCE_SIZE,
+ GL_TEXTURE_INTENSITY_SIZE,
+ GL_TEXTURE_DEPTH_SIZE,
+ GL_TEXTURE_STENCIL_SIZE,
+};
+
+enum piglit_result
+piglit_display(void)
+{
+ /* UNREACHED */
+ return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ GLuint tex;
+ int i, c;
+
+ if (!GLEW_VERSION_3_0) {
+ printf("Requires GL 3.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ for (i = 0; required_formats[i].token != GL_NONE; i++) {
+ GLint sizes[CHANNELS];
+ GLint types[CHANNELS];
+ bool format_pass = true;
+ GLenum format, type;
+ const struct sized_internalformat *f;
+
+ /* FINISHME: Add support for future GL versions. */
+ if (required_formats[i].version != 30)
+ continue;
+
+ f = get_sized_internalformat(required_formats[i].token);
+
+ if (f->token == GL_DEPTH24_STENCIL8 ||
+ f->token == GL_DEPTH32F_STENCIL8) {
+ format = GL_DEPTH_STENCIL;
+ type = GL_UNSIGNED_INT_24_8;
+ } else if (get_channel_size(f, D)) {
+ format = GL_DEPTH_COMPONENT;
+ type = GL_FLOAT;
+ } else {
+ format = GL_RGBA;
+ type = GL_FLOAT;
+
+ /* Have to specify integer data for integer textures. */
+ for (c = R; c <= I; c++) {
+ if (get_channel_type(f, c) == GL_UNSIGNED_INT ||
+ get_channel_type(f, c) == GL_INT) {
+ format = GL_RGBA_INTEGER;
+ type = GL_UNSIGNED_INT;
+ break;
+ }
+ }
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, f->token,
+ 1, 1, 0,
+ format, type, NULL);
+
+ if (glGetError() != 0) {
+ printf("Unexpected error creating %s texture\n",
+ f->name);
+ pass = false;
+ continue;
+ }
+
+ for (c = 0; c < CHANNELS; c++) {
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
+ size_queries[c], &sizes[c]);
+ if (c != S) {
+ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
+ type_queries[c],
+ &types[c]);
+ } else {
+ /* For stencil, there's no query for
+ * the type, so our table above
+ * records a type/size of unorm 8, and
+ * we'll just set the query result
+ * here to unorm so that we only look
+ * at the size.
+ */
+ if (sizes[c] != 0)
+ types[c] = GL_UNSIGNED_NORMALIZED;
+ else
+ types[c] = GL_NONE;
+ }
+
+ /* We use ~0 as the signal for the compressed
+ * texture formats. While the colors being
+ * interpolated across the 4x4 blocks have 8
+ * bits in them, the spec suggests reporting
+ * some approximate value less than that.
+ * From page 319 of the GL 3.0 spec:
+ *
+ * "Queries of value of TEXTURE RED SIZE,
+ * TEXTURE GREEN SIZE, [...] return the
+ * actual resolutions of the stored image
+ * array components, not the resolutions
+ * specified when the image array was
+ * defined. For texture images with a
+ * compressed internal format, the
+ * resolutions returned specify the
+ * component resolution of an
+ * uncompressed internal format that
+ * produces an image of roughly the same
+ * quality as the compressed image in
+ * question. Since the quality of the
+ * implementation’s compression algorithm
+ * is likely data-dependent, the returned
+ * component sizes should be treated only
+ * as rough approximations.
+ */
+ if (f->bits[c] == SCMP ||
+ f->bits[c] == UCMP) {
+ if (sizes[c] <= 0 || sizes[c] > 8)
+ format_pass = false;
+ } else {
+ if (sizes[c] != get_channel_size(f, c)) {
+ format_pass = false;
+ }
+ }
+
+ if (types[c] != get_channel_type(f, c))
+ format_pass = false;
+ }
+
+ if (!format_pass) {
+ printf("format %s:\n",
+ f->name);
+
+ printf(" expected: ");
+ for (c = 0; c < CHANNELS; c++) {
+ print_bits(get_channel_size(f, c),
+ get_channel_type(f, c));
+ printf(" ");
+ }
+ printf("\n");
+
+ printf(" observed: ");
+ for (c = 0; c < CHANNELS; c++) {
+ print_bits(sizes[c], types[c]);
+ printf(" ");
+ }
+ printf("\n");
+
+ pass = false;
+ }
+ }
+
+ glDeleteTextures(1, &tex);
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
diff --git a/tests/spec/gl-3.0/required-texture-attachment-formats.c b/tests/spec/gl-3.0/required-texture-attachment-formats.c
new file mode 100644
index 0000000..b8de859
--- /dev/null
+++ b/tests/spec/gl-3.0/required-texture-attachment-formats.c
@@ -0,0 +1,150 @@
+/* Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+#include "sized-internalformats.h"
+
+/**
+ * @file required-texture-attachment-formats.c
+ *
+ * Tests that the color-and-texturing required sized internal formats
+ * for GL 3.0 are supported as texture attachments. See page 294 of
+ * the GL 3.0 pdf (20080923) "Required Framebuffer Formats" and page
+ * 180 "Required Texture Formats".
+ */
+
+int piglit_width = 32;
+int piglit_height = 32;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+enum piglit_result
+piglit_display(void)
+{
+ /* UNREACHED */
+ return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ GLuint tex, fbo;
+ int i, c;
+
+ if (!GLEW_VERSION_3_0) {
+ printf("Requires GL 3.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ for (i = 0; required_formats[i].token != GL_NONE; i++) {
+ GLenum format, type, attachment, status;
+ const struct sized_internalformat *f;
+
+ /* FINISHME: Add support for future GL versions. */
+ if (required_formats[i].version != 30)
+ continue;
+
+ if (!required_formats[i].rb_required)
+ continue;
+
+ f = get_sized_internalformat(required_formats[i].token);
+
+ if (f->token == GL_DEPTH24_STENCIL8 ||
+ f->token == GL_DEPTH32F_STENCIL8) {
+ format = GL_DEPTH_STENCIL;
+ type = GL_UNSIGNED_INT_24_8;
+ attachment = GL_DEPTH_STENCIL_ATTACHMENT;
+ } else if (get_channel_size(f, D)) {
+ format = GL_DEPTH_COMPONENT;
+ type = GL_FLOAT;
+ attachment = GL_DEPTH_ATTACHMENT;
+ } else {
+ format = GL_RGBA;
+ type = GL_FLOAT;
+ attachment = GL_COLOR_ATTACHMENT0;
+
+ /* Have to specify integer data for integer textures. */
+ for (c = R; c <= I; c++) {
+ if (get_channel_type(f, c) == GL_UNSIGNED_INT ||
+ get_channel_type(f, c) == GL_INT) {
+ format = GL_RGBA_INTEGER;
+ type = GL_UNSIGNED_INT;
+ break;
+ }
+ }
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, f->token,
+ 1, 1, 0,
+ format, type, NULL);
+
+ if (glGetError() != 0) {
+ printf("Unexpected error creating %s texture\n",
+ f->name);
+ pass = false;
+ continue;
+ }
+
+ /* Testing of the sizes/types of the channels is left
+ * up to the required-sized-texture-formats test.
+ */
+
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+ glFramebufferTexture2D(GL_FRAMEBUFFER,
+ attachment,
+ GL_TEXTURE_2D,
+ tex, 0);
+
+ if (glGetError() != 0) {
+ printf("Unexpected error binding %s texture\n",
+ f->name);
+ pass = false;
+ continue;
+ }
+
+ if (attachment == GL_COLOR_ATTACHMENT0) {
+ glDrawBuffer(GL_COLOR_ATTACHMENT0);
+ } else {
+ glDrawBuffer(GL_NONE);
+ }
+
+ status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr, "%s fbo incomplete (status = 0x%04x)\n",
+ f->name, status);
+ pass = false;
+ } else {
+ printf("%s: fbo complete\n", f->name);
+ }
+
+ glDeleteFramebuffers(1, &fbo);
+ }
+
+ glDeleteTextures(1, &tex);
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
diff --git a/tests/util/CMakeLists.gl.txt b/tests/util/CMakeLists.gl.txt
index d8591ec..9279fb9 100644
--- a/tests/util/CMakeLists.gl.txt
+++ b/tests/util/CMakeLists.gl.txt
@@ -12,6 +12,7 @@ set(UTIL_SOURCES
piglit-transform-feedback.c
piglit-util-gl.c
piglit-vbo.cpp
+ sized-internalformats.c
)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
diff --git a/tests/util/sized-internalformats.c b/tests/util/sized-internalformats.c
new file mode 100644
index 0000000..6d8babc
--- /dev/null
+++ b/tests/util/sized-internalformats.c
@@ -0,0 +1,315 @@
+/* Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+#include "sized-internalformats.h"
+
+#define FORMAT(token, r, g, b, a, l, i, d, s) \
+ { #token, token, { r, g, b, a, l, i, d, s } }
+
+/* This list has to match up with the enums in sized-internalformats.h */
+static const struct {
+ int size;
+ GLenum type;
+} sized_format_bits[BITS_MAX] = {
+ { 0, GL_NONE },
+
+ { 32, GL_UNSIGNED_NORMALIZED },
+ { 32, GL_FLOAT },
+ { 32, GL_INT },
+ { 32, GL_UNSIGNED_INT },
+
+ { 24, GL_UNSIGNED_NORMALIZED },
+
+ { 16, GL_UNSIGNED_NORMALIZED },
+ { 16, GL_FLOAT },
+ { 16, GL_INT },
+ { 16, GL_UNSIGNED_INT },
+
+ { 12, GL_UNSIGNED_NORMALIZED },
+ { 10, GL_UNSIGNED_NORMALIZED },
+
+ { 8, GL_UNSIGNED_NORMALIZED },
+ { 8, GL_SIGNED_NORMALIZED },
+ { 8, GL_INT },
+ { 8, GL_UNSIGNED_INT },
+
+ { 5, GL_UNSIGNED_NORMALIZED },
+ { 4, GL_UNSIGNED_NORMALIZED },
+ { 3, GL_UNSIGNED_NORMALIZED },
+ { 2, GL_UNSIGNED_NORMALIZED },
+ { 1, GL_UNSIGNED_NORMALIZED },
+
+ { 11, GL_FLOAT },
+ { 10, GL_FLOAT },
+ { 9, GL_FLOAT },
+
+ { ~0, GL_UNSIGNED_NORMALIZED },
+ { ~0, GL_SIGNED_NORMALIZED },
+};
+
+const struct sized_internalformat sized_internalformats[] = {
+ /* Sized internal color formats, table 3.16 of the GL 3.0
+ * specification.
+ */
+ FORMAT(GL_ALPHA4, NONE, NONE, NONE, UN4, NONE, NONE, NONE, NONE),
+ FORMAT(GL_ALPHA8, NONE, NONE, NONE, UN8, NONE, NONE, NONE, NONE),
+ FORMAT(GL_ALPHA12, NONE, NONE, NONE, UN12, NONE, NONE, NONE, NONE),
+ FORMAT(GL_ALPHA16, NONE, NONE, NONE, UN16, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R8, UN8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R16, UN16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG8, UN8, UN8, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG16, UN16, UN16, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R3_G3_B2, UN3, UN3, UN2, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB4, UN4, UN4, UN4, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB5, UN5, UN5, UN5, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB8, UN8, UN8, UN8, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB10, UN10, UN10, UN10, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB12, UN12, UN12, UN12, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB16, UN16, UN16, UN16, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA2, UN2, UN2, UN2, UN2, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA4, UN4, UN4, UN4, UN4, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB5_A1, UN5, UN5, UN5, UN1, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA8, UN8, UN8, UN8, UN8, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB10_A2, UN10, UN10, UN10, UN2, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA12, UN12, UN12, UN12, UN12, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA16, UN16, UN16, UN16, UN16, NONE, NONE, NONE, NONE),
+ FORMAT(GL_SRGB8, UN8, UN8, UN8, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_SRGB8_ALPHA8, UN8, UN8, UN8, UN8, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R16F, F16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG16F, F16, F16, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB16F, F16, F16, F16, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA16F, F16, F16, F16, F16, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R32F, F32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG32F, F32, F32, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB32F, F32, F32, F32, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA32F, F32, F32, F32, F32, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R11F_G11F_B10F, F11, F11, F10, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB9_E5, F9, F9, F9, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R8I, I8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R8UI, U8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R16I, I16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R16UI, U16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R32I, I32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_R32UI, U32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG8I, I8, I8, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG8UI, U8, U8, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG16I, I16, I16, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG16UI, U16, U16, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG32I, I32, I32, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RG32UI, U32, U32, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB8I, I8, I8, I8, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB8UI, U8, U8, U8, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB16I, I16, I16, I16, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB16UI, U16, U16, U16, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB32I, I32, I32, I32, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGB32UI, U32, U32, U32, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA8I, I8, I8, I8, I8, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA8UI, U8, U8, U8, U8, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA16I, I16, I16, I16, I16, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA16UI, U16, U16, U16, U16, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA32I, I32, I32, I32, I32, NONE, NONE, NONE, NONE),
+ FORMAT(GL_RGBA32UI, U32, U32, U32, U32, NONE, NONE, NONE, NONE),
+
+ /* Sized internal luminance formats, table 3.17 of the GL 3.0
+ * specification.
+ */
+ FORMAT(GL_LUMINANCE4, NONE, NONE, NONE, NONE, UN4, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE8, NONE, NONE, NONE, NONE, UN8, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE12, NONE, NONE, NONE, NONE, UN12, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE16, NONE, NONE, NONE, NONE, UN16, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE4_ALPHA4, NONE, NONE, NONE, UN4, UN4, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE8_ALPHA8, NONE, NONE, NONE, UN8, UN8, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE12_ALPHA12, NONE, NONE, NONE, UN12, UN12, NONE, NONE, NONE),
+ FORMAT(GL_LUMINANCE16_ALPHA16, NONE, NONE, NONE, UN16, UN16, NONE, NONE, NONE),
+ FORMAT(GL_INTENSITY4, NONE, NONE, NONE, NONE, NONE, UN4, NONE, NONE),
+ FORMAT(GL_INTENSITY8, NONE, NONE, NONE, NONE, NONE, UN8, NONE, NONE),
+ FORMAT(GL_INTENSITY12, NONE, NONE, NONE, NONE, NONE, UN12, NONE, NONE),
+ FORMAT(GL_INTENSITY16, NONE, NONE, NONE, NONE, NONE, UN16, NONE, NONE),
+ FORMAT(GL_SLUMINANCE, NONE, NONE, NONE, NONE, UN8, NONE, NONE, NONE),
+ FORMAT(GL_SLUMINANCE8_ALPHA8, NONE, NONE, NONE, UN8, UN8, NONE, NONE, NONE),
+
+ /* Sized internal depth and stencil formats, table 3.18 of the
+ * GL 3.0 specification.
+ */
+ FORMAT(GL_DEPTH_COMPONENT16, NONE, NONE, NONE, NONE, NONE, NONE,
+ UN16, NONE),
+ FORMAT(GL_DEPTH_COMPONENT24, NONE, NONE, NONE, NONE, NONE, NONE,
+ UN24, NONE),
+ FORMAT(GL_DEPTH_COMPONENT32, NONE, NONE, NONE, NONE, NONE, NONE,
+ UN32, NONE),
+ FORMAT(GL_DEPTH_COMPONENT32F, NONE, NONE, NONE, NONE, NONE, NONE,
+ F32, NONE),
+ FORMAT(GL_DEPTH24_STENCIL8, NONE, NONE, NONE, NONE, NONE, NONE,
+ UN24, UN8),
+ FORMAT(GL_DEPTH32F_STENCIL8, NONE, NONE, NONE, NONE, NONE, NONE,
+ F32, UN8),
+
+ /* Specific compressed internal formats, table 3.19 of the GL
+ * 3.0 specification.
+ */
+ FORMAT(GL_COMPRESSED_RG_RGTC2, UCMP, UCMP, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_COMPRESSED_SIGNED_RG_RGTC2, SCMP, SCMP, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_COMPRESSED_RED_RGTC1, UCMP, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+ FORMAT(GL_COMPRESSED_SIGNED_RED_RGTC1, SCMP, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
+
+ { GL_NONE },
+};
+
+const struct required_format required_formats[] = {
+ { GL_RGBA32F, 30, true },
+ { GL_RGBA32I, 30, true },
+ { GL_RGBA32UI, 30, true },
+ { GL_RGBA16, 30, true },
+ { GL_RGBA16F, 30, true },
+ { GL_RGBA16I, 30, true },
+ { GL_RGBA16UI, 30, true },
+ { GL_RGBA8, 30, true },
+ { GL_RGBA8I, 30, true },
+ { GL_RGBA8UI, 30, true },
+ { GL_SRGB8_ALPHA8, 30, true },
+ { GL_RGB10_A2, 30, true },
+
+ { GL_RGB10_A2UI, 33, true },
+
+ { GL_RGB5_A1, 42, true },
+ { GL_RGBA4, 42, true },
+
+ { GL_R11F_G11F_B10F, 30, true },
+
+ /* Not in the headers! */
+ /* { GL_RGB565, 42 }, */
+
+ { GL_RG32F, 30, true },
+ { GL_RG32I, 30, true },
+ { GL_RG32UI, 30, true },
+ { GL_RG16, 30, true },
+ { GL_RG16F, 30, true },
+ { GL_RG16I, 30, true },
+ { GL_RG16UI, 30, true },
+ { GL_RG8, 30, true },
+ { GL_RG8I, 30, true },
+ { GL_RG8UI, 30, true },
+ { GL_R32F, 30, true },
+ { GL_R32I, 30, true },
+ { GL_R32UI, 30, true },
+ { GL_R16F, 30, true },
+ { GL_R16I, 30, true },
+ { GL_R16UI, 30, true },
+ { GL_R16, 30, true },
+ { GL_R8, 30, true },
+ { GL_R8I, 30, true },
+ { GL_R8UI, 30, true },
+
+ { GL_ALPHA8, 30, true }, /* deprecated */
+
+ /* Required color formats (texture-only): */
+
+ { GL_RGBA16_SNORM, 31, false },
+ { GL_RGB32F, 30, false },
+ { GL_RGB32I, 30, false },
+ { GL_RGB32UI, 30, false },
+
+ { GL_RGB16_SNORM, 31 },
+ { GL_RGB16F, 30, false },
+ { GL_RGB16I, 30, false },
+ { GL_RGB16UI, 30, false },
+ { GL_RGB16, 30, false },
+
+ { GL_RGB8_SNORM, 31 },
+ { GL_RGB8, 30, false },
+ { GL_RGB8I, 30, false },
+ { GL_RGB8UI, 30, false },
+ { GL_SRGB8, 30, false },
+
+ { GL_RGB9_E5, 30, false },
+
+ { GL_RG16_SNORM, 31, false },
+
+ { GL_COMPRESSED_RG_RGTC2, 30, false },
+ { GL_COMPRESSED_SIGNED_RG_RGTC2, 30, false },
+
+ { GL_R16_SNORM, 31, false },
+
+ { GL_COMPRESSED_RED_RGTC1, 30, false },
+ { GL_COMPRESSED_SIGNED_RED_RGTC1, 30, false },
+
+ { GL_DEPTH_COMPONENT32F, 30, false },
+ { GL_DEPTH_COMPONENT24, 30, false },
+ { GL_DEPTH_COMPONENT16, 30, false },
+
+ { GL_DEPTH32F_STENCIL8, 30, false },
+ { GL_DEPTH24_STENCIL8, 30, false },
+
+ { GL_NONE }
+};
+
+const struct sized_internalformat *
+get_sized_internalformat(GLenum token)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(sized_internalformats); i++) {
+ if (sized_internalformats[i].token == token)
+ return &sized_internalformats[i];
+ }
+
+ return NULL;
+}
+
+int
+get_channel_size(const struct sized_internalformat *f, enum channel c)
+{
+ return sized_format_bits[f->bits[c]].size;
+}
+
+GLenum
+get_channel_type(const struct sized_internalformat *f, enum channel c)
+{
+ return sized_format_bits[f->bits[c]].type;
+}
+
+void
+print_bits(int size, GLenum type)
+{
+ /* For compressed formats, there is no particular value for
+ * the channel size specified.
+ */
+ if (size == ~0)
+ printf("??");
+ else
+ printf("%2d", size);
+
+ if (type == GL_FLOAT)
+ printf("f ");
+ else if (type == GL_INT)
+ printf("i ");
+ else if (type == GL_UNSIGNED_INT)
+ printf("ui");
+ else if (type == GL_SIGNED_NORMALIZED)
+ printf("s ");
+ else if (type == GL_UNSIGNED_NORMALIZED ||
+ (size == 0 && type == GL_NONE))
+ printf(" ");
+ else
+ printf("??");
+}
diff --git a/tests/util/sized-internalformats.h b/tests/util/sized-internalformats.h
new file mode 100644
index 0000000..e01c2f3
--- /dev/null
+++ b/tests/util/sized-internalformats.h
@@ -0,0 +1,106 @@
+/* Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/* F=float, UN=unsigned normalized, SN=signed normalized, I=int,
+ * U=uint.
+ *
+ * This list has to match up with the table in sized-internalformats.c.
+ */
+enum bits_types {
+ NONE,
+
+ UN32,
+ F32,
+ I32,
+ U32,
+
+ UN24,
+
+ UN16,
+ F16,
+ I16,
+ U16,
+
+ UN12,
+ UN10,
+
+ UN8,
+ SN8,
+ I8,
+ U8,
+
+ UN5,
+ UN4,
+ UN3,
+ UN2,
+ UN1,
+
+ F11,
+ F10,
+ F9,
+
+
+ /* Compressed internalformats get treated specially. */
+ UCMP,
+ SCMP,
+
+ BITS_MAX,
+};
+
+enum channel {
+ R,
+ G,
+ B,
+ A,
+ L,
+ I,
+ D,
+ S,
+ CHANNELS,
+};
+
+struct sized_internalformat {
+ const char *name;
+ GLenum token;
+ enum bits_types bits[CHANNELS];
+};
+
+struct required_format {
+ GLenum token;
+ int version;
+ bool rb_required;
+};
+
+extern const struct sized_internalformat sized_internalformats[];
+extern const struct required_format required_formats[];
+
+const struct sized_internalformat *
+get_sized_internalformat(GLenum token);
+
+int
+get_channel_size(const struct sized_internalformat *f, enum channel c);
+
+GLenum
+get_channel_type(const struct sized_internalformat *f, enum channel c);
+
+void
+print_bits(int size, GLenum type);
--
1.7.7
More information about the Piglit
mailing list