[Piglit] [PATCH 6/9] arb_geometry_shader4: Test gl_PointSize.
Fabian Bieler
fabianbieler at fastmail.fm
Mon Jun 10 04:09:03 PDT 2013
Draw different sized points from a geometry shader.
---
tests/all.tests | 1 +
.../execution/CMakeLists.gl.txt | 1 +
.../arb_geometry_shader4/execution/point-size.c | 169 +++++++++++++++++++++
3 files changed, 171 insertions(+)
create mode 100644 tests/spec/arb_geometry_shader4/execution/point-size.c
diff --git a/tests/all.tests b/tests/all.tests
index 9c928a0..dce6afc 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2334,6 +2334,7 @@ arb_geometry_shader4 = Group()
for draw in ['', 'indexed']:
for prim in ['GL_LINES_ADJACENCY', 'GL_LINE_STRIP_ADJACENCY', 'GL_TRIANGLES_ADJACENCY', 'GL_TRIANGLE_STRIP_ADJACENCY']:
add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-ignore-adjacent-vertices {0} {1}'.format(draw, prim))
+add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-point-size')
add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-input-type')
add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-input-type-draw')
add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-output-type')
diff --git a/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt b/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
index f61cae2..408a939 100644
--- a/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
+++ b/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
@@ -11,3 +11,4 @@ link_libraries (
)
piglit_add_executable (arb_geometry_shader4-ignore-adjacent-vertices ignore-adjacent-vertices.c)
+piglit_add_executable (arb_geometry_shader4-point-size point-size.c)
diff --git a/tests/spec/arb_geometry_shader4/execution/point-size.c b/tests/spec/arb_geometry_shader4/execution/point-size.c
new file mode 100644
index 0000000..bef1738
--- /dev/null
+++ b/tests/spec/arb_geometry_shader4/execution/point-size.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright © 2011 The Piglit Project
+ *
+ * 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 point-size.c
+ *
+ * Invoke a geometry shader once to draw up to 8 different sized and colored
+ * points along a diagonal of the framebuffer. The points sizes are incrementing
+ * power-of-twos (starting at 1).
+ */
+
+#include "piglit-util-gl-common.h"
+
+static const char vs_text[] =
+ "void main()\n"
+ "{\n"
+ " gl_Position = vec4(0);\n"
+ "}\n";
+
+static const char gs_text[] =
+ "#extension GL_ARB_geometry_shader4: enable\n"
+ "uniform int point_count;\n"
+ "varying out float id;\n"
+ "void main()\n"
+ "{\n"
+ " for (int i = 0; i < point_count; ++i) {\n"
+ " gl_PointSize = pow(2.0, float(i));\n"
+ " float pos = pow(2.0, float(i+1)) - pow(2.0, float(i-1));\n"
+ " pos = pos / 128.0 - 1.0;\n"
+ " gl_Position = vec4(pos, pos, 0, 1);\n"
+ " id = float(i);\n"
+ " EmitVertex();\n"
+ " }\n"
+ "}\n";
+
+static const char fs_text[] =
+ "varying float id;\n"
+ "void main()\n"
+ "{\n"
+ " if (id == 0.0)\n"
+ " gl_FragColor = vec4(0, 0, 0, 1);\n"
+ " else if (id == 1.0)\n"
+ " gl_FragColor = vec4(0, 0, 1, 1);\n"
+ " else if (id == 2.0)\n"
+ " gl_FragColor = vec4(0, 1, 0, 1);\n"
+ " else if (id == 3.0)\n"
+ " gl_FragColor = vec4(0, 1, 1, 1);\n"
+ " else if (id == 4.0)\n"
+ " gl_FragColor = vec4(1, 0, 0, 1);\n"
+ " else if (id == 5.0)\n"
+ " gl_FragColor = vec4(1, 0, 1, 1);\n"
+ " else if (id == 6.0)\n"
+ " gl_FragColor = vec4(1, 1, 0, 1);\n"
+ " else if (id == 7.0)\n"
+ " gl_FragColor = vec4(1, 1, 1, 1);\n"
+ " else\n"
+ " /* Should never happen */\n"
+ " gl_FragColor = vec4(0, .5, 1, 1);\n"
+ "}\n";
+
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+ config.window_width = 256;
+ config.window_height = 256;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static int point_count;
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint prog;
+ GLuint vs, gs, fs;
+ GLfloat point_size_range[2];
+
+ piglit_require_extension("GL_ARB_geometry_shader4");
+
+ /* The number of points we draw depends on the maximum point size. */
+ glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, point_size_range);
+ point_count = (int)floorf(log2f(point_size_range[1])) + 1;
+ point_count = MAX2(point_count, 8);
+
+ /* Create shader. */
+ prog = glCreateProgram();
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+ gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_text);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
+ glAttachShader(prog, vs);
+ glAttachShader(prog, gs);
+ glAttachShader(prog, fs);
+ glDeleteShader(vs);
+ glDeleteShader(gs);
+ glDeleteShader(fs);
+
+ /* Link shader. */
+ glProgramParameteri(prog, GL_GEOMETRY_INPUT_TYPE_ARB, GL_POINTS);
+ glProgramParameteri(prog, GL_GEOMETRY_OUTPUT_TYPE_ARB, GL_POINTS);
+ glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB, 8);
+ glLinkProgram(prog);
+ if (!piglit_link_check_status(prog) ||
+ !piglit_check_gl_error(GL_NO_ERROR)) {
+ piglit_report_result(PIGLIT_FAIL);
+ }
+ glUseProgram(prog);
+ glUniform1i(glGetUniformLocation(prog, "point_count"), point_count);
+
+ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
+ glClearColor(.5, .5, .5, 1);
+}
+
+
+enum piglit_result
+piglit_display()
+{
+ const float grey[4] = {0.5, 0.5, 0.5, 1.0};
+ bool pass = true;
+ int i;
+
+ /* Draw */
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDrawArrays(GL_POINTS, 0, 1);
+
+ /* Test framebuffer */
+ for (i = 0; i < point_count; ++i) {
+ const int width = 1 << i;
+ const int pos0 = 0;
+ const int pos1 = 1 << i;
+ const float c[4] = {
+ (i >> 2) & 1, (i >> 1) & 1, (i >> 0) & 1, 1.0
+ };
+
+ pass = piglit_probe_rect_rgb(pos1, pos1, width, width, c) &&
+ pass;
+ pass = piglit_probe_rect_rgb(pos0, pos1, width, width, grey) &&
+ pass;
+ pass = piglit_probe_rect_rgb(pos1, pos0, width, width, grey) &&
+ pass;
+ }
+ pass = piglit_probe_rect_rgb(0, 0, 1, 1, grey) && pass;
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.8.1.2
More information about the Piglit
mailing list