1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.1 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2015 The Android Open Source Project
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 Framebuffer Default State Query tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es31fFramebufferDefaultStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "gluRenderContext.hpp"
27 #include "gluCallLogWrapper.hpp"
28 #include "gluObjectWrapper.hpp"
29 #include "glwFunctions.hpp"
30 #include "glwEnums.hpp"
31 
32 namespace deqp
33 {
34 namespace gles31
35 {
36 namespace Functional
37 {
38 namespace
39 {
40 
41 using namespace gls::StateQueryUtil;
42 
getVerifierSuffix(QueryType type)43 static const char* getVerifierSuffix (QueryType type)
44 {
45 	switch (type)
46 	{
47 		case QUERY_FRAMEBUFFER_INTEGER:	return "get_framebuffer_parameteriv";
48 		default:
49 			DE_ASSERT(DE_FALSE);
50 			return DE_NULL;
51 	}
52 }
53 
54 class FramebufferTest : public TestCase
55 {
56 public:
57 						FramebufferTest		(Context& context, QueryType verifier, const char* name, const char* desc);
58 	IterateResult		iterate				(void);
59 
60 protected:
61 	virtual void		checkInitial		(tcu::ResultCollector& result, glu::CallLogWrapper& gl) = 0;
62 	virtual void		checkSet			(tcu::ResultCollector& result, glu::CallLogWrapper& gl) = 0;
63 
64 	const QueryType		m_verifier;
65 };
66 
FramebufferTest(Context & context,QueryType verifier,const char * name,const char * desc)67 FramebufferTest::FramebufferTest (Context& context, QueryType verifier, const char* name, const char* desc)
68 	: TestCase		(context, name, desc)
69 	, m_verifier	(verifier)
70 {
71 }
72 
iterate(void)73 FramebufferTest::IterateResult FramebufferTest::iterate (void)
74 {
75 	glu::Framebuffer		fbo		(m_context.getRenderContext());
76 	glu::CallLogWrapper		gl		(m_context.getRenderContext().getFunctions(), m_testCtx.getLog());
77 	tcu::ResultCollector	result	(m_testCtx.getLog(), " // ERROR: ");
78 
79 	gl.enableLogging(true);
80 
81 	gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, *fbo);
82 	GLU_EXPECT_NO_ERROR(gl.glGetError(), "bind");
83 
84 	{
85 		const tcu::ScopedLogSection section(m_testCtx.getLog(), "Initial", "Initial");
86 		checkInitial(result, gl);
87 	}
88 
89 	{
90 		const tcu::ScopedLogSection	section(m_testCtx.getLog(), "Set", "Set");
91 		checkSet(result, gl);
92 	}
93 
94 	result.setTestContextResult(m_testCtx);
95 	return STOP;
96 }
97 
98 class FramebufferDimensionTest : public FramebufferTest
99 {
100 public:
101 	enum DimensionType
102 	{
103 		DIMENSION_WIDTH = 0,
104 		DIMENSION_HEIGHT,
105 
106 		DIMENSION_LAST
107 	};
108 
109 						FramebufferDimensionTest	(Context& context, QueryType verifier, DimensionType dimension, const char* name, const char* desc);
110 	void				checkInitial				(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
111 	void				checkSet					(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
112 
113 private:
114 	const DimensionType	m_dimension;
115 };
116 
FramebufferDimensionTest(Context & context,QueryType verifier,DimensionType dimension,const char * name,const char * desc)117 FramebufferDimensionTest::FramebufferDimensionTest (Context& context, QueryType verifier, DimensionType dimension, const char* name, const char* desc)
118 	: FramebufferTest	(context, verifier, name, desc)
119 	, m_dimension		(dimension)
120 {
121 	DE_ASSERT(dimension < DIMENSION_LAST);
122 }
123 
checkInitial(tcu::ResultCollector & result,glu::CallLogWrapper & gl)124 void FramebufferDimensionTest::checkInitial (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
125 {
126 	const glw::GLenum pname = (m_dimension == DIMENSION_WIDTH) ? (GL_FRAMEBUFFER_DEFAULT_WIDTH) : (GL_FRAMEBUFFER_DEFAULT_HEIGHT);
127 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, pname, 0, m_verifier);
128 }
129 
checkSet(tcu::ResultCollector & result,glu::CallLogWrapper & gl)130 void FramebufferDimensionTest::checkSet (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
131 {
132 	const glw::GLenum pname = (m_dimension == DIMENSION_WIDTH) ? (GL_FRAMEBUFFER_DEFAULT_WIDTH) : (GL_FRAMEBUFFER_DEFAULT_HEIGHT);
133 
134 	gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, pname, 32);
135 	GLU_EXPECT_NO_ERROR(gl.glGetError(), "set state");
136 
137 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, pname, 32, m_verifier);
138 }
139 
140 class FramebufferSamplesTest : public FramebufferTest
141 {
142 public:
143 						FramebufferSamplesTest	(Context& context, QueryType verifier, const char* name, const char* desc);
144 	void				checkInitial			(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
145 	void				checkSet				(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
146 };
147 
FramebufferSamplesTest(Context & context,QueryType verifier,const char * name,const char * desc)148 FramebufferSamplesTest::FramebufferSamplesTest (Context& context, QueryType verifier, const char* name, const char* desc)
149 	: FramebufferTest(context, verifier, name, desc)
150 {
151 }
152 
checkInitial(tcu::ResultCollector & result,glu::CallLogWrapper & gl)153 void FramebufferSamplesTest::checkInitial (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
154 {
155 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 0, m_verifier);
156 }
157 
checkSet(tcu::ResultCollector & result,glu::CallLogWrapper & gl)158 void FramebufferSamplesTest::checkSet (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
159 {
160 	gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 1);
161 	GLU_EXPECT_NO_ERROR(gl.glGetError(), "set state");
162 	verifyStateFramebufferIntegerMin(result, gl, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 1, m_verifier);
163 
164 	gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 0);
165 	GLU_EXPECT_NO_ERROR(gl.glGetError(), "set state");
166 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_SAMPLES, 0, m_verifier);
167 }
168 
169 class FramebufferFixedSampleLocationsTest : public FramebufferTest
170 {
171 public:
172 						FramebufferFixedSampleLocationsTest	(Context& context, QueryType verifier, const char* name, const char* desc);
173 	void				checkInitial						(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
174 	void				checkSet							(tcu::ResultCollector& result, glu::CallLogWrapper& gl);
175 };
176 
FramebufferFixedSampleLocationsTest(Context & context,QueryType verifier,const char * name,const char * desc)177 FramebufferFixedSampleLocationsTest::FramebufferFixedSampleLocationsTest (Context& context, QueryType verifier, const char* name, const char* desc)
178 	: FramebufferTest(context, verifier, name, desc)
179 {
180 }
181 
checkInitial(tcu::ResultCollector & result,glu::CallLogWrapper & gl)182 void FramebufferFixedSampleLocationsTest::checkInitial (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
183 {
184 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, 0, m_verifier);
185 }
186 
checkSet(tcu::ResultCollector & result,glu::CallLogWrapper & gl)187 void FramebufferFixedSampleLocationsTest::checkSet (tcu::ResultCollector& result, glu::CallLogWrapper& gl)
188 {
189 	gl.glFramebufferParameteri(GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, GL_TRUE);
190 	GLU_EXPECT_NO_ERROR(gl.glGetError(), "set state");
191 	verifyStateFramebufferInteger(result, gl, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS, GL_TRUE, m_verifier);
192 }
193 
194 } // anonymous
195 
FramebufferDefaultStateQueryTests(Context & context)196 FramebufferDefaultStateQueryTests::FramebufferDefaultStateQueryTests (Context& context)
197 	: TestCaseGroup(context, "framebuffer_default", "Framebuffer Default State Query tests")
198 {
199 }
200 
~FramebufferDefaultStateQueryTests(void)201 FramebufferDefaultStateQueryTests::~FramebufferDefaultStateQueryTests (void)
202 {
203 }
204 
init(void)205 void FramebufferDefaultStateQueryTests::init (void)
206 {
207 	static const QueryType verifiers[] =
208 	{
209 		QUERY_FRAMEBUFFER_INTEGER,
210 	};
211 
212 #define FOR_EACH_VERIFIER(X) \
213 	for (int verifierNdx = 0; verifierNdx < DE_LENGTH_OF_ARRAY(verifiers); ++verifierNdx)	\
214 	{																						\
215 		const char* verifierSuffix = getVerifierSuffix(verifiers[verifierNdx]);				\
216 		const QueryType verifier = verifiers[verifierNdx];								\
217 		this->addChild(X);																	\
218 	}
219 
220 	FOR_EACH_VERIFIER(new FramebufferDimensionTest				(m_context, verifier, FramebufferDimensionTest::DIMENSION_WIDTH,	(std::string("framebuffer_default_width_") + verifierSuffix).c_str(),					"Test FRAMEBUFFER_DEFAULT_WIDTH"));
221 	FOR_EACH_VERIFIER(new FramebufferDimensionTest				(m_context, verifier, FramebufferDimensionTest::DIMENSION_HEIGHT,	(std::string("framebuffer_default_height_") + verifierSuffix).c_str(),					"Test FRAMEBUFFER_DEFAULT_HEIGHT"));
222 	FOR_EACH_VERIFIER(new FramebufferSamplesTest				(m_context, verifier, 												(std::string("framebuffer_default_samples_") + verifierSuffix).c_str(),					"Test FRAMEBUFFER_DEFAULT_SAMPLES"));
223 	FOR_EACH_VERIFIER(new FramebufferFixedSampleLocationsTest	(m_context, verifier,												(std::string("framebuffer_default_fixed_sample_locations_") + verifierSuffix).c_str(),	"Test FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS"));
224 
225 #undef FOR_EACH_VERIFIER
226 }
227 
228 } // Functional
229 } // gles31
230 } // deqp
231