framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / getuniform-03.c
blob9de9993bfb2544c64e3b7b73212e47d13c6bf3c4
1 /*
2 * Copyright 2015 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 DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-util-gl.h"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config.supports_gl_compat_version = 21;
30 PIGLIT_GL_TEST_CONFIG_END
32 struct builtin_uniform_t {
33 const char *name;
34 GLenum type;
35 bool is_array;
36 bool found;
37 } uniforms[] = {
38 { "gl_DepthRange.near", GL_FLOAT, false , false },
39 { "gl_DepthRange.far", GL_FLOAT, false , false },
40 { "gl_DepthRange.diff", GL_FLOAT, false , false },
41 /* { "gl_NumSamples", GL_INT, false , false }, requires OGL 4.0 */
42 { "gl_ModelViewMatrix", GL_FLOAT_MAT4, false , false },
43 { "gl_ProjectionMatrix", GL_FLOAT_MAT4, false , false },
44 { "gl_ModelViewProjectionMatrix", GL_FLOAT_MAT4, false , false },
45 { "gl_TextureMatrix", GL_FLOAT_MAT4, true , false },
46 { "gl_NormalMatrix", GL_FLOAT_MAT3, false , false },
47 { "gl_ModelViewMatrixInverse", GL_FLOAT_MAT4, false , false },
48 { "gl_ProjectionMatrixInverse", GL_FLOAT_MAT4, false , false },
49 { "gl_TextureMatrixInverse", GL_FLOAT_MAT4, true , false },
50 { "gl_ModelViewMatrixTranspose", GL_FLOAT_MAT4, false , false },
51 { "gl_ProjectionMatrixTranspose", GL_FLOAT_MAT4, false , false },
52 { "gl_ModelViewProjectionMatrixTranspose", GL_FLOAT_MAT4, false , false },
53 { "gl_TextureMatrixTranspose", GL_FLOAT_MAT4, true , false },
54 { "gl_ModelViewMatrixInverseTranspose", GL_FLOAT_MAT4, false , false },
55 { "gl_ProjectionMatrixInverseTranspose", GL_FLOAT_MAT4, false , false },
56 { "gl_ModelViewProjectionMatrixInverseTranspose", GL_FLOAT_MAT4, false },
57 { "gl_TextureMatrixInverseTranspose", GL_FLOAT_MAT4, true , false },
58 { "gl_NormalScale", GL_FLOAT, false , false },
59 { "gl_ClipPlane", GL_FLOAT_VEC4, true , false },
60 { "gl_Point.size", GL_FLOAT, false , false },
61 { "gl_Point.sizeMin", GL_FLOAT, false , false },
62 { "gl_Point.sizeMax", GL_FLOAT, false , false },
63 { "gl_Point.fadeThresholdSize", GL_FLOAT, false , false },
64 { "gl_Point.distanceConstantAttenuation", GL_FLOAT, false , false },
65 { "gl_Point.distanceLinearAttenuation", GL_FLOAT, false , false },
66 { "gl_Point.distanceQuadraticAttenuation", GL_FLOAT, false , false },
67 { "gl_FrontMaterial.emission", GL_FLOAT_VEC4, false , false },
68 { "gl_FrontMaterial.ambient", GL_FLOAT_VEC4, false , false },
69 { "gl_FrontMaterial.diffuse", GL_FLOAT_VEC4, false , false },
70 { "gl_FrontMaterial.specular", GL_FLOAT_VEC4, false , false },
71 { "gl_FrontMaterial.shininess", GL_FLOAT, false , false },
72 { "gl_BackMaterial.emission", GL_FLOAT_VEC4, false , false },
73 { "gl_BackMaterial.ambient", GL_FLOAT_VEC4, false , false },
74 { "gl_BackMaterial.diffuse", GL_FLOAT_VEC4, false , false },
75 { "gl_BackMaterial.specular", GL_FLOAT_VEC4, false , false },
76 { "gl_BackMaterial.shininess", GL_FLOAT, false , false },
77 { "gl_LightSource[0].ambient", GL_FLOAT_VEC4, false , false },
78 { "gl_LightSource[0].diffuse", GL_FLOAT_VEC4, false , false },
79 { "gl_LightSource[0].specular", GL_FLOAT_VEC4, false , false },
80 { "gl_LightSource[0].position", GL_FLOAT_VEC4, false , false },
81 { "gl_LightSource[0].halfVector", GL_FLOAT_VEC4, false , false },
82 { "gl_LightSource[0].spotDirection", GL_FLOAT_VEC3, false , false },
83 { "gl_LightSource[0].spotExponent", GL_FLOAT, false , false },
84 { "gl_LightSource[0].spotCutoff", GL_FLOAT, false , false },
85 { "gl_LightSource[0].spotCosCutoff", GL_FLOAT, false , false },
86 { "gl_LightSource[0].constantAttenuation", GL_FLOAT, false , false },
87 { "gl_LightSource[0].linearAttenuation", GL_FLOAT, false , false },
88 { "gl_LightSource[0].quadraticAttenuation", GL_FLOAT, false , false },
89 { "gl_LightModel.ambient", GL_FLOAT_VEC4, false , false },
90 { "gl_FrontLightModelProduct.sceneColor", GL_FLOAT_VEC4, false , false },
91 { "gl_BackLightModelProduct.sceneColor", GL_FLOAT_VEC4, false , false },
92 { "gl_FrontLightProduct[0].ambient", GL_FLOAT_VEC4, true , false },
93 { "gl_FrontLightProduct[0].diffuse", GL_FLOAT_VEC4, true , false },
94 { "gl_FrontLightProduct[0].specular", GL_FLOAT_VEC4, true , false },
95 { "gl_BackLightProduct[0].ambient", GL_FLOAT_VEC4, true , false },
96 { "gl_BackLightProduct[0].diffuse", GL_FLOAT_VEC4, true , false },
97 { "gl_BackLightProduct[0].specular", GL_FLOAT_VEC4, true , false },
98 { "gl_TextureEnvColor", GL_FLOAT_VEC4, true , false },
99 { "gl_EyePlaneS", GL_FLOAT_VEC4, true , false },
100 { "gl_EyePlaneT", GL_FLOAT_VEC4, true , false },
101 { "gl_EyePlaneR", GL_FLOAT_VEC4, true , false },
102 { "gl_EyePlaneQ", GL_FLOAT_VEC4, true , false },
103 { "gl_ObjectPlaneS", GL_FLOAT_VEC4, true , false },
104 { "gl_ObjectPlaneT", GL_FLOAT_VEC4, true , false },
105 { "gl_ObjectPlaneR", GL_FLOAT_VEC4, true , false },
106 { "gl_ObjectPlaneQ", GL_FLOAT_VEC4, true , false },
107 { "gl_Fog.color", GL_FLOAT_VEC4, false , false },
108 { "gl_Fog.density", GL_FLOAT, false , false },
109 { "gl_Fog.start", GL_FLOAT, false , false },
110 { "gl_Fog.end", GL_FLOAT, false , false },
111 { "gl_Fog.scale", GL_FLOAT, false , false },
114 static const char vs_header[] =
115 "void main()\n"
116 "{\n"
117 " gl_Position = vec4(1);\n";
119 static const char vs_footer[] =
120 "}\n";
122 char *
123 gen_vs_shader_all()
125 /* strlen(" gl_Position += vec4(gl_ModelViewProjectionMatrixInverse
126 * "Transpose[0]);\n") */
127 size_t max_line_size = 64;
128 size_t uniforms_count = ARRAY_SIZE(uniforms);
129 size_t shader_len = strlen(vs_header) +
130 uniforms_count * max_line_size +
131 strlen(vs_footer) + 1;
132 size_t i;
134 /* allocate the shader */
135 char *vs_text = malloc(shader_len);
136 memset(vs_text, 0, shader_len);
138 /* add the header */
139 strcat(vs_text, vs_header);
141 /* add a reference to every uniform */
142 for (i = 0; i < uniforms_count; i++) {
143 strcat(vs_text, " gl_Position += ");
144 switch(uniforms[i].type) {
145 case GL_FLOAT_VEC3:
146 strcat(vs_text, "vec4(");
147 strcat(vs_text, uniforms[i].name);
148 strcat(vs_text, ", 1)");
149 break;
150 case GL_FLOAT_MAT4:
151 strcat(vs_text, "vec4(");
152 strcat(vs_text, uniforms[i].name);
153 strcat(vs_text, "[0])");
154 break;
155 case GL_FLOAT_MAT3:
156 strcat(vs_text, "vec4(");
157 strcat(vs_text, uniforms[i].name);
158 strcat(vs_text, ")");
159 break;
160 default:
161 strcat(vs_text, uniforms[i].name);
162 if (uniforms[i].is_array)
163 strcat(vs_text, "[0]");
165 strcat(vs_text, ";\n");
168 /* add the footer */
169 strcat(vs_text, vs_footer);
171 /* Uncomment the following to view the generated shader */
172 /*fprintf(stderr, "shader = '%s'\n", vs_text);*/
174 return vs_text;
177 enum piglit_result
178 piglit_display(void)
180 /* never called */
181 return PIGLIT_FAIL;
184 static struct builtin_uniform_t *
185 find_uniform(const char *name)
187 size_t i;
189 for (i = 0; i < ARRAY_SIZE(uniforms); i++) {
190 /* OpenGL ES 3.0 and OpenGL 4.2 require that the "[0]" be
191 * appended to the name. Earlier versions of the spec are
192 * ambiguous. Accept either name.
194 if (strcmp(uniforms[i].name, name) == 0 ||
195 (strcmp(name + strlen(name) - 3, "[0]") == 0 &&
196 strncmp(uniforms[i].name, name, strlen(name) - 3) == 0))
197 return &uniforms[i];
200 return NULL;
203 void
204 piglit_init(int argc, char **argv)
206 GLint numUniforms, i;
207 bool pass = true;
208 GLuint vs, prog;
209 char *vs_text;
211 piglit_require_vertex_shader();
212 piglit_require_fragment_shader();
214 vs_text = gen_vs_shader_all();
216 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
217 prog = piglit_link_simple_program(vs, 0);
218 if (!prog) {
219 printf("Compilation error. Aborting...\n");
220 piglit_report_result(PIGLIT_FAIL);
223 glUseProgram(prog);
224 free(vs_text);
226 glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &numUniforms);
227 if (numUniforms != ARRAY_SIZE(uniforms)) {
228 printf("Unexpected number of uniforms (found %d, expected "
229 "%lu)\n", numUniforms, ARRAY_SIZE(uniforms));
232 /* check the types of the active uniforms and check which ones got
233 * references by glGetActiveUniform for later comparaison. */
234 for (i = 0; i < numUniforms; i++) {
235 struct builtin_uniform_t *uniform;
236 GLcharARB name[100];
237 GLsizei len;
238 GLint size;
239 GLenum type;
241 glGetActiveUniform(prog, i, sizeof(name), &len, &size, &type,
242 name);
244 uniform = find_uniform(name);
246 if (!uniform) {
247 fprintf(stderr, "Cannot find uniform '%s'\n", name);
248 pass = false;
249 continue;
252 uniform->found = true;
254 if (type != uniform->type) {
255 printf("Wrong type for '%s' (found %s(0x%x)), "
256 "expected %s(0x%x))\n",
257 name, piglit_get_gl_enum_name(type), type,
258 piglit_get_gl_enum_name(uniform->type),
259 uniform->type);
260 pass = false;
264 /* check that no uniform got forgotten as there is the possibility that
265 * one got referenced twice!
267 for (i = 0; i < ARRAY_SIZE(uniforms); i++) {
268 if (uniforms[i].found == false) {
269 fprintf(stderr, "uniform '%s' is missing from the "
270 "active uniform list!\n",
271 uniforms[i].name);
273 /* A missing builtin is legal, as stated by page 80
274 * (page 94 of the PDF) of the OpenGL 2.1 spec:
276 * "The returned uniform name can be the name of
277 * built-in uniform state as well."
280 /* FIXME: verify that the missing uniform as not been
281 * forgotten by the implementation. One way could have
282 * been to count the number of components used by the
283 * uniforms and add more components until reaching
284 * shader then adding other uniforms to reach
285 * GL_MAX_VERTEX_UNIFORM_COMPONENTS. If the shader still
286 * compiles, and assuming that
287 * GL_MAX_VERTEX_UNIFORM_COMPONENTS reports a good value
288 * then we can assume that the compiler just replaced
289 * the uniform with something else. If it does not
290 * compile, then it probably lied somewhere!
292 * The problem with this approach is that counting the
293 * number of components used for some types such as
294 * matrices is implementation-dependent...
296 * Until we have such a way to verify, let's not fail
297 * the test!
302 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);