[Piglit] [PATCH] glsl-1.30/execution/vertexid: New test for using gl_VertexID.
Eric Anholt
eric at anholt.net
Tue Nov 8 19:14:12 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.
---
tests/all.tests | 1 +
tests/spec/glsl-1.30/execution/CMakeLists.gl.txt | 1 +
tests/spec/glsl-1.30/execution/vertexid.c | 159 ++++++++++++++++++++++
3 files changed, 161 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/glsl-1.30/execution/vertexid.c
diff --git a/tests/all.tests b/tests/all.tests
index 6345040..a8ef3b3 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -886,6 +886,7 @@ 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')
# 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..4acd6f8 100644
--- a/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
+++ b/tests/spec/glsl-1.30/execution/CMakeLists.gl.txt
@@ -19,3 +19,4 @@ 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 vertexid.c)
diff --git a/tests/spec/glsl-1.30/execution/vertexid.c b/tests/spec/glsl-1.30/execution/vertexid.c
new file mode 100644
index 0000000..a57bd45
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/vertexid.c
@@ -0,0 +1,159 @@
+/*
+ * 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.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();
+ 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 = true;
+ float vertex_array_drawarrays[] = {
+ 30, 10,
+ 40, 10,
+ 40, 20,
+ 30, 20,
+ };
+ float color_array_drawarrays[] = {
+ 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 vertex_array_drawelements[] = {
+ 50, 10,
+ 60, 10,
+ 60, 20,
+ 50, 20,
+ };
+ float color_array_drawelements[] = {
+ 0.5, 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,
+ };
+ int indices_drawelements[] = {
+ 0, 1, 2,
+ 0, 2, 3,
+ };
+ float red[] = {1, 0, 0, 0};
+ float green[] = {0, 1, 0, 0};
+ float blue[] = {0, 0, 1, 0};
+
+ piglit_ortho_projection(piglit_width, piglit_height, false);
+
+ glClearColor(0.5, 0.5, 0.5, 0.5);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* First quad: red (vertexids in first channel), using immediate mode.
+ */
+ glBegin(GL_TRIANGLE_FAN);
+ glColor4f(0.0, 0.5, 0.5, 0.5);
+ glVertex2f(10, 10);
+
+ glColor4f(1.0, 0.5, 0.5, 0.5);
+ glVertex2f(20, 10);
+
+ glColor4f(2.0, 0.5, 0.5, 0.5);
+ glVertex2f(20, 20);
+
+ glColor4f(3.0, 0.5, 0.5, 0.5);
+ glVertex2f(10, 20);
+ glEnd();
+
+ /* Second quad: green, using glDrawArrays. */
+ glVertexPointer(2, GL_FLOAT, 0, vertex_array_drawarrays);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glColorPointer(4, GL_FLOAT, 0, color_array_drawarrays);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ /* Third quad: blue, using glDrawElements. */
+ glVertexPointer(2, GL_FLOAT, 0, vertex_array_drawelements);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glColorPointer(4, GL_FLOAT, 0, color_array_drawelements);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT,
+ indices_drawelements);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ pass = piglit_probe_rect_rgba(10, 10, 10, 10, red);
+ pass = piglit_probe_rect_rgba(30, 10, 10, 10, green);
+ pass = piglit_probe_rect_rgba(50, 10, 10, 10, blue);
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.7.7
More information about the Piglit
mailing list