v2: add indirect addressing test
---
 tests/all.tests                                    |    1 +
 .../arb_uniform_buffer_object/CMakeLists.gl.txt    |    1 +
 tests/spec/arb_uniform_buffer_object/draw_test.c   |  246 ++++++++++++++++++++
 3 files changed, 248 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_uniform_buffer_object/draw_test.c

diff --git a/tests/all.tests b/tests/all.tests
index 2ddfa39..de138be 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1390,6 +1390,7 @@ arb_transform_feedback2['draw-auto'] = 
PlainExecTest(['arb_transform_feedback2-d
 arb_uniform_buffer_object = Group()
 spec['ARB_uniform_buffer_object'] = arb_uniform_buffer_object
 arb_uniform_buffer_object['standard_layout'] = 
concurrent_test('arb_uniform_buffer_object_standard_layout')
+arb_uniform_buffer_object['draw_test'] = 
PlainExecTest('arb_uniform_buffer_object_draw_test')
 
 ati_draw_buffers = Group()
 spec['ATI_draw_buffers'] = ati_draw_buffers
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt 
b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
index 72478a4..8f46101 100644
--- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
@@ -13,5 +13,6 @@ link_libraries (
 )
 
 add_executable (arb_uniform_buffer_object_standard_layout standard-layout.c)
+add_executable (arb_uniform_buffer_object_draw_test draw_test.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/arb_uniform_buffer_object/draw_test.c 
b/tests/spec/arb_uniform_buffer_object/draw_test.c
new file mode 100644
index 0000000..544c700
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/draw_test.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright © 2011 Marek Olšák <mar...@gmail.com>
+ * Copyright © 2011 Vincent Lejeune
+ *
+ * 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.
+ */
+
+ /**
+ * ARB_uniform_buffer_object test
+ *
+ * This test checks that uniform buffer object layout is correctly used in a
+ * fragment shader.
+ * It checks if vector, structure based and array based uniform buffer object
+ * elements are correctly handled.
+ *
+ * We do not specify any layout (packed, shared or std140) so we query
+ * offset/size/stride information using the spec API.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 64;
+int piglit_height = 64;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+static const char vert_shader_text[] =
+       "#version 130\n"
+       "in vec2 VertexPosition;\n"
+       "invariant gl_Position;\n"
+       "\n"
+       "void main ()\n"
+       "{\n"
+       "   gl_Position = vec4 (VertexPosition, 0.0, 1.0);\n"
+       "}\n"
+;
+
+static const char frag_shader_text[] =
+       "#version 130\n"
+       "#extension GL_ARB_uniform_buffer_object : enable\n "
+       "uniform colors {\n"
+       "   int mode;\n"
+       "   int index;\n"
+       "   vec3 red;\n"
+       "   struct {\n"
+       "      vec3 green;\n"
+       "      vec3 blue;\n"
+       "   } teststruct;\n"
+       "   vec3 testarray[3];"
+       "};\n"
+       "out vec3 fragColor;\n"
+       "\n"
+       "void main()\n"
+       "{\n"
+       "   if (mode == 0)\n"
+       "      fragColor = red;\n"
+       "   if (mode == 1)\n"
+       "      fragColor = teststruct.green + teststruct.blue;\n"
+       "   if (mode == 2)\n"
+       "   {\n"
+       "      fragColor = vec3(0.);\n"
+       "      for(int i = 0; i < 3; i++)\n"
+       "         fragColor += testarray[i];\n"
+       "   }\n"
+       "   if (mode == 3)\n"
+       "   {\n"
+       "      fragColor = testarray[index];"
+       "   }\n"
+       "}\n"
+;
+
+GLuint prog;
+GLuint uniform_buf;
+GLuint vertex_buf;
+GLuint positionAttrib;
+GLint ubo_id;
+GLint ubo_size;
+
+
+static const float verts[] = {
+       -0.25, -0.25,
+       -0.25, 0.25,
+       0.25, 0.25,
+       0.25, -0.25
+};
+
+const char* uniform_names[] = 
{"mode","index","red","teststruct.green","teststruct.blue","testarray"};
+
+static const GLint idx = 1;
+static const float red[] = {1, 0, 0};
+static const float green[] = {0, 1, 0};
+static const float blue[] = {0, 0, 1};
+static const float green_and_blue[] = {0, 1, 1};
+static const float white[] = {1, 1, 1};
+static const float colorArray[][3] = {
+       {1, 0, 0},
+       {0, 1, 0},
+       {0, 0, 1},
+};
+
+#define SET_UNIFORM_VALUE_INT(name,value) \
+       { \
+               GLuint ubo_var_id; \
+               GLint ubo_var_offset; \
+               glGetUniformIndices(prog, 1, &(name), &ubo_var_id); \
+               glGetActiveUniformsiv(prog, 1, &ubo_var_id, GL_UNIFORM_OFFSET, 
&ubo_var_offset); \
+               glBufferSubData(GL_UNIFORM_BUFFER, ubo_var_offset, 
sizeof(GLint),value ); \
+       }
+
+#define SET_UNIFORM_VALUE(name,value) \
+       { \
+               GLuint ubo_var_id; \
+               GLint ubo_var_offset; \
+               glGetUniformIndices(prog, 1, &(name), &ubo_var_id); \
+               glGetActiveUniformsiv(prog, 1, &ubo_var_id, GL_UNIFORM_OFFSET, 
&ubo_var_offset); \
+               glBufferSubData(GL_UNIFORM_BUFFER, ubo_var_offset, 
sizeof(value),value ); \
+       }
+
+#define SET_UNIFORM_ARRAY(name,value) \
+       { \
+               GLuint ubo_var_id; \
+               GLint ubo_var_offset; \
+               GLint ubo_var_size; \
+               GLint ubo_var_stride; \
+               unsigned i; \
+               glGetUniformIndices(prog, 1, &(name), &ubo_var_id); \
+               glGetActiveUniformsiv(prog, 1, &ubo_var_id, GL_UNIFORM_OFFSET, 
&ubo_var_offset); \
+               glGetActiveUniformsiv(prog, 1, &ubo_var_id, GL_UNIFORM_SIZE, 
&ubo_var_size); \
+               glGetActiveUniformsiv(prog, 1, &ubo_var_id, 
GL_UNIFORM_ARRAY_STRIDE, &ubo_var_stride); \
+               for (i = 0; i < ubo_var_size; i++) \
+                       glBufferSubData(GL_UNIFORM_BUFFER, ubo_var_offset + i * 
ubo_var_stride , sizeof((value)[i]),(value)[i] ); \
+       }
+
+void piglit_init(int argc, char **argv)
+{
+       GLuint vs;
+       GLuint fs;
+
+       piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+       /* Check the driver. */
+       if (!GLEW_VERSION_1_5) {
+               fprintf(stderr, "OpenGL 1.5 required.\n");
+               piglit_report_result(PIGLIT_SKIP);
+       }
+       piglit_require_GLSL();
+       piglit_require_extension("GL_ARB_uniform_buffer_object");
+
+
+       /* Create shaders. */
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert_shader_text);
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag_shader_text);
+       prog = piglit_CreateProgram();
+       piglit_AttachShader(prog,vs);
+       piglit_AttachShader(prog, fs);
+
+       piglit_LinkProgram(prog);
+       if (!piglit_link_check_status(prog)) {
+               piglit_DeleteProgram(prog);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       positionAttrib = glGetAttribLocation(prog,"VertexPosition");
+
+       glGenBuffers(1,&vertex_buf);
+       glBindBuffer(GL_ARRAY_BUFFER,vertex_buf);
+       glBufferData(GL_ARRAY_BUFFER,sizeof(verts),verts,GL_STATIC_DRAW);
+
+       ubo_id = glGetUniformBlockIndex(prog, "colors");
+       glGetActiveUniformBlockiv(prog, ubo_id,GL_UNIFORM_BLOCK_DATA_SIZE, 
&ubo_size);
+
+       /* Set up uniform buffer */
+       glGenBuffers(1,&uniform_buf);
+       glBindBuffer(GL_UNIFORM_BUFFER,uniform_buf);
+       glBufferData(GL_UNIFORM_BUFFER,ubo_size,0,GL_DYNAMIC_DRAW);
+
+       SET_UNIFORM_VALUE_INT(uniform_names[1],&idx)
+       SET_UNIFORM_VALUE(uniform_names[2],red)
+       SET_UNIFORM_VALUE(uniform_names[3],green)
+       SET_UNIFORM_VALUE(uniform_names[4],blue)
+       SET_UNIFORM_ARRAY(uniform_names[5],colorArray)
+
+       glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniform_buf);
+       glUniformBlockBinding(prog, ubo_id, 0);
+
+       assert(glGetError() == 0);
+
+       glClearColor(0., 0., 0., 1.0);
+       glEnableClientState(GL_VERTEX_ARRAY);
+}
+
+static void
+render_mode(GLint mode)
+{
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       piglit_UseProgram(prog);
+       glLoadIdentity();
+
+       glBindBuffer(GL_UNIFORM_BUFFER,uniform_buf);
+       SET_UNIFORM_VALUE_INT(uniform_names[0],&mode);
+
+       glBindBuffer(GL_ARRAY_BUFFER, vertex_buf);
+       glVertexAttribPointer(positionAttrib,2,GL_FLOAT,GL_FALSE,8,0);
+       glEnableVertexAttribArray(positionAttrib);
+       glDrawArrays(GL_QUADS, 0, 4);
+
+       assert(glGetError() == 0);
+}
+
+enum piglit_result piglit_display(void)
+{
+       GLboolean pass = GL_TRUE;
+
+       render_mode(0);
+       pass = piglit_probe_pixel_rgb(32, 32, red) && pass;
+
+       render_mode(1);
+       pass = piglit_probe_pixel_rgb(32, 32, green_and_blue) && pass;
+
+       render_mode(2);
+       pass = piglit_probe_pixel_rgb(32, 32, white) && pass;
+
+       render_mode(3);
+       pass = piglit_probe_pixel_rgb(32, 32, green) && pass;
+
+       glutSwapBuffers();
+
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
1.7.7

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to