[Piglit] [PATCH v2 6/6] nv_non_square_matrices: Add glUniformMatrix?x?fvNV tests
Rafal Mielniczuk
rafal.mielniczuk2 at gmail.com
Thu Feb 27 06:02:28 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.
v2: - Move empty piglit_display function to the bottom
- Make test data random
Signed-off-by: Rafal Mielniczuk <rafal.mielniczuk2 at gmail.com>
---
tests/all.py | 1 +
.../nv_non_square_matrices/CMakeLists.gles2.txt | 1 +
.../nv_non_square_matrices/set-uniform-matrix.c | 234 +++++++++++++++++++++
3 files changed, 236 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 20a3f6c..9cda06f 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..3a7f3ce
--- /dev/null
+++ b/tests/spec/nv_non_square_matrices/set-uniform-matrix.c
@@ -0,0 +1,234 @@
+/*
+ * 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
+
+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 void
+random_floats(GLfloat *array, int size)
+{
+ int i;
+
+ for (i = 0; i < size; ++i) {
+ array[i] = (float)(rand() % 10);
+ }
+}
+
+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)
+{
+ GLfloat input[12];
+ GLfloat result[12];
+ GLuint prog, i;
+
+ /**
+ * Randomize input and result arrays
+ */
+ random_floats(input, 12);
+ random_floats(result, 12);
+
+ prog = piglit_build_simple_program(vs, fs);
+ glUseProgram(prog);
+
+ /**
+ * Set target matrix values
+ */
+ (*pass_fun)(glGetUniformLocation(prog, "u"),
+ 1, false, input);
+
+ if (!piglit_check_gl_error(0)) {
+ fprintf(stderr, "glUniformMatrix failed for matrix type %s\n",
+ matrix_name);
+ return false;
+ }
+
+ /**
+ * Get target matrix values
+ */
+ 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;
+ }
+
+ /**
+ * Check if all values up to matrix_size are equal to the input matrix.
+ * Ensure that remaining values are unchanged, so that we know,
+ * that glGetUniformfv did not return too many values
+ */
+ for (i = 0; i < 12; ++i) {
+ if (result[i] != ((i < matrix_size) ? input[i] : result[i])) {
+ fprintf(stderr,
+ "glGetUniformfv returned bad matrix "
+ "values for type %s\n",
+ matrix_name);
+ return false;
+ }
+ }
+
+ /**
+ * Ensure that expected GL_INVALID_OPERATION will come from
+ * glGetUniformLocation call
+ */
+ if (!piglit_check_gl_error(GL_NO_ERROR)) {
+ fprintf(stderr, "Unexpected GL error detected in %s test\n",
+ matrix_name);
+ return false;
+ }
+
+ /**
+ * Test calling wrong glUniformMatrix?x?fvNV
+ */
+ (*fail_fun)(glGetUniformLocation(prog, "u"),
+ 1, false, input);
+
+ if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
+ fprintf(stderr,
+ "glGetUniformLocation did not return "
+ "expected error for wrong matrix type "
+ "in %s test\n", matrix_name);
+ return false;
+ }
+
+ return true;
+}
+
+void piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+
+ piglit_require_extension("GL_NV_non_square_matrices");
+
+ srand(0);
+
+ pass = test_uniform_matrix(vs_sources[0],
+ fs_source,
+ glUniformMatrix2x3fvNV,
+ glUniformMatrix4x3fvNV,
+ 6, "mat2x3") && pass;
+
+ pass = test_uniform_matrix(vs_sources[1],
+ fs_source,
+ glUniformMatrix3x2fvNV,
+ glUniformMatrix3x4fvNV,
+ 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,
+ glUniformMatrix3x2fvNV,
+ 12, "mat3x4") && pass;
+
+ pass = test_uniform_matrix(vs_sources[5],
+ fs_source,
+ glUniformMatrix4x3fvNV,
+ glUniformMatrix2x3fvNV,
+ 12, "mat4x3") && pass;
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_PASS;
+}
--
1.9.0
More information about the Piglit
mailing list