[Piglit] [PATCH] ext_depth_bounds_test: new test for the extension

Marek Olšák maraeo at gmail.com
Thu Aug 13 13:11:31 PDT 2015


From: Marek Olšák <marek.olsak at amd.com>

---
 tests/spec/CMakeLists.txt                          |   1 +
 tests/spec/ext_depth_bounds_test/CMakeLists.gl.txt |  14 ++
 tests/spec/ext_depth_bounds_test/CMakeLists.txt    |   1 +
 tests/spec/ext_depth_bounds_test/depth_bounds.c    | 160 +++++++++++++++++++++
 4 files changed, 176 insertions(+)
 create mode 100644 tests/spec/ext_depth_bounds_test/CMakeLists.gl.txt
 create mode 100644 tests/spec/ext_depth_bounds_test/CMakeLists.txt
 create mode 100644 tests/spec/ext_depth_bounds_test/depth_bounds.c

diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 0ed7aa3..eeb883d 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -69,6 +69,7 @@ add_subdirectory (arb_transform_feedback2)
 add_subdirectory (arb_transform_feedback3)
 add_subdirectory (arb_viewport_array)
 add_subdirectory (ati_envmap_bumpmap)
+add_subdirectory (ext_depth_bounds_test)
 add_subdirectory (ext_fog_coord)
 add_subdirectory (ext_framebuffer_multisample)
 add_subdirectory (ext_framebuffer_multisample_blit_scaled)
diff --git a/tests/spec/ext_depth_bounds_test/CMakeLists.gl.txt b/tests/spec/ext_depth_bounds_test/CMakeLists.gl.txt
new file mode 100644
index 0000000..7879390
--- /dev/null
+++ b/tests/spec/ext_depth_bounds_test/CMakeLists.gl.txt
@@ -0,0 +1,14 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (depth_bounds depth_bounds.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/ext_depth_bounds_test/CMakeLists.txt b/tests/spec/ext_depth_bounds_test/CMakeLists.txt
new file mode 100644
index 0000000..4a012b9
--- /dev/null
+++ b/tests/spec/ext_depth_bounds_test/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
\ No newline at end of file
diff --git a/tests/spec/ext_depth_bounds_test/depth_bounds.c b/tests/spec/ext_depth_bounds_test/depth_bounds.c
new file mode 100644
index 0000000..d45cd49
--- /dev/null
+++ b/tests/spec/ext_depth_bounds_test/depth_bounds.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright © 2015 Advanced Micro Devices, 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.
+ *
+ * Authors:
+ *    Marek Olšák <maraeo at gmail.com>
+ */
+
+#include "piglit-util-gl.h"
+#include <time.h>
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.window_width = 200;
+	config.window_height = 200;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE |
+			       PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool inplace;
+static const float size = 20;
+static float white_color[3] = {1, 1, 1};
+static float clear_color[3] = {0.1, 0.1, 0.1};
+
+void
+piglit_init(int argc, char **argv)
+{
+	inplace = argc == 2 && strcmp(argv[1], "-inplace") == 0;
+
+	piglit_require_extension("GL_EXT_depth_bounds_test");
+	piglit_gen_ortho_projection(0, piglit_width, 0, piglit_height, 0, -1, 0);
+	srand(time(NULL));
+	glDepthFunc(GL_ALWAYS);
+}
+
+enum {
+	PASS,
+	FAIL,
+};
+
+static struct {
+	unsigned expected;
+	float z0, z1, z2, z3;
+	float min, max;
+} test[] = {
+	{PASS, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0},
+	{PASS, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0},
+	{PASS, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0},
+
+	{PASS, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0},
+	{PASS, 0.7, 0.7, 0.7, 0.7, 0.5, 1.0},
+	{PASS, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0},
+	{FAIL, 0.3, 0.3, 0.3, 0.3, 0.5, 1.0},
+	{FAIL, 0.0, 0.0, 0.0, 0.0, 0.5, 1.0},
+
+	{FAIL, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5},
+	{FAIL, 0.7, 0.7, 0.7, 0.7, 0.0, 0.5},
+	{PASS, 0.5, 0.5, 0.5, 0.5, 0.0, 0.5},
+	{PASS, 0.3, 0.3, 0.3, 0.3, 0.0, 0.5},
+	{PASS, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5},
+
+	{FAIL, 0.29, 0.29, 0.29, 0.29, 0.3, 0.5},
+	{PASS, 0.31, 0.31, 0.31, 0.31, 0.3, 0.5},
+	{PASS, 0.49, 0.49, 0.49, 0.49, 0.3, 0.5},
+	{FAIL, 0.51, 0.51, 0.51, 0.51, 0.3, 0.5},
+
+	{PASS, 0.65, 0.65, 0.65, 0.65, 0.6, 0.7},
+	{FAIL, 0.90, 0.90, 0.90, 0.90, 0.6, 0.7},
+	{FAIL, 0.55, 0.55, 0.55, 0.55, 0.6, 0.7},
+};
+
+static void
+check_rect(int i, bool *pass)
+{
+	float x = size * (i % 10);
+	float y = size * (i / 10);
+
+	printf("Test %i, bounds=(%.2f, %.2f), z=(%.2f, %.2f, %.2f, %.2f)\n",
+	       i, test[i].min, test[i].max, test[i].z0, test[i].z1,
+	       test[i].z2, test[i].z3);
+
+	switch (test[i].expected) {
+	case PASS:
+		*pass = piglit_probe_rect_rgb(x, y, size, size, white_color) && *pass;
+		break;
+	case FAIL:
+		*pass = piglit_probe_rect_rgb(x, y, size, size, clear_color) && *pass;
+		break;
+	}
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = GL_TRUE;
+	int i;
+
+	glClearColor(clear_color[0], clear_color[1], clear_color[2], 1);
+	glClearDepth(1);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glColor3fv(white_color);
+	for (i = 0; i < ARRAY_SIZE(test); i++) {
+		float x = size * (i % 10);
+		float y = size * (i / 10);
+
+		glColorMask(0, 0, 0, 0);
+		glEnable(GL_DEPTH_TEST);
+		glBegin(GL_QUADS);
+		glVertex3f(x,      y,      test[i].z0);
+		glVertex3f(x+size, y,      test[i].z1);
+		glVertex3f(x+size, y+size, test[i].z2);
+		glVertex3f(x,      y+size, test[i].z3);
+		glEnd();
+		glDisable(GL_DEPTH_TEST);
+
+		glColorMask(1, 1, 1, 1);
+		glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
+		glDepthBoundsEXT(test[i].min, test[i].max);
+		glBegin(GL_QUADS);
+		/* use a random depth, it doesn't matter */
+		glVertex3f(x,      y,      (rand() % 11) * 0.1);
+		glVertex3f(x+size, y,      (rand() % 11) * 0.1);
+		glVertex3f(x+size, y+size, (rand() % 11) * 0.1);
+		glVertex3f(x,      y+size, (rand() % 11) * 0.1);
+		glEnd();
+		glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
+
+		if (inplace)
+			check_rect(i, &pass);
+	}
+
+	if (!inplace)
+		for (i = 0; i < ARRAY_SIZE(test); i++)
+			check_rect(i, &pass);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
2.1.4



More information about the Piglit mailing list