---
 tests/spec/CMakeLists.txt                          |    1 +
 .../arb_uniform_buffer_object/CMakeLists.gl.txt    |   17 ++
 .../spec/arb_uniform_buffer_object/CMakeLists.txt  |    1 +
 .../arb_uniform_buffer_object/standard-layout.c    |  169 ++++++++++++++++++++
 4 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_uniform_buffer_object/CMakeLists.txt
 create mode 100644 tests/spec/arb_uniform_buffer_object/standard-layout.c

diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index a4021c3..c1f3c85 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -38,3 +38,4 @@ add_subdirectory (ext_texture_integer)
 add_subdirectory (arb_draw_buffers)
 add_subdirectory (oes_draw_texture)
 add_subdirectory (arb_blend_func_extended)
+add_subdirectory (arb_uniform_buffer_object)
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt 
b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
new file mode 100644
index 0000000..72478a4
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
@@ -0,0 +1,17 @@
+include_directories(
+       ${GLEXT_INCLUDE_DIR}
+       ${OPENGL_INCLUDE_PATH}
+       ${GLUT_INCLUDE_DIR}
+       ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+       piglitutil
+       ${OPENGL_gl_LIBRARY}
+       ${OPENGL_glu_LIBRARY}
+       ${GLUT_glut_LIBRARY}
+)
+
+add_executable (arb_uniform_buffer_object_standard_layout standard-layout.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.txt 
b/tests/spec/arb_uniform_buffer_object/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_uniform_buffer_object/standard-layout.c 
b/tests/spec/arb_uniform_buffer_object/standard-layout.c
new file mode 100644
index 0000000..623960f
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/standard-layout.c
@@ -0,0 +1,169 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ * 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 the conformance of offset and size returned by
+ * glGetActiveUniformsiv for uniform in an UBO whose layout is
+ * std140 (and thus, standardised).
+ *
+ * The example shader and expected values for offset and size are
+ * taken from spec :
+ *
+ * http://www.opengl.org/registry/specs/ARB/uniform_buffer_object.txt
+ */
+
+#include "piglit-util.h"
+
+#define Elements(x) (sizeof(x)/sizeof(*(x)))
+
+
+int piglit_width = 100;
+int piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+static GLuint prog;
+
+static const struct result {
+   const char* name;
+   GLint offset;
+   GLint size;
+} expected_result[] =
+       {
+               { "a", 0, 1 },
+               { "b", 8, 1 },
+               { "c", 16, 1 },
+               { "f.d", 32, 1},
+               { "f.e", 40, 1},
+               { "g", 48, 1},
+               { "h", 64, 2},
+               { "i", 96, 1},
+               { "o[0].j", 128,1},
+               { "o[0].k", 144, 1},
+               { "o[0].l", 160, 2},
+               { "o[0].m", 192, 1},
+               { "o[0].n", 208, 2},
+               { "o[1].j", 304,1},
+               { "o[1].k", 320, 1},
+               { "o[1].l", 336, 2},
+               { "o[1].m", 368, 1},
+               { "o[1].n", 384, 2},
+       };
+
+
+
+static const char frag_shader_text[] =
+       "#version 130\n"
+       "#extension GL_ARB_uniform_buffer_object : enable \n"
+       "layout(std140) uniform test_ubo { \n"
+       "float a;\n"
+       "vec2 b;\n"
+       "vec3 c;\n"
+       "struct {\n"
+       "int d;\n"
+       "bvec2 e;\n"
+       "} f;\n"
+       "float g;\n"
+       "float h[2];\n"
+       "mat2x3 i;\n"
+       "struct {\n"
+       "uvec3 j;\n"
+       "vec2 k;\n"
+       "float l[2];\n"
+       "vec2 m;\n"
+       "mat3 n[2];\n"
+       "} o[2];"
+       "};\n"
+       "void main() {}";
+
+static void
+init(void)
+{
+       GLuint fs;
+
+       piglit_require_GLSL_version(120);
+
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag_shader_text);
+       prog = piglit_CreateProgram();
+       piglit_AttachShader(prog, fs);
+
+       piglit_LinkProgram(prog);
+       if (!piglit_link_check_status(prog)) {
+               piglit_DeleteProgram(prog);
+               piglit_report_result(PIGLIT_FAIL);
+       }
+
+       piglit_UseProgram(prog);
+       piglit_check_gl_error(0, PIGLIT_FAIL);
+}
+
+static bool
+validate_offset_and_size()
+{
+       unsigned i,index;
+       GLint offset,size;
+
+       for(i = 0; i < Elements(expected_result); i++) {
+               const char* temp_name = expected_result[i].name;
+               glGetUniformIndices(prog, 1, &temp_name, &index);
+               if (index == GL_INVALID_INDEX) {
+                       printf("%s not found\n",temp_name);
+                       return 0;
+               }
+               glGetActiveUniformsiv(prog, 1, &index, GL_UNIFORM_OFFSET, 
&offset);
+               if (offset != expected_result[i].offset) {
+                       printf("For %s : offset is %d, should be 
%d\n",temp_name,
+                               offset,expected_result[i].offset);
+                       return 0;
+               }
+               glGetActiveUniformsiv(prog, 1, &index, GL_UNIFORM_SIZE, &size);
+               if (size != expected_result[i].size) {
+                       printf("For %s : size is %d, should be %d\n",temp_name,
+                               size,expected_result[i].size);
+                       return 0;
+               }
+       }
+       return 1;
+
+}
+
+static void
+check_results_and_exit(void)
+{
+       GLboolean pass = GL_TRUE;
+       pass = validate_offset_and_size();
+       piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+       init();
+       check_results_and_exit();
+}
+
+enum piglit_result piglit_display(void)
+{
+       return 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