Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-useprogram-displaylist.c
blobb308d2ec6c92e41134e74e35c26d0ac84b7dc4ec
1 /*
2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Ben Holmes <shranzel@hotmail.com>
28 * tests for bug fdo 23746. The bug prevents glUseProgram from working when
29 * called within a display list.
32 #include "piglit-util.h"
34 int piglit_width = 400, piglit_height = 300;
35 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
37 static GLint progr;
38 static GLint progg;
39 static GLint fsr;
40 static GLint fsg;
41 static GLint vs;
42 static GLuint list;
44 static GLfloat vertices[12] = {150.0, 125.0, 0.0,
45 150.0, 175.0, 0.0,
46 100.0, 125.0, 0.0,
47 100.0, 175.0, 0.0};
49 static const char *vertShaderText =
50 "void main()\n"
51 "{ \n"
52 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
53 "} \n";
55 static const char *fragShaderTextRed =
56 "void main()\n"
57 "{ \n"
58 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
59 "} \n";
61 static const char *fragShaderTextGreen =
62 "void main()\n"
63 "{ \n"
64 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
65 "} \n";
67 static void
68 compileLinkProg(void)
70 GLint stat;
72 vs = glCreateShader(GL_VERTEX_SHADER);
73 fsr = glCreateShader(GL_FRAGMENT_SHADER);
74 fsg = glCreateShader(GL_FRAGMENT_SHADER);
75 glShaderSource(vs, 1, (const GLchar **) &vertShaderText, NULL);
76 glShaderSource(fsr, 1, (const GLchar **) &fragShaderTextRed, NULL);
77 glShaderSource(fsg, 1, (const GLchar **) &fragShaderTextGreen, NULL);
78 glCompileShader(vs);
79 glGetShaderiv(vs, GL_COMPILE_STATUS, &stat);
80 if (!stat) {
81 printf("error compiling vertex shader!\n");
82 exit(1);
84 glCompileShader(fsr);
85 glGetShaderiv(fsr, GL_COMPILE_STATUS, &stat);
86 if (!stat) {
87 printf("error compiling fragment red shader!\n");
88 exit(1);
91 glCompileShader(fsg);
92 glGetShaderiv(fsg, GL_COMPILE_STATUS, &stat);
93 if(!stat) {
94 printf("error compiling fragment green shader!\n");
95 exit(1);
98 progr = glCreateProgram();
99 glAttachShader(progr, vs);
100 glAttachShader(progr, fsr);
101 glLinkProgram(progr);
103 progg = glCreateProgram();
104 glAttachShader(progg, vs);
105 glAttachShader(progg, fsg);
106 glLinkProgram(progg);
109 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat),
110 vertices);
112 glEnableVertexAttribArray(0);
114 list = glGenLists(1);
115 glNewList(list, GL_COMPILE);
116 glUseProgram(progg);
117 glEndList();
121 void
122 piglit_init(int argc, char **argv)
124 if (!GLEW_VERSION_2_0) {
125 printf("Requires OpenGL 2.0\n");
126 piglit_report_result(PIGLIT_SKIP);
129 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
131 glClearColor(0.2, 0.2, 0.2, 1.0);
133 compileLinkProg();
136 enum piglit_result
137 piglit_display(void)
139 GLfloat green[3] = {0.0, 1.0, 0.0};
140 GLboolean pass = GL_TRUE;
142 glClear(GL_COLOR_BUFFER_BIT);
144 glUseProgram(progr);
145 glCallList(list);
147 glDrawArrays(GL_TRIANGLE_STRIP,0,4);
149 pass = piglit_probe_pixel_rgb(125, 150, green);
151 glFinish();
152 glutSwapBuffers();
154 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;