Before I get to specific comments, are you familiar with Piglit's "shader runner" framework (look at any of the Piglit files that end in ".shader_test"). It seems like this test could be rewritten as a shader runner test--that would make it shorter and more readable, and save a compilation step.<br>
<br>Other comments follow...<br><br>On 1 November 2011 03:59, <span dir="ltr"><<a href="mailto:jian.j.zhao@intel.com">jian.j.zhao@intel.com</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: Jian Zhao <<a href="mailto:jian.j.zhao@intel.com">jian.j.zhao@intel.com</a>><br>
<br>
Per the GL C Specification on glLinkProgram, it should use fixed function pipeline if there is no vertex shader or fragment shader. The spec is as following:<br>
"If program contains shader objects<br>
of type GL_VERTEX_SHADER but does not<br>
contain shader objects of type<br>
GL_FRAGMENT_SHADER, the vertex shader will<br>
be linked against the implicit interface for fixed functionality<br>
fragment processing. Similarly, if<br>
program contains shader objects of type<br>
GL_FRAGMENT_SHADER but it does not contain<br>
shader objects of type GL_VERTEX_SHADER,<br>
the fragment shader will be linked against the implicit<br>
interface for fixed functionality vertex processing."<br></blockquote><div><br>When quoting from the spec, can you site the particular version of the GL spec that you're quoting, and the section number you're quoting from? That will make it easier to figure out what went wrong if this test ever fails.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
---<br>
tests/shaders/CMakeLists.gl.txt | 1 +<br>
tests/shaders/glsl-no-vertex-shader-compiled.c | 165 ++++++++++++++++++++++++<br>
2 files changed, 166 insertions(+), 0 deletions(-)<br>
create mode 100644 tests/shaders/glsl-no-vertex-shader-compiled.c<br>
<br>
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt<br>
index 3dce256..d009395 100644<br>
--- a/tests/shaders/CMakeLists.gl.txt<br>
+++ b/tests/shaders/CMakeLists.gl.txt<br>
@@ -28,6 +28,7 @@ add_executable (fp-condition_codes-01 fp-condition_codes-01.c)<br>
add_executable (fp-lit-mask fp-lit-mask.c)<br>
add_executable (fp-lit-src-equals-dst fp-lit-src-equals-dst.c)<br>
add_executable (fp-fog fp-fog.c)<br>
+add_executable (glsl-no-vertex-shader-compiled glsl-no-vertex-shader-compiled.c)<br>
add_executable (fp-formats fp-formats.c)<br>
add_executable (fp-fragment-position fp-fragment-position.c)<br>
add_executable (fp-generic fp-generic.c)<br>
diff --git a/tests/shaders/glsl-no-vertex-shader-compiled.c b/tests/shaders/glsl-no-vertex-shader-compiled.c<br>
new file mode 100644<br>
index 0000000..0f90f6b<br>
--- /dev/null<br>
+++ b/tests/shaders/glsl-no-vertex-shader-compiled.c<br>
@@ -0,0 +1,165 @@<br>
+/*<br>
+ * Copyright © 2011 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>
+ * Authors:<br>
+ * Jian Zhao <<a href="mailto:jian.j.zhao@intel.com">jian.j.zhao@intel.com</a>><br>
+ *<br>
+ */<br>
+<br>
+/** @file glsl-no-vertex-shader-compiled.c<br>
+ *<br>
+ * Tests that OpenGL shader should work well when only have fragment shader(or vertext shader), but now if without vertext shader it doesn't work.<br>
+ In the OpenGL spec for glLinkProgram, as following says:<br>
+ "If program contains shader objects<br>
+ of type GL_VERTEX_SHADER but does not<br>
+ contain shader objects of type<br>
+ GL_FRAGMENT_SHADER, the vertex shader will<br>
+ be linked against the implicit interface for fixed functionality<br>
+ fragment processing. Similarly, if<br>
+ program contains shader objects of type<br>
+ GL_FRAGMENT_SHADER but it does not contain<br>
+ shader objects of type GL_VERTEX_SHADER,<br>
+ the fragment shader will be linked against the implicit<br>
+ interface for fixed functionality vertex processing."<br>
+ *<br>
+ */<br>
+<br>
+#include "piglit-util.h"<br>
+#include "piglit-framework.h"<br>
+<br>
+int piglit_width = 100, piglit_height = 100;<br>
+int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;<br>
+<br>
+static GLint prog;<br>
+<br>
+static const char fs_vector_template[] =<br>
+"#version 120\n"<br>
+"void myfunc2(void); \n"<br>
+"void myfunc3(void); \n"<br>
+"void main() \n"<br>
+"{ \n"<br>
+" gl_FragColor = gl_Color; \n"<br>
+" myfunc2(); \n"<br>
+"} \n"<br>
+"void myfunc2(void) \n"<br>
+"{ \n"<br>
+" gl_FragColor = vec4(0.2,0.2,0.2, 1.0); \n"<br>
+" myfunc3(); \n"<br>
+"} \n"<br>
+"void myfunc3(void) \n"<br>
+"{ \n"<br>
+" gl_FragColor = vec4(0.2,0.8,0.2,1.0); \n"<br>
+"} \n";<br>
+<br></blockquote><div><br>Are you trying to test something about the behavior of function calls here? If so, that should be split into its own test, with a comment explaining what you're trying to accomplish. If not, we should use the simplest possible fragment shader that allows us to test what we're trying to test, e.g.:<br>
<br>void main()<br>{<br> gl_FragColor = vec4(0.2, 0.8, 0.2, 1.0);<br>} <br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+ GLboolean result = PIGLIT_PASS;<br>
+ GLfloat expectedColor[4] = {0.2, 0.8, 0.2, 1.0};<br>
+<br>
+ glClearColor(1.0, 0.1, 0.1, 0.0);<br>
+ glClear(GL_COLOR_BUFFER_BIT );<br>
+<br>
+ glColor4f(0.0, 1.0, 0.0, 0.0);<br>
+ glBegin(GL_QUADS);<br>
+ glVertex3f(0.0, 0.0, 0.0);<br>
+ glVertex3f(0.5, 0.0, 0.0);<br>
+ glVertex3f(0.5, 0.5, 0.0);<br>
+ glVertex3f(0.0, 0.5, 0.0);<br>
+ glEnd();<br>
+<br>
+ result = piglit_probe_pixel_rgba(piglit_width /2, piglit_height / 2,<br>
+ expectedColor) ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+ glutSwapBuffers();<br>
+<br>
+ return result;<br>
+}<br>
+<br>
+static GLuint compile_shader(GLenum shaderType, const char * text)<br>
+{<br>
+ GLuint shader;<br>
+ GLint status;<br>
+<br>
+ shader = glCreateShaderObjectARB(shaderType);<br>
+ glShaderSourceARB(shader, 1, (const GLchar **)&text, NULL);<br>
+ glCompileShaderARB(shader);<br>
+<br>
+ glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);<br>
+ if (!status) {<br>
+ GLchar log[1000];<br>
+ GLsizei len;<br>
+ glGetInfoLogARB(shader, 1000, &len, log);<br>
+ fprintf(stderr, "Error: problem compiling shader: %s\n", log);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ return shader;<br>
+}<br>
+<br>
+static GLuint link_program(GLuint fs)<br>
+{<br>
+ GLuint program;<br>
+ GLint status;<br>
+<br>
+ program = glCreateProgramObjectARB();<br>
+<br>
+ if (fs)<br>
+ glAttachObjectARB(program, fs);<br>
+<br>
+ glLinkProgramARB(program);<br>
+ glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &status);<br>
+ if (!status) {<br>
+ GLchar log[1000];<br>
+ GLsizei len;<br>
+ glGetInfoLogARB(program, 1000, &len, log);<br>
+ fprintf(stderr, "Error: problem linking program: %s\n", log);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ return program;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ GLint fs;<br>
+ char *fs_buffer;<br>
+<br>
+ if (!GLEW_VERSION_2_0 || !GLEW_ARB_shader_objects || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) {<br>
+ printf("Requires ARB_shader_objects and ARB_{vertex,fragment}_shader\n");<br>
+ piglit_report_result(PIGLIT_SKIP);<br>
+ }<br>
+<br>
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);<br>
+<br>
+ fs_buffer = (char *) malloc(sizeof(char) * (strlen(fs_vector_template)+1));<br>
+ strcpy(fs_buffer, fs_vector_template);<br>
+ fs = compile_shader(GL_FRAGMENT_SHADER_ARB, fs_buffer);<br>
+<br>
+ prog = link_program(fs);<br>
+<br>
+ glUseProgramObjectARB(prog);<br>
+<br>
+ if(fs_buffer)<br>
+ free(fs_buffer);<br>
+}<br>
<font color="#888888">--<br>
1.7.0.1<br>
<br>
</font><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>
<br></blockquote></div><br>