[Piglit] [PATCH] Add test case for glClearBuffer in mixed format color buffers
Anuj Phogat
anuj.phogat at gmail.com
Wed Dec 14 12:47:00 PST 2011
Adding test case to verify the functionality of glClearBuffer[fui]v functions
with mixed format color buffers. generate_color_fbo() will be merged with
generate_simple_fbo() in a later commit.
Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
Major changes made to the test case:
- Indentation correction
- Moved the test for using glClearBuffer[fui]v functions in color buffers of
different format, out of first for loop. This is because result of clearing
integer buffers using glClearBufferfv or clearing float buffers with
glClearBufferiv/glClearBufferuiv is undefined. But no error should be
generated.
tests/all.tests | 1 +
tests/spec/gl-3.0/api/CMakeLists.gl.txt | 1 +
tests/spec/gl-3.0/api/clearbuffer-common.c | 119 +++++++++++
tests/spec/gl-3.0/api/clearbuffer-common.h | 8 +
tests/spec/gl-3.0/api/clearbuffer-mixed-format.c | 248 ++++++++++++++++++++++
5 files changed, 377 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/gl-3.0/api/clearbuffer-mixed-format.c
diff --git a/tests/all.tests b/tests/all.tests
index b713de0..8bfd373 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -809,6 +809,7 @@ add_concurrent_test(gl30, 'clearbuffer-depth-stencil')
add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')
add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
add_concurrent_test(gl30, 'clearbuffer-stencil')
+add_concurrent_test(gl30, 'clearbuffer-mixed-format')
add_concurrent_test(gl30, 'getfragdatalocation')
gl30['minmax'] = concurrent_test('gl-3.0-minmax')
add_concurrent_test(gl30, 'gl-3.0-required-sized-texture-formats')
diff --git a/tests/spec/gl-3.0/api/CMakeLists.gl.txt b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
index 466ffeb..5a34380 100644
--- a/tests/spec/gl-3.0/api/CMakeLists.gl.txt
+++ b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
@@ -18,6 +18,7 @@ add_executable (clearbuffer-depth-stencil clearbuffer-common.c clearbuffer-depth
add_executable (clearbuffer-invalid-drawbuffer clearbuffer-invalid-drawbuffer.c)
add_executable (clearbuffer-invalid-buffer clearbuffer-invalid-buffer.c)
add_executable (clearbuffer-stencil clearbuffer-common.c clearbuffer-stencil.c)
+add_executable (clearbuffer-mixed-format clearbuffer-common.c clearbuffer-mixed-format.c)
add_executable (getfragdatalocation getfragdatalocation.c)
# vim: ft=cmake:
diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.c b/tests/spec/gl-3.0/api/clearbuffer-common.c
index 0c1fc06..67a4a80 100644
--- a/tests/spec/gl-3.0/api/clearbuffer-common.c
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.c
@@ -173,6 +173,125 @@ simple_probe(bool color, const float *color_value,
return pass;
}
+GLuint
+generate_color_fbo(GLenum internalformat)
+{
+ GLuint fb;
+ GLuint rb;
+ GLenum status;
+
+ glGenFramebuffers(1, &fb);
+ glBindFramebuffer(GL_FRAMEBUFFER, fb);
+ glGenRenderbuffers(1, &rb);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb);
+ glRenderbufferStorage(GL_RENDERBUFFER,
+ internalformat,
+ piglit_width,
+ piglit_height);
+
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_RENDERBUFFER,
+ rb);
+
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+ status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
+ fprintf(stderr,
+ "Framebuffer with color"
+ "attachment was not complete: 0x%04x\n",
+ status);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ if (status == GL_FRAMEBUFFER_UNSUPPORTED) {
+ glDeleteRenderbuffers(1, &rb);
+ glDeleteFramebuffers(1, &fb);
+ return 0;
+ }
+ /* Color buffer is cleared to default RGBA (0, 0, 0, 0) color */
+ glClear(GL_COLOR_BUFFER_BIT);
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+ return fb;
+}
+
+/* This function supports reading pixel color values from multiple
+ * format color buffers
+ */
+bool
+probe_rect_color(int x, int y, int w, int h,
+ GLenum format, GLenum type,
+ GLvoid *refcolor)
+{
+ int i, j, p;
+ if (type == GL_FLOAT)
+ {
+ if (!piglit_probe_rect_rgba(0, 0,
+ piglit_width, piglit_height,
+ (GLfloat*)refcolor))
+ return false;
+ }
+ else if (type == GL_UNSIGNED_INT)
+ {
+ GLuint *probe;
+ GLuint *pixels = malloc(w*h*4*sizeof(unsigned int));
+ GLuint *expected = (GLuint*)refcolor;
+ glReadPixels(x, y, w, h, format, type, pixels);
+
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ probe = &pixels[(j*w+i)*4];
+ for (p = 0; p < 4; ++p) {
+ if (fabs(probe[p] - expected[p]) >=
+ piglit_tolerance[p]) {
+ printf("Probe at (%d,%d)\n",
+ x+i, y+j);
+ printf(" Expected: %d %d %d %d\n",
+ expected[0], expected[1],
+ expected[2], expected[3]);
+ printf(" Observed: %d %d %d %d\n",
+ probe[0], probe[1],
+ probe[2], probe[3]);
+ free(pixels);
+ return false;
+ }
+ }
+ }
+ }
+ free(pixels);
+ }
+ else if (type == GL_INT)
+ {
+ GLint *probe;
+ GLint *pixels = malloc(w*h*4*sizeof(int));
+ GLint *expected = (GLint*)refcolor;
+ glReadPixels(x, y, w, h, format, type, pixels);
+
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ probe = &pixels[(j*w+i)*4];
+ for (p = 0; p < 4; ++p) {
+ if (fabs(probe[p] - expected[p]) >=
+ piglit_tolerance[p]) {
+ printf("Probe at (%d,%d)\n",
+ x+i, y+j);
+ printf(" Expected: %d %d %d %d\n",
+ expected[0], expected[1],
+ expected[2], expected[3]);
+ printf(" Observed: %d %d %d %d\n",
+ probe[0], probe[1],
+ probe[2], probe[3]);
+ free(pixels);
+ return false;
+ }
+ }
+ }
+ }
+ free(pixels);
+ }
+ return true;
+}
+
enum piglit_result
piglit_display(void)
{
diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.h b/tests/spec/gl-3.0/api/clearbuffer-common.h
index e5afc51..00cdc7f 100644
--- a/tests/spec/gl-3.0/api/clearbuffer-common.h
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.h
@@ -31,3 +31,11 @@ extern bool
simple_probe(bool color, const float *color_value,
bool stencil, int stencil_value,
bool depth, float depth_value);
+
+extern GLuint
+generate_color_fbo(GLenum internalformat);
+
+extern bool
+probe_rect_color(int x, int y, int width, int height,
+ GLenum format, GLenum type, GLvoid *refcolor);
+
diff --git a/tests/spec/gl-3.0/api/clearbuffer-mixed-format.c b/tests/spec/gl-3.0/api/clearbuffer-mixed-format.c
new file mode 100644
index 0000000..6efa593
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-mixed-format.c
@@ -0,0 +1,248 @@
+/* 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.
+ */
+
+/*
+ * \file clearbuffer-mixed-format.c
+ * Verify clearing mixed format color buffers with glClearBuffer[fui]v functions
+ *
+ * This test works by generating several mixed foarmt color framebuffer objects
+ * and attempting to clear the color buffer of those FBOs by calling
+ * glClearBufferfv/glClearBufferiv/glClearBufferuiv.
+ *
+ * - FBOs with a float color buffer attachment. glClearBufferfv should clear
+ * the color buffer to desired float value. glClearBufferuiv/glClearBufferiv
+ * should not modify the color data in float buffer.
+ *
+ * - FBOs with a unsigned integer color buffer attachment. glClearBufferuiv
+ * should clear the color buffer to desired integer value. glClearBufferfv
+ * or glClearBufferiv should not modify the data in float color buffer
+ *
+ * - FBOs with a signed integer color buffer attachment. glClearBufferiv
+ * should clear the color buffer to desired integer value. glClearBufferfv
+ * or glClearBufferuiv should not modify the data in float color buffer
+ *
+ * - No error should be generated for using glClearBufferuiv or
+ * glClearBufferiv on a float color buffer or using glClearBufferfv on a
+ * integer color buffers
+ *
+ *
+ * \author Anuj Phogat
+ */
+
+#include "piglit-util.h"
+#include "clearbuffer-common.h"
+
+#define COUNT ARRAY_SIZE(test_vectors)
+
+void piglit_init(int argc, char **argv)
+{
+ static const float fcolor[4][4] = {
+ { 0.5, 0.3, 0.7, 0.0 },
+ { 0.8, 0.0, 0.2, 1.0 },
+ { 1.2, -2.9, 0.2, 5.8 },
+ { 0.5, 2.5, -5.2, 1.0 } };
+
+ static const unsigned int uicolor[4][4] = {
+ { 10, 90, 100, 150 },
+ { 100, 190, 200, 15 },
+ { 15, 25, 20, 15 },
+ { 10, 80, 0, 25 }, };
+
+ static const int icolor[4][4] = {
+ { -10, -90, 100, 15 },
+ { 100, 190, 200, -15 },
+ { -50, -50, -50, 50 },
+ { -80, 170, 0, 0 } };
+
+ static const struct {
+ GLenum fb_format;
+ GLenum rp_format;
+ GLenum type;
+ GLvoid *clear_color;
+ } test_vectors[] = {
+ /* GL_RGBA8, GL_RGBA16 clamps the color vaues to [0, 1] */
+ { GL_RGBA8, GL_RGBA,
+ GL_FLOAT, (GLvoid *)fcolor[0] },
+ { GL_RGBA16, GL_RGBA,
+ GL_FLOAT, (GLvoid *)fcolor[1] },
+
+ /* GL_RGBA16F, GL_RGBA32F doesn't clamp color values to [0, 1] */
+ { GL_RGBA16F, GL_RGBA,
+ GL_FLOAT, (GLvoid *)fcolor[2] },
+ { GL_RGBA32F, GL_RGBA,
+ GL_FLOAT, (GLvoid *)fcolor[3] },
+
+ /* Integer formats */
+ { GL_RGBA8UI, GL_RGBA_INTEGER,
+ GL_UNSIGNED_INT, (GLvoid *)uicolor[0] },
+ { GL_RGBA16UI, GL_RGBA_INTEGER,
+ GL_UNSIGNED_INT, (GLvoid *)uicolor[1] },
+ { GL_RGBA32UI, GL_RGBA_INTEGER,
+ GL_UNSIGNED_INT, (GLvoid *)uicolor[2] },
+
+ { GL_RGBA8I, GL_RGBA_INTEGER,
+ GL_INT, (GLvoid *)icolor[0] },
+ { GL_RGBA16I, GL_RGBA_INTEGER,
+ GL_INT, (GLvoid *)icolor[1] },
+ { GL_RGBA32I, GL_RGBA_INTEGER,
+ GL_INT, (GLvoid *)icolor[2] },
+ };
+
+ GLuint fb[COUNT];
+ bool pass = true;
+ GLenum err;
+ int i, j;
+
+ piglit_require_gl_version(30);
+
+ for (i = 0; i < COUNT; i++) {
+ fb[i] = generate_color_fbo(test_vectors[i].fb_format);
+
+ if (fb[i] == 0) {
+ if (!piglit_automatic) {
+ printf("Skipping framebuffer %d with color"
+ " renderbuffer attachment\n",
+ i);
+ }
+ }
+ if (!piglit_automatic)
+ printf("Created framebuffer %d with a color"
+ " renderbuffer attachment\n",
+ i);
+
+ /* Clear the color buffer to a unique color. Also verify that:
+ * - glClearBufferuiv has no effect on float color buffer
+ * or integer buffer
+ * - glClearBufferfv has no effect on integer color buffers
+ * - glClearBufferiv has no effect on float or unsigned
+ * integer color buffer
+ */
+ switch (test_vectors[i].type) {
+
+ /*Float buffer types*/
+ case GL_FLOAT:
+ glClearBufferfv(GL_COLOR,
+ 0,
+ (GLfloat *)test_vectors[i].clear_color);
+
+ /* Test the pixel values of color buffer against
+ * expected color values
+ */
+ pass = pass && probe_rect_color(0,
+ 0,
+ piglit_width, piglit_height,
+ test_vectors[i].rp_format,
+ test_vectors[i].type,
+ test_vectors[i].clear_color);
+ break;
+
+ /* Signed/unsigned integer buffer types */
+ case GL_INT:
+ glClearBufferiv(GL_COLOR,
+ 0,
+ (GLint *)test_vectors[i].clear_color);
+
+ /* Test the pixel values of color buffer against
+ * expected color values
+ */
+ pass = pass && probe_rect_color(0,
+ 0,
+ piglit_width, piglit_height,
+ test_vectors[i].rp_format,
+ test_vectors[i].type,
+ test_vectors[i].clear_color);
+ break;
+
+ case GL_UNSIGNED_INT:
+ glClearBufferuiv(GL_COLOR,
+ 0,
+ (GLuint *)test_vectors[i].clear_color);
+
+ /* Test the pixel values of color buffer against
+ * expected color values
+ */
+ pass = pass && probe_rect_color(0,
+ 0,
+ piglit_width, piglit_height,
+ test_vectors[i].rp_format,
+ test_vectors[i].type,
+ test_vectors[i].clear_color);
+ break;
+ }
+
+ /* Test the color buffer values of all existing FBOs against
+ * their expected color values. Previously issued glClearBuffer
+ * functions should not modify color buffers of other existing
+ * FBOs
+ */
+ for (j = 0; j < i; j++)
+ {
+ /* Bind previously created FBO */
+ glBindFramebuffer(GL_FRAMEBUFFER, fb[j]);
+ pass = pass && probe_rect_color(0,
+ 0,
+ piglit_width, piglit_height,
+ test_vectors[j].rp_format,
+ test_vectors[j].type,
+ test_vectors[j].clear_color);
+ }
+ /* Check GL error */
+ err = glGetError();
+ if (err != GL_NO_ERROR) {
+ piglit_get_gl_error_name(err);
+ pass = false;
+ }
+ }
+
+ /* No GL error should be generated for clearing integer buffers using
+ * glClearBufferfv or clearing float buffers with glClearBufferiv/
+ * glClearBufferuiv. But the result of ClearBuffer is undefined.
+ * Reference: OpenGL 3.0 specification section 4.2.3 "Clearing the
+ * Buffers"
+ */
+ for (i = 0; i < COUNT; i++)
+ {
+ /* Bind previously created FBO */
+ glBindFramebuffer(GL_FRAMEBUFFER, fb[j]);
+
+ glClearBufferuiv(GL_COLOR,
+ 0,
+ uicolor[0]);
+ glClearBufferiv(GL_COLOR,
+ 0,
+ icolor[0]);
+ glClearBufferfv(GL_COLOR,
+ 0,
+ fcolor[0]);
+
+ err = glGetError();
+ if (err != GL_NO_ERROR) {
+ piglit_get_gl_error_name(err);
+ pass = false;
+ }
+ }
+ /* Delete all generated framebuffer objects */
+ glDeleteFramebuffers(COUNT, fb);
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+ piglit_present_results();
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
1.7.7.4
More information about the Piglit
mailing list