framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / gl-3.0 / render-integer.c
blobca2e1fe40a52cf6fae7c202b1b4c9c1e7b9f2aec
1 /*
2 * Copyright 2014 VMware, Inc.
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.
24 /**
25 * Test OpenGL 3.0 rendering to integer texture formats.
26 * Brian Paul
27 * 19 June 2014
30 #include "piglit-util-gl.h"
32 static struct piglit_gl_test_config * piglit_config;
33 static enum piglit_result test_format(void * data);
35 #define CREATE_TEST(name) \
36 { \
37 #name, \
38 #name, \
39 test_format, \
40 (void *)(intptr_t)name \
42 static struct piglit_subtest tests[] = {
43 CREATE_TEST(GL_RGBA32I),
44 CREATE_TEST(GL_RGB32I),
45 CREATE_TEST(GL_RG32I),
46 CREATE_TEST(GL_R32I),
47 CREATE_TEST(GL_RGBA16I),
48 CREATE_TEST(GL_RGB16I),
49 CREATE_TEST(GL_RG16I),
50 CREATE_TEST(GL_R16I),
51 CREATE_TEST(GL_RGBA8I),
52 CREATE_TEST(GL_RGB8I),
53 CREATE_TEST(GL_RG8I),
54 CREATE_TEST(GL_R8I),
56 CREATE_TEST(GL_RGBA32UI),
57 CREATE_TEST(GL_RGB32UI),
58 CREATE_TEST(GL_RG32UI),
59 CREATE_TEST(GL_R32UI),
60 CREATE_TEST(GL_RGBA16UI),
61 CREATE_TEST(GL_RGB16UI),
62 CREATE_TEST(GL_RG16UI),
63 CREATE_TEST(GL_R16UI),
64 CREATE_TEST(GL_RGBA8UI),
65 CREATE_TEST(GL_RGB8UI),
66 CREATE_TEST(GL_RG8UI),
67 CREATE_TEST(GL_R8UI),
68 { 0 },
70 #undef CREATE_TEST
72 PIGLIT_GL_TEST_CONFIG_BEGIN
73 piglit_config = &config;
74 config.subtests = tests;
75 config.supports_gl_compat_version = 30;
76 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
77 config.khr_no_error_support = PIGLIT_NO_ERRORS;
79 PIGLIT_GL_TEST_CONFIG_END
82 static const char *vertShaderText =
83 "#version 130 \n"
84 "uniform ivec4 int_in; \n"
85 "flat out ivec4 int_val; \n"
86 " \n"
87 "void main() \n"
88 "{ \n"
89 " gl_Position = gl_Vertex; \n"
90 " int_val = int_in; \n"
91 "} \n";
93 static const char *fragShaderText =
94 "#version 130 \n"
95 "uniform ivec4 int_bias;\n"
96 "flat in ivec4 int_val;\n"
97 "out ivec4 int_result;\n"
98 "void main()\n"
99 "{ \n"
100 " int_result = int_val + int_bias; \n"
101 "} \n";
104 static const GLint bias[4] = {1, 2, 3, 4};
106 static GLuint Prog;
107 static GLint IntInUniform, IntBiasUniform;
108 static GLint TexSize = 200;
111 static void
112 sum(int *s, const int *a, const int *b)
114 int i;
115 for (i = 0; i < 4; i++)
116 s[i] = a[i] + b[i];
120 static bool
121 probe_int(int x, int y, const int *color, GLenum intFormat)
123 int actual[4], expected[4];
125 sum(expected, color, bias);
127 switch (intFormat) {
128 case GL_RGBA32I:
129 case GL_RGBA32UI:
130 case GL_RGBA16I:
131 case GL_RGBA16UI:
132 case GL_RGBA8I:
133 case GL_RGBA8UI:
134 break;
135 case GL_RGB32I:
136 case GL_RGB32UI:
137 case GL_RGB16I:
138 case GL_RGB16UI:
139 case GL_RGB8I:
140 case GL_RGB8UI:
141 expected[3] = 1;
142 break;
143 case GL_RG32I:
144 case GL_RG32UI:
145 case GL_RG16I:
146 case GL_RG16UI:
147 case GL_RG8I:
148 case GL_RG8UI:
149 expected[2] = 0;
150 expected[3] = 1;
151 break;
152 case GL_R32I:
153 case GL_R32UI:
154 case GL_R16I:
155 case GL_R16UI:
156 case GL_R8I:
157 case GL_R8UI:
158 expected[1] = 0;
159 expected[2] = 0;
160 expected[3] = 1;
161 break;
162 default:
163 assert(!"Unexpected format in probe_int()");
166 /* need to clamp for 8-bit formats */
167 if (intFormat == GL_RGBA8I ||
168 intFormat == GL_RGB8I ||
169 intFormat == GL_RG8I ||
170 intFormat == GL_R8I) {
171 expected[0] = CLAMP(expected[0], -128, 127);
172 expected[1] = CLAMP(expected[1], -128, 127);
173 expected[2] = CLAMP(expected[2], -128, 127);
174 expected[3] = CLAMP(expected[3], -128, 127);
176 else if (intFormat == GL_RGBA8UI ||
177 intFormat == GL_RGB8UI ||
178 intFormat == GL_RG8UI ||
179 intFormat == GL_R8UI) {
180 expected[0] = CLAMP(expected[0], 0, 255);
181 expected[1] = CLAMP(expected[1], 0, 255);
182 expected[2] = CLAMP(expected[2], 0, 255);
183 expected[3] = CLAMP(expected[3], 0, 255);
186 glReadPixels(x, y, 1, 1, GL_RGBA_INTEGER, GL_INT, actual);
188 if (actual[0] != expected[0] ||
189 actual[1] != expected[1] ||
190 actual[2] != expected[2] ||
191 actual[3] != expected[3]) {
192 printf("Failure at pixel (%d, %d):\n", x, y);
193 printf("Format: %s\n", piglit_get_gl_enum_name(intFormat));
194 printf("Expected: %d, %d, %d, %d\n",
195 expected[0], expected[1], expected[2], expected[3]);
196 printf("Found: %d, %d, %d, %d\n",
197 actual[0], actual[1], actual[2], actual[3]);
198 return false;
201 return true;
205 static bool
206 setup_fbo(GLenum intFormat)
208 GLuint tex, fbo;
209 GLenum status;
211 glGenTextures(1, &tex);
212 glBindTexture(GL_TEXTURE_2D, tex);
213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
215 glTexImage2D(GL_TEXTURE_2D, 0, intFormat, TexSize, TexSize, 0,
216 GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, NULL);
218 glGenFramebuffers(1, &fbo);
219 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
221 glFramebufferTexture2D(GL_FRAMEBUFFER,
222 GL_COLOR_ATTACHMENT0,
223 GL_TEXTURE_2D, tex, 0);
224 if (!piglit_check_gl_error(GL_NO_ERROR)) {
225 fprintf(stderr, "Failed to create integer FBO.\n");
226 piglit_report_result(PIGLIT_FAIL);
227 return false;
230 status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
231 if (status != GL_FRAMEBUFFER_COMPLETE) {
232 printf("Incomplete fbo for format %s (status %s)\n",
233 piglit_get_gl_enum_name(intFormat),
234 piglit_get_gl_enum_name(status));
235 return false;
238 return true;
243 static enum piglit_result
244 test_format(void * data)
246 GLenum intFormat = (GLenum)(intptr_t)data;
247 static const GLint red[4] = {1000, 0, 0, 0};
248 static const GLint green[4] = {2000, 0, 0, 0};
249 static const GLint blue[4] = {0, 0, 3000, 0};
250 static const GLint alpha[4] = {0, 0, 0, 4000};
251 int x0 = TexSize / 4;
252 int y0 = TexSize / 4;
253 int x1 = TexSize * 3 / 4;
254 int y1 = TexSize * 3 / 4;
255 bool pass = true;
257 if (!setup_fbo(intFormat)) {
258 return PIGLIT_SKIP;
261 /* Draw different value into each texture quadrant */
262 glUniform4iv(IntInUniform, 1, red);
263 piglit_draw_rect(-1, -1, 1, 1);
265 glUniform4iv(IntInUniform, 1, green);
266 piglit_draw_rect(0, -1, 1, 1);
268 glUniform4iv(IntInUniform, 1, blue);
269 piglit_draw_rect(-1, 0, 1, 1);
271 glUniform4iv(IntInUniform, 1, alpha);
272 piglit_draw_rect(0, 0, 1, 1);
274 pass = probe_int(x0, y0, red, intFormat) && pass;
275 pass = probe_int(x1, y0, green, intFormat) && pass;
276 pass = probe_int(x0, y1, blue, intFormat) && pass;
277 pass = probe_int(x1, y1, alpha, intFormat) && pass;
279 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
283 enum piglit_result
284 piglit_display(void)
286 enum piglit_result result = PIGLIT_PASS;
288 result = piglit_run_selected_subtests(
289 tests,
290 piglit_config->selected_subtests,
291 piglit_config->num_selected_subtests,
292 result);
294 return result;
298 void
299 piglit_init(int argc, char **argv)
301 piglit_require_gl_version(30);
303 Prog = piglit_build_simple_program(vertShaderText, fragShaderText);
304 if (!Prog) {
305 printf("Failed to compile/link program\n");
306 piglit_report_result(PIGLIT_FAIL);
309 glBindFragDataLocation(Prog, 0, "int_result");
310 glLinkProgram(Prog);
311 glUseProgram(Prog);
313 IntInUniform = glGetUniformLocation(Prog, "int_in");
314 IntBiasUniform = glGetUniformLocation(Prog, "int_bias");
316 glUniform4iv(IntBiasUniform, 1, bias);