2 * Copyright © 2009 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
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
24 * Eric Anholt <eric@anholt.net>
28 /** @file read-front.c
30 * Tests that reading the front buffer after a draw to back and swap
33 * This catches a regression in the Intel driver with DRI2, where the
34 * read buffer didn't have an actual buffer present if it hadn't been
35 * used as a draw buffer.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config
.supports_gl_compat_version
= 10;
44 config
.requires_displayed_window
= true;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
47 PIGLIT_GL_TEST_CONFIG_END
49 static GLboolean clear_front_first
;
54 GLboolean pass
= GL_TRUE
;
55 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
56 static float green
[] = {0.0, 1.0, 0.0, 0.0};
58 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
60 if (clear_front_first
) {
61 /* This should allocate the front buffer in the driver
62 * if it hasn't been allocated already.
64 glDrawBuffer(GL_FRONT
);
65 glClear(GL_COLOR_BUFFER_BIT
);
66 glDrawBuffer(GL_BACK
);
69 glClear(GL_COLOR_BUFFER_BIT
);
71 piglit_draw_rect(0, piglit_height
/ 2, piglit_width
, piglit_height
);
73 glReadBuffer(GL_FRONT
);
75 piglit_swap_buffers();
77 pass
&= piglit_probe_rect_rgb(0, 0,
78 piglit_width
, piglit_height
/ 2, blue
);
79 pass
&= piglit_probe_rect_rgb(0, piglit_height
/ 2,
80 piglit_width
, piglit_height
/ 2, green
);
82 glReadBuffer(GL_BACK
);
84 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
89 piglit_init(int argc
, char **argv
)
93 glClearColor(0.0, 0.0, 1.0, 0.0);
95 for (i
= 1; i
< argc
; i
++) {
96 if (strcmp(argv
[i
], "clear-front-first") == 0) {
97 clear_front_first
= GL_TRUE
;