[Piglit] [PATCH 2/3] gl-3.0: Test clearing stencil buffers with glClearBufferiv

Ian Romanick idr at freedesktop.org
Fri Nov 4 10:33:29 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This test passes on Mesa's swrast, Mesa's i965, and NVIDIA's
closed-source driver.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/all.tests                             |    1 +
 tests/spec/gl-3.0/api/CMakeLists.gl.txt     |    1 +
 tests/spec/gl-3.0/api/clearbuffer-stencil.c |  158 +++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/gl-3.0/api/clearbuffer-stencil.c

diff --git a/tests/all.tests b/tests/all.tests
index 13c8791..efd6f35 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -791,6 +791,7 @@ spec['!OpenGL 3.0'] = gl30
 add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')
 add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
 add_concurrent_test(gl30, 'clearbuffer-depth')
+add_concurrent_test(gl30, 'clearbuffer-stencil')
 
 # Group spec/glsl-1.00
 spec['glsl-1.00'] = Group()
diff --git a/tests/spec/gl-3.0/api/CMakeLists.gl.txt b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
index 8842884..9ce476b 100644
--- a/tests/spec/gl-3.0/api/CMakeLists.gl.txt
+++ b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
@@ -15,5 +15,6 @@ link_libraries (
 add_executable (clearbuffer-depth clearbuffer-common.c clearbuffer-depth.c)
 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)
 
 # vim: ft=cmake:
diff --git a/tests/spec/gl-3.0/api/clearbuffer-stencil.c b/tests/spec/gl-3.0/api/clearbuffer-stencil.c
new file mode 100644
index 0000000..35cb0e4
--- /dev/null
+++ b/tests/spec/gl-3.0/api/clearbuffer-stencil.c
@@ -0,0 +1,158 @@
+/* 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-stencil.c
+ * Verify clearing stencil buffers with glClearBufferiv
+ *
+ * This test works by generating several framebuffer objects and attempting to
+ * clear the depth buffer of those FBOs by calling \c glClearBufferfv.
+ *
+ *     - An FBO with only a color attachment.  This should not generate an
+ *       error, but the color data should not be modified.
+ *
+ *     - An FBO with only a stencil attachment.
+ *
+ *     - An FBO with a stencil attachment and a color attachment.  The color
+ *       data should not be modified.
+ *
+ *     - An FBO with a depth attachment and a stencil attachment.  The depth
+ *       data should not be modified.
+ *
+ *     - An FBO with a packed depth/stencil attachment.  The depth data
+ *       should not be modified.
+ *
+ * In each case, \c glClearBufferfv is called twice.  Each call uses a
+ * different clear value.  This ensures that the test doesn't erroneously pass
+ * because the depth buffer was already filled with the clear color.
+ *
+ * \author Ian Romanick
+ */
+#include "piglit-util.h"
+#include "clearbuffer-common.h"
+
+void piglit_init(int argc, char **argv)
+{
+	static const struct {
+		bool color;
+		bool stencil;
+		bool depth;
+		bool packed;
+	} test_vectors[] = {
+		{ true,  false, false, false },
+		{ false, true,  false, false },
+		{ true,  true,  false, false },
+		{ false, true,  true,  false },
+		{ true,  true,  true,  false },
+		{ false, true,  true,  true },
+		{ true,  true,  true,  true },
+	};
+
+	static const int first[4]  = { 0x01, 0x00, 0x00, 0x00 };
+	static const int second[4] = { 0xfe, 0x88, 0x88, 0x88 };
+
+	unsigned i;
+	bool pass = true;
+
+	piglit_require_gl_version(30);
+
+	for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
+		GLenum err;
+		GLuint fb = generate_simple_fbo(test_vectors[i].color,
+						test_vectors[i].stencil,
+						test_vectors[i].depth,
+						test_vectors[i].packed);
+
+		if (fb == 0) {
+			if (!piglit_automatic) {
+				printf("Skipping framebuffer %s color, "
+				       "%s depth, and "
+				       "%s stencil (%s).\n",
+				       test_vectors[i].color
+				       ? "with" : "without",
+				       test_vectors[i].depth
+				       ? "with" : "without",
+				       test_vectors[i].stencil
+				       ? "with" : "without",
+				       test_vectors[i].packed
+				       ? "packed" : "separate");
+			}
+
+			continue;
+		}
+
+		if (!piglit_automatic) {
+			printf("Trying framebuffer %s color, "
+			       "%s depth and "
+			       "%s stencil (%s)...\n",
+			       test_vectors[i].color ? "with" : "without",
+			       test_vectors[i].depth ? "with" : "without",
+			       test_vectors[i].stencil ? "with" : "without",
+			       test_vectors[i].packed ? "packed" : "separate");
+		}
+
+		/* The GL spec says nothing about generating an error for
+		 * clearing a buffer that does not exist.  Certainly glClear
+		 * does not.
+		 */
+		glClearBufferiv(GL_STENCIL, 0, first);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"First call to glClearBufferiv erroneously "
+				"generated a GL error (%s, 0x%04x)\n",
+				piglit_get_gl_error_name(err), err);
+			pass = false;
+		}
+
+		pass = simple_probe(test_vectors[i].color,
+				    default_color,
+				    test_vectors[i].stencil,
+				    first[0],
+				    test_vectors[i].depth,
+				    default_depth)
+			&& pass;
+
+		glClearBufferiv(GL_STENCIL, 0, second);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"Second call to glClearBufferiv erroneously "
+				"generated a GL error (%s, 0x%04x)\n",
+				piglit_get_gl_error_name(err), err);
+			pass = false;
+		}
+
+		pass = simple_probe(test_vectors[i].color,
+				    default_color,
+				    test_vectors[i].stencil,
+				    second[0],
+				    test_vectors[i].depth,
+				    default_depth)
+			&& pass;
+
+		glDeleteFramebuffers(1, &fb);
+		piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.6.4



More information about the Piglit mailing list