Hi,

The attached patch adds a test for ARB_clip_control.
Please review!

Greetings

Mathias
>From 05c1b406510a5c71f16674c83ed894a17c5e5796 Mon Sep 17 00:00:00 2001
Message-Id: <05c1b406510a5c71f16674c83ed894a17c5e5796.1413996915.git.mathias.froehl...@gmx.net>
From: =?UTF-8?q?Mathias=20Fr=C3=B6hlich?= <[email protected]>
Date: Mon, 15 Sep 2014 21:42:07 +0200
Subject: [PATCH] Add test for ARB_clip_control.

---
 registry/gl.xml                                    |  23 ++-
 tests/spec/CMakeLists.txt                          |   1 +
 tests/spec/arb_clip_control/CMakeLists.gl.txt      |  15 ++
 tests/spec/arb_clip_control/CMakeLists.txt         |   1 +
 .../clip-control-depth-precision.c                 | 164 ++++++++++++++++
 tests/spec/arb_clip_control/clip-control.c         | 218 +++++++++++++++++++++
 6 files changed, 421 insertions(+), 1 deletion(-)
 create mode 100644 tests/spec/arb_clip_control/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_clip_control/CMakeLists.txt
 create mode 100644 tests/spec/arb_clip_control/clip-control-depth-precision.c
 create mode 100644 tests/spec/arb_clip_control/clip-control.c

diff --git a/registry/gl.xml b/registry/gl.xml
index 30e8d9f..d432d3d 100644
--- a/registry/gl.xml
+++ b/registry/gl.xml
@@ -7916,7 +7916,12 @@ typedef unsigned int GLhandleARB;
         <enum value="0x934A" name="GL_LOCATION_COMPONENT"/>
         <enum value="0x934B" name="GL_TRANSFORM_FEEDBACK_BUFFER_INDEX"/>
         <enum value="0x934C" name="GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE"/>
-            <unused start="0x934D" end="0x9364"/>
+            <unused start="0x934D" end="0x935B"/>
+        <enum value="0x935C" name="GL_CLIP_ORIGIN"/>
+        <enum value="0x935D" name="GL_CLIP_DEPTH_MODE"/>
+        <enum value="0x935E" name="GL_NEGATIVE_ONE_TO_ONE"/>
+        <enum value="0x935F" name="GL_ZERO_TO_ONE"/>
+            <unused start="0x9360" end="0x9364"/>
         <enum value="0x9365" name="GL_CLEAR_TEXTURE"/>
             <unused start="0x9366" end="0x937F"/>
     </enums>
@@ -9085,6 +9090,11 @@ typedef unsigned int GLhandleARB;
             <glx type="render" opcode="2"/>
         </command>
         <command>
+            <proto>void <name>glClipControl</name></proto>
+            <param><ptype>GLenum</ptype> <name>origin</name></param>
+            <param><ptype>GLenum</ptype> <name>depth</name></param>
+        </command>
+        <command>
             <proto><ptype>GLenum</ptype> <name>glCheckFramebufferStatus</name></proto>
             <param group="FramebufferTarget"><ptype>GLenum</ptype> <name>target</name></param>
             <glx type="vendor" opcode="1427"/>
@@ -33515,6 +33525,17 @@ typedef unsigned int GLhandleARB;
                 <command name="glClearTexSubImage"/>
             </require>
         </extension>
+        <extension name="GL_ARB_clip_control" supported="gl">
+            <require>
+                <enum name="GL_LOWER_LEFT"/>
+                <enum name="GL_UPPER_LEFT"/>
+                <enum name="GL_NEGATIVE_ONE_TO_ONE"/>
+                <enum name="GL_ZERO_TO_ONE"/>
+                <enum name="GL_CLIP_ORIGIN"/>
+                <enum name="GL_CLIP_DEPTH_MODE"/>
+                <command name="glClipControl"/>
+            </require>
+        </extension>
         <extension name="GL_ARB_color_buffer_float" supported="gl">
             <require>
                 <enum name="GL_RGBA_FLOAT_MODE_ARB"/>
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 62e6487..1be8089 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -3,6 +3,7 @@ add_subdirectory (arb_base_instance)
 add_subdirectory (arb_buffer_storage)
 add_subdirectory (arb_clear_buffer_object)
 add_subdirectory (arb_clear_texture)
