[Piglit] [PATCH 3/7] arb_vertex_attrib_binding: Test setting and changing formats

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


This test verifies that changing attrib formats between draw calls
works as expected.
---
 tests/all.tests                                    |    1 +
 .../arb_vertex_attrib_binding/CMakeLists.gl.txt    |    1 +
 tests/spec/arb_vertex_attrib_binding/format.c      |  147 ++++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 tests/spec/arb_vertex_attrib_binding/format.c

diff --git a/tests/all.tests b/tests/all.tests
index b0772e0..5938a17 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1393,6 +1393,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['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_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 bd534ae..f6dbbb3 100644
--- a/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
+++ b/tests/spec/arb_vertex_attrib_binding/CMakeLists.gl.txt
@@ -10,6 +10,7 @@ link_libraries (
 )
 
 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)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_vertex_attrib_binding/format.c b/tests/spec/arb_vertex_attrib_binding/format.c
new file mode 100644
index 0000000..130b65a
--- /dev/null
+++ b/tests/spec/arb_vertex_attrib_binding/format.c
@@ -0,0 +1,147 @@
+/*
+ * 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 formats 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"
+	"uniform vec2 offset;\n"
+	"varying vec4 col;\n"
+	"void main() {\n"
+	"    col = color;\n"
+	"    gl_Position = pos + vec4(offset, vec2(0,0));\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, offset;
+
+enum piglit_result
+piglit_display(void)
+{
+	const struct Vertex verts[] = {
+		{ { -.25,  .25 }, { 255,   255,   0, 255 } },
+		{ {  .25,  .25 }, { 255,   255,   0, 255 } },
+		{ { -.25, -.25 }, { 255,   255,   0, 255 } },
+		{ {  .25, -.25 }, { 255,   255,   0, 255 } },
+	};
+
+	const float yellow[]= { 1.0, 1.0, 0.0, 1.0 };
+	const float cyan[]  = { 0.0, 1.0, 1.0, 1.0 };
+
+	GLuint vbo, vao;
+	bool pass = true;
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), (const GLvoid *) verts, GL_STATIC_DRAW);
+
+	/* Bind the vertex buffer to binding point 0 */
+	glBindVertexBuffer(0, vbo, 0, sizeof(struct Vertex));
+
+	/* Set up the attrib -> binding mapping */
+	glVertexAttribBinding(pos,   0);
+	glVertexAttribBinding(color, 0);
+
+	/* Set up the format and offset for the position */
+	glVertexAttribFormat(pos, 2, GL_FLOAT, GL_FALSE, offsetof(struct Vertex, pos));
+
+	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);
+
+	/* Set the color format to RGBA order */
+	glUniform2f(offset, -.4, 0);
+	glVertexAttribFormat(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(struct Vertex, color));
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	/* Set the color format to BGRA order */
+	glUniform2f(offset,  .4, 0);
+	glVertexAttribFormat(color, GL_BGRA, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(struct Vertex, color));
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	pass = piglit_probe_pixel_rgba(piglit_width * .25, piglit_height * .5, yellow);
+	pass = piglit_probe_pixel_rgba(piglit_width * .75, piglit_height * .5, cyan);
+
+	piglit_present_results();
+
+	glDeleteBuffers(1, &vbo);
+	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");
+	offset = glGetUniformLocation(program, "offset");
+}
-- 
1.7.10.4



More information about the Piglit mailing list