arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-blit-check-limits.c
blobceb6f2f71911424a4dd92b23cd815a760fff64a9
1 /*
2 * Copyright (C) 2018 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.
25 /** @file fbo-blit-check-limits.c
27 * Test FBO blits with different possible buffer sizes
28 * Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108088
29 * Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110239
31 * \author Vadym Shovkoplias <vadym.shovkoplias@globallogic.com>
32 * \author Sergii Romantsov <sergii.romantsov@globallogic.com>
35 #include "piglit-util-gl.h"
37 #define FB_SIZE 160
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_compat_version = 10;
43 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
44 config.requires_displayed_window = true;
45 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 config.window_width = FB_SIZE;
47 config.window_height = FB_SIZE;
49 PIGLIT_GL_TEST_CONFIG_END
52 typedef struct _rgba {
53 float r;
54 float g;
55 float b;
56 float a;
57 } rgba;
59 // Yellow - back buffer left side color
60 #define BACK1_R 1.0f
61 #define BACK1_G 1.0f
62 #define BACK1_B 0.0f
63 static const rgba BACK1 = { BACK1_R, BACK1_G, BACK1_B, 1.0f };
65 // Green - back buffer right side color
66 #define BACK2_R 0.0f
67 #define BACK2_G 1.0f
68 #define BACK2_B 0.0f
69 static const rgba BACK2 = { BACK2_R, BACK2_G, BACK2_B, 1.0f };
71 // Red - front buffer color
72 #define FRONT_R 1.0f
73 #define FRONT_G 0.0f
74 #define FRONT_B 0.0f
75 static const rgba FRONT = { FRONT_R, FRONT_G, FRONT_B, 1.0f };
77 typedef struct _fb_data {
78 int read;
79 int write;
80 rgba color_lb;
81 rgba color_lt;
82 rgba color_right;
83 } fb_data;
85 static const fb_data fb_params[] = {
86 { .read = 0, .write = 0,
87 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
88 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
89 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
91 { .read = 0, .write = FB_SIZE,
92 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
93 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
94 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
96 { .read = 0, .write = FB_SIZE << 1,
97 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
98 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
99 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
101 { .read = 0, .write = INT_MAX,
102 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
103 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
104 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
107 { .read = 1, .write = FB_SIZE,
108 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
109 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
110 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
112 { .read = 1, .write = INT_MAX,
113 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
114 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
115 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
118 { .read = FB_SIZE >> 2, .write = 0,
119 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
120 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
121 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
123 { .read = FB_SIZE >> 2, .write = FB_SIZE << 1,
124 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
125 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
126 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
128 { .read = FB_SIZE >> 2, .write = FB_SIZE,
129 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
130 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
131 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
133 { .read = FB_SIZE >> 2, .write = 0x7ffffff,
134 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
135 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
136 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
138 { .read = FB_SIZE >> 2, .write = INT_MAX,
139 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
140 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
141 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
144 { .read = FB_SIZE >> 1, .write = 1,
145 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
146 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
147 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
149 { .read = FB_SIZE >> 1, .write = 2,
150 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
151 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
152 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
154 { .read = FB_SIZE >> 1, .write = FB_SIZE >> 1,
155 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
156 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
157 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
159 { .read = FB_SIZE >> 1, .write = FB_SIZE,
160 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
161 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
162 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
164 { .read = FB_SIZE >> 1, .write = 0x7ffffff,
165 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
166 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
167 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
169 { .read = FB_SIZE >> 1, .write = INT_MAX,
170 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
171 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
172 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
175 { .read = FB_SIZE, .write = 0,
176 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
177 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
178 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
180 { .read = FB_SIZE, .write = 1,
181 .color_lb = { BACK2_R, BACK2_G, BACK2_B, 1.0f },
182 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
183 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
185 { .read = FB_SIZE, .write = 2,
186 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
187 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
188 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
190 { .read = FB_SIZE, .write = FB_SIZE >> 1,
191 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
192 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
193 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
195 { .read = FB_SIZE, .write = FB_SIZE,
196 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
197 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
198 .color_right = { BACK2_R, BACK2_G, BACK2_B, 1.0f },
200 { .read = FB_SIZE, .write = 0x7ffffff,
201 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
202 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
203 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
205 { .read = FB_SIZE, .write = INT_MAX,
206 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
207 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
208 .color_right = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
211 { .read = INT_MIN, .write = 1,
212 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
213 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
214 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
216 { .read = INT_MIN, .write = 2,
217 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
218 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
219 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
221 { .read = INT_MIN, .write = INT_MIN,
222 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
223 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
224 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
226 { .read = INT_MIN, .write = 0x7ffffff,
227 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
228 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
229 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
231 { .read = INT_MIN, .write = INT_MAX,
232 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
233 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
234 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
237 { .read = -FB_SIZE, .write = -FB_SIZE,
238 .color_lb = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
239 .color_lt = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
240 .color_right = { FRONT_R, FRONT_G, FRONT_B, 1.0f },
243 { .read = INT_MAX, .write = INT_MAX,
244 .color_lb = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
245 .color_lt = { BACK1_R, BACK1_G, BACK1_B, 1.0f },
246 .color_right = { BACK2_R, BACK2_G, BACK2_B, 1.0f },
250 static bool draw(const fb_data *const sizes)
252 bool success = 1;
254 glDrawBuffer(GL_BACK);
255 /* back buffer right side green */
256 glClearColor(BACK2.r, BACK2.g, BACK2.b, BACK2.a);
257 glClear(GL_COLOR_BUFFER_BIT);
259 /* back buffer left side yellow */
260 glColor4f(BACK1.r, BACK1.g, BACK1.b, BACK1.a);
261 piglit_draw_rect(-1.0, -1.0, 1.0, 2.0);
263 glDrawBuffer(GL_FRONT);
264 /* front buffer red */
265 glClearColor(FRONT.r, FRONT.g, FRONT.b, FRONT.a);
266 glClear(GL_COLOR_BUFFER_BIT);
268 glReadBuffer(GL_BACK);
270 glBlitFramebufferEXT(0, 0, sizes->read, sizes->read,
271 0, 0, sizes->write, sizes->write,
272 GL_COLOR_BUFFER_BIT, GL_NEAREST);
274 glReadBuffer(GL_FRONT);
276 success &= piglit_probe_pixel_rgb(0, 0, (float*)(&sizes->color_lb));
277 success &= piglit_probe_pixel_rgb(FB_SIZE - 1, 0, (float*)(&sizes->color_right));
278 success &= piglit_probe_pixel_rgb(0, FB_SIZE - 1, (float*)(&sizes->color_lt));
279 success &= piglit_probe_pixel_rgb(FB_SIZE - 1, FB_SIZE - 1, (float*)(&sizes->color_right));
281 if (!success)
282 fprintf(stderr, "Failed blit src(0,0;%d,%d) - dst(0,0;%d,%d)\n",
283 sizes->read, sizes->read, sizes->write, sizes->write);
285 glFlush();
286 return success;
289 enum piglit_result piglit_display(void)
291 bool success = 1;
292 for (int i = 0; i < sizeof(fb_params) / sizeof(fb_params[0]); ++i)
294 success &= draw(&fb_params[i]);
296 return success ? PIGLIT_PASS : PIGLIT_FAIL;
299 void piglit_init(int argc, char **argv)
301 piglit_require_extension("GL_EXT_framebuffer_object");
302 piglit_require_extension("GL_EXT_framebuffer_blit");