<div dir="ltr">On 20 August 2013 10:56, Nicholas Mack <span dir="ltr"><<a href="mailto:nichmack@gmail.com" target="_blank">nichmack@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 tests/spec/arb_provoking_vertex/CMakeLists.gl.txt  |   1 +<br>
 .../arb_provoking_vertex/xfb-before-flatshading.c  | 203 +++++++++++++++++++++<br>
 2 files changed, 204 insertions(+)<br>
 create mode 100644 tests/spec/arb_provoking_vertex/xfb-before-flatshading.c<br>
<br>
diff --git a/tests/spec/arb_provoking_vertex/CMakeLists.gl.txt b/tests/spec/arb_provoking_vertex/CMakeLists.gl.txt<br>
index a5ebff9..d70637c 100644<br>
--- a/tests/spec/arb_provoking_vertex/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_provoking_vertex/CMakeLists.gl.txt<br>
@@ -12,5 +12,6 @@ link_libraries (<br>
 piglit_add_executable (arb-provoking-vertex-control provoking-vertex-control.c)<br>
 piglit_add_executable (arb-provoking-vertex-initial provoking-vertex-initial.c)<br>
 piglit_add_executable (arb-quads-follow-provoking-vertex quads-follow-provoking-vertex.c)<br>
+piglit_add_executable (arb-xfb-before-flatshading xfb-before-flatshading.c)<br>
<br>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_provoking_vertex/xfb-before-flatshading.c b/tests/spec/arb_provoking_vertex/xfb-before-flatshading.c<br>
new file mode 100644<br>
index 0000000..359ad68<br>
--- /dev/null<br>
+++ b/tests/spec/arb_provoking_vertex/xfb-before-flatshading.c<br>
@@ -0,0 +1,203 @@<br>
+/**<br>
+ * Copyright © 2013 Intel Corporation<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>
+<br>
+/**<br>
+ * Test that transform feedback occurs before flatshading<br>
+ *<br>
+ * Section 2.16(Transform Feedback) of OpenGL 3.2 Core says:<br>
+ * "In transform feedback mode, attributes of the vertices of transformed<br>
+ * primitives processed by a vertex shader, or primitives generated by a<br>
+ * geometry shader if one is active, are written out to one or more buffer<br>
+ * objects. The vertices are fed back after vertex color clamping, but before<br>
+ * flatshading and clipping."<br>
+ *<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 32;<br>
+        config.supports_gl_core_version = 32;<br>
+<br>
+       config.window_width = 100;<br>
+       config.window_height = 100;<br>
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static const char *vstext =<br>
+       "#version 130\n"<br>
+       "in vec3 vert1;\n"<br>
+       "in vec3 color;\n"<br>
+       "flat out vec3 color1;\n"<br>
+       "out vec3 vert;\n"<br>
+       "void main() {\n"<br>
+       "       gl_Position = vec4(vert1, 1.);\n"<br>
+       "       vert = vert1;\n"<br>
+       "       color1 = color;\n"<br>
+       "}\n";<br>
+<br>
+static const char *fstext =<br>
+       "#version 130\n"<br>
+       "in vec3 vert;\n"<br>
+       "flat in vec3 color1;\n"<br>
+       "void main() {\n"<br>
+       "       gl_FragColor = vec4(color1, 1.);\n"<br>
+       "}\n";<br>
+<br>
+static GLuint vao;<br>
+static GLuint vertBuff;<br>
+static GLuint indexBuf;<br>
+static GLuint vertColorBuf;<br>
+<br>
+static GLfloat vertices[] = {<br>
+       -1.0, 1.0, 0.0,<br>
+        1.0, 1.0, 0.0,<br>
+        1.0,-1.0, 0.0,<br>
+       -1.0,-1.0, 0.0<br>
+};<br>
+static GLsizei vertSize = sizeof(vertices);<br>
+<br>
+static GLfloat vertColors[] = {<br>
+       1.0, 0.0, 0.0,<br>
+       0.0, 1.0, 0.0,<br>
+       0.0, 0.0, 1.0,<br>
+       0.0, 1.0, 0.0<br>
+};<br>
+static GLsizei vertColorSize = sizeof(vertColors);<br>
+<br>
+static GLuint indices[] = {<br>
+       0, 1, 2, 0, 2, 3<br>
+};<br>
+static GLsizei indSize = sizeof(indices);<br>
+<br>
+static GLuint xfb_buf;<br>
+static GLuint prog;<br>
+<br>
+/* Only capture the color data into the transform feedback buffer */<br>
+static const char *varyings[] = { "color1" };<br>
+<br>
+/* Calculate number of floats contained in the transform varyings */<br>
+static int numVaryingFloats = ARRAY_SIZE(varyings) * ARRAY_SIZE(indices) * 3;<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       bool pass = true;<br>
+       GLuint vs = 0, fs = 0;<br>
+       GLuint vertIndex;<br>
+       GLuint vertColorIndex;<br>
+<br>
+       prog = glCreateProgram();<br>
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);<br>
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fstext);<br>
+       glAttachShader(prog, vs);<br>
+       glAttachShader(prog, fs);<br>
+       glTransformFeedbackVaryings(prog, ARRAY_SIZE(varyings), varyings,<br>
+                                       GL_INTERLEAVED_ATTRIBS);<br>
+       glLinkProgram(prog);<br>
+       if(!piglit_link_check_status(prog)){<br>
+               glDeleteProgram(prog);<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+       }<br>
+<br>
+       glUseProgram(prog);<br>
+<br>
+       glGenBuffers(1, &vertBuff);<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertBuff);<br>
+       glBufferData(GL_ARRAY_BUFFER, vertSize, vertices, GL_STATIC_DRAW);<br>
+<br>
+       glGenBuffers(1, &indexBuf);<br>
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf);<br>
+       glBufferData(GL_ELEMENT_ARRAY_BUFFER, indSize,<br>
+                       indices, GL_STATIC_DRAW);<br>
+<br>
+       glGenBuffers(1, &vertColorBuf);<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertColorBuf);<br>
+       glBufferData(GL_ARRAY_BUFFER, vertColorSize,<br>
+                       vertColors, GL_STATIC_DRAW);<br>
+<br>
+       glGenVertexArrays(1, &vao);<br>
+       glBindVertexArray(vao);<br>
+<br>
+       vertIndex = glGetAttribLocation(prog, "vert1");<br>
+       vertColorIndex = glGetAttribLocation(prog, "color");<br>
+<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertBuff);<br>
+       glEnableVertexAttribArray(vertIndex);<br>
+       glVertexAttribPointer(vertIndex, 3, GL_FLOAT, GL_FALSE, 0, 0);<br>
+<br>
+       glBindBuffer(GL_ARRAY_BUFFER, vertColorBuf);<br>
+       glEnableVertexAttribArray(vertColorIndex);<br>
+       glVertexAttribPointer(vertColorIndex, 3, GL_FLOAT, GL_FALSE, 0, 0);<br>
+<br>
+       glGenBuffers(1, &xfb_buf);<br>
+       glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, xfb_buf);<br>
+       glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER,<br>
+                       numVaryingFloats * sizeof(float),<br>
+                       NULL, GL_STREAM_READ);<br>
+<br>
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       float *xBuffer;<br>
+       int i;<br>
+       bool pass = true;<br>
+<br>
+       glClearColor(0.2, 0.2, 0.2, 1.0);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       glBindVertexArray(vao);<br>
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuf);<br>
+<br>
+       glBeginTransformFeedback(GL_TRIANGLES);<br>
+       glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices),<br>
+                       GL_UNSIGNED_INT, NULL);<br>
+       glEndTransformFeedback();<br>
+<br>
+       xBuffer = (float*)glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY);<br>
+       /* Compare transform feedback color data with original color data */<br>
+       for(i = 0; i < numVaryingFloats/3; i++) {<br>
+               bool unchanged = true;<br>
+               if(xBuffer[i*3+0] != vertColors[0+3*indices[i]])<br>
+                       unchanged = false;<br>
+               if(xBuffer[i*3+1] != vertColors[1+3*indices[i]])<br>
+                       unchanged = false;<br>
+               if(xBuffer[i*3+2] != vertColors[2+3*indices[i]])<br>
+                       unchanged = false;<br>
+               if(!unchanged) {<br>
+                       printf("Vertex %d color was modified before being "<br>
+                               "copied into the transform buffer.\n", i);<br></blockquote><div><br></div><div>Generally it's easier to debug failures in tests like these if we printf the expected/actual values, e.g.:<br>
<br></div>printf("Incorrect data for vertex %d:\n", i);<br>printf("Expected (%f, %f, %f)\n", vertColors[0+3*indices[i]],<br>       vertColors[1+3*indices[i]], vertColors[2+3*indices[i]]);<br>printf("Actual (%f, %f, %f)\n", xBuffer[i*3+0], xBuffer[i*3+1],<br>
       xBuffer[i*3+2]);<br><br></div><div class="gmail_quote">With that fixed, and with the test added to all.tests in this patch (rather than in patch 5), this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div class="gmail_quote"> <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                       pass = false;<br>
+               }<br>
+       }<br>
+       glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);<br>
+<br>
+       piglit_present_results();<br>
+<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
<span class=""><font color="#888888">--<br>
1.8.3.1<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div>