1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Texture State Query tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fTextureStateQueryTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "glsStateQueryUtil.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwEnums.hpp"
29 #include "glwFunctions.hpp"
30 #include "deRandom.hpp"
33 using namespace glw; // GLint and other GL types
34 using namespace deqp::gls;
35 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
44 namespace TextureParamVerifiers
49 class TexParamVerifier : protected glu::CallLogWrapper
52 TexParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
53 virtual ~TexParamVerifier (); // make GCC happy
55 const char* getTestNamePostfix (void) const;
57 virtual void verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference) = DE_NULL;
58 virtual void verifyFloat (tcu::TestContext& testCtx, GLenum target, GLenum name, GLfloat reference) = DE_NULL;
60 const char* const m_testNamePostfix;
63 TexParamVerifier::TexParamVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
64 : glu::CallLogWrapper (gl, log)
65 , m_testNamePostfix (testNamePostfix)
69 TexParamVerifier::~TexParamVerifier ()
73 const char* TexParamVerifier::getTestNamePostfix (void) const
75 return m_testNamePostfix;
78 class GetTexParameterIVerifier : public TexParamVerifier
81 GetTexParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log);
83 void verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
84 void verifyFloat (tcu::TestContext& testCtx, GLenum target, GLenum name, GLfloat reference);
87 GetTexParameterIVerifier::GetTexParameterIVerifier (const glw::Functions& gl, tcu::TestLog& log)
88 : TexParamVerifier(gl, log, "_gettexparameteri")
92 void GetTexParameterIVerifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
96 StateQueryMemoryWriteGuard<GLint> state;
97 glGetTexParameteriv(target, name, &state);
99 if (!state.verifyValidity(testCtx))
102 if (state != reference)
104 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
106 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
107 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid texture param value");
111 void GetTexParameterIVerifier::verifyFloat (tcu::TestContext& testCtx, GLenum target, GLenum name, GLfloat reference)
115 const GLint expectedGLStateMax = StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint>(reference);
116 const GLint expectedGLStateMin = StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint>(reference);
118 StateQueryMemoryWriteGuard<GLint> state;
119 glGetTexParameteriv(target, name, &state);
121 if (!state.verifyValidity(testCtx))
124 if (state < expectedGLStateMin || state > expectedGLStateMax)
126 testCtx.getLog() << TestLog::Message << "// ERROR: expected in range [" << expectedGLStateMin << ", " << expectedGLStateMax << "]; got " << state << TestLog::EndMessage;
128 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
129 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid texture param value");
133 class GetTexParameterFVerifier : public TexParamVerifier
136 GetTexParameterFVerifier (const glw::Functions& gl, tcu::TestLog& log);
138 void verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference);
139 void verifyFloat (tcu::TestContext& testCtx, GLenum target, GLenum name, GLfloat reference);
142 GetTexParameterFVerifier::GetTexParameterFVerifier (const glw::Functions& gl, tcu::TestLog& log)
143 : TexParamVerifier(gl, log, "_gettexparameterf")
147 void GetTexParameterFVerifier::verifyInteger (tcu::TestContext& testCtx, GLenum target, GLenum name, GLint reference)
149 DE_ASSERT(reference == GLint(GLfloat(reference))); // reference integer must have 1:1 mapping to float for this to work. Reference value is always such value in these tests
153 const GLfloat referenceAsFloat = GLfloat(reference);
155 StateQueryMemoryWriteGuard<GLfloat> state;
156 glGetTexParameterfv(target, name, &state);
158 if (!state.verifyValidity(testCtx))
161 if (state != referenceAsFloat)
163 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << referenceAsFloat << "; got " << state << TestLog::EndMessage;
165 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
166 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
170 void GetTexParameterFVerifier::verifyFloat (tcu::TestContext& testCtx, GLenum target, GLenum name, GLfloat reference)
174 StateQueryMemoryWriteGuard<GLfloat> state;
175 glGetTexParameterfv(target, name, &state);
177 if (!state.verifyValidity(testCtx))
180 if (state != reference)
182 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
184 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
185 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
189 } // TextureParamVerifiers
194 using namespace TextureParamVerifiers;
198 class TextureCase : public ApiCase
201 TextureCase (Context& context, TexParamVerifier* verifier, const char* name, const char* description, GLenum textureTarget)
202 : ApiCase (context, name, description)
203 , m_textureTarget (textureTarget)
204 , m_verifier (verifier)
208 virtual void testTexture (void) = DE_NULL;
212 GLuint textureId = 0;
213 glGenTextures(1, &textureId);
214 glBindTexture(m_textureTarget, textureId);
215 expectError(GL_NO_ERROR);
219 glDeleteTextures(1, &textureId);
220 expectError(GL_NO_ERROR);
224 GLenum m_textureTarget;
225 TexParamVerifier* m_verifier;
228 class TextureWrapCase : public TextureCase
231 TextureWrapCase (Context& context, TexParamVerifier* verifier, const char* name, const char* description, GLenum textureTarget, GLenum valueName)
232 : TextureCase (context, verifier, name, description, textureTarget)
233 , m_valueName (valueName)
237 void testTexture (void)
239 const GLenum wrapValues[] = {GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT};
241 m_verifier->verifyInteger(m_testCtx, m_textureTarget, m_valueName, GL_REPEAT);
242 expectError(GL_NO_ERROR);
244 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
246 glTexParameteri(m_textureTarget, m_valueName, wrapValues[ndx]);
247 expectError(GL_NO_ERROR);
249 m_verifier->verifyInteger(m_testCtx, m_textureTarget, m_valueName, wrapValues[ndx]);
250 expectError(GL_NO_ERROR);
253 //check unit conversions with float
255 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(wrapValues); ++ndx)
257 glTexParameterf(m_textureTarget, m_valueName, (GLfloat)wrapValues[ndx]);
258 expectError(GL_NO_ERROR);
260 m_verifier->verifyInteger(m_testCtx, m_textureTarget, m_valueName, wrapValues[ndx]);
261 expectError(GL_NO_ERROR);
269 class TextureMagFilterCase : public TextureCase
272 TextureMagFilterCase (Context& context, TexParamVerifier* verifier, const char* name, const char* description, GLenum textureTarget)
273 : TextureCase(context, verifier, name, description, textureTarget)
277 void testTexture (void)
279 const GLenum magValues[] = {GL_NEAREST, GL_LINEAR};
281 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
282 expectError(GL_NO_ERROR);
284 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(magValues); ++ndx)
286 glTexParameteri(m_textureTarget, GL_TEXTURE_MAG_FILTER, magValues[ndx]);
287 expectError(GL_NO_ERROR);
289 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MAG_FILTER, magValues[ndx]);
290 expectError(GL_NO_ERROR);
293 //check unit conversions with float
295 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(magValues); ++ndx)
297 glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, (GLfloat)magValues[ndx]);
298 expectError(GL_NO_ERROR);
300 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MAG_FILTER, magValues[ndx]);
301 expectError(GL_NO_ERROR);
306 class TextureMinFilterCase : public TextureCase
309 TextureMinFilterCase (Context& context, TexParamVerifier* verifier, const char* name, const char* description, GLenum textureTarget)
310 : TextureCase(context, verifier, name, description, textureTarget)
314 void testTexture (void)
316 const GLenum minValues[] = {GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR};
318 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
319 expectError(GL_NO_ERROR);
321 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(minValues); ++ndx)
323 glTexParameteri(m_textureTarget, GL_TEXTURE_MIN_FILTER, minValues[ndx]);
324 expectError(GL_NO_ERROR);
326 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MIN_FILTER, minValues[ndx]);
327 expectError(GL_NO_ERROR);
330 //check unit conversions with float
332 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(minValues); ++ndx)
334 glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, (GLfloat)minValues[ndx]);
335 expectError(GL_NO_ERROR);
337 m_verifier->verifyInteger(m_testCtx, m_textureTarget, GL_TEXTURE_MIN_FILTER, minValues[ndx]);
338 expectError(GL_NO_ERROR);
345 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \
346 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
348 TexParamVerifier* verifier = (VERIFIERS)[_verifierNdx]; \
352 TextureStateQueryTests::TextureStateQueryTests (Context& context)
353 : TestCaseGroup (context, "texture", "Texture State Query tests")
354 , m_verifierInt (DE_NULL)
355 , m_verifierFloat (DE_NULL)
359 TextureStateQueryTests::~TextureStateQueryTests (void)
364 void TextureStateQueryTests::init (void)
366 using namespace TextureParamVerifiers;
368 DE_ASSERT(m_verifierInt == DE_NULL);
369 DE_ASSERT(m_verifierFloat == DE_NULL);
371 m_verifierInt = new GetTexParameterIVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
372 m_verifierFloat = new GetTexParameterFVerifier(m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
374 TexParamVerifier* verifiers[] = {m_verifierInt, m_verifierFloat};
379 GLenum textureTarget;
382 { "texture_2d", GL_TEXTURE_2D},
383 { "texture_cube_map", GL_TEXTURE_CUBE_MAP}
386 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(textureTargets); ++ndx)
388 FOR_EACH_VERIFIER(verifiers, addChild(new TextureWrapCase (m_context, verifier, (std::string(textureTargets[ndx].name) + "_texture_wrap_s" + verifier->getTestNamePostfix()).c_str(), "TEXTURE_WRAP_S", textureTargets[ndx].textureTarget, GL_TEXTURE_WRAP_S)));
389 FOR_EACH_VERIFIER(verifiers, addChild(new TextureWrapCase (m_context, verifier, (std::string(textureTargets[ndx].name) + "_texture_wrap_t" + verifier->getTestNamePostfix()).c_str(), "TEXTURE_WRAP_T", textureTargets[ndx].textureTarget, GL_TEXTURE_WRAP_T)));
391 FOR_EACH_VERIFIER(verifiers, addChild(new TextureMagFilterCase (m_context, verifier, (std::string(textureTargets[ndx].name) + "_texture_mag_filter" + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MAG_FILTER", textureTargets[ndx].textureTarget)));
392 FOR_EACH_VERIFIER(verifiers, addChild(new TextureMinFilterCase (m_context, verifier, (std::string(textureTargets[ndx].name) + "_texture_min_filter" + verifier->getTestNamePostfix()).c_str(), "TEXTURE_MIN_FILTER", textureTargets[ndx].textureTarget)));
396 void TextureStateQueryTests::deinit (void)
400 delete m_verifierInt;
401 m_verifierInt = NULL;
405 delete m_verifierFloat;
406 m_verifierFloat = NULL;
409 this->TestCaseGroup::deinit();