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
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.
25 * Test OpenGL 3.0 rendering to integer texture formats.
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) \
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
),
47 CREATE_TEST(GL_RGBA16I
),
48 CREATE_TEST(GL_RGB16I
),
49 CREATE_TEST(GL_RG16I
),
51 CREATE_TEST(GL_RGBA8I
),
52 CREATE_TEST(GL_RGB8I
),
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
),
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
=
84 "uniform ivec4 int_in; \n"
85 "flat out ivec4 int_val; \n"
89 " gl_Position = gl_Vertex; \n"
90 " int_val = int_in; \n"
93 static const char *fragShaderText
=
95 "uniform ivec4 int_bias;\n"
96 "flat in ivec4 int_val;\n"
97 "out ivec4 int_result;\n"
100 " int_result = int_val + int_bias; \n"
104 static const GLint bias
[4] = {1, 2, 3, 4};
107 static GLint IntInUniform
, IntBiasUniform
;
108 static GLint TexSize
= 200;
112 sum(int *s
, const int *a
, const int *b
)
115 for (i
= 0; i
< 4; i
++)
121 probe_int(int x
, int y
, const int *color
, GLenum intFormat
)
123 int actual
[4], expected
[4];
125 sum(expected
, color
, bias
);
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]);
206 setup_fbo(GLenum intFormat
)
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
);
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
));
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;
257 if (!setup_fbo(intFormat
)) {
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
;
286 enum piglit_result result
= PIGLIT_PASS
;
288 result
= piglit_run_selected_subtests(
290 piglit_config
->selected_subtests
,
291 piglit_config
->num_selected_subtests
,
299 piglit_init(int argc
, char **argv
)
301 piglit_require_gl_version(30);
303 Prog
= piglit_build_simple_program(vertShaderText
, fragShaderText
);
305 printf("Failed to compile/link program\n");
306 piglit_report_result(PIGLIT_FAIL
);
309 glBindFragDataLocation(Prog
, 0, "int_result");
313 IntInUniform
= glGetUniformLocation(Prog
, "int_in");
314 IntBiasUniform
= glGetUniformLocation(Prog
, "int_bias");
316 glUniform4iv(IntBiasUniform
, 1, bias
);