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  esextcDrawBuffersIndexedCoverage.hpp
26 * \brief Draw Buffers Indexed tests 1. Coverage
27 */ /*-------------------------------------------------------------------*/
28
29#include "esextcDrawBuffersIndexedCoverage.hpp"
30#include "glwEnums.hpp"
31
32namespace glcts
33{
34
35/** Constructor
36 *
37 *  @param context     Test context
38 *  @param name        Test case's name
39 *  @param description Test case's description
40 **/
41DrawBuffersIndexedCoverage::DrawBuffersIndexedCoverage(Context& context, const ExtParameters& extParams,
42													   const char* name, const char* description)
43	: TestCaseBase(context, extParams, name, description)
44{
45	/* Left blank on purpose */
46}
47
48void DrawBuffersIndexedCoverage::init()
49{
50	if (!isExtensionSupported("GL_OES_draw_buffers_indexed"))
51	{
52		throw tcu::NotSupportedError(DRAW_BUFFERS_INDEXED_NOT_SUPPORTED);
53	}
54}
55
56tcu::TestNode::IterateResult DrawBuffersIndexedCoverage::iterate()
57{
58	const glw::Functions& gl = m_context.getRenderContext().getFunctions();
59
60	// Check number of available draw buffers
61	glw::GLint maxDrawBuffers = 0;
62	gl.getIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
63	if (maxDrawBuffers < 4)
64	{
65		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Minimum number of draw buffers too low");
66		return STOP;
67	}
68
69	// Check that all functions executed properly
70	glw::GLint	 valueI;
71	glw::GLint64   valueLI;
72	glw::GLboolean valueB;
73	for (int i = 0; i < maxDrawBuffers; ++i)
74	{
75		gl.enablei(GL_BLEND, i);
76		gl.disablei(GL_BLEND, i);
77
78		gl.isEnabledi(GL_BLEND, i);
79		gl.colorMaski(i, GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
80		gl.blendEquationi(i, GL_MIN);
81		gl.blendEquationSeparatei(i, GL_MAX, GL_FUNC_SUBTRACT);
82		gl.blendFunci(i, GL_ZERO, GL_SRC_COLOR);
83		gl.blendFuncSeparatei(i, GL_CONSTANT_COLOR, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE);
84
85		gl.getIntegeri_v(GL_BLEND_DST_ALPHA, i, &valueI);
86		gl.getInteger64i_v(GL_BLEND_DST_ALPHA, i, &valueLI);
87		gl.getBooleani_v(GL_BLEND_SRC_RGB, i, &valueB);
88	}
89
90	// Restore default state
91	gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
92	gl.blendEquation(GL_FUNC_ADD);
93	gl.blendFunc(GL_ONE, GL_ZERO);
94
95	// Check for error
96	glw::GLenum error_code = gl.getError();
97	if (error_code != GL_NO_ERROR)
98	{
99		m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Some functions generated error");
100		return STOP;
101	}
102
103	m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
104	return STOP;
105}
106
107} // namespace glcts
108