glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / gles-2.0 / draw-buffers.c
blob182366ade7501a176b952528de5acbd0a3f70cf6
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Authors:
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
38 * hold:
39 * - <n> is zero,
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
45 * conditions hold:
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[] = {
72 GL_COLOR_ATTACHMENT0,
73 GL_COLOR_ATTACHMENT1,
74 GL_COLOR_ATTACHMENT2,
77 static const GLenum invalid_buffer_list[] = {
78 GL_COLOR_ATTACHMENT0,
79 GL_BACK,
80 GL_COLOR_ATTACHMENT1,
83 static GLuint
84 create_fbo(int max_draw_buffers)
86 GLuint fbo;
87 GLuint depth;
88 int test_attachments = MIN2(max_draw_buffers, TEXTURE_AMOUNT);
89 GLuint textures[TEXTURE_AMOUNT];
90 GLint param;
91 unsigned i;
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,
105 GL_TEXTURE_2D,
106 textures[i], 0);
110 /* Test adding invalid attachment. */
111 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
112 GL_FALSE,
113 GL_TEXTURE_2D,
114 textures[0], 0);
116 if (!piglit_check_gl_error(GL_INVALID_ENUM))
117 return 0;
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,
126 GL_FALSE,
127 GL_RENDERBUFFER_EXT,
128 depth);
130 if (!piglit_check_gl_error(GL_INVALID_ENUM))
131 return 0;
133 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
134 GL_DEPTH_ATTACHMENT_EXT,
135 GL_RENDERBUFFER_EXT,
136 depth);
138 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
139 GL_FRAMEBUFFER_COMPLETE) {
140 return 0;
143 /* Test invalid attachment with GetFramebufferAttachmentParameteriv. */
144 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FALSE,
145 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &param);
147 if (!piglit_check_gl_error(GL_INVALID_ENUM))
148 return 0;
150 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
152 return fbo;
155 static GLboolean
156 run_test(void)
158 const GLenum back = GL_BACK;
159 const GLenum att0 = GL_COLOR_ATTACHMENT0;
160 GLuint fbo;
161 GLint max_buffers;
163 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
165 glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &max_buffers);
166 if (!piglit_check_gl_error(GL_NO_ERROR))
167 return false;
169 /* Error cases when default framebuffer is bound. */
170 glDrawBuffersEXT(0, &back);
171 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
172 return false;
174 if (max_buffers >= 2) {
175 glDrawBuffersEXT(2, &back);
176 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
177 return false;
180 if (max_buffers >= 3) {
181 glDrawBuffersEXT(3, &att0);
182 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
183 return false;
186 /* Positive case with default framebuffer. */
187 glDrawBuffersEXT(1, &back);
188 if (!piglit_check_gl_error(GL_NO_ERROR))
189 return false;
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))
194 return false;
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))
202 return false;
205 glDrawBuffersEXT(max_buffers + 1, valid_buffer_list);
206 if (!piglit_check_gl_error(GL_INVALID_VALUE))
207 return false;
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))
212 return false;
214 return true;
218 enum piglit_result
219 piglit_display(void)
221 GLboolean pass = run_test();
223 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
226 void
227 piglit_init(int argc, char **argv)
229 piglit_require_extension("GL_EXT_draw_buffers");