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 Float State Query tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fFloatStateQueryTests.hpp"
25 #include "glsStateQueryUtil.hpp"
26 #include "es2fApiCase.hpp"
27 #include "gluRenderContext.hpp"
28 #include "tcuRenderTarget.hpp"
29 #include "tcuFormatUtil.hpp"
30 #include "deRandom.hpp"
32 #include "glwEnums.hpp"
36 using namespace glw; // GLint and other GL types
37 using namespace deqp::gls;
38 using deqp::gls::StateQueryUtil::StateQueryMemoryWriteGuard;
46 namespace FloatStateQueryVerifiers
51 const int FLOAT_EXPANSION_E = 0x03FF; // 10 bits error allowed, requires 22 accurate bits
52 const int FLOAT_EXPANSION_E_64 = 0x07FF;
54 GLint64 expandGLFloatToInteger (GLfloat f)
56 const GLuint64 referenceValue = (GLint64)((f * double(0xFFFFFFFFULL) - 1) / 2);
57 return referenceValue;
60 GLint clampToGLint (GLint64 val)
62 return (GLint)de::clamp<GLint64>(val, std::numeric_limits<GLint>::min(), std::numeric_limits<GLint>::max());
69 class StateVerifier : protected glu::CallLogWrapper
72 StateVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix);
73 virtual ~StateVerifier (); // make GCC happy
75 const char* getTestNamePostfix (void) const;
77 virtual void verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference) = DE_NULL;
79 // "Expanded" == Float to int conversion converts from [-1.0 to 1.0] -> [MIN_INT MAX_INT]
80 virtual void verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference) = DE_NULL;
81 virtual void verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1) = DE_NULL;
82 virtual void verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3) = DE_NULL;
84 // verify that the given range is completely whitin the GL state range
85 virtual void verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max) = DE_NULL;
88 const char* const m_testNamePostfix;
91 StateVerifier::StateVerifier (const glw::Functions& gl, tcu::TestLog& log, const char* testNamePostfix)
92 : glu::CallLogWrapper (gl, log)
93 , m_testNamePostfix (testNamePostfix)
98 StateVerifier::~StateVerifier ()
102 const char* StateVerifier::getTestNamePostfix (void) const
104 return m_testNamePostfix;
107 // GetBooleanVerifier
109 class GetBooleanVerifier : public StateVerifier
112 GetBooleanVerifier (const glw::Functions& gl, tcu::TestLog& log);
113 void verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
114 void verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
115 void verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1);
116 void verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3);
117 void verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max);
120 GetBooleanVerifier::GetBooleanVerifier (const glw::Functions& gl, tcu::TestLog& log)
121 : StateVerifier(gl, log, "_getboolean")
125 void GetBooleanVerifier::verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
129 StateQueryMemoryWriteGuard<GLboolean> state;
130 glGetBooleanv(name, &state);
132 if (!state.verifyValidity(testCtx))
135 const GLboolean expectedGLState = reference != 0.0f ? GL_TRUE : GL_FALSE;
137 if (state != expectedGLState)
139 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << (expectedGLState==GL_TRUE ? "GL_TRUE" : "GL_FALSE") << "; got " << (state == GL_TRUE ? "GL_TRUE" : (state == GL_FALSE ? "GL_FALSE" : "non-boolean")) << TestLog::EndMessage;
140 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
141 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
145 void GetBooleanVerifier::verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
147 DE_ASSERT(de::inRange(reference, -1.0f, 1.0f));
148 verifyFloat(testCtx, name, reference);
151 void GetBooleanVerifier::verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1)
153 DE_ASSERT(de::inRange(reference0, -1.0f, 1.0f));
154 DE_ASSERT(de::inRange(reference1, -1.0f, 1.0f));
158 const GLboolean referenceAsGLBoolean[] =
160 reference0 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
161 reference1 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
164 StateQueryMemoryWriteGuard<GLboolean[2]> boolVector2;
165 glGetBooleanv(name, boolVector2);
167 if (!boolVector2.verifyValidity(testCtx))
170 if (boolVector2[0] != referenceAsGLBoolean[0] ||
171 boolVector2[1] != referenceAsGLBoolean[1])
173 testCtx.getLog() << TestLog::Message << "// ERROR: expected "
174 << (boolVector2[0] ? "GL_TRUE" : "GL_FALSE") << " "
175 << (boolVector2[1] ? "GL_TRUE" : "GL_FALSE") << " "
176 << TestLog::EndMessage;
178 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
179 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
183 void GetBooleanVerifier::verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3)
187 const GLboolean referenceAsGLBoolean[] =
189 reference0 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
190 reference1 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
191 reference2 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
192 reference3 != 0.0f ? GLboolean(GL_TRUE) : GLboolean(GL_FALSE),
195 StateQueryMemoryWriteGuard<GLboolean[4]> boolVector4;
196 glGetBooleanv(name, boolVector4);
198 if (!boolVector4.verifyValidity(testCtx))
201 if (boolVector4[0] != referenceAsGLBoolean[0] ||
202 boolVector4[1] != referenceAsGLBoolean[1] ||
203 boolVector4[2] != referenceAsGLBoolean[2] ||
204 boolVector4[3] != referenceAsGLBoolean[3])
206 testCtx.getLog() << TestLog::Message << "// ERROR: expected "
207 << (referenceAsGLBoolean[0] ? "GL_TRUE" : "GL_FALSE") << " "
208 << (referenceAsGLBoolean[1] ? "GL_TRUE" : "GL_FALSE") << " "
209 << (referenceAsGLBoolean[2] ? "GL_TRUE" : "GL_FALSE") << " "
210 << (referenceAsGLBoolean[3] ? "GL_TRUE" : "GL_FALSE") << TestLog::EndMessage;
212 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
213 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean value");
217 void GetBooleanVerifier::verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max)
221 StateQueryMemoryWriteGuard<GLboolean[2]> range;
222 glGetBooleanv(name, range);
224 if (!range.verifyValidity(testCtx))
227 if (range[0] == GL_FALSE)
229 if (max < 0 || min < 0)
231 testCtx.getLog() << TestLog::Message << "// ERROR: range [" << min << ", " << max << "] is not in range [" << (range[0] == GL_TRUE ? "GL_TRUE" : (range[0] == GL_FALSE ? "GL_FALSE" : "non-boolean")) << ", " << (range[1] == GL_TRUE ? "GL_TRUE" : (range[1] == GL_FALSE ? "GL_FALSE" : "non-boolean")) << "]" << TestLog::EndMessage;
232 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
233 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean range");
237 if (range[1] == GL_FALSE)
239 if (max > 0 || min > 0)
241 testCtx.getLog() << TestLog::Message << "// ERROR: range [" << min << ", " << max << "] is not in range [" << (range[0] == GL_TRUE ? "GL_TRUE" : (range[0] == GL_FALSE ? "GL_FALSE" : "non-boolean")) << ", " << (range[1] == GL_TRUE ? "GL_TRUE" : (range[1] == GL_FALSE ? "GL_FALSE" : "non-boolean")) << "]" << TestLog::EndMessage;
242 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
243 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid boolean range");
251 class GetIntegerVerifier : public StateVerifier
254 GetIntegerVerifier (const glw::Functions& gl, tcu::TestLog& log);
255 void verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
256 void verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
257 void verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1);
258 void verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3);
259 void verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max);
262 GetIntegerVerifier::GetIntegerVerifier (const glw::Functions& gl, tcu::TestLog& log)
263 : StateVerifier(gl, log, "_getinteger")
267 void GetIntegerVerifier::verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
271 const GLint expectedGLStateMax = StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint>(reference);
272 const GLint expectedGLStateMin = StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint>(reference);
274 StateQueryMemoryWriteGuard<GLint> state;
275 glGetIntegerv(name, &state);
277 if (!state.verifyValidity(testCtx))
280 if (state < expectedGLStateMin || state > expectedGLStateMax)
282 testCtx.getLog() << TestLog::Message << "// ERROR: expected rounding to the nearest integer, valid range [" << expectedGLStateMin << "," << expectedGLStateMax << "]; got " << state << TestLog::EndMessage;
283 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
284 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
288 void GetIntegerVerifier::verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
290 DE_ASSERT(de::inRange(reference, -1.0f, 1.0f));
295 const GLint expectedGLStateMax = clampToGLint(expandGLFloatToInteger(reference) + FLOAT_EXPANSION_E);
296 const GLint expectedGLStateMin = clampToGLint(expandGLFloatToInteger(reference) - FLOAT_EXPANSION_E);
298 StateQueryMemoryWriteGuard<GLint> state;
299 glGetIntegerv(name, &state);
301 if (!state.verifyValidity(testCtx))
304 if (state < expectedGLStateMin || state > expectedGLStateMax)
306 testCtx.getLog() << TestLog::Message << "// ERROR: expected in range [" << toHex(expectedGLStateMin) << "," << toHex(expectedGLStateMax) << "]; got " << toHex((GLint)state) << TestLog::EndMessage;
307 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
308 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
312 void GetIntegerVerifier::verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1)
314 DE_ASSERT(de::inRange(reference0, -1.0f, 1.0f));
315 DE_ASSERT(de::inRange(reference1, -1.0f, 1.0f));
320 const GLint referenceAsGLintMin[] =
322 clampToGLint(expandGLFloatToInteger(reference0) - FLOAT_EXPANSION_E),
323 clampToGLint(expandGLFloatToInteger(reference1) - FLOAT_EXPANSION_E)
325 const GLint referenceAsGLintMax[] =
327 clampToGLint(expandGLFloatToInteger(reference0) + FLOAT_EXPANSION_E),
328 clampToGLint(expandGLFloatToInteger(reference1) + FLOAT_EXPANSION_E)
331 StateQueryMemoryWriteGuard<GLint[2]> floatVector2;
332 glGetIntegerv(name, floatVector2);
334 if (!floatVector2.verifyValidity(testCtx))
337 if (floatVector2[0] < referenceAsGLintMin[0] || floatVector2[0] > referenceAsGLintMax[0] ||
338 floatVector2[1] < referenceAsGLintMin[1] || floatVector2[1] > referenceAsGLintMax[1])
340 testCtx.getLog() << TestLog::Message
341 << "// ERROR: expected in ranges "
342 << "[" << toHex(referenceAsGLintMin[0]) << " " << toHex(referenceAsGLintMax[0]) << "], "
343 << "[" << toHex(referenceAsGLintMin[1]) << " " << toHex(referenceAsGLintMax[1]) << "]"
345 << toHex(floatVector2[0]) << ", "
346 << toHex(floatVector2[1]) << " "<< TestLog::EndMessage;
348 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
349 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
353 void GetIntegerVerifier::verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3)
358 const GLint referenceAsGLintMin[] =
360 clampToGLint(expandGLFloatToInteger(reference0) - FLOAT_EXPANSION_E),
361 clampToGLint(expandGLFloatToInteger(reference1) - FLOAT_EXPANSION_E),
362 clampToGLint(expandGLFloatToInteger(reference2) - FLOAT_EXPANSION_E),
363 clampToGLint(expandGLFloatToInteger(reference3) - FLOAT_EXPANSION_E)
365 const GLint referenceAsGLintMax[] =
367 clampToGLint(expandGLFloatToInteger(reference0) + FLOAT_EXPANSION_E),
368 clampToGLint(expandGLFloatToInteger(reference1) + FLOAT_EXPANSION_E),
369 clampToGLint(expandGLFloatToInteger(reference2) + FLOAT_EXPANSION_E),
370 clampToGLint(expandGLFloatToInteger(reference3) + FLOAT_EXPANSION_E)
373 StateQueryMemoryWriteGuard<GLint[4]> floatVector4;
374 glGetIntegerv(name, floatVector4);
376 if (!floatVector4.verifyValidity(testCtx))
379 if (floatVector4[0] < referenceAsGLintMin[0] || floatVector4[0] > referenceAsGLintMax[0] ||
380 floatVector4[1] < referenceAsGLintMin[1] || floatVector4[1] > referenceAsGLintMax[1] ||
381 floatVector4[2] < referenceAsGLintMin[2] || floatVector4[2] > referenceAsGLintMax[2] ||
382 floatVector4[3] < referenceAsGLintMin[3] || floatVector4[3] > referenceAsGLintMax[3])
384 testCtx.getLog() << TestLog::Message
385 << "// ERROR: expected in ranges "
386 << "[" << toHex(referenceAsGLintMin[0]) << " " << toHex(referenceAsGLintMax[0]) << "], "
387 << "[" << toHex(referenceAsGLintMin[1]) << " " << toHex(referenceAsGLintMax[1]) << "], "
388 << "[" << toHex(referenceAsGLintMin[2]) << " " << toHex(referenceAsGLintMax[2]) << "], "
389 << "[" << toHex(referenceAsGLintMin[3]) << " " << toHex(referenceAsGLintMax[3]) << "]"
391 << toHex(floatVector4[0]) << ", "
392 << toHex(floatVector4[1]) << ", "
393 << toHex(floatVector4[2]) << ", "
394 << toHex(floatVector4[3]) << " "<< TestLog::EndMessage;
396 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
397 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
401 void GetIntegerVerifier::verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max)
405 const GLint testRangeAsGLint[] =
407 StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint>(min),
408 StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint>(max)
411 StateQueryMemoryWriteGuard<GLint[2]> range;
412 glGetIntegerv(name, range);
414 if (!range.verifyValidity(testCtx))
417 // check if test range outside of gl state range
418 if (testRangeAsGLint[0] < range[0] ||
419 testRangeAsGLint[1] > range[1])
421 testCtx.getLog() << TestLog::Message
422 << "// ERROR: range ["
423 << testRangeAsGLint[0] << ", "
424 << testRangeAsGLint[1] << "]"
425 << " is not in range ["
427 << range[1] << "]" << TestLog::EndMessage;
429 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
430 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer range");
434 //GetInteger64Verifier
436 class GetInteger64Verifier : public StateVerifier
439 GetInteger64Verifier (const glw::Functions& gl, tcu::TestLog& log);
440 void verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
441 void verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
442 void verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1);
443 void verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3);
444 void verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max);
447 GetInteger64Verifier::GetInteger64Verifier (const glw::Functions& gl, tcu::TestLog& log)
448 : StateVerifier(gl, log, "_getinteger64")
452 void GetInteger64Verifier::verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
456 const GLint64 expectedGLStateMax = StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint64>(reference);
457 const GLint64 expectedGLStateMin = StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint64>(reference);
459 StateQueryMemoryWriteGuard<GLint64> state;
460 glGetInteger64v(name, &state);
462 if (!state.verifyValidity(testCtx))
465 if (state < expectedGLStateMin || state > expectedGLStateMax)
467 testCtx.getLog() << TestLog::Message << "// ERROR: expected rounding to the nearest integer, valid range [" << expectedGLStateMin << "," << expectedGLStateMax << "]; got " << state << TestLog::EndMessage;
468 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
469 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
473 void GetInteger64Verifier::verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
475 DE_ASSERT(de::inRange(reference, -1.0f, 1.0f));
480 const GLint64 expectedGLStateMax = expandGLFloatToInteger(reference) + FLOAT_EXPANSION_E_64;
481 const GLint64 expectedGLStateMin = expandGLFloatToInteger(reference) - FLOAT_EXPANSION_E_64;
483 StateQueryMemoryWriteGuard<GLint64> state;
484 glGetInteger64v(name, &state);
486 if (!state.verifyValidity(testCtx))
489 if (state < expectedGLStateMin || state > expectedGLStateMax)
491 testCtx.getLog() << TestLog::Message << "// ERROR: expected in range [" << toHex(expectedGLStateMin) << "," << toHex(expectedGLStateMax) << "]; got " << toHex((GLint64)state) << TestLog::EndMessage;
492 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
493 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
497 void GetInteger64Verifier::verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1)
499 DE_ASSERT(de::inRange(reference0, -1.0f, 1.0f));
500 DE_ASSERT(de::inRange(reference1, -1.0f, 1.0f));
505 const GLint64 referenceAsGLintMin[] =
507 expandGLFloatToInteger(reference0) - FLOAT_EXPANSION_E_64,
508 expandGLFloatToInteger(reference1) - FLOAT_EXPANSION_E_64
510 const GLint64 referenceAsGLintMax[] =
512 expandGLFloatToInteger(reference0) + FLOAT_EXPANSION_E_64,
513 expandGLFloatToInteger(reference1) + FLOAT_EXPANSION_E_64
516 StateQueryMemoryWriteGuard<GLint64[2]> floatVector2;
517 glGetInteger64v(name, floatVector2);
519 if (!floatVector2.verifyValidity(testCtx))
522 if (floatVector2[0] < referenceAsGLintMin[0] || floatVector2[0] > referenceAsGLintMax[0] ||
523 floatVector2[1] < referenceAsGLintMin[1] || floatVector2[1] > referenceAsGLintMax[1])
525 testCtx.getLog() << TestLog::Message
526 << "// ERROR: expected in ranges "
527 << "[" << toHex(referenceAsGLintMin[0]) << " " << toHex(referenceAsGLintMax[0]) << "], "
528 << "[" << toHex(referenceAsGLintMin[1]) << " " << toHex(referenceAsGLintMax[1]) << "]"
530 << toHex(floatVector2[0]) << ", "
531 << toHex(floatVector2[1]) << " "<< TestLog::EndMessage;
533 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
534 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
538 void GetInteger64Verifier::verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3)
543 const GLint64 referenceAsGLintMin[] =
545 expandGLFloatToInteger(reference0) - FLOAT_EXPANSION_E_64,
546 expandGLFloatToInteger(reference1) - FLOAT_EXPANSION_E_64,
547 expandGLFloatToInteger(reference2) - FLOAT_EXPANSION_E_64,
548 expandGLFloatToInteger(reference3) - FLOAT_EXPANSION_E_64
550 const GLint64 referenceAsGLintMax[] =
552 expandGLFloatToInteger(reference0) + FLOAT_EXPANSION_E_64,
553 expandGLFloatToInteger(reference1) + FLOAT_EXPANSION_E_64,
554 expandGLFloatToInteger(reference2) + FLOAT_EXPANSION_E_64,
555 expandGLFloatToInteger(reference3) + FLOAT_EXPANSION_E_64
558 StateQueryMemoryWriteGuard<GLint64[4]> floatVector4;
559 glGetInteger64v(name, floatVector4);
561 if (!floatVector4.verifyValidity(testCtx))
564 if (floatVector4[0] < referenceAsGLintMin[0] || floatVector4[0] > referenceAsGLintMax[0] ||
565 floatVector4[1] < referenceAsGLintMin[1] || floatVector4[1] > referenceAsGLintMax[1] ||
566 floatVector4[2] < referenceAsGLintMin[2] || floatVector4[2] > referenceAsGLintMax[2] ||
567 floatVector4[3] < referenceAsGLintMin[3] || floatVector4[3] > referenceAsGLintMax[3])
569 testCtx.getLog() << TestLog::Message
570 << "// ERROR: expected in ranges "
571 << "[" << toHex(referenceAsGLintMin[0]) << " " << toHex(referenceAsGLintMax[0]) << "], "
572 << "[" << toHex(referenceAsGLintMin[1]) << " " << toHex(referenceAsGLintMax[1]) << "], "
573 << "[" << toHex(referenceAsGLintMin[2]) << " " << toHex(referenceAsGLintMax[2]) << "], "
574 << "[" << toHex(referenceAsGLintMin[3]) << " " << toHex(referenceAsGLintMax[3]) << "]"
576 << toHex(floatVector4[0]) << ", "
577 << toHex(floatVector4[1]) << ", "
578 << toHex(floatVector4[2]) << ", "
579 << toHex(floatVector4[3]) << " "<< TestLog::EndMessage;
581 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
582 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer value");
586 void GetInteger64Verifier::verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max)
590 const GLint64 testRangeAsGLint[] =
592 StateQueryUtil::roundGLfloatToNearestIntegerHalfUp<GLint64>(min),
593 StateQueryUtil::roundGLfloatToNearestIntegerHalfDown<GLint64>(max)
596 StateQueryMemoryWriteGuard<GLint64[2]> range;
597 glGetInteger64v(name, range);
599 if (!range.verifyValidity(testCtx))
602 // check if test range outside of gl state range
603 if (testRangeAsGLint[0] < range[0] ||
604 testRangeAsGLint[1] > range[1])
606 testCtx.getLog() << TestLog::Message
607 << "// ERROR: range ["
608 << testRangeAsGLint[0] << ", "
609 << testRangeAsGLint[1] << "]"
610 << " is not in range ["
612 << range[1] << "]" << TestLog::EndMessage;
614 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
615 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid integer range");
621 class GetFloatVerifier : public StateVerifier
624 GetFloatVerifier (const glw::Functions& gl, tcu::TestLog& log);
625 void verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
626 void verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference);
627 void verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1);
628 void verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3);
629 void verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max);
632 GetFloatVerifier::GetFloatVerifier (const glw::Functions& gl, tcu::TestLog& log)
633 : StateVerifier(gl, log, "_getfloat")
637 void GetFloatVerifier::verifyFloat (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
641 StateQueryMemoryWriteGuard<GLfloat> state;
642 glGetFloatv(name, &state);
644 if (!state.verifyValidity(testCtx))
647 if (state != reference)
649 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference << "; got " << state << TestLog::EndMessage;
650 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
651 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
655 void GetFloatVerifier::verifyFloatExpanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference)
657 DE_ASSERT(de::inRange(reference, -1.0f, 1.0f));
658 verifyFloat(testCtx, name, reference);
661 void GetFloatVerifier::verifyFloat2Expanded (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1)
663 DE_ASSERT(de::inRange(reference0, -1.0f, 1.0f));
664 DE_ASSERT(de::inRange(reference1, -1.0f, 1.0f));
668 StateQueryMemoryWriteGuard<GLfloat[2]> floatVector2;
669 glGetFloatv(name, floatVector2);
671 if (!floatVector2.verifyValidity(testCtx))
674 if (floatVector2[0] != reference0 ||
675 floatVector2[1] != reference1)
677 testCtx.getLog() << TestLog::Message << "// ERROR: expected " << reference0 << ", " << reference1 << "; got " << floatVector2[0] << " " << floatVector2[1] << TestLog::EndMessage;
679 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
680 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
684 void GetFloatVerifier::verifyFloat4Color (tcu::TestContext& testCtx, GLenum name, GLfloat reference0, GLfloat reference1, GLfloat reference2, GLfloat reference3)
688 StateQueryMemoryWriteGuard<GLfloat[4]> floatVector4;
689 glGetFloatv(name, floatVector4);
691 if (!floatVector4.verifyValidity(testCtx))
694 if (floatVector4[0] != reference0 ||
695 floatVector4[1] != reference1 ||
696 floatVector4[2] != reference2 ||
697 floatVector4[3] != reference3)
699 testCtx.getLog() << TestLog::Message
700 << "// ERROR: expected "<< reference0 << ", " << reference1 << ", " << reference2 << ", " << reference3
701 << "; got " << floatVector4[0] << ", " << floatVector4[1] << ", " << floatVector4[2] << ", " << floatVector4[3]
702 << TestLog::EndMessage;
704 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
705 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float value");
709 void GetFloatVerifier::verifyFloatRange (tcu::TestContext& testCtx, GLenum name, GLfloat min, GLfloat max)
713 StateQueryMemoryWriteGuard<GLfloat[2]> floatVector2;
714 glGetFloatv(name, floatVector2);
716 if (!floatVector2.verifyValidity(testCtx))
719 if (floatVector2[0] > min ||
720 floatVector2[1] < max)
722 testCtx.getLog() << TestLog::Message << "// ERROR: expected in range [" << min << ", " << max << "]; got [" << floatVector2[0] << " " << floatVector2[1] << "]" << TestLog::EndMessage;
724 if (testCtx.getTestResult() == QP_TEST_RESULT_PASS)
725 testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Got invalid float range");
729 } // FloatStateQueryVerifiers
734 using namespace FloatStateQueryVerifiers;
736 class DepthRangeCase : public ApiCase
739 DepthRangeCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
740 : ApiCase (context, name, description)
741 , m_verifier (verifier)
747 de::Random rnd(0xabcdef);
749 m_verifier->verifyFloat2Expanded(m_testCtx, GL_DEPTH_RANGE, 0.0f, 1.0f);
750 expectError(GL_NO_ERROR);
753 const struct FixedTest
763 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(fixedTests); ++ndx)
765 glDepthRangef(fixedTests[ndx].n, fixedTests[ndx].f);
767 m_verifier->verifyFloat2Expanded(m_testCtx, GL_DEPTH_RANGE, fixedTests[ndx].n, fixedTests[ndx].f);
768 expectError(GL_NO_ERROR);
773 const int numIterations = 120;
774 for (int i = 0; i < numIterations; ++i)
776 GLfloat n = rnd.getFloat(0, 1);
777 GLfloat f = rnd.getFloat(0, 1);
780 m_verifier->verifyFloat2Expanded(m_testCtx, GL_DEPTH_RANGE, n, f);
781 expectError(GL_NO_ERROR);
786 StateVerifier* m_verifier;
789 class LineWidthCase : public ApiCase
792 LineWidthCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
793 : ApiCase (context, name, description)
794 , m_verifier (verifier)
800 de::Random rnd(0xabcdef);
802 GLfloat range[2] = {1};
803 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, range);
804 expectError(GL_NO_ERROR);
806 m_verifier->verifyFloat(m_testCtx, GL_LINE_WIDTH, 1.0f);
807 expectError(GL_NO_ERROR);
809 const int numIterations = 120;
810 for (int i = 0; i < numIterations; ++i)
812 const GLfloat reference = rnd.getFloat(range[0], range[1]);
814 glLineWidth(reference);
815 m_verifier->verifyFloat(m_testCtx, GL_LINE_WIDTH, reference);
816 expectError(GL_NO_ERROR);
820 StateVerifier* m_verifier;
823 class PolygonOffsetFactorCase : public ApiCase
826 PolygonOffsetFactorCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
827 : ApiCase (context, name, description)
828 , m_verifier (verifier)
834 de::Random rnd(0xabcdef);
836 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_FACTOR, 0.0f);
837 expectError(GL_NO_ERROR);
840 const float fixedTests[] =
842 0.0f, 0.5f, -0.5f, 1.5f
844 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(fixedTests); ++ndx)
846 glPolygonOffset(fixedTests[ndx], 0);
847 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_FACTOR, fixedTests[ndx]);
848 expectError(GL_NO_ERROR);
853 const int numIterations = 120;
854 for (int i = 0; i < numIterations; ++i)
856 const GLfloat reference = rnd.getFloat(-64000, 64000);
858 glPolygonOffset(reference, 0);
859 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_FACTOR, reference);
860 expectError(GL_NO_ERROR);
865 StateVerifier* m_verifier;
868 class PolygonOffsetUnitsCase : public ApiCase
871 PolygonOffsetUnitsCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
872 : ApiCase (context, name, description)
873 , m_verifier (verifier)
879 de::Random rnd(0xabcdef);
881 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_UNITS, 0.0f);
882 expectError(GL_NO_ERROR);
885 const float fixedTests[] =
887 0.0f, 0.5f, -0.5f, 1.5f
889 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(fixedTests); ++ndx)
891 glPolygonOffset(0, fixedTests[ndx]);
892 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_UNITS, fixedTests[ndx]);
893 expectError(GL_NO_ERROR);
898 const int numIterations = 120;
899 for (int i = 0; i < numIterations; ++i)
901 const GLfloat reference = rnd.getFloat(-64000, 64000);
903 glPolygonOffset(0, reference);
904 m_verifier->verifyFloat(m_testCtx, GL_POLYGON_OFFSET_UNITS, reference);
905 expectError(GL_NO_ERROR);
910 StateVerifier* m_verifier;
913 class SampleCoverageCase : public ApiCase
916 SampleCoverageCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
917 : ApiCase (context, name, description)
918 , m_verifier (verifier)
924 de::Random rnd(0xabcdef);
926 m_verifier->verifyFloat(m_testCtx, GL_SAMPLE_COVERAGE_VALUE, 1.0f);
927 expectError(GL_NO_ERROR);
930 const float fixedTests[] =
932 0.0f, 0.5f, 0.45f, 0.55f
934 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(fixedTests); ++ndx)
936 glSampleCoverage(fixedTests[ndx], GL_FALSE);
937 m_verifier->verifyFloat(m_testCtx, GL_SAMPLE_COVERAGE_VALUE, fixedTests[ndx]);
938 expectError(GL_NO_ERROR);
943 const float clampTests[] =
945 -1.0f, -1.5f, 1.45f, 3.55f
947 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(clampTests); ++ndx)
949 glSampleCoverage(clampTests[ndx], GL_FALSE);
950 m_verifier->verifyFloat(m_testCtx, GL_SAMPLE_COVERAGE_VALUE, de::clamp(clampTests[ndx], 0.0f, 1.0f));
951 expectError(GL_NO_ERROR);
956 const int numIterations = 120;
957 for (int i = 0; i < numIterations; ++i)
959 GLfloat reference = rnd.getFloat(0, 1);
960 GLboolean invert = rnd.getBool() ? GL_TRUE : GL_FALSE;
962 glSampleCoverage(reference, invert);
963 m_verifier->verifyFloat(m_testCtx, GL_SAMPLE_COVERAGE_VALUE, reference);
964 expectError(GL_NO_ERROR);
969 StateVerifier* m_verifier;
972 class ColorClearCase : public ApiCase
975 ColorClearCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
976 : ApiCase (context, name, description)
977 , m_verifier (verifier)
983 de::Random rnd(0xabcdef);
985 // \note Initial color clear value check is temorarily removed. (until the framework does not alter it)
986 //m_verifier->verifyFloat4Color(m_testCtx, GL_COLOR_CLEAR_VALUE, 0, 0, 0, 0);
987 //expectError(GL_NO_ERROR);
990 const struct FixedTest
995 { 0.5f, 1.0f, 0.5f, 1.0f },
996 { 0.0f, 0.5f, 0.0f, 0.5f },
997 { 0.0f, 0.0f, 0.0f, 0.0f },
998 { 1.0f, 1.0f, 1.0f, 1.0f },
1000 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(fixedTests); ++ndx)
1002 glClearColor(fixedTests[ndx].r, fixedTests[ndx].g, fixedTests[ndx].b, fixedTests[ndx].a);
1003 m_verifier->verifyFloat4Color(m_testCtx, GL_COLOR_CLEAR_VALUE, fixedTests[ndx].r, fixedTests[ndx].g, fixedTests[ndx].b, fixedTests[ndx].a);
1004 expectError(GL_NO_ERROR);
1009 const int numIterations = 120;
1010 for (int i = 0; i < numIterations; ++i)
1012 const GLfloat r = rnd.getFloat(0, 1);
1013 const GLfloat g = rnd.getFloat(0, 1);
1014 const GLfloat b = rnd.getFloat(0, 1);
1015 const GLfloat a = rnd.getFloat(0, 1);
1017 glClearColor(r, g, b, a);
1018 m_verifier->verifyFloat4Color(m_testCtx, GL_COLOR_CLEAR_VALUE, r, g, b, a);
1019 expectError(GL_NO_ERROR);
1024 StateVerifier* m_verifier;
1027 class DepthClearCase : public ApiCase
1030 DepthClearCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
1031 : ApiCase (context, name, description)
1032 , m_verifier (verifier)
1038 const int numIterations = 120;
1040 de::Random rnd(0xabcdef);
1042 m_verifier->verifyFloatExpanded(m_testCtx, GL_DEPTH_CLEAR_VALUE, 1);
1043 expectError(GL_NO_ERROR);
1045 for (int i = 0; i < numIterations; ++i)
1047 const GLfloat ref = rnd.getFloat(0, 1);
1050 m_verifier->verifyFloatExpanded(m_testCtx, GL_DEPTH_CLEAR_VALUE, ref);
1051 expectError(GL_NO_ERROR);
1055 StateVerifier* m_verifier;
1058 class AliasedPointSizeRangeCase : public ApiCase
1061 AliasedPointSizeRangeCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
1062 : ApiCase (context, name, description)
1063 , m_verifier (verifier)
1069 m_verifier->verifyFloatRange(m_testCtx, GL_ALIASED_POINT_SIZE_RANGE, 1, 1);
1070 expectError(GL_NO_ERROR);
1073 StateVerifier* m_verifier;
1076 class AliasedLineWidthRangeCase : public ApiCase
1079 AliasedLineWidthRangeCase (Context& context, StateVerifier* verifier, const char* name, const char* description)
1080 : ApiCase (context, name, description)
1081 , m_verifier (verifier)
1087 m_verifier->verifyFloatRange(m_testCtx, GL_ALIASED_LINE_WIDTH_RANGE, 1, 1);
1088 expectError(GL_NO_ERROR);
1091 StateVerifier* m_verifier;
1094 #define FOR_EACH_VERIFIER(VERIFIERS, CODE_BLOCK) \
1095 for (int _verifierNdx = 0; _verifierNdx < DE_LENGTH_OF_ARRAY(VERIFIERS); _verifierNdx++) \
1097 StateVerifier* verifier = (VERIFIERS)[_verifierNdx]; \
1103 FloatStateQueryTests::FloatStateQueryTests (Context& context)
1104 : TestCaseGroup (context, "floats", "Float Values")
1105 , m_verifierBoolean (DE_NULL)
1106 , m_verifierInteger (DE_NULL)
1107 , m_verifierFloat (DE_NULL)
1111 FloatStateQueryTests::~FloatStateQueryTests (void)
1116 void FloatStateQueryTests::init (void)
1118 DE_ASSERT(m_verifierBoolean == DE_NULL);
1119 DE_ASSERT(m_verifierInteger == DE_NULL);
1120 DE_ASSERT(m_verifierFloat == DE_NULL);
1122 m_verifierBoolean = new GetBooleanVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
1123 m_verifierInteger = new GetIntegerVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
1124 m_verifierFloat = new GetFloatVerifier (m_context.getRenderContext().getFunctions(), m_context.getTestContext().getLog());
1126 StateVerifier* verifiers[] = {m_verifierBoolean, m_verifierInteger, m_verifierFloat};
1128 FOR_EACH_VERIFIER(verifiers, addChild(new DepthRangeCase (m_context, verifier, (std::string("depth_range") + verifier->getTestNamePostfix()).c_str(), "DEPTH_RANGE")));
1129 FOR_EACH_VERIFIER(verifiers, addChild(new LineWidthCase (m_context, verifier, (std::string("line_width") + verifier->getTestNamePostfix()).c_str(), "LINE_WIDTH")));
1130 FOR_EACH_VERIFIER(verifiers, addChild(new PolygonOffsetFactorCase (m_context, verifier, (std::string("polygon_offset_factor") + verifier->getTestNamePostfix()).c_str(), "POLYGON_OFFSET_FACTOR")));
1131 FOR_EACH_VERIFIER(verifiers, addChild(new PolygonOffsetUnitsCase (m_context, verifier, (std::string("polygon_offset_units") + verifier->getTestNamePostfix()).c_str(), "POLYGON_OFFSET_UNITS")));
1132 FOR_EACH_VERIFIER(verifiers, addChild(new SampleCoverageCase (m_context, verifier, (std::string("sample_coverage_value") + verifier->getTestNamePostfix()).c_str(), "SAMPLE_COVERAGE_VALUE")));
1133 FOR_EACH_VERIFIER(verifiers, addChild(new ColorClearCase (m_context, verifier, (std::string("color_clear_value") + verifier->getTestNamePostfix()).c_str(), "COLOR_CLEAR_VALUE")));
1134 FOR_EACH_VERIFIER(verifiers, addChild(new DepthClearCase (m_context, verifier, (std::string("depth_clear_value") + verifier->getTestNamePostfix()).c_str(), "DEPTH_CLEAR_VALUE")));
1135 FOR_EACH_VERIFIER(verifiers, addChild(new AliasedPointSizeRangeCase (m_context, verifier, (std::string("aliased_point_size_range") + verifier->getTestNamePostfix()).c_str(), "ALIASED_POINT_SIZE_RANGE")));
1136 FOR_EACH_VERIFIER(verifiers, addChild(new AliasedLineWidthRangeCase (m_context, verifier, (std::string("aliased_line_width_range") + verifier->getTestNamePostfix()).c_str(), "ALIASED_LINE_WIDTH_RANGE")));
1139 void FloatStateQueryTests::deinit (void)
1141 if (m_verifierBoolean)
1143 delete m_verifierBoolean;
1144 m_verifierBoolean = DE_NULL;
1146 if (m_verifierInteger)
1148 delete m_verifierInteger;
1149 m_verifierInteger = DE_NULL;
1151 if (m_verifierFloat)
1153 delete m_verifierFloat;
1154 m_verifierFloat = DE_NULL;
1157 this->TestCaseGroup::deinit();