2 * Copyright © 2015 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 * Tapani Pälli <tapani.palli@intel.com>
27 /** @file draw-buffers.c
29 * Tests GL_EXT_draw_buffers implementation
31 * Test iterates over valid and invalid arguments and checks that the
32 * implementation returns correct error codes.
34 * GL_EXT_draw_buffers specification "Errors" section states:
36 * "The INVALID_OPERATION error is generated if DrawBuffersEXT is called
37 * when the default framebuffer is bound and any of the following conditions
40 * - <n> is greater than 1 and less than MAX_DRAW_BUFFERS_EXT,
41 * - <bufs> contains a value other than BACK or NONE.
43 * The INVALID_OPERATION error is generated if DrawBuffersEXT is called
44 * when bound to a draw framebuffer object and any of the following
46 * - the <i>th value in <bufs> is not COLOR_ATTACHMENT<i>_EXT or NONE.
48 * The INVALID_VALUE error is generated if DrawBuffersEXT is called
49 * with a value of <n> which is greater than MAX_DRAW_BUFFERS_EXT.
51 * The INVALID_ENUM error is generated by FramebufferRenderbuffer if
52 * the <attachment> parameter is not one of the values listed in Table 4.x.
54 * The INVALID_ENUM error is generated by FramebufferTexture2D if
55 * the <attachment> parameter is not one of the values listed in Table 4.x.
57 * The INVALID_ENUM error is generated by GetFramebufferAttachmentParameteriv
58 * if the <attachment> parameter is not one of the values listed in Table 4.x."
61 #include "piglit-util-gl.h"
63 PIGLIT_GL_TEST_CONFIG_BEGIN
65 config
.supports_gl_es_version
= 20;
67 PIGLIT_GL_TEST_CONFIG_END
69 #define TEXTURE_AMOUNT 3
71 static const GLenum valid_buffer_list
[] = {
77 static const GLenum invalid_buffer_list
[] = {
84 create_fbo(int max_draw_buffers
)
88 int test_attachments
= MIN2(max_draw_buffers
, TEXTURE_AMOUNT
);
89 GLuint textures
[TEXTURE_AMOUNT
];
93 /* Generate fbo with test_attachments color attachments. */
94 glGenFramebuffers(1, &fbo
);
95 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
96 glGenTextures(test_attachments
, textures
);
98 for (i
= 0; i
< test_attachments
; i
++) {
99 glBindTexture(GL_TEXTURE_2D
, textures
[i
]);
100 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 0, GL_RGBA
,
101 GL_UNSIGNED_BYTE
, NULL
);
103 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
104 GL_COLOR_ATTACHMENT0_EXT
+ i
,
110 /* Test adding invalid attachment. */
111 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
116 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
119 /* Create a depth buffer. */
120 glGenRenderbuffersEXT(1, &depth
);
121 glBindRenderbuffer(GL_RENDERBUFFER_EXT
, depth
);
122 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT
, GL_DEPTH_COMPONENT16
, 4, 4);
124 /* Test adding invalid renderbuffer. */
125 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT
,
130 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
133 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT
,
134 GL_DEPTH_ATTACHMENT_EXT
,
138 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
139 GL_FRAMEBUFFER_COMPLETE
) {
143 /* Test invalid attachment with GetFramebufferAttachmentParameteriv. */
144 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_FALSE
,
145 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
, ¶m
);
147 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
150 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
158 const GLenum back
= GL_BACK
;
159 const GLenum att0
= GL_COLOR_ATTACHMENT0
;
163 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
165 glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT
, &max_buffers
);
166 if (!piglit_check_gl_error(GL_NO_ERROR
))
169 /* Error cases when default framebuffer is bound. */
170 glDrawBuffersEXT(0, &back
);
171 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
174 if (max_buffers
>= 2) {
175 glDrawBuffersEXT(2, &back
);
176 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
180 if (max_buffers
>= 3) {
181 glDrawBuffersEXT(3, &att0
);
182 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
186 /* Positive case with default framebuffer. */
187 glDrawBuffersEXT(1, &back
);
188 if (!piglit_check_gl_error(GL_NO_ERROR
))
191 /* Create user fbo for rest of the tests. */
192 fbo
= create_fbo(max_buffers
);
193 if (!fbo
|| !piglit_check_gl_error(GL_NO_ERROR
))
196 /* Error cases when user framebuffer is bound. */
197 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
199 if (max_buffers
>= 3) {
200 glDrawBuffersEXT(3, invalid_buffer_list
);
201 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
205 glDrawBuffersEXT(max_buffers
+ 1, valid_buffer_list
);
206 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
209 /* Positive case with user framebuffer. */
210 glDrawBuffersEXT(MIN2(max_buffers
, TEXTURE_AMOUNT
), valid_buffer_list
);
211 if (!piglit_check_gl_error(GL_NO_ERROR
))
221 GLboolean pass
= run_test();
223 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
227 piglit_init(int argc
, char **argv
)
229 piglit_require_extension("GL_EXT_draw_buffers");