2 * Copyright © 2011 Red Hat
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
25 * \file error-at-begin.c
28 * ARB_blend_func_extended states in ERRORS section
29 * "The error INVALID_OPERATION is generated by Begin or any procedure that
30 * implicitly calls Begin if any draw buffer has a blend function requiring the
31 * second color input (SRC1_COLOR, ONE_MINUS_SRC1_COLOR, SRC1_ALPHA or
32 * ONE_MINUS_SRC1_ALPHA), and a framebuffer is bound that has more than
33 * the value of MAX_DUAL_SOURCE_DRAW_BUFFERS-1 active color attachements."
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
52 static GLuint max_buffers
;
60 glGenFramebuffers(1, &fbo
);
61 glBindFramebuffer(GL_FRAMEBUFFER_EXT
, fbo
);
63 glGenRenderbuffers(max_buffers
, rb
);
65 for (i
= 0; i
< max_buffers
; i
++) {
66 glBindRenderbuffer(GL_RENDERBUFFER_EXT
, rb
[i
]);
68 glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT
,
69 GL_COLOR_ATTACHMENT0
+ i
,
72 glRenderbufferStorage(GL_RENDERBUFFER_EXT
, GL_RGBA
,
73 piglit_width
, piglit_height
);
77 void piglit_init(int argc
, char **argv
)
79 GLint max_dual_source
;
82 piglit_require_gl_version(30);
83 piglit_require_extension("GL_ARB_blend_func_extended");
84 piglit_require_extension("GL_ARB_draw_buffers_blend");
87 /* This test needs some number of draw buffers, so make sure the
88 * implementation isn't broken. This enables the test to generate a
89 * useful failure message.
91 glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS
, &max_dual_source
);
92 if (max_dual_source
< 1) {
94 "ARB_blend_func_extended requires GL_MAX_DUAL_SOURCE_DRAW_BUFFERS >= 1. "
97 piglit_report_result(PIGLIT_FAIL
);
100 max_buffers
= max_dual_source
+ 1;
104 for (i
= 0; i
< max_buffers
; i
++)
105 buffers
[i
] = GL_COLOR_ATTACHMENT0_EXT
+ i
;
107 glDrawBuffersARB(max_buffers
, buffers
);
109 for (i
= 0; i
< max_buffers
; i
++) {
110 if (i
>= max_dual_source
)
111 glBlendFunciARB(i
, GL_SRC1_ALPHA
, GL_ONE_MINUS_SRC1_ALPHA
);
113 glBlendFunciARB(i
, GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
114 glEnableIndexedEXT(GL_BLEND
, i
);
119 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
120 piglit_report_result(PIGLIT_FAIL
);
122 piglit_report_result(PIGLIT_PASS
);