[Piglit] [PATCH] Test case on rendering with only fragment shader but no vertex shader.
jian.j.zhao at intel.com
jian.j.zhao at intel.com
Tue Nov 1 03:59:52 PDT 2011
From: Jian Zhao <jian.j.zhao at intel.com>
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:
"If program contains shader objects
of type GL_VERTEX_SHADER but does not
contain shader objects of type
GL_FRAGMENT_SHADER, the vertex shader will
be linked against the implicit interface for fixed functionality
fragment processing. Similarly, if
program contains shader objects of type
GL_FRAGMENT_SHADER but it does not contain
shader objects of type GL_VERTEX_SHADER,
the fragment shader will be linked against the implicit
interface for fixed functionality vertex processing."
---
tests/shaders/CMakeLists.gl.txt | 1 +
tests/shaders/glsl-no-vertex-shader-compiled.c | 165 ++++++++++++++++++++++++
2 files changed, 166 insertions(+), 0 deletions(-)
create mode 100644 tests/shaders/glsl-no-vertex-shader-compiled.c
diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt
index 3dce256..d009395 100644
--- a/tests/shaders/CMakeLists.gl.txt
+++ b/tests/shaders/CMakeLists.gl.txt
@@ -28,6 +28,7 @@ add_executable (fp-condition_codes-01 fp-condition_codes-01.c)
add_executable (fp-lit-mask fp-lit-mask.c)
add_executable (fp-lit-src-equals-dst fp-lit-src-equals-dst.c)
add_executable (fp-fog fp-fog.c)
+add_executable (glsl-no-vertex-shader-compiled glsl-no-vertex-shader-compiled.c)
add_executable (fp-formats fp-formats.c)
add_executable (fp-fragment-position fp-fragment-position.c)
add_executable (fp-generic fp-generic.c)
diff --git a/tests/shaders/glsl-no-vertex-shader-compiled.c b/tests/shaders/glsl-no-vertex-shader-compiled.c
new file mode 100644
index 0000000..0f90f6b
--- /dev/null
+++ b/tests/shaders/glsl-no-vertex-shader-compiled.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * 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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * 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 NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Authors:
+ * Jian Zhao <jian.j.zhao at intel.com>
+ *
+ */
+
+/** @file glsl-no-vertex-shader-compiled.c
+ *
+ * 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.
+ In the OpenGL spec for glLinkProgram, as following says:
+ "If program contains shader objects
+ of type GL_VERTEX_SHADER but does not
+ contain shader objects of type
+ GL_FRAGMENT_SHADER, the vertex shader will
+ be linked against the implicit interface for fixed functionality
+ fragment processing. Similarly, if
+ program contains shader objects of type
+ GL_FRAGMENT_SHADER but it does not contain
+ shader objects of type GL_VERTEX_SHADER,
+ the fragment shader will be linked against the implicit
+ interface for fixed functionality vertex processing."
+ *
+ */
+
+#include "piglit-util.h"
+#include "piglit-framework.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;
+
+static GLint prog;
+
+static const char fs_vector_template[] =
+"#version 120\n"
+"void myfunc2(void); \n"
+"void myfunc3(void); \n"
+"void main() \n"
+"{ \n"
+" gl_FragColor = gl_Color; \n"
+" myfunc2(); \n"
+"} \n"
+"void myfunc2(void) \n"
+"{ \n"
+" gl_FragColor = vec4(0.2,0.2,0.2, 1.0); \n"
+" myfunc3(); \n"
+"} \n"
+"void myfunc3(void) \n"
+"{ \n"
+" gl_FragColor = vec4(0.2,0.8,0.2,1.0); \n"
+"} \n";
+
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean result = PIGLIT_PASS;
+ GLfloat expectedColor[4] = {0.2, 0.8, 0.2, 1.0};
+
+ glClearColor(1.0, 0.1, 0.1, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT );
+
+ glColor4f(0.0, 1.0, 0.0, 0.0);
+ glBegin(GL_QUADS);
+ glVertex3f(0.0, 0.0, 0.0);
+ glVertex3f(0.5, 0.0, 0.0);
+ glVertex3f(0.5, 0.5, 0.0);
+ glVertex3f(0.0, 0.5, 0.0);
+ glEnd();
+
+ result = piglit_probe_pixel_rgba(piglit_width /2, piglit_height / 2,
+ expectedColor) ? PIGLIT_PASS : PIGLIT_FAIL;
+ glutSwapBuffers();
+
+ return result;
+}
+
+static GLuint compile_shader(GLenum shaderType, const char * text)
+{
+ GLuint shader;
+ GLint status;
+
+ shader = glCreateShaderObjectARB(shaderType);
+ glShaderSourceARB(shader, 1, (const GLchar **)&text, NULL);
+ glCompileShaderARB(shader);
+
+ glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+ if (!status) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetInfoLogARB(shader, 1000, &len, log);
+ fprintf(stderr, "Error: problem compiling shader: %s\n", log);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ return shader;
+}
+
+static GLuint link_program(GLuint fs)
+{
+ GLuint program;
+ GLint status;
+
+ program = glCreateProgramObjectARB();
+
+ if (fs)
+ glAttachObjectARB(program, fs);
+
+ glLinkProgramARB(program);
+ glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &status);
+ if (!status) {
+ GLchar log[1000];
+ GLsizei len;
+ glGetInfoLogARB(program, 1000, &len, log);
+ fprintf(stderr, "Error: problem linking program: %s\n", log);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ return program;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLint fs;
+ char *fs_buffer;
+
+ if (!GLEW_VERSION_2_0 || !GLEW_ARB_shader_objects || !GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) {
+ printf("Requires ARB_shader_objects and ARB_{vertex,fragment}_shader\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+ fs_buffer = (char *) malloc(sizeof(char) * (strlen(fs_vector_template)+1));
+ strcpy(fs_buffer, fs_vector_template);
+ fs = compile_shader(GL_FRAGMENT_SHADER_ARB, fs_buffer);
+
+ prog = link_program(fs);
+
+ glUseProgramObjectARB(prog);
+
+ if(fs_buffer)
+ free(fs_buffer);
+}
--
1.7.0.1
More information about the Piglit
mailing list