2 * Copyright © 2014 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 /** \file blit-multiple-render-targets.cpp
26 * This test verifies that glBlitFramebuffer() works as expected in case of
27 * multiple render targets.
29 * From Section 4.3.2, page 268 of OpenGL 4.0 spec:
31 * "When the color buffer is transferred, values are taken from the read
32 * buffer of the read framebuffer and written to each of the draw buffers
33 * of the draw framebuffer."
36 #include "piglit-fbo.h"
37 using namespace piglit_util_fbo
;
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
42 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
47 static Fbo multisample_fbo
;
50 print_usage_and_exit(char *prog_name
)
52 printf("Usage: %s <num_samples>\n", prog_name
);
53 piglit_report_result(PIGLIT_FAIL
);
58 piglit_init(int argc
, char **argv
)
61 print_usage_and_exit(argv
[0]);
63 /* 1st arg: num_samples */
65 int num_samples
= strtol(argv
[1], &endptr
, 0);
66 if (endptr
!= argv
[1] + strlen(argv
[1]))
67 print_usage_and_exit(argv
[0]);
69 piglit_require_extension("GL_ARB_framebuffer_object");
71 /* Skip the test if num_samples > GL_MAX_SAMPLES */
73 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
74 if (num_samples
> max_samples
)
75 piglit_report_result(PIGLIT_SKIP
);
77 FboConfig
Config(num_samples
, piglit_width
, piglit_height
);
79 /* Setup fbo with renderbuffer and texture attachments */
80 Config
.num_rb_attachments
= 2;
81 Config
.rb_attachment
[0] = GL_COLOR_ATTACHMENT0
;
82 Config
.rb_attachment
[1] = GL_COLOR_ATTACHMENT1
;
84 Config
.num_tex_attachments
= 4;
85 for (int i
= 0; i
< Config
.num_tex_attachments
; i
++)
86 Config
.tex_attachment
[i
] = GL_COLOR_ATTACHMENT2
+ i
;
88 multisample_fbo
.setup(Config
);
90 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
91 piglit_report_result(PIGLIT_FAIL
);
95 extern "C" enum piglit_result
100 {GL_COLOR_ATTACHMENT1
,
101 GL_COLOR_ATTACHMENT4
,
102 GL_COLOR_ATTACHMENT5
,
104 GL_COLOR_ATTACHMENT0
,
105 GL_COLOR_ATTACHMENT2
,
106 GL_COLOR_ATTACHMENT3
};
108 const float expected
[][4] =
109 {{0.0, 1.0, 0.0, 1.0}, /* GL_COLOR_ATTACHMENT1 */
110 {0.0, 1.0, 0.0, 1.0}, /* GL_COLOR_ATTACHMENT4 */
111 {0.0, 1.0, 0.0, 1.0}, /* GL_COLOR_ATTACHMENT5 */
113 {0.0, 0.0, 1.0, 1.0}, /* GL_COLOR_ATTACHMENT0 */
114 {0.0, 0.0, 1.0, 1.0}, /* GL_COLOR_ATTACHMENT2 */
115 {0.0, 0.0, 1.0, 1.0}};/* GL_COLOR_ATTACHMENT3 */
117 /* Clear piglit_winsys_fbo to green color */
118 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
119 glClearColor(0.0, 1.0, 0.0, 1.0);
120 glClear(GL_COLOR_BUFFER_BIT
);
122 /* Clear all color attachements of multisample_fbo to blue color */
123 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisample_fbo
.handle
);
124 glDrawBuffers(6, bufs
);
125 glClearColor(0.0, 0.0, 1.0, 1.0);
126 glClear(GL_COLOR_BUFFER_BIT
);
128 /* Set the draw buffers for BlitFramebuffer */
129 glDrawBuffers(3, bufs
);
131 /* Blit from piglit_winsys_fbo to multisample_fbo. Blitting should
132 * happen in to all the draw buffers set above.
134 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
135 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisample_fbo
.handle
);
136 glBlitFramebuffer(0, 0, piglit_width
, piglit_height
,
137 0, 0, piglit_width
, piglit_height
,
141 for (unsigned i
= 0; i
< ARRAY_SIZE(bufs
); i
++) {
144 /* Resolve the contents of multisample_fbo in to
147 glBindFramebuffer(GL_READ_FRAMEBUFFER
, multisample_fbo
.handle
);
148 glReadBuffer(bufs
[i
]);
149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
150 glClearColor(0.0, 0.0, 0.0, 1.0);
151 glClear(GL_COLOR_BUFFER_BIT
);
153 glBlitFramebuffer(0, 0, piglit_width
, piglit_height
,
154 0, 0, piglit_width
, piglit_height
,
158 /* Verify the contents */
159 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
160 result
= piglit_probe_rect_rgba(0, 0, piglit_width
,
161 piglit_height
, expected
[i
]);
162 pass
= result
&& pass
;
163 printf("Attachment = GL_COLOR_ATTACHMENT%d, Result = %s\n",
164 bufs
[i
] - GL_COLOR_ATTACHMENT0
,
165 result
? "pass" : "fail");
166 piglit_present_results();
169 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
170 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;