[Piglit] [PATCH 6/6] nv_non_square_matrices: Add glUniformMatrix?x?fvNV tests

Rafal Mielniczuk rafal.mielniczuk2 at gmail.com
Wed Feb 26 08:18:40 PST 2014


Checks if calling glUniformMatrix?x?fvNV set correct values
to the matrix uniform.

Verifies that calling the wrong glUniformMatrix?x?fvNV function for each
uniform generates GL_INVALID_OPERATION.
---
 tests/all.py                                       |   1 +
 .../nv_non_square_matrices/CMakeLists.gles2.txt    |   1 +
 .../nv_non_square_matrices/set-uniform-matrix.c    | 196 +++++++++++++++++++++
 3 files changed, 198 insertions(+)
 create mode 100644 tests/spec/nv_non_square_matrices/set-uniform-matrix.c

diff --git a/tests/all.py b/tests/all.py
index 6698f22..38dc560 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3046,6 +3046,7 @@ nv_conditional_render['vertex_array'] = PlainExecTest(['nv_conditional_render-ve
 nv_non_square_matrices = Group()
 spec['NV_non_square_matrices'] = nv_non_square_matrices
 nv_non_square_matrices['get-active-matrix'] = concurrent_test('nv_non_square_matrices-get-active-matrix')
+nv_non_square_matrices['set-uniform-matrix'] = concurrent_test('nv_non_square_matrices-set-uniform-matrix')
 import_glsl_parser_tests(spec['NV_non_square_matrices'],
 			 os.path.join(testsDir, 'spec', 'nv_non_square_matrices'),
 			 ['compiler'])
diff --git a/tests/spec/nv_non_square_matrices/CMakeLists.gles2.txt b/tests/spec/nv_non_square_matrices/CMakeLists.gles2.txt
index 7084944..6a20578 100644
--- a/tests/spec/nv_non_square_matrices/CMakeLists.gles2.txt
+++ b/tests/spec/nv_non_square_matrices/CMakeLists.gles2.txt
@@ -9,5 +9,6 @@ link_libraries (
 )
 
 piglit_add_executable (nv_non_square_matrices-get-active-matrix get-active-matrix.c)
+piglit_add_executable (nv_non_square_matrices-set-uniform-matrix set-uniform-matrix.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/nv_non_square_matrices/set-uniform-matrix.c b/tests/spec/nv_non_square_matrices/set-uniform-matrix.c
new file mode 100644
index 0000000..55f2804
--- /dev/null
+++ b/tests/spec/nv_non_square_matrices/set-uniform-matrix.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014 Rafal Mielniczuk <rafal.mielniczuk2 at gmail.com>
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL AUTHORS AND/OR THEIR SUPPLIERS
+ * 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.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_PASS;
+}
+
+static const char * const fs_source =
+	"#version 100\n"
+	"void main() {\n"
+	"	gl_FragColor = vec4(0.0);\n"
+	"}\n"
+;
+
+static const char * const vs_sources[] = {
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat2x3 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec2(1.0, 1.0), 1.0);\n"
+	"}\n",
+
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat3x2 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec3(1.0, 1.0, 1.0), 1.0, 1.0);\n"
+	"}\n",
+
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat2x4 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec2(1.0, 1.0));\n"
+	"}\n",
+
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat4x2 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec4(1.0, 1.0, 1.0, 1.0), 1.0, 1.0);\n"
+	"}\n",
+
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat3x4 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec3(1.0, 1.0, 1.0));\n"
+	"}\n",
+
+	"#version 100\n"
+	"#extension GL_NV_non_square_matrices: require\n"
+	"uniform mat4x3 u;\n"
+	"void main() {\n"
+	"	gl_Position = vec4(u * vec4(1.0, 1.0, 1.0, 1.0), 1.0);\n"
+	"}\n",
+};
+
+typedef void (*set_function_t)(GLint, GLsizei, GLboolean, const GLfloat *);
+
+static bool
+test_uniform_matrix(const char *vs, const char *fs,
+		    set_function_t pass_fun, set_function_t fail_fun,
+		    int matrix_size, const char *matrix_name)
+{
+	static const GLfloat mat[12] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+					 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
+	GLuint prog, i;
+	GLfloat result[12];
+
+	prog = piglit_build_simple_program(vs, fs);
+	glUseProgram(prog);
+
+	/**
+	 * Set target matrix values to 1.0
+	 */
+	(*pass_fun)(glGetUniformLocation(prog, "u"),
+		    1, false, mat);
+
+	if (!piglit_check_gl_error(0)) {
+		fprintf(stderr, "glUniformMatrix failed for matrix type %s\n",
+			matrix_name);
+		return false;
+	}
+
+	memset(result, 0, sizeof result);
+
+	glGetUniformfv(prog,
+		       glGetUniformLocation(prog, "u"),
+		       result);
+
+	if (!piglit_check_gl_error(0)) {
+		fprintf(stderr, "glGetUniformfv failed for matrix type %s\n",
+			matrix_name);
+		return false;
+	}
+
+	for (i = 0; i < 12; ++i) {
+		/**
+		 * Check if all values up to matrix_size are equal to 1.
+		 * Ensure that remaining values are zeroes, so that we know,
+		 * that glGetUniformfv did not return too many values
+		 */
+		if (result[i] != ((i < matrix_size) ? 1.0 : 0.0)) {
+			fprintf(stderr,
+				"glGetUniformfv returned bad matrix "
+				"values for type %s\n",
+				matrix_name);
+			return false;
+		}
+	}
+
+	/**
+	 * Test calling wrong glUniformMatrix?x?fvNV
+	 */
+	(*fail_fun)(glGetUniformLocation(prog, "u"),
+		    1, false, mat);
+
+	if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
+		return false;
+	}
+
+	return true;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	bool pass = true;
+
+	piglit_require_extension("GL_NV_non_square_matrices");
+
+	pass = test_uniform_matrix(vs_sources[0],
+				   fs_source,
+				   glUniformMatrix2x3fvNV, glUniformMatrix3x2fvNV,
+				   6, "mat2x3") && pass;
+
+	pass = test_uniform_matrix(vs_sources[1],
+				   fs_source,
+				   glUniformMatrix3x2fvNV, glUniformMatrix2x3fvNV,
+				   6, "mat3x2") && pass;
+
+	pass = test_uniform_matrix(vs_sources[2],
+				   fs_source,
+				   glUniformMatrix2x4fvNV, glUniformMatrix4x2fvNV,
+				   8, "mat2x4") && pass;
+
+	pass = test_uniform_matrix(vs_sources[3],
+				   fs_source,
+				   glUniformMatrix4x2fvNV, glUniformMatrix2x4fvNV,
+				   8, "mat4x2") && pass;
+
+	pass = test_uniform_matrix(vs_sources[4],
+				   fs_source,
+				   glUniformMatrix3x4fvNV, glUniformMatrix4x3fvNV,
+				   12, "mat3x4") && pass;
+
+	pass = test_uniform_matrix(vs_sources[5],
+				   fs_source,
+				   glUniformMatrix4x3fvNV, glUniformMatrix3x4fvNV,
+				   12, "mat4x3") && pass;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.9.0



More information about the Piglit mailing list