2 * Copyright © 2013 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
21 * DEALINGS IN THE SOFTWARE.
25 * \file blit-between-clears.c
27 * Some implementations (i965/gen7+ in particular) contain logic to
28 * avoid performing a redundant fast color clear on a buffer that is
29 * already in the cleared state. This test verifies that blitting to
30 * a buffer takes it out of the cleared state, so a subsequent fast
31 * color clear will take effect.
34 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 11;
41 config
.window_width
= RB_WIDTH
;
42 config
.window_height
= RB_HEIGHT
;
43 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
44 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
52 piglit_init(int argc
, char **argv
)
58 piglit_require_gl_version(11);
59 piglit_require_extension("GL_ARB_framebuffer_object");
61 /* Set up framebuffer */
62 glGenFramebuffers(1, &fb
);
63 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
64 glGenRenderbuffers(1, &rb
);
65 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
66 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA
,
68 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
70 if (!piglit_check_gl_error(GL_NO_ERROR
))
71 piglit_report_result(PIGLIT_FAIL
);
72 fb_status
= glCheckFramebufferStatus(GL_FRAMEBUFFER
);
73 if (fb_status
!= GL_FRAMEBUFFER_COMPLETE
) {
74 printf("Framebuffer status: %s\n",
75 piglit_get_gl_enum_name(fb_status
));
76 piglit_report_result(PIGLIT_FAIL
);
85 static const GLfloat green
[] = { 0.0, 1.0, 0.0, 1.0 };
87 /* Fast clear the auxiliary framebuffer to red. */
88 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fb
);
89 glClearColor(1, 0, 0, 1);
90 glClear(GL_COLOR_BUFFER_BIT
);
92 /* Fast clear the window system framebuffer to green. */
93 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
94 glClearColor(0, 1, 0, 1);
95 glClear(GL_COLOR_BUFFER_BIT
);
97 /* Blit the auxiliary framebuffer to the window system
98 * framebuffer, turning it red.
100 glBindFramebuffer(GL_READ_FRAMEBUFFER
, fb
);
101 glBlitFramebuffer(0, 0, RB_WIDTH
, RB_HEIGHT
,
102 0, 0, piglit_width
, piglit_height
,
103 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
105 /* Fast clear the window system framebuffer back to green. */
106 glClear(GL_COLOR_BUFFER_BIT
);
108 /* Verify that the second clear actually took effect. */
109 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
110 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
113 if (!piglit_check_gl_error(GL_NO_ERROR
))
116 piglit_present_results();
117 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;