[Piglit] [PATCH 7/7] arb_vertex_attrib_binding: Test zero-stride bindings

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


---
 tests/all.tests                                    |    1 +
 .../arb_vertex_attrib_binding/CMakeLists.gl.txt    |    1 +
 tests/spec/arb_vertex_attrib_binding/zero-stride.c |  139 ++++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 tests/spec/arb_vertex_attrib_binding/zero-stride.c

diff --git a/tests/all.tests b/tests/all.tests
index 3dded1e..db97221 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1398,6 +1398,7 @@ arb_vertex_attrib_binding['format'] = concurrent_test('arb_vertex_attrib_binding
 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_attrib_binding['zero-stride'] = concurrent_test('arb_vertex_attrib_binding-zero-stride')
 
 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 55f7280..4abd4ee 100644
--- a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
+++ b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
@@ -15,5 +15,6 @@ 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)
+piglit_add_executable (arb_vertex_attrib_binding-zero-stride zero-stride.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_vertex_attrib_binding/zero-stride.c b/tests/spec/arb_vertex_attrib_binding/zero-stride.c
new file mode 100644
index 0000000..83b56e4
--- /dev/null
+++ b/tests/spec/arb_vertex_attrib_binding/zero-stride.c
@@ -0,0 +1,139 @@
+/*
+ * 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 zero-stride.c
+ *
+ * Tests that drawing with zero-stride buffer bindings works.
+ */
+
+#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"
+	"}";
+
+static GLuint program;
+static GLuint pos, color;
+
+enum piglit_result
+piglit_display(void)
+{
+	const struct {
+		float x, y;
+	} verts[] = {
+		{ -1,  1 }, { 1,  1 },
+		{ -1, -1 }, { 1, -1 }
+	};
+
+	const float green[] = { 0.0, 1.0, 0.0, 1.0 };
+
+	GLuint vbo1, vbo2, vao;
+	bool pass = true;
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	glGenBuffers(1, &vbo1);
+	glGenBuffers(1, &vbo2);
+
+	/* vbo1 contains the vertex positions */
+	glBindBuffer(GL_ARRAY_BUFFER, vbo1);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), (const GLvoid *) verts, GL_STATIC_DRAW);
+
+	/* vbo2 contains the color data */
+	glBindBuffer(GL_ARRAY_BUFFER, vbo2);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(green), (const GLvoid *) green, GL_STATIC_DRAW);
+
+	/* Bind the VBO's */
+	glBindVertexBuffer(0, vbo1, 0, sizeof(verts[0]));
+	glBindVertexBuffer(1, vbo2, 0, 0); /* Zero-stride */
+
+	/* Set up the attrib -> binding mapping */
+	glVertexAttribBinding(pos,   0);
+	glVertexAttribBinding(color, 1);
+
+	/* Set up the formats and enable the arrays */
+	glVertexAttribFormat(pos, 2, GL_FLOAT, GL_FALSE, 0);
+	glVertexAttribFormat(color, 4, GL_FLOAT, GL_FALSE, 0);
+
+	glEnableVertexAttribArray(pos);
+	glEnableVertexAttribArray(color);
+
+	glViewport(0, 0, piglit_width, piglit_height);
+	glClearColor(1.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glUseProgram(program);
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	pass = piglit_probe_pixel_rgba(piglit_width * .5, piglit_height * .5, green);
+
+	piglit_present_results();
+
+	glDeleteBuffers(1, &vbo1);
+	glDeleteBuffers(1, &vbo2);
+
+	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