framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / shaders / getuniform-01.c
blob5b7210da01c03c0c7fb9ce8c407caef928632461
1 /*
2 * Copyright © 2010 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 /**
25 * \file getuniform-01.c
26 * Verify that glGetUniformfv fetches uniform arrays correctly
28 * This test reproduces the failure reported in bugzilla #29823.
29 * https://bugs.freedesktop.org/show_bug.cgi?id=29823
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
40 PIGLIT_GL_TEST_CONFIG_END
42 static const char vs_text[] =
43 "uniform float c[4];\n"
44 "varying vec4 color;\n"
45 "\n"
46 "void main()\n"
47 "{\n"
48 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
49 " color = vec4(c[3], c[2], c[1], c[0]);\n"
50 "}\n"
53 static const char fs_text[] =
54 "varying vec4 color;\n"
55 "void main() { gl_FragColor = color; }\n"
58 static GLint prog;
59 static GLint base_location;
60 static GLint array_location[4];
62 enum piglit_result
63 piglit_display(void)
65 return PIGLIT_FAIL;
68 union data_blob {
69 float f;
70 uint32_t u;
73 void
74 validate_buffer(const union data_blob *buffer, unsigned size, float expected)
76 unsigned i;
78 if (buffer[0].f != expected) {
79 printf("index 0: got %f, expected %f\n",
80 buffer[0].f, expected);
81 piglit_report_result(PIGLIT_FAIL);
82 } else if (!piglit_automatic) {
83 printf("index 0: got %f, expected %f (good)\n",
84 buffer[0].f, expected);
87 for (i = 1; i < size; i++) {
88 if (buffer[i].u != 0xdeadbeef) {
89 printf("glGetUniformfv overrun at index %u!\n", i);
90 piglit_report_result(PIGLIT_FAIL);
94 if (!piglit_automatic) {
95 printf("No buffer overrun.\n");
99 void
100 piglit_init(int argc, char **argv)
102 static const float uniform_data[4] = {
103 12.0, 0.5, 3.14169, 42.0
105 GLint vs;
106 GLint fs;
107 unsigned i;
108 union data_blob buffer[16];
110 piglit_require_vertex_shader();
111 piglit_require_fragment_shader();
113 vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
114 fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
116 prog = piglit_link_simple_program(vs, fs);
118 glUseProgram(prog);
120 base_location = glGetUniformLocation(prog, "c");
121 if (base_location < 0) {
122 printf("Could not get location of `c'.\n");
123 piglit_report_result(PIGLIT_FAIL);
126 for (i = 0; i < 4; i++) {
127 char name[5];
129 name[0] = 'c';
130 name[1] = '[';
131 name[2] = '0' + i;
132 name[3] = ']';
133 name[4] = '\0';
134 array_location[i] = glGetUniformLocation(prog, name);
135 if (array_location[i] < 0) {
136 printf("Could not get location of `%s'.\n", name);
137 piglit_report_result(PIGLIT_FAIL);
141 /* From page 80 of the OpenGL 2.1 spec:
143 * The first element of a uniform array is identified using the
144 * name of the uniform array appended with "[0]". Except if the
145 * last part of the string name indicates a uniform array, then
146 * the location of the first element of that array can be
147 * retrieved by either using the name of the uniform array, or the
148 * name of the uniform array appended with "[0]".
150 if (base_location != array_location[0]) {
151 printf("Locations of `c' = %d and `c[0]' = %d, but they "
152 "should be the same.\n",
153 base_location, array_location[0]);
154 piglit_report_result(PIGLIT_FAIL);
157 glUniform1fv(base_location, 4, uniform_data);
159 /* From page 264 of the OpenGL 2.1 spec:
161 * In order to query the values of an array of uniforms, a
162 * GetUniform* command needs to be issued for each array element.
164 * This means that querying using the location of 'array' is the same
165 * as 'array[0]'.
167 printf("Getting array element 0 from base location...\n");
168 for (i = 0; i < ARRAY_SIZE(buffer); i++) {
169 buffer[i].u = 0xdeadbeef;
172 glGetUniformfv(prog, base_location, (GLfloat *) buffer);
173 validate_buffer(buffer, ARRAY_SIZE(buffer), uniform_data[0]);
175 printf("Getting one array element at a time...\n");
176 for (i = 0; i < 4; i++) {
177 unsigned j;
178 for (j = 0; j < ARRAY_SIZE(buffer); j++) {
179 buffer[j].u = 0xdeadbeef;
182 glGetUniformfv(prog, array_location[i],
183 (GLfloat *) buffer);
184 validate_buffer(buffer, ARRAY_SIZE(buffer), uniform_data[i]);
187 piglit_report_result(PIGLIT_PASS);