[Piglit] [PATCH] glsl-1.10/fragdepth: add new, simple test of gl_FragDepth
Brian Paul
brianp at vmware.com
Tue Aug 5 15:07:18 PDT 2014
---
tests/all.py | 1 +
tests/spec/glsl-1.10/execution/CMakeLists.gl.txt | 1 +
tests/spec/glsl-1.10/execution/fragdepth.c | 115 ++++++++++++++++++++++
3 files changed, 117 insertions(+)
create mode 100644 tests/spec/glsl-1.10/execution/fragdepth.c
diff --git a/tests/all.py b/tests/all.py
index 9d7a861..36436b8 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1002,6 +1002,7 @@ add_shader_test_dir(spec['glsl-1.10']['execution'],
os.path.join(testsDir, 'spec', 'glsl-1.10', 'execution'),
recursive=True)
add_concurrent_test(spec['glsl-1.10']['execution'], 'glsl-render-after-bad-attach')
+add_concurrent_test(spec['glsl-1.10']['execution'], 'glsl-1.10-fragdepth')
spec['glsl-1.10']['execution']['clipping'] = {}
for mode in ['fixed', 'pos_clipvert', 'clipvert_pos']:
cmdline = 'clip-plane-transformation ' + mode
diff --git a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
index 311fe01..0ddc221 100644
--- a/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
+++ b/tests/spec/glsl-1.10/execution/CMakeLists.gl.txt
@@ -12,3 +12,4 @@ link_libraries (
)
piglit_add_executable (glsl-render-after-bad-attach glsl-render-after-bad-attach.c)
+piglit_add_executable (glsl-1.10-fragdepth fragdepth.c)
diff --git a/tests/spec/glsl-1.10/execution/fragdepth.c b/tests/spec/glsl-1.10/execution/fragdepth.c
new file mode 100644
index 0000000..61521ca
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/fragdepth.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2014 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 GLSL gl_FragDepth output.
+ * We draw overlapping red and green quads. The red quad is at Z=0
+ * while the green quad's fragment depths vary from left to right.
+ * Should see intersecting quads.
+ *
+ * Brian Paul
+ * 5 August 2014
+ */
+
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const char *vs_text =
+ "varying float z; \n"
+ "void main() {\n"
+ " gl_FrontColor = gl_Color; \n"
+ " gl_Position = gl_Vertex;\n"
+ " // convert Z from [-1, 1] to [0, 1] \n"
+ " z = gl_Vertex.x * 0.5 + 0.5; \n"
+ "}\n";
+static const char *fs_text =
+ "varying float z; \n"
+ "void main() { \n"
+ " gl_FragDepth = z; \n"
+ " gl_FragColor = gl_Color; \n"
+ "}\n";
+
+static GLuint program;
+
+
+enum piglit_result
+piglit_display(void)
+{
+ static const float red[3] = {1.0, 0.0, 0.0};
+ static const float green[3] = {0.0, 1.0, 0.0};
+ int x = piglit_width / 2;
+ int y = piglit_height / 2;
+
+ glViewport(0, 0, piglit_width, piglit_height);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ /* Draw a red quad at z = 0 */
+ glUseProgram(0);
+ glColor3f(1, 0, 0);
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2f(-0.5, -0.5);
+ glVertex2f( 0.5, -0.5);
+ glVertex2f( 0.5, 0.5);
+ glVertex2f(-0.5, 0.5);
+ glEnd();
+
+ /* Draw green quad w/ fragment shader which writes gl_FragDepth*/
+ glUseProgram(program);
+ glColor3f(0, 1, 0);
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex2f(-0.75, -0.25);
+ glVertex2f( 0.75, -0.25);
+ glVertex2f( 0.75, 0.25);
+ glVertex2f(-0.75, 0.25);
+ glEnd();
+
+ if (!piglit_probe_pixel_rgb(x-10, y, green)) {
+ return PIGLIT_FAIL;
+ }
+
+ if (!piglit_probe_pixel_rgb(x+10, y, red)) {
+ return PIGLIT_FAIL;
+ }
+
+ piglit_present_results();
+
+ return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_GLSL();
+
+ program = piglit_build_simple_program(vs_text, fs_text);
+
+ glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
+ glEnable(GL_DEPTH_TEST);
+}
--
1.7.10.4
More information about the Piglit
mailing list