[Piglit] [PATCH 04/10] GL_ARB_ubo: New test for glGetActiveUniformsiv(GL_UNIFORM_TYPE).

Eric Anholt eric at anholt.net
Thu Aug 9 09:22:10 PDT 2012


I would have tested the getter on non-ubo uniforms, except I can't
just use std140 layout to trivially guarantee activeness for them.
---
 tests/all.tests                                    |    1 +
 .../arb_uniform_buffer_object/CMakeLists.gl.txt    |    1 +
 .../getactiveuniformsiv-uniform-type.c             |  106 ++++++++++++++++++++
 3 files changed, 108 insertions(+)
 create mode 100644 tests/spec/arb_uniform_buffer_object/getactiveuniformsiv-uniform-type.c

diff --git a/tests/all.tests b/tests/all.tests
index 2a8417c..1fb6038 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1905,6 +1905,7 @@ arb_uniform_buffer_object['getactiveuniformblockiv-uniform-block-data-size'] = c
 arb_uniform_buffer_object['getactiveuniformblockname'] = concurrent_test('arb_uniform_buffer_object-getactiveuniformblockname')
 arb_uniform_buffer_object['getactiveuniformname'] = concurrent_test('arb_uniform_buffer_object-getactiveuniformname')
 arb_uniform_buffer_object['getactiveuniformsiv-uniform-block-index'] = concurrent_test('arb_uniform_buffer_object-getactiveuniformsiv-uniform-block-index')
+arb_uniform_buffer_object['getactiveuniformsiv-uniform-type'] = concurrent_test('arb_uniform_buffer_object-getactiveuniformsiv-uniform-type')
 arb_uniform_buffer_object['getintegeri_v'] = concurrent_test('arb_uniform_buffer_object-getintegeri_v')
 arb_uniform_buffer_object['getprogramiv'] = concurrent_test('arb_uniform_buffer_object-getprogramiv')
 arb_uniform_buffer_object['getuniformblockindex'] = concurrent_test('arb_uniform_buffer_object-getuniformblockindex')
diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
index 0285b46..4f772bf 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 0000000..ecff027
--- /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;
+}
-- 
1.7.10.4



More information about the Piglit mailing list