Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / fp-incomplete-tex.c
blobcd6beac1d32866c9ae4d76b9f3d3dad087891be3
1 /*
2 * Copyright (c) The Piglit project 2007
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /**
25 * According to the ARB_fragment_program spec, section 3.11.6,
26 * sampling an incomplete texture image yields (0,0,0,1).
29 #include "piglit-util.h"
31 int piglit_width = 100, piglit_height = 100;
32 int piglit_window_mode = GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH;
34 #define NUM_PROGRAMS 5
36 static GLuint FragProg[NUM_PROGRAMS];
38 static const char* const ProgramText[NUM_PROGRAMS] = {
39 "!!ARBfp1.0\n"
40 "TEX result.color, fragment.color, texture[0], 2D;\n"
41 "END",
43 "!!ARBfp1.0\n"
44 "TEX result.color, fragment.color, texture[0], 3D;\n"
45 "END",
47 "!!ARBfp1.0\n"
48 "TEX result.color, fragment.color, texture[0], 1D;\n"
49 "END",
51 "!!ARBfp1.0\n"
52 "TEX result.color, fragment.color, texture[0], CUBE;\n"
53 "END",
55 "!!ARBfp1.0\n"
56 "TEX result.color, fragment.color, texture[0], RECT;\n"
57 "END"
60 static void DoFrame(void)
62 int i;
64 glClearColor(0.3, 0.3, 0.3, 0.3);
65 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
67 glEnable(GL_FRAGMENT_PROGRAM_ARB);
69 for(i = 0; i < NUM_PROGRAMS; ++i) {
70 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[i]);
72 glPushMatrix();
73 glTranslatef(i/2, i%2, 0);
74 glBegin(GL_QUADS);
75 glVertex2f(0, 0);
76 glVertex2f(1, 0);
77 glVertex2f(1, 1);
78 glVertex2f(0, 1);
79 glEnd();
80 glPopMatrix();
83 glutSwapBuffers();
86 static const struct {
87 const char* name;
88 float x, y;
89 float expected[4];
90 } Probes[] = {
92 "incomplete 2D",
93 0.5, 0.5,
94 { 0,0,0,1 }
97 "incomplete 3D",
98 0.5, 1.5,
99 { 0,0,0,1 }
102 "incomplete 1D",
103 1.5, 0.5,
104 { 0,0,0,1 }
107 "incomplete CUBE",
108 1.5, 1.5,
109 { 0,0,0,1 }
112 "incomplete RECT",
113 2.5, 0.5,
114 { 0,0,0,1 }
118 "sanity",
119 2.5, 1.5,
120 { 0.3,0.3,0.3,0.3 }
123 // Sentinel!
126 0, 0,
127 { 0, 0, 0, 0 }
131 static int DoTest( void )
133 int idx;
134 GLfloat dmax;
136 glReadBuffer( GL_FRONT );
137 dmax = 0;
139 idx = 0;
140 while(Probes[idx].name) {
141 GLfloat probe[4];
142 GLfloat delta[4];
143 int i;
145 glReadPixels((int)(Probes[idx].x * piglit_width / 3),
146 (int)(Probes[idx].y * piglit_height / 2),
147 1, 1,
148 GL_RGBA, GL_FLOAT, probe);
150 printf("%20s (%3.1f,%3.1f): %f,%f,%f,%f",
151 Probes[idx].name,
152 Probes[idx].x, Probes[idx].y,
153 probe[0], probe[1], probe[2], probe[3]);
155 for(i = 0; i < 4; ++i) {
156 delta[i] = probe[i] - Probes[idx].expected[i];
158 if (delta[i] > dmax) dmax = delta[i];
159 else if (-delta[i] > dmax) dmax = -delta[i];
162 printf(" Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
164 idx++;
167 printf("Max delta: %f\n", dmax);
169 if (dmax >= 0.02)
170 return 0;
171 else
172 return 1;
176 enum piglit_result
177 piglit_display(void)
179 int pass;
181 DoFrame();
182 pass = DoTest();
184 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
188 static void Reshape(int width, int height)
190 piglit_width = width;
191 piglit_height = height;
192 glViewport(0, 0, width, height);
193 glMatrixMode(GL_PROJECTION);
194 glLoadIdentity();
195 glOrtho(0.0, 3.0, 0.0, 2.0, -2.0, 6.0);
196 glScalef(1.0, 1.0, -1.0); // flip z-axis
197 glMatrixMode(GL_MODELVIEW);
198 glLoadIdentity();
201 void
202 piglit_init(int argc, char **argv)
204 int i;
206 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
208 glutReshapeFunc(Reshape);
210 piglit_require_fragment_program();
212 for(i = 0; i < NUM_PROGRAMS; ++i)
213 FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
215 Reshape(piglit_width, piglit_height);