This test puts the pos, size, rotation and color info for four objects
in an array which is stored in a UBO. For each drawing command, index
into the array to get the object parameters.
---
tests/all.py | 2 +
.../arb_uniform_buffer_object/CMakeLists.gl.txt | 1 +
.../arb_uniform_buffer_object/rendering-array.c | 209 +++++++++++++++++++++
3 files changed, 212 insertions(+)
create mode 100644 tests/spec/arb_uniform_buffer_object/rendering-array.c
diff --git a/tests/all.py b/tests/all.py
index 7f02653..f854604 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3614,6 +3614,8 @@ with profile.group_manager(
'referenced-by-shader')
g(['arb_uniform_buffer_object-rendering'], 'rendering')
g(['arb_uniform_buffer_object-rendering', 'offset'], 'rendering-offset')
+ g(['arb_uniform_buffer_object-rendering-array'], 'rendering-array')
+ g(['arb_uniform_buffer_object-rendering-array', 'offset'],
'rendering-array-offset')
g(['arb_uniform_buffer_object-rendering-dsa'], 'rendering-dsa')
g(['arb_uniform_buffer_object-rendering-dsa', 'offset'],
'rendering-dsa-offset')
g(['arb_uniform_buffer_object-row-major'], 'row-major')
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
index 541a100..6bdcde8 100644
--- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
@@ -38,6 +38,7 @@ piglit_add_executable
(arb_uniform_buffer_object-negative-getactiveuniformblocki
piglit_add_executable (arb_uniform_buffer_object-negative-getactiveuniformsiv
negative-getactiveuniformsiv.c)
piglit_add_executable (arb_uniform_buffer_object-referenced-by-shader
referenced-by-shader.c)
piglit_add_executable (arb_uniform_buffer_object-rendering rendering.c)
+piglit_add_executable (arb_uniform_buffer_object-rendering-array
rendering-array.c)
piglit_add_executable (arb_uniform_buffer_object-rendering-dsa
rendering-dsa.c)
piglit_add_executable (arb_uniform_buffer_object-row-major row-major.c)
piglit_add_executable (arb_uniform_buffer_object-uniformblockbinding
uniformblockbinding.c)
diff --git a/tests/spec/arb_uniform_buffer_object/rendering-array.c
b/tests/spec/arb_uniform_buffer_object/rendering-array.c
new file mode 100644
index 0000000..1535e92
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/rendering-array.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2016 VMware, Inc.
+ *
+ * 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 rendering-array.c
+ *
+ * Test rendering with a UBO containing an array of structs.
+ * We draw four squares with different positions, sizes, rotations and colors
+ * where those parameters come from an array in a UBO. Each draw command
+ * indexes into a different element of that array.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.supports_gl_compat_version = 20;
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+PIGLIT_GL_TEST_CONFIG_END
+
+
+static const char vert_shader_text[] =
+ "#extension GL_ARB_uniform_buffer_object : require\n"
+ "\n"
+ "layout(std140) uniform;\n"
+ "uniform ub_info { \n"
+ " struct { \n"
+ " vec2 pos; \n"
+ " float size; \n"
+ " float rotation; \n"
+ " vec4 color; \n"
+ " } info [4];\n"
+ "};\n"
+ "\n"
+ "uniform int j; \n"
+ "varying vec4 color; \n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " int i; \n"
+ " mat2 m;\n"
+ " for (i = 0; i < 4; i++) { \n"
+ " if (i == j) { \n"
+ " m[0][0] = m[1][1] = cos(info[i].rotation); \n"
+ " m[0][1] = sin(info[i].rotation); \n"
+ " m[1][0] = -m[0][1]; \n"
+ " gl_Position.xy = m * gl_Vertex.xy * vec2(info[i].size) +
info[i].pos;\n"
+ " gl_Position.zw = vec2(0, 1);\n"
+ " color = info[i].color; \n"
+ " } \n"
+ " } \n"
+ "}\n";
+
+static const char frag_shader_text[] =
+ "#extension GL_ARB_uniform_buffer_object : require\n"
+ "\n"
+ "varying vec4 color; \n"
+ "\n"
+ "layout(std140) uniform;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = color;\n"
+ "}\n";
+
+#define NUM_SQUARES 4
+
+static GLuint prog;
+static GLuint ubo_buffer;
+static GLint alignment;
+static bool test_buffer_offset = false;
+static int uniform_j;
+
+struct object_info {
+ float pos[2];
+ float size, rotation;
+ float color[4];
+};
+
+/* This data are copied into the UBO */
+static const struct object_info obj_info[NUM_SQUARES] = {
+ { {-0.5, -0.5}, 0.1, 0.0, {1.0, 0.0, 0.0, 1.0} },
+ { { 0.5, -0.5}, 0.2, 0.1, {0.0, 1.0, 0.0, 1.0} },
+ { {-0.5, 0.5}, 0.3, 0.2, {0.0, 0.0, 1.0, 1.0} },
+ { { 0.5, 0.5}, 0.4, 0.3, {1.0, 1.0, 1.0, 1.0} }
+};
+
+
+static void
+setup_ubos(void)
+{
+ static const char *ubo_name = "ub_info";
+ GLint ubo_index, ubo_size;
+
+ glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
+ printf("GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT = %d\n", alignment);
+
+ if (test_buffer_offset) {
+ printf("Testing buffer offset %d\n", alignment);
+ }
+ else {
+ /* we use alignment as the offset */
+ alignment = 0;