Home | History | Annotate | Download | only in draw_buffers_indexed
      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  **/
     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 
     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  **/
     60 DrawBuffersIndexedBase::BlendMaskStateMachine::BlendMaskStateMachine(Context& context, tcu::TestLog& log)
     61 	: state(4), gl(context.getRenderContext().getFunctions()), testLog(log)
     62 {
     63 }
     64 
     65 DrawBuffersIndexedBase::BlendMaskStateMachine::BlendMaskStateMachine(Context& context, tcu::TestLog& log, int dbs)
     66 	: state(dbs), gl(context.getRenderContext().getFunctions()), testLog(log)
     67 {
     68 }
     69 
     70 /** Helper class member functions
     71  *
     72  **/
     73 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckEnumGeneral(glw::GLenum e, glw::GLenum s)
     74 {
     75 	glw::GLint	 i;
     76 	glw::GLint64   li;
     77 	glw::GLboolean b;
     78 	glw::GLfloat   f;
     79 
     80 	gl.getIntegerv(e, &i);
     81 	gl.getInteger64v(e, &li);
     82 	gl.getBooleanv(e, &b);
     83 	gl.getFloatv(e, &f);
     84 	if ((static_cast<glw::GLenum>(i) != s) || (static_cast<glw::GLenum>(li) != s) ||
     85 		(static_cast<glw::GLenum>(f) != s) || (b != (s ? GL_TRUE : GL_FALSE)))
     86 	{
     87 		testLog << tcu::TestLog::Message << "General state should be set to " << s
     88 				<< " but found the following values:\n"
     89 				<< "int: " << i << "\n"
     90 				<< "int64: " << li << "\n"
     91 				<< "bool: " << b << tcu::TestLog::EndMessage;
     92 		return false;
     93 	}
     94 	return true;
     95 }
     96 
     97 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckEnumForBuffer(int idx, glw::GLenum e, glw::GLenum s)
     98 {
     99 	glw::GLint	 i;
    100 	glw::GLint64   li;
    101 	glw::GLboolean b;
    102 
    103 	gl.getIntegeri_v(e, idx, &i);
    104 	gl.getInteger64i_v(e, idx, &li);
    105 	gl.getBooleani_v(e, idx, &b);
    106 	if ((static_cast<glw::GLenum>(i) != s) || (static_cast<glw::GLenum>(li) != s) || (b != (s ? GL_TRUE : GL_FALSE)))
    107 	{
    108 		testLog << tcu::TestLog::Message << "State for " << e << " in buffer #" << idx << " should be set to " << s
    109 				<< " but found the following values:\n"
    110 				<< "int: " << i << "\n"
    111 				<< "int64: " << li << "\n"
    112 				<< "bool: " << b << tcu::TestLog::EndMessage;
    113 		return false;
    114 	}
    115 	return true;
    116 }
    117 
    118 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckBuffer(int idx)
    119 {
    120 	if (gl.isEnabledi(GL_BLEND, idx) != state[idx].enable)
    121 	{
    122 		testLog << tcu::TestLog::Message << "Blending for buffer #" << idx << " set to: " << !state[idx].enable
    123 				<< " but should be " << state[idx].enable << "!" << tcu::TestLog::EndMessage;
    124 		return false;
    125 	}
    126 
    127 	bool result = true;
    128 
    129 	result &= CheckEnumForBuffer(idx, GL_BLEND_EQUATION_RGB, state[idx].mode_rgb);
    130 	result &= CheckEnumForBuffer(idx, GL_BLEND_EQUATION_ALPHA, state[idx].mode_a);
    131 	result &= CheckEnumForBuffer(idx, GL_BLEND_SRC_RGB, state[idx].func_src_rgb);
    132 	result &= CheckEnumForBuffer(idx, GL_BLEND_SRC_ALPHA, state[idx].func_src_a);
    133 	result &= CheckEnumForBuffer(idx, GL_BLEND_DST_RGB, state[idx].func_dst_rgb);
    134 	result &= CheckEnumForBuffer(idx, GL_BLEND_DST_ALPHA, state[idx].func_dst_a);
    135 
    136 	glw::GLint	 ia[4];
    137 	glw::GLint64   lia[4];
    138 	glw::GLboolean ba[4];
    139 
    140 	gl.getIntegeri_v(GL_COLOR_WRITEMASK, idx, ia);
    141 	gl.getInteger64i_v(GL_COLOR_WRITEMASK, idx, lia);
    142 	gl.getBooleani_v(GL_COLOR_WRITEMASK, idx, ba);
    143 	if ((ia[0] != state[idx].mask_r) || (static_cast<int>(lia[0]) != state[idx].mask_r) ||
    144 		(static_cast<int>(ba[0]) != state[idx].mask_r) || (ia[1] != state[idx].mask_g) ||
    145 		(static_cast<int>(lia[1]) != state[idx].mask_g) || (static_cast<int>(ba[1]) != state[idx].mask_g) ||
    146 		(ia[2] != state[idx].mask_b) || (static_cast<int>(lia[2]) != state[idx].mask_b) ||
    147 		(static_cast<int>(ba[2]) != state[idx].mask_b) || (ia[3] != state[idx].mask_a) ||
    148 		(static_cast<int>(lia[3]) != state[idx].mask_a) || (static_cast<int>(ba[3]) != state[idx].mask_a))
    149 	{
    150 		testLog << tcu::TestLog::Message << "GL_COLOR_WRITEMASK for buffer #" << idx << " should be set to("
    151 				<< state[idx].mask_r << ", " << state[idx].mask_g << ", " << state[idx].mask_b << ", "
    152 				<< state[idx].mask_a << ")\n"
    153 				<< "but the following values was set:\n"
    154 				<< "int: " << ia[0] << ", " << ia[1] << ", " << ia[2] << ", " << ia[3] << "\n"
    155 				<< "int64: " << lia[0] << ", " << lia[1] << ", " << lia[2] << ", " << lia[3] << "\n"
    156 				<< "bool: " << ba[0] << ", " << ba[1] << ", " << ba[2] << ", " << ba[3] << tcu::TestLog::EndMessage;
    157 		result = false;
    158 	}
    159 	if (idx == 0)
    160 	{
    161 		result &= CheckEnumGeneral(GL_BLEND_EQUATION_RGB, state[idx].mode_rgb);
    162 		result &= CheckEnumGeneral(GL_BLEND_EQUATION_ALPHA, state[idx].mode_a);
    163 		result &= CheckEnumGeneral(GL_BLEND_SRC_RGB, state[idx].func_src_rgb);
    164 		result &= CheckEnumGeneral(GL_BLEND_SRC_ALPHA, state[idx].func_src_a);
    165 		result &= CheckEnumGeneral(GL_BLEND_DST_RGB, state[idx].func_dst_rgb);
    166 		result &= CheckEnumGeneral(GL_BLEND_DST_ALPHA, state[idx].func_dst_a);
    167 
    168 		glw::GLfloat fa[4];
    169 
    170 		gl.getIntegerv(GL_COLOR_WRITEMASK, ia);
    171 		gl.getInteger64v(GL_COLOR_WRITEMASK, lia);
    172 		gl.getBooleanv(GL_COLOR_WRITEMASK, ba);
    173 		gl.getFloatv(GL_COLOR_WRITEMASK, fa);
    174 		if ((ia[0] != state[idx].mask_r) || (static_cast<int>(lia[0]) != state[idx].mask_r) ||
    175 			(ia[1] != state[idx].mask_g) || (static_cast<int>(lia[1]) != state[idx].mask_g) ||
    176 			(ia[2] != state[idx].mask_b) || (static_cast<int>(lia[2]) != state[idx].mask_b) ||
    177 			(ia[3] != state[idx].mask_a) || (static_cast<int>(lia[3]) != state[idx].mask_a) ||
    178 			(static_cast<int>(ba[0]) != state[idx].mask_r) || (static_cast<int>(fa[0]) != state[idx].mask_r) ||
    179 			(static_cast<int>(ba[1]) != state[idx].mask_g) || (static_cast<int>(fa[1]) != state[idx].mask_g) ||
    180 			(static_cast<int>(ba[2]) != state[idx].mask_b) || (static_cast<int>(fa[2]) != state[idx].mask_b) ||
    181 			(static_cast<int>(ba[3]) != state[idx].mask_a) || (static_cast<int>(fa[3]) != state[idx].mask_a))
    182 		{
    183 			testLog << tcu::TestLog::Message << "GL_COLOR_WRITEMASK for buffer #" << idx << " should be set to("
    184 					<< state[idx].mask_r << ", " << state[idx].mask_g << ", " << state[idx].mask_b << ", "
    185 					<< state[idx].mask_a << ")\n"
    186 					<< "but the following values was set:\n"
    187 					<< "int: " << ia[0] << ", " << ia[1] << ", " << ia[2] << ", " << ia[3] << "\n"
    188 					<< "int64: " << lia[0] << ", " << lia[1] << ", " << lia[2] << ", " << lia[3] << "\n"
    189 					<< "bool: " << ba[0] << ", " << ba[1] << ", " << ba[2] << ", " << ba[3] << "\n"
    190 					<< "float: " << fa[0] << ", " << fa[1] << ", " << fa[2] << ", " << fa[3]
    191 					<< tcu::TestLog::EndMessage;
    192 			result = false;
    193 		}
    194 	}
    195 	return result;
    196 }
    197 
    198 bool DrawBuffersIndexedBase::BlendMaskStateMachine::CheckAll()
    199 {
    200 	for (unsigned int i = 0; i < state.size(); ++i)
    201 	{
    202 		if (!CheckBuffer(i))
    203 		{
    204 			return false;
    205 		}
    206 	}
    207 	return true;
    208 }
    209 
    210 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetEnablei(int idx)
    211 {
    212 	gl.enablei(GL_BLEND, idx);
    213 	state[idx].enable = GL_TRUE;
    214 }
    215 
    216 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDisablei(int idx)
    217 {
    218 	gl.disablei(GL_BLEND, idx);
    219 	state[idx].enable = GL_FALSE;
    220 }
    221 
    222 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetColorMaski(int idx, glw::GLboolean r, glw::GLboolean g,
    223 																  glw::GLboolean b, glw::GLboolean a)
    224 {
    225 	gl.colorMaski(idx, r, g, b, a);
    226 	state[idx].mask_r = r;
    227 	state[idx].mask_g = g;
    228 	state[idx].mask_b = b;
    229 	state[idx].mask_a = a;
    230 }
    231 
    232 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationi(int idx, glw::GLenum mode)
    233 {
    234 	gl.blendEquationi(idx, mode);
    235 	state[idx].mode_rgb = mode;
    236 	state[idx].mode_a   = mode;
    237 }
    238 
    239 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationSeparatei(int idx, glw::GLenum rgb, glw::GLenum a)
    240 {
    241 	gl.blendEquationSeparatei(idx, rgb, a);
    242 	state[idx].mode_rgb = rgb;
    243 	state[idx].mode_a   = a;
    244 }
    245 
    246 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFunci(int idx, glw::GLenum src, glw::GLenum dst)
    247 {
    248 	gl.blendFunci(idx, src, dst);
    249 	state[idx].func_src_rgb = src;
    250 	state[idx].func_src_a   = src;
    251 	state[idx].func_dst_rgb = dst;
    252 	state[idx].func_dst_a   = dst;
    253 }
    254 
    255 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFuncSeparatei(int idx, glw::GLenum src_rgb,
    256 																		  glw::GLenum dst_rgb, glw::GLenum src_a,
    257 																		  glw::GLenum dst_a)
    258 {
    259 	gl.blendFuncSeparatei(idx, src_rgb, dst_rgb, src_a, dst_a);
    260 	state[idx].func_src_rgb = src_rgb;
    261 	state[idx].func_src_a   = src_a;
    262 	state[idx].func_dst_rgb = dst_rgb;
    263 	state[idx].func_dst_a   = dst_a;
    264 }
    265 
    266 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetEnable()
    267 {
    268 	// all draw buffers
    269 	gl.enable(GL_BLEND);
    270 	for (unsigned int i = 0; i < state.size(); ++i)
    271 	{
    272 		state[i].enable = GL_TRUE;
    273 	}
    274 }
    275 
    276 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDisable()
    277 {
    278 	// all draw buffers
    279 	gl.disable(GL_BLEND);
    280 	for (unsigned int i = 0; i < state.size(); ++i)
    281 	{
    282 		state[i].enable = GL_FALSE;
    283 	}
    284 }
    285 
    286 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetColorMask(glw::GLboolean r, glw::GLboolean g, glw::GLboolean b,
    287 																 glw::GLboolean a)
    288 {
    289 	// all draw buffers
    290 	gl.colorMask(r, g, b, a);
    291 	for (unsigned int i = 0; i < state.size(); ++i)
    292 	{
    293 		state[i].mask_r = r;
    294 		state[i].mask_g = g;
    295 		state[i].mask_b = b;
    296 		state[i].mask_a = a;
    297 	}
    298 }
    299 
    300 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquation(glw::GLenum mode)
    301 {
    302 	// all draw buffers
    303 	gl.blendEquation(mode);
    304 	for (unsigned int i = 0; i < state.size(); ++i)
    305 	{
    306 		state[i].mode_rgb = mode;
    307 		state[i].mode_a   = mode;
    308 	}
    309 }
    310 
    311 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendEquationSeparate(glw::GLenum rgb, glw::GLenum a)
    312 {
    313 	// all draw buffers
    314 	gl.blendEquationSeparate(rgb, a);
    315 	for (unsigned int i = 0; i < state.size(); ++i)
    316 	{
    317 		state[i].mode_rgb = rgb;
    318 		state[i].mode_a   = a;
    319 	}
    320 }
    321 
    322 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFunc(glw::GLenum src, glw::GLenum dst)
    323 {
    324 	// all draw buffers
    325 	gl.blendFunc(src, dst);
    326 	for (unsigned int i = 0; i < state.size(); ++i)
    327 	{
    328 		state[i].func_src_rgb = src;
    329 		state[i].func_src_a   = src;
    330 		state[i].func_dst_rgb = dst;
    331 		state[i].func_dst_a   = dst;
    332 	}
    333 }
    334 
    335 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetBlendFuncSeparate(glw::GLenum src_rgb, glw::GLenum dst_rgb,
    336 																		 glw::GLenum src_a, glw::GLenum dst_a)
    337 {
    338 	// all draw buffers
    339 	gl.blendFuncSeparate(src_rgb, dst_rgb, src_a, dst_a);
    340 	for (unsigned int i = 0; i < state.size(); ++i)
    341 	{
    342 		state[i].func_src_rgb = src_rgb;
    343 		state[i].func_src_a   = src_a;
    344 		state[i].func_dst_rgb = dst_rgb;
    345 		state[i].func_dst_a   = dst_a;
    346 	}
    347 }
    348 
    349 void DrawBuffersIndexedBase::BlendMaskStateMachine::SetDefaults()
    350 {
    351 	SetDisable();
    352 	SetColorMask(1, 1, 1, 1);
    353 	SetBlendEquation(GL_FUNC_ADD);
    354 	SetBlendFunc(GL_ONE, GL_ZERO);
    355 }
    356 
    357 } // namespace glcts
    358