[Piglit] [PATCH] Add test case clearbuffer mixed format

Anuj Phogat anuj.phogat at gmail.com
Mon Dec 12 11:29:06 PST 2011


Adding a new testcase to verify clearing mixed format color buffers with 
glClearBufferfv/glClearBufferiv/glClearBufferuiv

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
Tested this testcase after applying a patch sent by Dave Airlie On Nov 27
with a subject "[Mesa-dev] [PATCH] format_unpack: add 8/16 rgba/rgb types."
This patch seems to be pending to push on mesa. I'll appreciate any feedbacks
on this test case.

 tests/all.tests                                  |    1 +
 tests/spec/gl-3.0/api/CMakeLists.gl.txt          |    1 +
 tests/spec/gl-3.0/api/clearbuffer-mixed-format.c |  305 ++++++++++++++++++++++
 3 files changed, 307 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 13e97a7..926d7cb 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -802,6 +802,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')
 add_concurrent_test(gl30, 'gl-3.0-required-sized-texture-formats')
 add_concurrent_test(gl30, 'gl-3.0-required-renderbuffer-attachment-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-mixed-format.c b/tests/spec/gl-3.0/api/clearbuffer-mixed-format.c
new file mode 100644
index 0000000..2f8fb08
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-mixed-format.c
@@ -0,0 +1,305 @@
+/* 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 glClearBufferfv/glClearBufferiv/glClearBufferuiv
+ *
+ * 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 color buffer.
+ *     
+ *     - FBOs with a unsigned integer color buffer attachment. glClearBufferuiv should clear the color
+ *       buffer to desired integer value. glClearBufferfv/glClearBufferiv should not modify the color 
+ *       data in float color buffer.
+ *
+ *     - FBOs with a signed integer color buffer attachment. glClearBufferiv should clear the color 
+ *       buffer to desired integer value. glClearBufferfv/glClearBufferuiv should not modify the color
+ *       data in float color buffer.
+ *
+ *     - No error should be generated for using glClearBufferuiv/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 FBO_COUNT 10
+
+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);
+	glFinish();
+	piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+	return fb;
+}
+
+/* This function supports reading pixel color values from multiple format color buffers */
+int
+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)
+	{
+		piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, (GLfloat*)refcolor);
+	}
+	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 0;
+					}
+				}
+			}
+		}
+		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 0;
+					}
+				}
+			}
+		}
+		free(pixels);
+	}
+return 1;
+}
+
+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[6][4] = { {  10,   90, 100, 150 },
+	                                             { 100,  190, 200,  15 }, 
+	                                             { 100,  190, 200,  15 }, 
+	                                             {  10,   80,  0,   25 }, 
+	                                             { 110,   85,  10,  75 }, 
+	                                             {  90,  120,  60,  30 } };
+
+	static const unsigned int  icolor[6][4] = { {  -10,  -90, 100,  15 },
+	                                             { 100,  190, 200, -15 }, 
+	                                             { -50,  -50, -50,  50 }, 
+	                                             { -30,  -10,  20,  50 }, 
+	                                             { -70,   20, -40, 100 }, 
+	                                             { -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[FBO_COUNT];
+	GLenum err;
+	bool pass = true;
+	int i,j;
+
+	piglit_require_gl_version(30);
+
+        for (i = 0; i < FBO_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\n", i);
+			}
+		}
+		if (!piglit_automatic) 
+			printf("Created framebuffer %d with a color renderbuffer attachment\n", i);
+		
+		/* Clear the color buffer to a unique color
+		 * We use glClearBufferfv glClearBufferiv and glClearBufferuiv to verify that:
+		 *        - glClearBufferuiv should have no effect on float color  buffer or integer buffer
+		 *        - glClearBufferfv should have no effect on integer color buffers
+		 *        - glClearBufferiv should have no effect on float color buffer 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);
+			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);
+
+			/* Clearing the float buffer using glClearBufferuiv or glClearBufferiv should
+			 * not modify color buffer data */
+			glClearBufferuiv(GL_COLOR, 0,(GLuint *)test_vectors[i].clear_color);
+			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);
+
+			glClearBufferiv(GL_COLOR, 0, (GLint *)test_vectors[i].clear_color);
+			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:
+		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);
+
+			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);
+		
+			/*Clearing the integer buffer using glClearBufferfv should not modify color buffer data*/
+			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;
+		}
+
+		/*Check GL error:
+		 *    - No GL error should be generated for clearing a buffer of type float/uint/int using
+		 *    	glClearBufferiv, glClearBufferuiv or glClearBufferfv. OpenGL 3.0 spec. section 4.2.3
+		 *    	says: "The result of ClearBuffer is undefined if no conversion between the type of
+		 *    	the specified value and the type of the buffer being cleared is defined (for example,
+		 *    	if ClearBufferi is called with a fixed- or floating-point buffer, or if ClearBufferf
+		 *    	is called with a signed or unsigned integer buffer). This is not an error."
+		 *    	*/
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			piglit_get_gl_error_name(err);
+			pass = false;
+		}
+
+		/* Test the color buffer values of all existing FBOs against their expected color values.
+		 * Previously issued glClearBuffer[uif]v 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);
+		}
+	}
+       	/* Delete all generated framebuffer objects */
+	glDeleteFramebuffers(FBO_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