[Piglit] [PATCH 5/7] arb_vertex_attrib_binding: Test changing offsets
Fredrik Höglund
fredrik at kde.org
Thu Jul 11 21:16:20 PDT 2013
This test verifies that changing vertex buffer offsets between
draw calls works as expected.
---
tests/all.tests | 1 +
.../arb_vertex_attrib_binding/CMakeLists.gl.txt | 1 +
tests/spec/arb_vertex_attrib_binding/offsets.c | 175 ++++++++++++++++++++
3 files changed, 177 insertions(+)
create mode 100644 tests/spec/arb_vertex_attrib_binding/offsets.c
diff --git a/tests/all.tests b/tests/all.tests
index 8b560a2..e126be9 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['offsets'] = concurrent_test('arb_vertex_attrib_binding-offsets')
arb_vertex_buffer_object = Group()
spec['ARB_vertex_buffer_object'] = arb_vertex_buffer_object
diff --git a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
index 0bed3bb..11a9e4d 100644
--- a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
+++ b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
@@ -13,5 +13,6 @@ 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-offsets offsets.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_vertex_attrib_binding/offsets.c b/tests/spec/arb_vertex_attrib_binding/offsets.c
new file mode 100644
index 0000000..ec99bea
--- /dev/null
+++ b/tests/spec/arb_vertex_attrib_binding/offsets.c
@@ -0,0 +1,175 @@
+/*
+ * 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 offsets.c
+ *
+ * Tests that changing vertex buffer offsets between draw calls
+ * works 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 vec4 color;\n"
+ "varying vec4 col;\n"
+ "void main() {\n"
+ " col = color;\n"
+ " gl_Position = pos;\n"
+ "}";
+
+const char *fs_source =
+ "varying vec4 col;\n"
+ "void main() {\n"
+ " gl_FragColor = col;\n"
+ "}";
+
+struct Vertex
+{
+ float pos[2];
+ unsigned char color[4];
+};
+
+static GLuint program;
+static GLuint pos, color;
+
+enum piglit_result
+piglit_display(void)
+{
+ const struct Vertex verts[] = {
+ /* Top row */
+ { { -1, 1 }, { 255, 0, 0, 255 } },
+ { { 0, 1 }, { 255, 0, 0, 255 } },
+ { { 0, 0 }, { 255, 0, 0, 255 } },
+ { { -1, 0 }, { 255, 0, 0, 255 } },
+
+ { { 0, 1 }, { 0, 255, 0, 255 } },
+ { { 1, 1 }, { 0, 255, 0, 255 } },
+ { { 1, 0 }, { 0, 255, 0, 255 } },
+ { { 0, 0 }, { 0, 255, 0, 255 } },
+
+ /* Bottom row */
+ { { -1, 0 }, { 0, 0, 255, 255 } },
+ { { 0, 0 }, { 0, 0, 255, 255 } },
+ { { 0, -1 }, { 0, 0, 255, 255 } },
+ { { -1, -1 }, { 0, 0, 255, 255 } },
+
+ { { 0, 0 }, { 255, 255, 255, 255 } },
+ { { 1, 0 }, { 255, 255, 255, 255 } },
+ { { 1, -1 }, { 255, 255, 255, 255 } },
+ { { 0, -1 }, { 255, 255, 255, 255 } }
+ };
+
+ const GLushort indices[] = {
+ 1, 0, 3, 3, 2, 1,
+ 5, 4, 7, 7, 6, 5
+ };
+
+ const float red[] = { 1.0, 0.0, 0.0, 1.0 };
+ const float green[] = { 0.0, 1.0, 0.0, 1.0 };
+ const float blue[] = { 0.0, 0.0, 1.0, 1.0 };
+ const float white[] = { 1.0, 1.0, 1.0, 1.0 };
+
+ GLuint vbo, ibo, vao;
+ bool pass = true;
+
+ glGenVertexArrays(1, &vao);
+ glBindVertexArray(vao);
+
+ glGenBuffers(1, &vbo);
+ glGenBuffers(1, &ibo);
+
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(verts), (const GLvoid *) verts, GL_STATIC_DRAW);
+
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), (const GLvoid *) indices, GL_STATIC_DRAW);
+
+ /* Set up the attrib formats and offsets */
+ glVertexAttribFormat(pos, 2, GL_FLOAT, GL_FALSE, offsetof(struct Vertex, pos));
+ glVertexAttribFormat(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(struct Vertex, color));
+
+ /* Set up the attrib -> binding mapping */
+ glVertexAttribBinding(pos, 0);
+ glVertexAttribBinding(color, 0);
+
+ glEnableVertexAttribArray(pos);
+ glEnableVertexAttribArray(color);
+
+ glViewport(0, 0, piglit_width, piglit_height);
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glUseProgram(program);
+
+ /* Bind vbo to binding point 0 and set the offset to zero for the top row */
+ glBindVertexBuffer(0, vbo, 0, sizeof(struct Vertex));
+ glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_SHORT, NULL);
+
+ /* Change the offset to sizeof(Vertex) * 8 for the bottom row */
+ glBindVertexBuffer(0, vbo, sizeof(struct Vertex) * 8, sizeof(struct Vertex));
+ glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_SHORT, NULL);
+
+ pass = piglit_probe_pixel_rgba(piglit_width * .25, piglit_height * .75, red);
+ pass = piglit_probe_pixel_rgba(piglit_width * .75, piglit_height * .75, green);
+ pass = piglit_probe_pixel_rgba(piglit_width * .25, piglit_height * .25, blue);
+ pass = piglit_probe_pixel_rgba(piglit_width * .75, piglit_height * .25, white);
+
+ piglit_present_results();
+
+ glDeleteBuffers(1, &vbo);
+ glDeleteBuffers(1, &ibo);
+
+ 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);
+
+ /* Set up the vertex arrays */
+ pos = glGetAttribLocation(program, "pos");
+ color = glGetAttribLocation(program, "color");
+}
--
1.7.10.4
More information about the Piglit
mailing list