+add_subdirectory (arb_clip_control)
 add_subdirectory (arb_color_buffer_float)
 add_subdirectory (arb_copy_image)
 add_subdirectory (arb_compute_shader)
diff --git a/tests/spec/arb_clip_control/CMakeLists.gl.txt b/tests/spec/arb_clip_control/CMakeLists.gl.txt
new file mode 100644
index 0000000..3951bfb
--- /dev/null
+++ b/tests/spec/arb_clip_control/CMakeLists.gl.txt
@@ -0,0 +1,15 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (clip-control clip-control.c)
+piglit_add_executable (clip-control-depth-precision clip-control-depth-precision.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_clip_control/CMakeLists.txt b/tests/spec/arb_clip_control/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_clip_control/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_clip_control/clip-control-depth-precision.c b/tests/spec/arb_clip_control/clip-control-depth-precision.c
new file mode 100644
index 0000000..7e969f9
--- /dev/null
+++ b/tests/spec/arb_clip_control/clip-control-depth-precision.c
@@ -0,0 +1,164 @@
+/*
+ * Copyright Mathias Fröhlich <[email protected]>
+ *
+ * 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:
+ *    Mathias Fröhlich <[email protected]>
+ */
+
+/** @file clip-control-depth-precision.c
+ *
+ * Test for NV_depth_buffer_float not clamping the near and far values.
+ * This is actually the application level use case setting up a
+ * projection matrix with and infinite far away far plane and a near plane
+ * at 1.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLdouble projection[16] = { 0.0, };
+
+	piglit_require_extension("GL_ARB_clip_control");
+	piglit_require_extension("GL_EXT_framebuffer_object");
+	piglit_require_extension("GL_EXT_framebuffer_blit");
+
+	/* Set up a projection matrix mapping z = -1 to z = 1
+	 * and z = -inf to z = 0 in projection space.
+	 * Given the clip control setting below, this is just
+	 * written as is into the float depth buffer.
+	 */
+	projection[0 + 4*0] = 1;
+	projection[1 + 4*1] = (GLdouble)piglit_width/piglit_height;
+	projection[2 + 4*3] = 1;
+	projection[3 + 4*2] = -1;
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadMatrixd(projection);
+
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+}
+
+void
+quad(double px, double py, double pz, double size)
+{
+	glBegin(GL_QUADS);
+	glVertex3d(px - 0.5*size, py - 0.5*size, pz);
+	glVertex3d(px + 0.5*size, py - 0.5*size, pz);
+	glVertex3d(px + 0.5*size, py + 0.5*size, pz);
+	glVertex3d(px - 0.5*size, py + 0.5*size, pz);
+	glEnd();
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLfloat red[3] = { 1, 0, 0 };
+	GLfloat green[3] = { 0, 1, 0 };
+	GLboolean pass = GL_TRUE;
+	GLuint fb, cb, db;
+	GLenum status;
+	int range10;
+
+	glGenRenderbuffers(1, &cb);
+	glBindRenderbuffer(GL_RENDERBUFFER, cb);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, piglit_width, piglit_height);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenRenderbuffers(1, &db);
+	glBindRenderbuffer(GL_RENDERBUFFER, db);
+	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, piglit_width, piglit_height);
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+	glGenFramebuffers(1, &fb);
+	glBindFramebuffer(GL_FRAMEBUFFER, fb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cb);
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, db);
+
+	status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+	if (status != GL_FRAMEBUFFER_COMPLETE) {
+		printf("FBO incomplete status 0x%X\n", status);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
+	glClearDepth(0);
+	glDepthRange(0, 1);
+	glClearColor(0, 0, 0, 1);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glEnable(GL_DEPTH_TEST);
+	glDepthFunc(GL_GREATER);
+
+	for (range10 = 0; range10 < 16; ++range10) {
+		int width = piglit_width/4;
+		int height = piglit_height/4;
+		int tilex = range10 % 4;
+		int tiley = range10 / 4;
+		int x = tilex*width;
+		int y = tiley*height;
+		double z = pow(10, 1 + range10);
+
+		/* Set up a new viewport for each deoth we want to test */
+		glViewport(x, y, width, height);
+
+		/* Draw a red surface at given distance z */
+		glColor3fv(red);
+		quad(0, 0, -z, z);
+
+		pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, red) && pass;
+
+		/* And a green one just close in front of that red one */
+		glColor3fv(green);
+		quad(0, 0, (10*FLT_EPSILON - 1)*z, 0.5*z);
+		quad(0, 0, -z, 0.5*z);
+
+		pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, green) && pass;
+	}
+
+	/* copy the result to the back buffer */
+
+	/* set viewport to window size */
+	glViewport(0, 0, piglit_width, piglit_height);
+
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width, piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+	glDeleteFramebuffers(1, &fb);
+	glDeleteRenderbuffers(1, &cb);
+	glDeleteRenderbuffers(1, &db);
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/arb_clip_control/clip-control.c b/tests/spec/arb_clip_control/clip-control.c
new file mode 100644
index 0000000..f360c59
--- /dev/null
+++ b/tests/spec/arb_clip_control/clip-control.c
@@ -0,0 +1,218 @@
+/*
+ * Copyright Mathias Fröhlich <[email protected]>
+ *
+ * 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:
+ *    Mathias Fröhlich <[email protected]>
+ */
+
+/** @file clip-control.c
+ *
+ * Basic test for ARB_clip_contol.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_clip_control");
+
+	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
+
+void
+quad(float base_x, float base_y, float z)
+{
+	glBegin(GL_QUADS);
+	glVertex3f(base_x,	base_y,	     z);
+	glVertex3f(base_x + 10, base_y,	     z);
+	glVertex3f(base_x + 10, base_y + 10, z);
+	glVertex3f(base_x,	base_y + 10, z);
+	glEnd();
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass = GL_TRUE;
+	GLint value;
+
+	/* The initial values */
+	glGetIntegerv(GL_CLIP_ORIGIN, &value);
+	pass = pass && (value == GL_LOWER_LEFT);
+	glGetIntegerv(GL_CLIP_DEPTH_MODE, &value);
+	pass = pass && (value == GL_NEGATIVE_ONE_TO_ONE);
+
+	glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
+	glGetIntegerv(GL_CLIP_ORIGIN, &value);
+	pass = pass && (value == GL_LOWER_LEFT);
+	glGetIntegerv(GL_CLIP_DEPTH_MODE, &value);
+	pass = pass && (value == GL_ZERO_TO_ONE);
+
+	glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE);
+	glGetIntegerv(GL_CLIP_ORIGIN, &value);
+	pass = pass && (value == GL_UPPER_LEFT);
+	glGetIntegerv(GL_CLIP_DEPTH_MODE, &value);
+	pass = pass && (value == GL_ZERO_TO_ONE);
+
+	glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+	glGetIntegerv(GL_CLIP_ORIGIN, &value);
+	pass = pass && (value == GL_UPPER_LEFT);
+	glGetIntegerv(GL_CLIP_DEPTH_MODE, &value);
+	pass = pass && (value == GL_NEGATIVE_ONE_TO_ONE);
+
+	piglit_reset_gl_error();
+	glClipControl(GL_RGB, GL_NEGATIVE_ONE_TO_ONE);
+	pass && piglit_check_gl_error(GL_INVALID_ENUM);
+
+	piglit_reset_gl_error();
+	glClipControl(GL_LOWER_LEFT, GL_RGB);
+	pass && piglit_check_gl_error(GL_INVALID_ENUM);
+
+	/* Now prepare the draw buffer */
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glEnable(GL_DEPTH_TEST);
+
+	/* Also test the winding order logic */
+	glEnable(GL_CULL_FACE);
+	glCullFace(GL_BACK);
+
+	/* Back to default */
+	glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+
+	/* inside the clip space */
+	quad(10, 10, 1.0);
+	quad(10, 30, 0.5);
+	quad(10, 50, 0.0);
+	quad(10, 70, -0.5);
+
+	/* outside the clip space */
+	quad(10, 90, 1.5);
+	quad(10, 110, -1.5);
+
+	glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
+
+	/* inside the clip space */
+	quad(30, 10, 0.0);
+	quad(30, 30, -0.25);
+	quad(30, 50, -0.5);
+	quad(30, 70, -0.75);
+
+	/* outside the clip space */
+	quad(30, 90, 0.25);
+	quad(30, 110, -1.25);
+
+	glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+
+	/* inside the clip space */
+	quad(50, piglit_height - 20, 1.0);
+	quad(50, piglit_height - 40, 0.5);
+	quad(50, piglit_height - 60, 0.0);
+	quad(50, piglit_height - 80, -0.5);
+
+	/* outside the clip space */
+	quad(50, piglit_height - 100, 1.5);
+	quad(50, piglit_height - 120, -1.5);
+
+	glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE);
+
+	/* inside the clip space */
+	quad(70, piglit_height - 20, 0.0);
+	quad(70, piglit_height - 40, -0.25);
+	quad(70, piglit_height - 60, -0.5);
+	quad(70, piglit_height - 80, -0.75);
+
+	/* outside the clip space */
+	quad(70, piglit_height - 100, 0.25);
+	quad(70, piglit_height - 120, -1.25);
+
+	/* Back to default */
+	glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
+
+	/* The clear value */
+	pass = piglit_probe_pixel_depth(5, 5, 1.0) && pass;
+
+	/* The few patches drawn above */
+
+	/* glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); */
+
+	/* the written depth value */
+	pass = piglit_probe_pixel_depth(15, 15, 0.0) && pass;
+	pass = piglit_probe_pixel_depth(15, 35, 0.25) && pass;
+	pass = piglit_probe_pixel_depth(15, 55, 0.5) && pass;
+	pass = piglit_probe_pixel_depth(15, 75, 0.75) && pass;
+
+	/* still the clear value */
+	pass = piglit_probe_pixel_depth(15, 95, 1.0) && pass;
+	pass = piglit_probe_pixel_depth(15, 115, 1.0) && pass;
+
+
+	/* glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); */
+
+	/* the written depth value */
+	pass = piglit_probe_pixel_depth(35, 15, 0.0) && pass;
+	pass = piglit_probe_pixel_depth(35, 35, 0.25) && pass;
+	pass = piglit_probe_pixel_depth(35, 55, 0.5) && pass;
+	pass = piglit_probe_pixel_depth(35, 75, 0.75) && pass;
+
+	/* still the clear value */
+	pass = piglit_probe_pixel_depth(35, 95, 1.0) && pass;
+	pass = piglit_probe_pixel_depth(35, 115, 1.0) && pass;
+
+
+	/* glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE); */
+
+	/* the written depth value */
+	pass = piglit_probe_pixel_depth(55, 15, 0.0) && pass;
+	pass = piglit_probe_pixel_depth(55, 35, 0.25) && pass;
+	pass = piglit_probe_pixel_depth(55, 55, 0.5) && pass;
+	pass = piglit_probe_pixel_depth(55, 75, 0.75) && pass;
+
+	/* still the clear value */
+	pass = piglit_probe_pixel_depth(55, 95, 1.0) && pass;
+	pass = piglit_probe_pixel_depth(55, 115, 1.0) && pass;
+
+
+	/* glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE); */
+
+	/* the written depth value */
+	pass = piglit_probe_pixel_depth(75, 15, 0.0) && pass;
+	pass = piglit_probe_pixel_depth(75, 35, 0.25) && pass;
+	pass = piglit_probe_pixel_depth(75, 55, 0.5) && pass;
+	pass = piglit_probe_pixel_depth(75, 75, 0.75) && pass;
+
+	/* still the clear value */
+	pass = piglit_probe_pixel_depth(75, 95, 1.0) && pass;
+	pass = piglit_probe_pixel_depth(75, 115, 1.0) && pass;
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.9.3

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to