[Piglit] [PATCH 6/7] arb_vertex_attrib_binding: Test instance-divisor
Fredrik Höglund
fredrik at kde.org
Thu Jul 11 21:16:21 PDT 2013
---
tests/all.tests | 1 +
.../arb_vertex_attrib_binding/CMakeLists.gl.txt | 1 +
.../arb_vertex_attrib_binding/instance-divisor.c | 186 ++++++++++++++++++++
3 files changed, 188 insertions(+)
create mode 100644 tests/spec/arb_vertex_attrib_binding/instance-divisor.c
diff --git a/tests/all.tests b/tests/all.tests
index e126be9..3dded1e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1396,6 +1396,7 @@ arb_vertex_attrib_binding['buffers'] = concurrent_test('arb_vertex_attrib_bindin
arb_vertex_attrib_binding['errors'] = concurrent_test('arb_vertex_attrib_binding-errors')
arb_vertex_attrib_binding['format'] = concurrent_test('arb_vertex_attrib_binding-format')
arb_vertex_attrib_binding['get'] = concurrent_test('arb_vertex_attrib_binding-get')
+arb_vertex_attrib_binding['instance-divisor'] = concurrent_test('arb_vertex_attrib_binding-instance-divisor')
arb_vertex_attrib_binding['offsets'] = concurrent_test('arb_vertex_attrib_binding-offsets')
arb_vertex_buffer_object = Group()
diff --git a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
index 11a9e4d..55f7280 100644
--- a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
+++ b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
@@ -13,6 +13,7 @@ piglit_add_executable (arb_vertex_attrib_binding-buffers buffers.c)
piglit_add_executable (arb_vertex_attrib_binding-errors errors.c)
piglit_add_executable (arb_vertex_attrib_binding-format format.c)
piglit_add_executable (arb_vertex_attrib_binding-get get.c)
+piglit_add_executable (arb_vertex_attrib_binding-instance-divisor instance-divisor.c)
piglit_add_executable (arb_vertex_attrib_binding-offsets offsets.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_vertex_attrib_binding/instance-divisor.c b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
new file mode 100644
index 0000000..88ae454
--- /dev/null
+++ b/tests/spec/arb_vertex_attrib_binding/instance-divisor.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2013 Fredrik Höglund
+ *
+ * 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 instance-divisor.c
+ *
+ * Tests that instance-divisors work as expected.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+
+ config.window_width = 128;
+ config.window_height = 128;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+const char *vs_source =
+ "attribute vec4 pos;\n"
+ "attribute vec2 offset;\n"
+ "attribute vec4 color;\n"
+ "uniform vec2 global_offset;\n"
+ "varying vec4 col;\n"
+ "void main() {\n"
+ " col = color;\n"
+ " gl_Position = pos + vec4(global_offset + offset, vec2(0, 0));\n"
+ "}";
+
+const char *fs_source =
+ "varying vec4 col;\n"
+ "void main() {\n"
+ " gl_FragColor = col;\n"
+ "}";
+
+struct vec2
+{
+ float x, y;
+};
+
+struct vec4
+{
+ float x, y, z, w;
+};
+
+static GLuint program;
+static GLuint pos, offset, color, global_offset;
+
+enum piglit_result
+piglit_display(void)
+{
+ const struct vec2 quad[] = {
+ { -0.125, 0.125 }, { 0.125, 0.125 },
+ { -0.125, -0.125 }, { 0.125, -0.125 }
+ };
+
+ const struct vec2 offsets[] = {
+ { -.75, 0 }, { -.25, 0 }, { .25, 0 }, { .75, 0 }
+ };
+
+ const struct vec4 colors[] = {
+ { 1.0, 0.0, 0.0, 1.0 },
+ { 0.0, 1.0, 0.0, 1.0 },
+ { 0.0, 0.0, 1.0, 1.0 },
+ { 1.0, 1.0, 1.0, 1.0 }
+ };
+
+ GLuint vbo1, vbo2, vbo3, vao;
+ bool pass = true;
+
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ glGenBuffers(1, &vbo1);
+ glGenBuffers(1, &vbo2);
+ glGenBuffers(1, &vbo3);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo1);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(quad), (const GLvoid *) quad, GL_STATIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo2);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(offsets), (const GLvoid *) offsets, GL_STATIC_DRAW);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo3);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(colors), (const GLvoid *) colors, GL_STATIC_DRAW);
+
+ /* Bind the vertex buffers */
+ glBindVertexBuffer(0, vbo1, 0, sizeof(struct vec2));
+ glBindVertexBuffer(1, vbo2, 0, sizeof(struct vec2));
+ glBindVertexBuffer(2, vbo3, 0, sizeof(struct vec4));
+
+ /* Set up the formats and relative offsets */
+ glVertexAttribFormat(pos, 2, GL_FLOAT, GL_FALSE, 0);
+ glVertexAttribFormat(offset, 2, GL_FLOAT, GL_FALSE, 0);
+ glVertexAttribFormat(color, 4, GL_FLOAT, GL_FALSE, 0);
+
+ /* Set up the attrib -> binding mapping, and enable the arrays */
+ glVertexAttribBinding(pos, 0);
+ glVertexAttribBinding(offset, 1);
+ glVertexAttribBinding(color, 2);
+
+ glEnableVertexAttribArray(pos);
+ glEnableVertexAttribArray(offset);
+ glEnableVertexAttribArray(color);
+
+ /* Set the instance divisor for the offsets */
+ glVertexBindingDivisor(1, 1);
+
+ glViewport(0, 0, piglit_width, piglit_height);
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glUseProgram(program);
+
+ /* Draw the squares with the divisor for the colors set to 1 */
+ glUniform2f(global_offset, 0, .5);
+ glVertexBindingDivisor(2, 1);
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 4);
+
+ /* Set the divisor to 2 and draw the squares again */
+ glUniform2f(global_offset, 0, -.5);
+ glVertexBindingDivisor(2, 2);
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 4);
+
+ pass = piglit_probe_pixel_rgba(piglit_width * .125, piglit_height * .75, (const float *) &colors[0]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .375, piglit_height * .75, (const float *) &colors[1]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .625, piglit_height * .75, (const float *) &colors[2]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .875, piglit_height * .75, (const float *) &colors[3]);
+
+ pass = piglit_probe_pixel_rgba(piglit_width * .125, piglit_height * .25, (const float *) &colors[0]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .375, piglit_height * .25, (const float *) &colors[0]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .625, piglit_height * .25, (const float *) &colors[1]);
+ pass = piglit_probe_pixel_rgba(piglit_width * .875, piglit_height * .25, (const float *) &colors[1]);
+
+ piglit_present_results();
+
+ glDeleteBuffers(1, &vbo1);
+ glDeleteBuffers(1, &vbo2);
+ glDeleteBuffers(1, &vbo3);
+
+ glDeleteVertexArrays(1, &vao);
+
+ glUseProgram(0);
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vs, fs;
+
+ piglit_require_extension("GL_ARB_vertex_attrib_binding");
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+ program = piglit_link_simple_program(vs, fs);
+
+ pos = glGetAttribLocation(program, "pos");
+ offset = glGetAttribLocation(program, "offset");
+ color = glGetAttribLocation(program, "color");
+ global_offset = glGetUniformLocation(program, "global_offset");
+}
--
1.7.10.4
More information about the Piglit
mailing list