ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / gles-2.0 / draw-buffers.c
blob18c17813d9674c12c0c3c75e50fe15474be69fdd
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()
86 GLuint fbo;
87 GLuint depth;
88 GLuint textures[TEXTURE_AMOUNT];
89 GLint param;
90 unsigned i;
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,
104 GL_TEXTURE_2D,
105 textures[i], 0);
109 /* Test adding invalid attachment. */
110 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
111 GL_FALSE,
112 GL_TEXTURE_2D,
113 textures[0], 0);
115 if (!piglit_check_gl_error(GL_INVALID_ENUM))
116 return 0;
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,
125 GL_FALSE,
126 GL_RENDERBUFFER_EXT,
127 depth);
129 if (!piglit_check_gl_error(GL_INVALID_ENUM))
130 return 0;
132 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
133 GL_DEPTH_ATTACHMENT_EXT,
134 GL_RENDERBUFFER_EXT,
135 depth);
137 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
138 GL_FRAMEBUFFER_COMPLETE) {
139 return 0;
142 /* Test invalid attachment with GetFramebufferAttachmentParameteriv. */
143 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FALSE,
144 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &param);
146 if (!piglit_check_gl_error(GL_INVALID_ENUM))
147 return 0;
149 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
151 return fbo;
154 static GLboolean
155 run_test(void)
157 const GLenum back = GL_BACK;
158 const GLenum att0 = GL_COLOR_ATTACHMENT0;
159 GLuint fbo;
160 GLint max_buffers;
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))
167 return false;
169 glDrawBuffersEXT(2, &back);
170 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
171 return false;
173 glDrawBuffersEXT(3, &att0);
174 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
175 return false;
177 /* Positive case with default framebuffer. */
178 glDrawBuffersEXT(1, &back);
179 if (!piglit_check_gl_error(GL_NO_ERROR))
180 return false;
182 /* Create user fbo for rest of the tests. */
183 fbo = create_fbo();
184 if (!fbo || !piglit_check_gl_error(GL_NO_ERROR))
185 return false;
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))
192 return false;
194 glGetIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &max_buffers);
195 if (!piglit_check_gl_error(GL_NO_ERROR))
196 return false;
198 glDrawBuffersEXT(max_buffers + 1, valid_buffer_list);
199 if (!piglit_check_gl_error(GL_INVALID_VALUE))
200 return false;
202 /* Positive case with user framebuffer. */
203 glDrawBuffersEXT(TEXTURE_AMOUNT, valid_buffer_list);
204 if (!piglit_check_gl_error(GL_NO_ERROR))
205 return false;
207 return true;
211 enum piglit_result
212 piglit_display(void)
214 GLboolean pass = run_test();
216 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
219 void
220 piglit_init(int argc, char **argv)
222 piglit_require_extension("GL_EXT_draw_buffers");