[Piglit] [PATCH] degenerate-prims: test that prims with too few vertices don't draw anything

Brian Paul brianp at vmware.com
Thu Feb 21 07:38:07 PST 2013


v2: use new piglit_get_prim_name() function.
---
 tests/all.tests                  |    1 +
 tests/general/CMakeLists.gl.txt  |    1 +
 tests/general/degenerate-prims.c |  108 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 tests/general/degenerate-prims.c

diff --git a/tests/all.tests b/tests/all.tests
index c52c6cf..4b7e076 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -476,6 +476,7 @@ add_plain_test(gl11, 'clear-accum')
 add_concurrent_test(gl11, 'clipflat')
 add_plain_test(gl11, 'copypixels-draw-sync')
 add_plain_test(gl11, 'copypixels-sync')
+add_plain_test(gl11, 'degenerate-prims')
 add_plain_test(gl11, 'depthfunc')
 add_plain_test(gl11, 'depthrange-clear')
 add_plain_test(gl11, 'dlist-clear')
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index d356525..c3a0748 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -27,6 +27,7 @@ piglit_add_executable (copy-pixels copy-pixels.c)
 piglit_add_executable (copypixels-sync copypixels-sync.c)
 piglit_add_executable (copypixels-draw-sync copypixels-draw-sync.c)
 piglit_add_executable (depth-clamp-range depth-clamp-range.c)
+piglit_add_executable (degenerate-prims degenerate-prims.c)
 piglit_add_executable (dlist-clear dlist-clear.c)
 piglit_add_executable (dlist-color-material dlist-color-material.c)
 piglit_add_executable (dlist-fdo3129-01 dlist-fdo3129-01.c)
diff --git a/tests/general/degenerate-prims.c b/tests/general/degenerate-prims.c
new file mode 100644
index 0000000..53e8d5f
--- /dev/null
+++ b/tests/general/degenerate-prims.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2013 VMware, Inc.
+ *
+ * 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.
+ *
+ */
+
+
+/**
+ * Test drawing primitives with too few vertices.  In particular,
+ * GL_QUADS and GL_QUAD_STRIP with 3 verts seems to regress every
+ * once in a while in Mesa.
+ *
+ * Brian Paul
+ * Feb 2013
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+	config.supports_gl_compat_version = 10;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+/**
+ * Test a specific degenerate primitive.
+ * The expected outcome is that nothing will be drawn.
+ */
+static bool
+test_prim(GLenum prim, unsigned numVerts, const void *verts)
+{
+	static const float black[] = {0, 0, 0, 0};
+	bool pass;
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glVertexPointer(2, GL_FLOAT, 0, verts);
+	glEnable(GL_VERTEX_ARRAY);
+	glDrawArrays(prim, 0, numVerts);
+
+	/* Nothing should have been drawn / look for all black */
+	pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, black);
+
+	piglit_present_results();
+
+	if (!pass) {
+		piglit_report_subtest_result(PIGLIT_FAIL, "Primitive: %s",
+					     piglit_get_prim_name(prim));
+	}
+
+	return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	static const float
+		verts2[2][2] = { {-1, -1}, {1, 1} },
+		verts3[3][2] = { {-1, -1}, {1, -1}, {0, 1} },
+		verts4[4][2] = { {-1, -1}, {1, -1}, {1, 1}, {-1, 1} };
+	static bool pass = true;
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(-1, 1, -1, 1, -1, 1);
+
+	glColor3f(1, 1, 1);
+
+	pass = test_prim(GL_POINTS, 0, verts2) && pass;
+	pass = test_prim(GL_LINES, 1, verts2) && pass;
+	pass = test_prim(GL_LINE_STRIP, 1, verts2) && pass;
+	pass = test_prim(GL_LINE_LOOP, 1, verts2) && pass;
+	pass = test_prim(GL_TRIANGLES, 2, verts3) && pass;
+	pass = test_prim(GL_TRIANGLE_STRIP, 2, verts3) && pass;
+	pass = test_prim(GL_TRIANGLE_FAN, 2, verts3) && pass;
+	pass = test_prim(GL_QUADS, 3, verts4) && pass;
+	pass = test_prim(GL_QUAD_STRIP, 3, verts4) && pass;
+	pass = test_prim(GL_POLYGON, 2, verts4) && pass;
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* nop */
+}
-- 
1.7.3.4



More information about the Piglit mailing list