[Piglit] [PATCH] glsl-1.30/execution/vertexid-*: New tests for using gl_VertexID.
Eric Anholt
eric at anholt.net
Wed Nov 9 17:17:31 PST 2011
A few different draw calls are tested to hopefully make sure the
hardware is wired up like we expect. Also, provide different vertex
data and do a silly compare in each to be sure that we aren't
accidentally using the wrong data for gl_VertexID due to miscellaneous
bugs I could imagine.
v2: Split into a separate test per draw call type.
---
tests/all.tests | 3 +
tests/spec/glsl-1.30/execution/CMakeLists.gl.txt | 3 +
tests/spec/glsl-1.30/execution/vertexid-beginend.c | 101 ++++++++++++++++++
.../spec/glsl-1.30/execution/vertexid-drawarrays.c | 107 +++++++++++++++++++
.../glsl-1.30/execution/vertexid-drawelements.c | 111 ++++++++++++++++++++
5 files changed, 325 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/glsl-1.30/execution/vertexid-beginend.c
create mode 100644 tests/spec/glsl-1.30/execution/vertexid-drawarrays.c
create mode 100644 tests/spec/glsl-1.30/execution/vertexid-drawelements.c
diff --git a/tests/all.tests b/tests/all.tests
index 6345040..c7fec42 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -886,6 +886,9 @@ for arg in ['vs_basic', 'vs_xfb', 'vs_fbo', 'fs_basic', 'fs_fbo']:
spec['glsl-1.30']['execution']['clipping']['clip-plane-transformation pos'] = \
concurrent_test('clip-plane-transformation pos')
spec['glsl-1.30']['texel-offset-limits'] = concurrent_test('glsl-1.30-texel-offset-limits')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-beginend')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-drawarrays')
+add_concurrent_test(spec['glsl-1.30']['execution'], 'vertexid-drawelements')
# Group AMD_conservative_depth
spec['AMD_conservative_depth'] = Group()
diff --git a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
index e817ecf..c9a816d 100644
--- a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
+++ b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
@@ -19,3 +19,6 @@ add_executable (fs-texelFetchOffset-2D fs-texelFetchOffset-2D.c)
IF (NOT MSVC)
add_executable (isinf-and-isnan isinf-and-isnan.c)
ENDIF (NOT MSVC)
+add_executable (vertexid-beginend vertexid-beginend.c)
+add_executable (vertexid-drawarrays vertexid-drawarrays.c)
+add_executable (vertexid-drawelements vertexid-drawelements.c)
diff --git a/tests/spec/glsl-1.30/execution/vertexid-beginend.c b/tests/spec/glsl-1.30/execution/vertexid-beginend.c
new file mode 100644
index 0000000..983376a
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/vertexid-beginend.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * 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 vertexid-beginend.c
+ *
+ * Test that gl_VertexID has the correct values.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 70;
+int piglit_height = 30;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static const char vs_text[] =
+ "#version 130\n"
+ "\n"
+ "/* This is floating point so we can use immediate mode */\n"
+ "out vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = ftransform();\n"
+ " color = vec4(equal(vec4(gl_VertexID), gl_Color));\n"
+ "}\n";
+
+static const char fs_text[] =
+ "#version 130\n"
+ "\n"
+ "in vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vs, fs, prog;
+
+ piglit_require_GLSL_version(130);
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
+ prog = piglit_link_simple_program(vs, fs);
+
+ if (!vs || !fs || !prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ glUseProgram(prog);
+}
+
+enum piglit_result
+piglit_display()
+{
+ bool pass;
+ float green[] = {0, 1, 0, 0};
+
+ glBegin(GL_TRIANGLE_FAN);
+ glColor4f(0.5, 0.0, 0.5, 0.5);
+ glVertex2f(-1, -1);
+
+ glColor4f(0.5, 1.0, 0.5, 0.5);
+ glVertex2f(1, -1);
+
+ glColor4f(0.5, 2.0, 0.5, 0.5);
+ glVertex2f(1, 1);
+
+ glColor4f(0.5, 3.0, 0.5, 0.5);
+ glVertex2f(-1, 1);
+ glEnd();
+
+ pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+ green);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/glsl-1.30/execution/vertexid-drawarrays.c b/tests/spec/glsl-1.30/execution/vertexid-drawarrays.c
new file mode 100644
index 0000000..bd2ee68
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/vertexid-drawarrays.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * 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 vertexid-drawarrays.c
+ *
+ * Test that gl_VertexID has the correct values.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 70;
+int piglit_height = 30;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static const char vs_text[] =
+ "#version 130\n"
+ "\n"
+ "/* This is floating point so we can use immediate mode */\n"
+ "out vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ " color = vec4(equal(vec4(gl_VertexID), gl_Color));\n"
+ "}\n";
+
+static const char fs_text[] =
+ "#version 130\n"
+ "\n"
+ "in vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vs, fs, prog;
+
+ piglit_require_GLSL_version(130);
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
+ prog = piglit_link_simple_program(vs, fs);
+
+ if (!vs || !fs || !prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ glUseProgram(prog);
+}
+
+enum piglit_result
+piglit_display()
+{
+ bool pass;
+ float vertex_array[] = {
+ -1, -1,
+ 1, -1,
+ 1, 1,
+ -1, 1,
+ };
+ float color_array[] = {
+ 0.5, 0.0, 0.5, 0.5,
+ 0.5, 1.0, 0.5, 0.5,
+ 0.5, 2.0, 0.5, 0.5,
+ 0.5, 3.0, 0.5, 0.5,
+ };
+ float green[] = {0, 1, 0, 0};
+
+ glVertexPointer(2, GL_FLOAT, 0, vertex_array);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glColorPointer(4, GL_FLOAT, 0, color_array);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+ green);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
diff --git a/tests/spec/glsl-1.30/execution/vertexid-drawelements.c b/tests/spec/glsl-1.30/execution/vertexid-drawelements.c
new file mode 100644
index 0000000..257de9b
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/vertexid-drawelements.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * 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 vertexid-drawelements.c
+ *
+ * Test that gl_VertexID has the correct values.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 70;
+int piglit_height = 30;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+static const char vs_text[] =
+ "#version 130\n"
+ "\n"
+ "/* This is floating point so we can use immediate mode */\n"
+ "out vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ " color = vec4(equal(vec4(gl_VertexID), gl_Color));\n"
+ "}\n";
+
+static const char fs_text[] =
+ "#version 130\n"
+ "\n"
+ "in vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vs, fs, prog;
+
+ piglit_require_GLSL_version(130);
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
+ prog = piglit_link_simple_program(vs, fs);
+
+ if (!vs || !fs || !prog)
+ piglit_report_result(PIGLIT_FAIL);
+
+ glUseProgram(prog);
+}
+
+enum piglit_result
+piglit_display()
+{
+ bool pass;
+ float vertex_array[] = {
+ -1, -1,
+ 1, -1,
+ 1, 1,
+ -1, 1,
+ };
+ float color_array[] = {
+ 0.5, 0.0, 0.5, 0.5,
+ 0.5, 1.0, 0.5, 0.5,
+ 0.5, 2.0, 0.5, 0.5,
+ 0.5, 3.0, 0.5, 0.5,
+ };
+ int indices[] = {
+ 0, 1, 2,
+ 0, 2, 3,
+ };
+ float green[] = {0, 1, 0, 0};
+
+ glVertexPointer(2, GL_FLOAT, 0, vertex_array);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glColorPointer(4, GL_FLOAT, 0, color_array);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
+ green);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.7.7
More information about the Piglit
mailing list