[Piglit] [PATCH 11/18] Add test for all user defined clip planes
Fabian Bieler
fabianbieler at fastmail.fm
Sun Jan 7 22:14:06 UTC 2018
Previously the only fixed function user defined clip plane test used
only one clip plane and no coordinate transformation.
This new test uses all clip planes and a non-identity coordinate
transformation matrix.
The test works as follows:
Arrange all clip planes perpendicular to the x-y-plane with equal angles
between them and a distance of 0.5 to the origin.
The user defined clip space should thus be a n-prism of infinite height
centered around the z-axis where n is GL_MAX_CLIP_PLANES.
Draw a quad filling the screen.
The resulting render should be an n-sided regular polygon.
Test color on either side of each edge of the polygon.
---
tests/all.py | 1 +
tests/spec/gl-1.0/CMakeLists.gl.txt | 1 +
tests/spec/gl-1.0/user-clip-all-planes.c | 119 +++++++++++++++++++++++++++++++
3 files changed, 121 insertions(+)
create mode 100644 tests/spec/gl-1.0/user-clip-all-planes.c
diff --git a/tests/all.py b/tests/all.py
index ac1947ca4..32ab2b610 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -754,6 +754,7 @@ with profile.test_list.group_manager(
g(['gl-1.0-scissor-stencil-clear'])
g(['gl-1.0-texgen'])
g(['gl-1.0-textured-triangle'])
+ g(['gl-1.0-user-clip-all-planes'])
with profile.test_list.group_manager(
PiglitGLTest,
diff --git a/tests/spec/gl-1.0/CMakeLists.gl.txt b/tests/spec/gl-1.0/CMakeLists.gl.txt
index fcb1d1d68..355df7472 100644
--- a/tests/spec/gl-1.0/CMakeLists.gl.txt
+++ b/tests/spec/gl-1.0/CMakeLists.gl.txt
@@ -8,6 +8,7 @@ link_libraries (
${OPENGL_gl_LIBRARY}
)
+piglit_add_executable (gl-1.0-user-clip-all-planes user-clip-all-planes.c)
piglit_add_executable (gl-1.0-beginend-coverage beginend-coverage.c)
piglit_add_executable (gl-1.0-blend-func blend.c)
piglit_add_executable (gl-1.0-dlist-beginend dlist-beginend.c)
diff --git a/tests/spec/gl-1.0/user-clip-all-planes.c b/tests/spec/gl-1.0/user-clip-all-planes.c
new file mode 100644
index 000000000..ea2932716
--- /dev/null
+++ b/tests/spec/gl-1.0/user-clip-all-planes.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright © 2017 Fabian Bieler
+ *
+ * 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 user-clip-all-planes.c
+ *
+ * Arrange all clip planes perpendicular to the x-y-plane with equal angles
+ * between them and a distance of 0.5 to the origin.
+ * The user defined clip space should thus form a n-prism of infinite height
+ * centered around the z-axis where n is GL_MAX_CLIP_PLANES.
+ *
+ * Draw a green quad filling the screen.
+ *
+ * The resulting render should be an n-sided regular polygon.
+ *
+ * Disable clipping, enable blending and draw the expected polygon in blue.
+ *
+ * Check that the entire screen is either black (clear color) or teal.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB;
+ config.window_width = 500;
+ config.window_height = 250;
+ config.khr_no_error_support = PIGLIT_NO_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+ int max_clip_planes;
+ const float black[4] = {0, 0, 0, 1};
+ const float green[4] = {0, 1, 0, 1};
+ const float blue[4] = {0, 0, 1, 1};
+ const float teal[4] = {0, 1, 1, 1};
+ bool pass = true;
+
+ /* Use some coordinate transformation to check that clip planes are
+ * transformed correctly.
+ */
+ glLoadIdentity();
+ glScalef(0.5, 1, 1);
+
+ glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes);
+
+ for (int i = 0; i < max_clip_planes; ++i) {
+ const double phi = 2 * M_PI / max_clip_planes * i;
+ const double clip_plane[] = { -cos(phi), -sin(phi), 0, 0.5 };
+ glClipPlane(GL_CLIP_PLANE0 + i, clip_plane);
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* First pass: Clipped quad */
+ for (int i = 0; i < max_clip_planes; ++i)
+ glEnable(GL_CLIP_PLANE0 + i);
+
+ glColor4fv(green);
+ piglit_draw_rect(-2, -1, 4, 2);
+
+ for (int i = 0; i < max_clip_planes; ++i)
+ glDisable(GL_CLIP_PLANE0 + i);
+
+ /* Second pass: Polygon */
+ glEnable(GL_BLEND);
+
+ glColor4fv(blue);
+ glBegin(GL_POLYGON);
+ const double alpha = M_PI / max_clip_planes; /* half exterior angle */
+ const double r = 0.5 / cos(alpha); /* circumradius */
+ for (int i = 0; i < max_clip_planes; ++i) {
+ const double phi = 2 * M_PI / max_clip_planes * i + alpha;
+ const double x = cos(phi) * r;
+ const double y = sin(phi) * r;
+ glVertex2d(x, y);
+ }
+ glEnd();
+
+ glDisable(GL_BLEND);
+
+ /* Check render */
+ pass = piglit_probe_rect_two_rgb(0, 0, piglit_width, piglit_height,
+ black, teal);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ glBlendFunc(GL_ONE, GL_ONE);
+}
--
2.15.1
More information about the Piglit
mailing list