commit 5dc4db0c84420eae6871b385ab93917a7e938c9e Author: Alexander Sabourenkov Date: Wed Nov 2 05:02:30 2011 +0400 add glsl-pointvarying test diff --git a/tests/all.tests b/tests/all.tests index 4648507..e189c2e 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -378,6 +378,7 @@ add_plain_test(shaders, 'getuniform-02') add_plain_test(shaders, 'glsl-invalid-asm-01') add_plain_test(shaders, 'glsl-invalid-asm-02') add_plain_test(shaders, 'glsl-novertexdata') +add_plain_test(shaders, 'glsl-pointvarying') add_plain_test(shaders, 'glsl-preprocessor-comments') add_plain_test(shaders, 'glsl-reload-source') add_plain_test(shaders, 'glsl-uniform-out-of-bounds') diff --git a/tests/shaders/CMakeLists.gl.txt b/tests/shaders/CMakeLists.gl.txt index 175458c..cb19cf5 100644 --- a/tests/shaders/CMakeLists.gl.txt +++ b/tests/shaders/CMakeLists.gl.txt @@ -65,6 +65,7 @@ add_executable (getuniform-02 getuniform-02.c) add_executable (glsl-invalid-asm-01 glsl-invalid-asm-01.c) add_executable (glsl-invalid-asm-02 glsl-invalid-asm-02.c) add_executable (glsl-novertexdata glsl-novertexdata.c) +add_executable (glsl-pointvarying glsl-pointvarying.c) add_executable (glsl-orangebook-ch06-bump glsl-orangebook-ch06-bump.c) add_executable (glsl-reload-source glsl-reload-source.c) add_executable (glsl-unused-varying glsl-unused-varying.c) diff --git a/tests/shaders/glsl-pointvarying.c b/tests/shaders/glsl-pointvarying.c new file mode 100644 index 0000000..f330bea --- /dev/null +++ b/tests/shaders/glsl-pointvarying.c @@ -0,0 +1,123 @@ +/* + * Copyright © 2009 Intel Corporation + * Copyright © 2010 VMware, Inc. + * + * 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. + */ + +/** + * \file glsl-pointvarying.c + * + * Test if we can reliably pass colors via varyings between shaders. + * + * This test is based on the glsl-novertexdata.c test written + * by Ian. + * + * \author Ian Romanick + * \author Brian Paul + * \author Alexander Sabourenkov + */ + +#include "piglit-util.h" +#include "piglit-framework.h" + +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; +int piglit_width = 100; +int piglit_height = 100; + +static const GLchar *vertShaderText = + "attribute vec4 attrib;\n" + "varying float comp;\n" + "void main()\n" + "{\n" + " comp = 1.0;\n" + " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n" + "} \n"; + +static const GLchar *fragShaderText = + "varying float comp;\n" + "void main()\n" + "{\n" + " gl_FragColor = vec4(comp, 0.0, comp, 1.0);\n" + "} \n"; + +enum piglit_result +piglit_display(void) +{ + static const GLfloat expColor[4] = {0, 1, 0, 1}; + GLint vs, fs; + GLint prog; + GLint stat; + enum piglit_result result; + + vs = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vs, 1, &vertShaderText, NULL); + + glCompileShader(vs); + glGetShaderiv(vs, GL_COMPILE_STATUS, &stat); + if (!stat) { + printf("glsl-pointvarying: error compiling vertex shader!\n"); + exit(1); + } + + fs = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(vs, 1, &fragShaderText, NULL); + + glCompileShader(fs); + glGetShaderiv(fs, GL_COMPILE_STATUS, &stat); + if (!stat) { + printf("glsl-pointvarying: error compiling fragment shader!\n"); + exit(1); + } + + prog = glCreateProgram(); + glAttachShader(prog, vs); + glAttachShader(prog, fs); + glLinkProgram(prog); + glUseProgram(prog); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + + glClear(GL_COLOR_BUFFER_BIT); + + glPointSize(20.0); + glDrawArrays(GL_POINTS, 0, 1); + + result = piglit_probe_pixel_rgba(piglit_width /2, piglit_height / 2, + expColor) + ? PIGLIT_PASS : PIGLIT_FAIL; + + glutSwapBuffers(); + + return result; +} + + +void +piglit_init(int argc, char **argv) +{ + if (!GLEW_VERSION_2_0) { + printf("Requires OpenGL 2.0\n"); + piglit_report_result(PIGLIT_SKIP); + exit(1); + } +}