1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23 
24 /*!
25  * \file esextcDrawBuffersIndexedBase.cpp
26  * \brief Base class for Draw Buffers Indexed extension tests 1-6
27  */ /*-------------------------------------------------------------------*/
28 
29 #include "esextcDrawBuffersIndexedBase.hpp"
30 #include "tcuTestLog.hpp"
31 
32 namespace glcts
33 {
34 
35 /** Base class constructor
36  *
37  *  @param context     Test context
38  *  @param name        Test case's name
39  *  @param description Test case's description
40  **/
DrawBuffersIndexedBase(Context & context,const ExtParameters & extParams,const char * name,const char * description)41 DrawBuffersIndexedBase::DrawBuffersIndexedBase(Context &context, const ExtParameters &extParams, const char *name,
42                                                const char *description)
43     : TestCaseBase(context, extParams, name, description)
44 {
45     /* Left blank on purpose */
46 }
47 
init()48 void DrawBuffersIndexedBase::init()
49 {
50     if (!isExtensionSupported("GL_OES_draw_buffers_indexed"))
51     {
52         throw tcu::NotSupportedError(DRAW_BUFFERS_INDEXED_NOT_SUPPORTED);
53     }
54 }
55 
56 /** Helper class constructors
57  *
58  *  @param context     Test context
59  **/
BlendMaskStateMachine(Context & context,tcu::TestLog & log)60 DrawBuffersIndexedBase::BlendMaskStateMachine::BlendMaskStateMachine(Context &context, tcu::TestLog &log)
61     : state(4)
62     , gl(context.getRenderContext().getFunctions())
63     , testLog(log)
64 {
65 }
66 
BlendMaskStateMachine(Context & context,tcu::TestLog & log,int dbs)67 DrawBuffersIndexedBase::BlendMaskStateMachine::BlendMaskStateMachine(Context &context, tcu::TestLog &log, int dbs)
68     : state(dbs)
69     , gl(context.getRenderContext().getFunctions())
70     , testLog(log)
71 {
72 }
73 
74 /** Helper class member functions
75  *
76  **/
CheckEnumGeneral(glw::GLenum e,glw::GLenum s)77 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckEnumGeneral(glw::GLenum e, glw::GLenum s)
78 {
79     glw::GLint i;
80     glw::GLint64 li;
81     glw::GLboolean b;
82     glw::GLfloat f;
83 
84     gl.getIntegerv(e, &i);
85     gl.getInteger64v(e, &li);
86     gl.getBooleanv(e, &b);
87     gl.getFloatv(e, &f);
88     if ((static_cast<glw::GLenum>(i) != s) || (static_cast<glw::GLenum>(li) != s) ||
89         (static_cast<glw::GLenum>(f) != s) || (b != (s ? GL_TRUE : GL_FALSE)))
90     {
91         testLog << tcu::TestLog::Message << "General state should be set to " << s
92                 << " but found the following values:\n"
93                 << "int: " << i << "\n"
94                 << "int64: " << li << "\n"
95                 << "bool: " << b << tcu::TestLog::EndMessage;
96         return false;
97     }
98     return true;
99 }
100 
CheckEnumForBuffer(int idx,glw::GLenum e,glw::GLenum s)101 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckEnumForBuffer(int idx, glw::GLenum e, glw::GLenum s)
102 {
103     glw::GLint i;
104     glw::GLint64 li;
105     glw::GLboolean b;
106 
107     gl.getIntegeri_v(e, idx, &i);
108     gl.getInteger64i_v(e, idx, &li);
109     gl.getBooleani_v(e, idx, &b);
110     if ((static_cast<glw::GLenum>(i) != s) || (static_cast<glw::GLenum>(li) != s) || (b != (s ? GL_TRUE : GL_FALSE)))
111     {
112         testLog << tcu::TestLog::Message << "State for " << e << " in buffer #" << idx << " should be set to " << s
113                 << " but found the following values:\n"
114                 << "int: " << i << "\n"
115                 << "int64: " << li << "\n"
116                 << "bool: " << b << tcu::TestLog::EndMessage;
117         return false;
118     }
119     return true;
120 }
121 
CheckBuffer(int idx)122 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckBuffer(int idx)
123 {
124     if (gl.isEnabledi(GL_BLEND, idx) != state[idx].enable)
125     {
126         testLog << tcu::TestLog::Message << "Blending for buffer #" << idx << " set to: " << !state[idx].enable
127                 << " but should be " << state[idx].enable << "!" << tcu::TestLog::EndMessage;
128         return false;
129     }
130 
131     bool result = true;
132 
133     result &= CheckEnumForBuffer(idx, GL_BLEND_EQUATION_RGB, state[idx].mode_rgb);
134     result &= CheckEnumForBuffer(idx, GL_BLEND_EQUATION_ALPHA, state[idx].mode_a);
135     result &= CheckEnumForBuffer(idx, GL_BLEND_SRC_RGB, state[idx].func_src_rgb);
136     result &= CheckEnumForBuffer(idx, GL_BLEND_SRC_ALPHA, state[idx].func_src_a);
137     result &= CheckEnumForBuffer(idx, GL_BLEND_DST_RGB, state[idx].func_dst_rgb);
138     result &= CheckEnumForBuffer(idx, GL_BLEND_DST_ALPHA, state[idx].func_dst_a);
139 
140     glw::GLint ia[4];
141     glw::GLint64 lia[4];
142     glw::GLboolean ba[4];
143 
144     gl.getIntegeri_v(GL_COLOR_WRITEMASK, idx, ia);
145     gl.getInteger64i_v(GL_COLOR_WRITEMASK, idx, lia);
146     gl.getBooleani_v(GL_COLOR_WRITEMASK, idx, ba);
147     if ((ia[0] != state[idx].mask_r) || (static_cast<int>(lia[0]) != state[idx].mask_r) ||
148         (static_cast<int>(ba[0]) != state[idx].mask_r) || (ia[1] != state[idx].mask_g) ||
149         (static_cast<int>(lia[1]) != state[idx].mask_g) || (static_cast<int>(ba[1]) != state[idx].mask_g) ||
150         (ia[2] != state[idx].mask_b) || (static_cast<int>(lia[2]) != state[idx].mask_b) ||
151         (static_cast<int>(ba[2]) != state[idx].mask_b) || (ia[3] != state[idx].mask_a) ||
152         (static_cast<int>(lia[3]) != state[idx].mask_a) || (static_cast<int>(ba[3]) != state[idx].mask_a))
153     {
154         testLog << tcu::TestLog::Message << "GL_COLOR_WRITEMASK for buffer #" << idx << " should be set to("
155                 << state[idx].mask_r << ", " << state[idx].mask_g << ", " << state[idx].mask_b << ", "
156                 << state[idx].mask_a << ")\n"
157                 << "but the following values was set:\n"
158                 << "int: " << ia[0] << ", " << ia[1] << ", " << ia[2] << ", " << ia[3] << "\n"
159                 << "int64: " << lia[0] << ", " << lia[1] << ", " << lia[2] << ", " << lia[3] << "\n"
160                 << "bool: " << ba[0] << ", " << ba[1] << ", " << ba[2] << ", " << ba[3] << tcu::TestLog::EndMessage;
161         result = false;
162     }
163     if (idx == 0)
164     {
165         result &= CheckEnumGeneral(GL_BLEND_EQUATION_RGB, state[idx].mode_rgb);
166         result &= CheckEnumGeneral(GL_BLEND_EQUATION_ALPHA, state[idx].mode_a);
167         result &= CheckEnumGeneral(GL_BLEND_SRC_RGB, state[idx].func_src_rgb);
168         result &= CheckEnumGeneral(GL_BLEND_SRC_ALPHA, state[idx].func_src_a);
169         result &= CheckEnumGeneral(GL_BLEND_DST_RGB, state[idx].func_dst_rgb);
170         result &= CheckEnumGeneral(GL_BLEND_DST_ALPHA, state[idx].func_dst_a);
171 
172         glw::GLfloat fa[4];
173 
174         gl.getIntegerv(GL_COLOR_WRITEMASK, ia);
175         gl.getInteger64v(GL_COLOR_WRITEMASK, lia);
176         gl.getBooleanv(GL_COLOR_WRITEMASK, ba);
177         gl.getFloatv(GL_COLOR_WRITEMASK, fa);
178         if ((ia[0] != state[idx].mask_r) || (static_cast<int>(lia[0]) != state[idx].mask_r) ||
179             (ia[1] != state[idx].mask_g) || (static_cast<int>(lia[1]) != state[idx].mask_g) ||
180             (ia[2] != state[idx].mask_b) || (static_cast<int>(lia[2]) != state[idx].mask_b) ||
181             (ia[3] != state[idx].mask_a) || (static_cast<int>(lia[3]) != state[idx].mask_a) ||
182             (static_cast<int>(ba[0]) != state[idx].mask_r) || (static_cast<int>(fa[0]) != state[idx].mask_r) ||
183             (static_cast<int>(ba[1]) != state[idx].mask_g) || (static_cast<int>(fa[1]) != state[idx].mask_g) ||
184             (static_cast<int>(ba[2]) != state[idx].mask_b) || (static_cast<int>(fa[2]) != state[idx].mask_b) ||
185             (static_cast<int>(ba[3]) != state[idx].mask_a) || (static_cast<int>(fa[3]) != state[idx].mask_a))
186         {
187             testLog << tcu::TestLog::Message << "GL_COLOR_WRITEMASK for buffer #" << idx << " should be set to("
188                     << state[idx].mask_r << ", " << state[idx].mask_g << ", " << state[idx].mask_b << ", "
189                     << state[idx].mask_a << ")\n"
190                     << "but the following values was set:\n"
191                     << "int: " << ia[0] << ", " << ia[1] << ", " << ia[2] << ", " << ia[3] << "\n"
192                     << "int64: " << lia[0] << ", " << lia[1] << ", " << lia[2] << ", " << lia[3] << "\n"
193                     << "bool: " << ba[0] << ", " << ba[1] << ", " << ba[2] << ", " << ba[3] << "\n"
194                     << "float: " << fa[0] << ", " << fa[1] << ", " << fa[2] << ", " << fa[3]
195                     << tcu::TestLog::EndMessage;
196             result = false;
197         }
198     }
199     return result;
200 }
201 
CheckAll()202 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckAll()
203 {
204     for (unsigned int i = 0; i < state.size(); ++i)
205     {
206         if (!CheckBuffer(i))
207         {
208             return false;
209         }
210     }
211     return true;
212 }
213 
SetEnablei(int idx)214 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetEnablei(int idx)
215 {
216     gl.enablei(GL_BLEND, idx);
217     state[idx].enable = GL_TRUE;
218 }
219 
SetDisablei(int idx)220 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDisablei(int idx)
221 {
222     gl.disablei(GL_BLEND, idx);
223     state[idx].enable = GL_FALSE;
224 }
225 
SetColorMaski(int idx,glw::GLboolean r,glw::GLboolean g,glw::GLboolean b,glw::GLboolean a)226 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetColorMaski(int idx, glw::GLboolean r, glw::GLboolean g,
227                                                                   glw::GLboolean b, glw::GLboolean a)
228 {
229     gl.colorMaski(idx, r, g, b, a);
230     state[idx].mask_r = r;
231     state[idx].mask_g = g;
232     state[idx].mask_b = b;
233     state[idx].mask_a = a;
234 }
235 
SetBlendEquationi(int idx,glw::GLenum mode)236 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationi(int idx, glw::GLenum mode)
237 {
238     gl.blendEquationi(idx, mode);
239     state[idx].mode_rgb = mode;
240     state[idx].mode_a   = mode;
241 }
242 
SetBlendEquationSeparatei(int idx,glw::GLenum rgb,glw::GLenum a)243 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationSeparatei(int idx, glw::GLenum rgb, glw::GLenum a)
244 {
245     gl.blendEquationSeparatei(idx, rgb, a);
246     state[idx].mode_rgb = rgb;
247     state[idx].mode_a   = a;
248 }
249 
SetBlendFunci(int idx,glw::GLenum src,glw::GLenum dst)250 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFunci(int idx, glw::GLenum src, glw::GLenum dst)
251 {
252     gl.blendFunci(idx, src, dst);
253     state[idx].func_src_rgb = src;
254     state[idx].func_src_a   = src;
255     state[idx].func_dst_rgb = dst;
256     state[idx].func_dst_a   = dst;
257 }
258 
SetBlendFuncSeparatei(int idx,glw::GLenum src_rgb,glw::GLenum dst_rgb,glw::GLenum src_a,glw::GLenum dst_a)259 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFuncSeparatei(int idx, glw::GLenum src_rgb,
260                                                                           glw::GLenum dst_rgb, glw::GLenum src_a,
261                                                                           glw::GLenum dst_a)
262 {
263     gl.blendFuncSeparatei(idx, src_rgb, dst_rgb, src_a, dst_a);
264     state[idx].func_src_rgb = src_rgb;
265     state[idx].func_src_a   = src_a;
266     state[idx].func_dst_rgb = dst_rgb;
267     state[idx].func_dst_a   = dst_a;
268 }
269 
SetEnable()270 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetEnable()
271 {
272     // all draw buffers
273     gl.enable(GL_BLEND);
274     for (unsigned int i = 0; i < state.size(); ++i)
275     {
276         state[i].enable = GL_TRUE;
277     }
278 }
279 
SetDisable()280 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDisable()
281 {
282     // all draw buffers
283     gl.disable(GL_BLEND);
284     for (unsigned int i = 0; i < state.size(); ++i)
285     {
286         state[i].enable = GL_FALSE;
287     }
288 }
289 
SetColorMask(glw::GLboolean r,glw::GLboolean g,glw::GLboolean b,glw::GLboolean a)290 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetColorMask(glw::GLboolean r, glw::GLboolean g, glw::GLboolean b,
291                                                                  glw::GLboolean a)
292 {
293     // all draw buffers
294     gl.colorMask(r, g, b, a);
295     for (unsigned int i = 0; i < state.size(); ++i)
296     {
297         state[i].mask_r = r;
298         state[i].mask_g = g;
299         state[i].mask_b = b;
300         state[i].mask_a = a;
301     }
302 }
303 
SetBlendEquation(glw::GLenum mode)304 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquation(glw::GLenum mode)
305 {
306     // all draw buffers
307     gl.blendEquation(mode);
308     for (unsigned int i = 0; i < state.size(); ++i)
309     {
310         state[i].mode_rgb = mode;
311         state[i].mode_a   = mode;
312     }
313 }
314 
SetBlendEquationSeparate(glw::GLenum rgb,glw::GLenum a)315 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationSeparate(glw::GLenum rgb, glw::GLenum a)
316 {
317     // all draw buffers
318     gl.blendEquationSeparate(rgb, a);
319     for (unsigned int i = 0; i < state.size(); ++i)
320     {
321         state[i].mode_rgb = rgb;
322         state[i].mode_a   = a;
323     }
324 }
325 
SetBlendFunc(glw::GLenum src,glw::GLenum dst)326 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFunc(glw::GLenum src, glw::GLenum dst)
327 {
328     // all draw buffers
329     gl.blendFunc(src, dst);
330     for (unsigned int i = 0; i < state.size(); ++i)
331     {
332         state[i].func_src_rgb = src;
333         state[i].func_src_a   = src;
334         state[i].func_dst_rgb = dst;
335         state[i].func_dst_a   = dst;
336     }
337 }
338 
SetBlendFuncSeparate(glw::GLenum src_rgb,glw::GLenum dst_rgb,glw::GLenum src_a,glw::GLenum dst_a)339 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFuncSeparate(glw::GLenum src_rgb, glw::GLenum dst_rgb,
340                                                                          glw::GLenum src_a, glw::GLenum dst_a)
341 {
342     // all draw buffers
343     gl.blendFuncSeparate(src_rgb, dst_rgb, src_a, dst_a);
344     for (unsigned int i = 0; i < state.size(); ++i)
345     {
346         state[i].func_src_rgb = src_rgb;
347         state[i].func_src_a   = src_a;
348         state[i].func_dst_rgb = dst_rgb;
349         state[i].func_dst_a   = dst_a;
350     }
351 }
352 
SetDefaults()353 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDefaults()
354 {
355     SetDisable();
356     SetColorMask(1, 1, 1, 1);
357     SetBlendEquation(GL_FUNC_ADD);
358     SetBlendFunc(GL_ONE, GL_ZERO);
359 }
360 
361 } // namespace glcts
362