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
[] = {
88 GLuint textures
[TEXTURE_AMOUNT
];
92 /* Generate fbo with TEXTURE_AMOUNT color attachments. */
93 glGenFramebuffers(1, &fbo
);
94 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
95 glGenTextures(TEXTURE_AMOUNT
, textures
);
97 for (i
= 0; i
< TEXTURE_AMOUNT
; i
++) {
98 glBindTexture(GL_TEXTURE_2D
, textures
[i
]);
99 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 0, GL_RGBA
,
100 GL_UNSIGNED_BYTE
, NULL
);
102 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
103 GL_COLOR_ATTACHMENT0_EXT
+ i
,
109 /* Test adding invalid attachment. */
110 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
115 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
118 /* Create a depth buffer. */
119 glGenRenderbuffersEXT(1, &depth
);
120 glBindRenderbuffer(GL_RENDERBUFFER_EXT
, depth
);
121 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT
, GL_DEPTH_COMPONENT16
, 4, 4);
123 /* Test adding invalid renderbuffer. */
124 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT
,
129 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
132 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT
,
133 GL_DEPTH_ATTACHMENT_EXT
,
137 if (glCheckFramebufferStatus(GL_FRAMEBUFFER
) !=
138 GL_FRAMEBUFFER_COMPLETE
) {
142 /* Test invalid attachment with GetFramebufferAttachmentParameteriv. */
143 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER
, GL_FALSE
,
144 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
, ¶m
);
146 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
157 const GLenum back
= GL_BACK
;
158 const GLenum att0
= GL_COLOR_ATTACHMENT0
;
162 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
164 /* Error cases when default framebuffer is bound. */
165 glDrawBuffersEXT(0, &back
);
166 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
169 glDrawBuffersEXT(2, &back
);
170 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
173 glDrawBuffersEXT(3, &att0
);
174 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
177 /* Positive case with default framebuffer. */
178 glDrawBuffersEXT(1, &back
);
179 if (!piglit_check_gl_error(GL_NO_ERROR
))
182 /* Create user fbo for rest of the tests. */
184 if (!fbo
|| !piglit_check_gl_error(GL_NO_ERROR
))
187 /* Error cases when user framebuffer is bound. */
188 glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
190 glDrawBuffersEXT(3, invalid_buffer_list
);
191 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
194 glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT
, &max_buffers
);
195 if (!piglit_check_gl_error(GL_NO_ERROR
))
198 glDrawBuffersEXT(max_buffers
+ 1, valid_buffer_list
);
199 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
202 /* Positive case with user framebuffer. */
203 glDrawBuffersEXT(TEXTURE_AMOUNT
, valid_buffer_list
);
204 if (!piglit_check_gl_error(GL_NO_ERROR
))
214 GLboolean pass
= run_test();
216 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
220 piglit_init(int argc
, char **argv
)
222 piglit_require_extension("GL_EXT_draw_buffers");