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_extension("GL_ARB_framebuffer_object");
60 /* Set up framebuffer */
61 glGenFramebuffers(1, &fb
);
62 glBindFramebuffer(GL_FRAMEBUFFER
, fb
);
63 glGenRenderbuffers(1, &rb
);
64 glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
65 glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA
,
67 glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
69 if (!piglit_check_gl_error(GL_NO_ERROR
))
70 piglit_report_result(PIGLIT_FAIL
);
71 fb_status
= glCheckFramebufferStatus(GL_FRAMEBUFFER
);
72 if (fb_status
!= GL_FRAMEBUFFER_COMPLETE
) {
73 printf("Framebuffer status: %s\n",
74 piglit_get_gl_enum_name(fb_status
));
75 piglit_report_result(PIGLIT_FAIL
);
84 static const GLfloat green
[] = { 0.0, 1.0, 0.0, 1.0 };
86 /* Fast clear the auxiliary framebuffer to red. */
87 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fb
);
88 glClearColor(1, 0, 0, 1);
89 glClear(GL_COLOR_BUFFER_BIT
);
91 /* Fast clear the window system framebuffer to green. */
92 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
93 glClearColor(0, 1, 0, 1);
94 glClear(GL_COLOR_BUFFER_BIT
);
96 /* Blit the auxiliary framebuffer to the window system
97 * framebuffer, turning it red.
99 glBindFramebuffer(GL_READ_FRAMEBUFFER
, fb
);
100 glBlitFramebuffer(0, 0, RB_WIDTH
, RB_HEIGHT
,
101 0, 0, piglit_width
, piglit_height
,
102 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
104 /* Fast clear the window system framebuffer back to green. */
105 glClear(GL_COLOR_BUFFER_BIT
);
107 /* Verify that the second clear actually took effect. */
108 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
109 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
112 if (!piglit_check_gl_error(GL_NO_ERROR
))
115 piglit_present_results();
116 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;