[Piglit] [PATCH 4/7] arb_vertex_attrib_binding: Test switching buffers

Fredrik Höglund fredrik at kde.org
Thu Jul 11 21:16:19 PDT 2013


This test verifies that switching vertex buffers between draw calls
works as expected.
---
 tests/all.tests                                    |    1 +
 .../arb_vertex_attrib_binding/CMakeLists.gl.txt    |    1 +
 tests/spec/arb_vertex_attrib_binding/buffers.c     |  178 ++++++++++++++++++++
 3 files changed, 180 insertions(+)
 create mode 100644 tests/spec/arb_vertex_attrib_binding/buffers.c

diff --git a/tests/all.tests b/tests/all.tests
index 5938a17..8b560a2 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1392,6 +1392,7 @@ arb_vertex_array_object['isvertexarray'] = concurrent_test('arb_vertex_array-isv
 
 arb_vertex_attrib_binding = Group()
 spec['ARB_vertex_attrib_binding'] = arb_vertex_attrib_binding
+arb_vertex_attrib_binding['buffers'] = concurrent_test('arb_vertex_attrib_binding-buffers')
 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')
diff --git a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
index f6dbbb3..0bed3bb 100644
--- a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
+++ b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
@@ -9,6 +9,7 @@ link_libraries (
 	${OPENGL_glu_LIBRARY}
 )
 
+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)
diff --git a/tests/spec/arb_vertex_attrib_binding/buffers.c b/tests/spec/arb_vertex_attrib_binding/buffers.c
new file mode 100644
index 0000000..bba8c17
--- /dev/null
+++ b/tests/spec/arb_vertex_attrib_binding/buffers.c
@@ -0,0 +1,178 @@
+/*
+ * 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 buffers.c
+ *
+ * Tests that switching buffers 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 top[] = {
+		{ { -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 } },
+	};
+
+	const struct Vertex bottom[] = {
+		{ { -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 vbo1, vbo2, ibo, vao;
+	bool pass = true;
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	glGenBuffers(1, &vbo1);
+	glGenBuffers(1, &vbo2);
+	glGenBuffers(1, &ibo);
+
+	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(top), (const GLvoid *) top, GL_STATIC_DRAW);
+
+	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(bottom), (const GLvoid *) bottom, 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 vbo1 to binding point 0 */
+	glBindVertexBuffer(0, vbo1, 0, sizeof(struct Vertex));
+	glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_SHORT, NULL);
+
+	/* Bind vbo2 to binding point 0 */
+	glBindVertexBuffer(0, vbo2, 0, 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, &vbo1);
+	glDeleteBuffers(1, &vbo2);
+	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);
+
+	pos   = glGetAttribLocation(program, "pos");
+	color = glGetAttribLocation(program, "color");
+}
-- 
1.7.10.4



More information about the Piglit mailing list