summaryrefslogtreecommitdiff
path: root/tests/spec/arb_uniform_buffer_object
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2012-07-25 12:41:42 -0700
committerEric Anholt <eric@anholt.net>2012-08-23 13:08:29 -0700
commitc3c8b4c90af19cc395cf11db64405e82a9cd8833 (patch)
tree8a2dee990209681bca682bb5c4c8322dce619fb7 /tests/spec/arb_uniform_buffer_object
parent89c498b5fe0a514ab1306361741ff931df4b571b (diff)
GL_ARB_ubo: New test for glGetActiveUniformsiv(GL_UNIFORM_TYPE).
I would have tested the getter on non-ubo uniforms, except I can't just use std140 layout to trivially guarantee activeness for them.
Diffstat (limited to 'tests/spec/arb_uniform_buffer_object')
-rw-r--r--tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt1
-rw-r--r--tests/spec/arb_uniform_buffer_object/getactiveuniformsiv-uniform-type.c106
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
index 0285b46d2..4f772bfa6 100644
--- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
+++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
@@ -16,6 +16,7 @@ add_executable (arb_uniform_buffer_object-getactiveuniformblockiv-uniform-block-
add_executable (arb_uniform_buffer_object-getactiveuniformblockname getactiveuniformblockname.c)
add_executable (arb_uniform_buffer_object-getactiveuniformname getactiveuniformname.c)
add_executable (arb_uniform_buffer_object-getactiveuniformsiv-uniform-block-index getactiveuniformsiv-uniform-block-index.c)
+add_executable (arb_uniform_buffer_object-getactiveuniformsiv-uniform-type getactiveuniformsiv-uniform-type.c uniform-types.c)
add_executable (arb_uniform_buffer_object-getintegeri_v getintegeri_v.c)
add_executable (arb_uniform_buffer_object-getprogramiv getprogramiv.c)
add_executable (arb_uniform_buffer_object-getuniformblockindex getuniformblockindex.c)
diff --git a/tests/spec/arb_uniform_buffer_object/getactiveuniformsiv-uniform-type.c b/tests/spec/arb_uniform_buffer_object/getactiveuniformsiv-uniform-type.c
new file mode 100644
index 000000000..ecff027d7
--- /dev/null
+++ b/tests/spec/arb_uniform_buffer_object/getactiveuniformsiv-uniform-type.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * 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 getactiveuniformsiv-uniform-type.c
+ *
+ * Tests that glGetActiveUniformsiv() returns the correct enum for
+ * GL_UNIFORM_TYPE for variables in a UBO.
+ */
+
+#define _GNU_SOURCE
+#include "piglit-util-gl-common.h"
+#include "uniform-types.h"
+
+PIGLIT_GL_TEST_MAIN(
+ 10 /*window_width*/,
+ 10 /*window_height*/,
+ GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA)
+
+static bool
+test_format(const struct uniform_type *type)
+{
+ /* Using 140 to get unsigned ints. */
+ const char *fs_template =
+ "#version 140\n"
+ "layout(std140) uniform ubo {\n"
+ " float align_test;\n"
+ " %s u;\n"
+ "};\n"
+ "\n"
+ "void main() {\n"
+ " gl_FragColor = vec4(align_test);\n"
+ "}\n";
+ char *fs_source;
+ GLuint fs, prog;
+ const char *uniform_name = "u";
+ GLuint uniform_index;
+ GLint uniform_type;
+
+ asprintf(&fs_source, fs_template, type->type);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+ free(fs_source);
+ prog = piglit_link_simple_program(0, fs);
+ if (!fs || !prog) {
+ fprintf(stderr, "Failed to compile shader:\n%s", fs_source);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ glGetUniformIndices(prog, 1, &uniform_name, &uniform_index);
+ glGetActiveUniformsiv(prog, 1, &uniform_index,
+ GL_UNIFORM_TYPE, &uniform_type);
+
+ glDeleteShader(fs);
+ glDeleteProgram(prog);
+
+ printf("%-20s %20s %20s%s\n",
+ type->type,
+ piglit_get_gl_enum_name(uniform_type),
+ piglit_get_gl_enum_name(type->gl_type),
+ uniform_type == type->gl_type ? "" : " FAIL");
+
+ return uniform_type == type->gl_type;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ unsigned int i;
+
+ piglit_require_extension("GL_ARB_uniform_buffer_object");
+ piglit_require_GLSL_version(140);
+
+ printf("%-20s %20s %20s\n", "type", "GL_UNIFORM_TYPE", "expected");
+ printf("--------------------------------------------------------------\n");
+ for (i = 0; uniform_types[i].type; i++) {
+ pass = test_format(&uniform_types[i]) && pass;
+ }
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result piglit_display(void)
+{
+ /* UNREACHED */
+ return PIGLIT_FAIL;
+}