On 18 October 2011 17:33, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net">eric@anholt.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
From: tom fogal <<a href="mailto:tfogal@sci.utah.edu">tfogal@sci.utah.edu</a>><br>
<br>
v2: lots of hacking by anholt to make it look more like a normal<br>
piglit test and make all results visible at once.<br>
---<br>
tests/all.tests | 1 +<br>
tests/shaders/CMakeLists.gl.txt | 1 +<br>
tests/shaders/glsl-fs-normalmatrix.c | 166 ++++++++++++++++++++++++++++++++++<br>
3 files changed, 168 insertions(+), 0 deletions(-)<br>
create mode 100644 tests/shaders/glsl-fs-normalmatrix.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 0248164..89bd03d 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -396,6 +396,7 @@ add_plain_test(shaders, 'glsl-fs-loop')<br>
add_plain_test(shaders, 'glsl-fs-loop-nested')<br>
add_plain_test(shaders, 'glsl-fs-mix')<br>
add_plain_test(shaders, 'glsl-fs-mix-constant')<br>
+add_concurrent_test(shaders, 'glsl-fs-normalmatrix')<br>
add_plain_test(shaders, 'glsl-fs-pointcoord')<br>
add_plain_test(shaders, 'glsl-fs-raytrace-bug27060')<br>
add_plain_test(shaders, 'glsl-fs-sampler-numbering')<br>
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt<br>
index 3dce256..ed72b21 100644<br>
--- a/tests/shaders/CMakeLists.gl.txt<br>
+++ b/tests/shaders/CMakeLists.gl.txt<br>
@@ -82,6 +82,7 @@ add_executable (glsl-fs-loop glsl-fs-loop.c)<br>
add_executable (glsl-fs-loop-nested glsl-fs-loop-nested.c)<br>
add_executable (glsl-fs-mix glsl-fs-mix.c)<br>
add_executable (glsl-fs-mix-constant glsl-fs-mix-constant.c)<br>
+add_executable (glsl-fs-normalmatrix glsl-fs-normalmatrix.c)<br>
IF (NOT MSVC)<br>
add_executable (glsl-fs-raytrace-bug27060 glsl-fs-raytrace-bug27060.c)<br>
ENDIF (NOT MSVC)<br>
diff --git a/tests/shaders/glsl-fs-normalmatrix.c b/tests/shaders/glsl-fs-normalmatrix.c<br>
new file mode 100644<br>
index 0000000..b55a80a<br>
--- /dev/null<br>
+++ b/tests/shaders/glsl-fs-normalmatrix.c<br>
@@ -0,0 +1,166 @@<br>
+/*<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
+ * Authors:<br>
+ * Tom Fogal<br>
+ *<br>
+ */<br>
+<br>
+/** @file glsl-fs-normalmatrix.c<br>
+ *<br>
+ * Tests gl_NormalMatrix for appropriate initial values.<br>
+ */<br>
+<br>
+#include "piglit-util.h"<br>
+<br>
+int piglit_width = 30, piglit_height = 30;<br>
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;<br>
+<br>
+static const char vert[] = {<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_Position = ftransform();\n"<br>
+ "}\n"<br>
+};<br>
+<br>
+/* Creates a fragment shader which colors everything green if<br>
+ * gl_NormalMatrix[col].row<br>
+ * is between 'low' and 'high', otherwise everything is red.<br>
+ * The returned string is dynamically allocated and must be free'd by the<br>
+ * caller.<br>
+ */<br>
+static char *<br>
+generate_fs(int row, int col)<br>
+{<br>
+ static const char *fs_template =<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " if (%f <= gl_NormalMatrix[%u].%c &&\n"<br>
+ " gl_NormalMatrix[%u].%c <= %f)\n"<br>
+ " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"<br>
+ " else\n"<br>
+ " gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);\n"<br>
+ "}\n";<br></blockquote><div><br>I think it would be clearer to use uniforms rather than all of this string interpolation. If we did that, then if I'm not mistaken, this whole test could be converted into a shader_runner test..<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+ char *result;<br>
+ char row_char = "xyz"[row];<br>
+ float expected_matrix[] = {<br>
+ 1, 0, 0,<br>
+ 0, 1, 0,<br>
+ 0, 0, 1,<br>
+ };<br>
+ float expected = expected_matrix[row * 3 + col];<br>
+ float low = expected - .01;<br>
+ float high = expected + .01;<br>
+<br>
+ if (0) {<br>
+ printf("test: %g <= gl_NormalMatrix[%u].%c <= %g\n",<br>
+ low, col, row_char, high);<br>
+ }<br>
+<br>
+ result = calloc(1, strlen(fs_template) + 100);<br>
+ sprintf(result, fs_template, low, col, row_char, col, row_char, high);<br>
+<br>
+ return result;<br>
+}<br>
+<br>
+static bool<br>
+test(int row, int col)<br>
+{<br>
+ GLint vs, fs, prog;<br>
+ float green[] = {0.0, 1.0, 0.0, 0.0};<br>
+ char *fs_source;<br>
+ bool pass;<br>
+ int w = piglit_width / 3;<br>
+ int h = piglit_height / 3;<br>
+ int x = col * w;<br>
+ int y = (2 - row) * h;<br>
+<br>
+ fs_source = generate_fs(row, col);<br>
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);<br>
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);<br>
+ prog = piglit_link_simple_program(vs, fs);<br>
+ glUseProgram(prog);<br>
+<br>
+ if (!fs || !vs || !prog) {<br>
+ printf("Failed to compile with fragment shader:\n%s\n",<br>
+ fs_source);<br>
+ return false;<br>
+ }<br>
+<br>
+ piglit_draw_rect(x, y, w, h);<br>
+ pass = piglit_probe_rect_rgb(x, y, w, h, green);<br>
+<br>
+ /* clean up shaders. */<br>
+ free(fs_source);<br>
+ glUseProgram(0);<br>
+ glDeleteShader(vs);<br>
+ glDeleteShader(fs);<br>
+ glDeleteProgram(prog);<br>
+<br>
+ return pass;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+ GLboolean pass = GL_TRUE;<br>
+ int row, col;<br>
+<br>
+ /* Set up projection matrix so we can just draw using window<br>
+ * coordinates.<br>
+ */<br>
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);<br>
+<br>
+ /* Set the modelview to identity, which means normalmatrix<br>
+ * should also be identity.<br>
+ */<br>
+ glMatrixMode(GL_MODELVIEW);<br>
+ glLoadIdentity();<br>
+<br>
+ for (row = 0; row < 3; row++) {<br>
+ for (col = 0; col < 3; col++) {<br>
+ pass = test(row, col) && pass;<br>
+ }<br>
+ }<br>
+<br>
+ piglit_present_results();<br>
+<br>
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ if (!GLEW_VERSION_2_0) {<br>
+ printf("Requires OpenGL 2.0\n");<br>
+ piglit_report_result(PIGLIT_SKIP);<br>
+ }<br>
+ piglit_require_GLSL();<br>
+<br>
+ printf("gl_NormalMatrix access results are displayed as:\n");<br>
+ printf(" x y z\n");<br>
+ printf(" +-+-+-+\n");<br>
+ printf("row 0 |1|0|0|\n");<br>
+ printf(" +-+-+-+\n");<br>
+ printf("row 1 |0|1|0|\n");<br>
+ printf(" +-+-+-+\n");<br>
+ printf("row 2 |0|0|1|\n");<br>
+ printf(" +-+-+-+\n");<br>
+}<br>
<font color="#888888">--<br>
1.7.7<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></blockquote></div><br>