1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES 3.0 Module 3e5c31af7Sopenharmony_ci * ------------------------------------------------- 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 17e5c31af7Sopenharmony_ci * limitations under the License. 18e5c31af7Sopenharmony_ci * 19e5c31af7Sopenharmony_ci *//*! 20e5c31af7Sopenharmony_ci * \file 21e5c31af7Sopenharmony_ci * \brief Prerequisite tests. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "es3fPrerequisiteTests.hpp" 25e5c31af7Sopenharmony_ci#include "deRandom.h" 26e5c31af7Sopenharmony_ci#include "tcuRGBA.hpp" 27e5c31af7Sopenharmony_ci#include "tcuSurface.hpp" 28e5c31af7Sopenharmony_ci#include "tcuTextureUtil.hpp" 29e5c31af7Sopenharmony_ci#include "tcuTestLog.hpp" 30e5c31af7Sopenharmony_ci#include "tcuRenderTarget.hpp" 31e5c31af7Sopenharmony_ci#include "gluPixelTransfer.hpp" 32e5c31af7Sopenharmony_ci#include "gluStateReset.hpp" 33e5c31af7Sopenharmony_ci 34e5c31af7Sopenharmony_ci#include "glw.h" 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_ciusing tcu::RGBA; 37e5c31af7Sopenharmony_ciusing tcu::Surface; 38e5c31af7Sopenharmony_ciusing tcu::TestLog; 39e5c31af7Sopenharmony_ci 40e5c31af7Sopenharmony_cinamespace deqp 41e5c31af7Sopenharmony_ci{ 42e5c31af7Sopenharmony_cinamespace gles3 43e5c31af7Sopenharmony_ci{ 44e5c31af7Sopenharmony_cinamespace Functional 45e5c31af7Sopenharmony_ci{ 46e5c31af7Sopenharmony_ci 47e5c31af7Sopenharmony_ciclass StateResetCase : public TestCase 48e5c31af7Sopenharmony_ci{ 49e5c31af7Sopenharmony_cipublic: 50e5c31af7Sopenharmony_ci StateResetCase (Context& context); 51e5c31af7Sopenharmony_ci virtual ~StateResetCase (void); 52e5c31af7Sopenharmony_ci virtual TestCase::IterateResult iterate (void); 53e5c31af7Sopenharmony_ci}; 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ciStateResetCase::StateResetCase (Context& context) 56e5c31af7Sopenharmony_ci : TestCase(context, "state_reset", "State Reset Test") 57e5c31af7Sopenharmony_ci{ 58e5c31af7Sopenharmony_ci} 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_ciStateResetCase::~StateResetCase (void) 61e5c31af7Sopenharmony_ci{ 62e5c31af7Sopenharmony_ci} 63e5c31af7Sopenharmony_ci 64e5c31af7Sopenharmony_ciTestCase::IterateResult StateResetCase::iterate (void) 65e5c31af7Sopenharmony_ci{ 66e5c31af7Sopenharmony_ci try 67e5c31af7Sopenharmony_ci { 68e5c31af7Sopenharmony_ci glu::resetState(m_context.getRenderContext(), m_context.getContextInfo()); 69e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 70e5c31af7Sopenharmony_ci } 71e5c31af7Sopenharmony_ci catch (const tcu::TestError& e) 72e5c31af7Sopenharmony_ci { 73e5c31af7Sopenharmony_ci m_testCtx.getLog() << e; 74e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 75e5c31af7Sopenharmony_ci } 76e5c31af7Sopenharmony_ci 77e5c31af7Sopenharmony_ci return TestCase::STOP; 78e5c31af7Sopenharmony_ci} 79e5c31af7Sopenharmony_ci 80e5c31af7Sopenharmony_ciclass ClearColorCase : public TestCase 81e5c31af7Sopenharmony_ci{ 82e5c31af7Sopenharmony_cipublic: 83e5c31af7Sopenharmony_ci ClearColorCase (Context& context); 84e5c31af7Sopenharmony_ci virtual ~ClearColorCase (void); 85e5c31af7Sopenharmony_ci virtual TestCase::IterateResult iterate (void); 86e5c31af7Sopenharmony_ci 87e5c31af7Sopenharmony_ciprivate: 88e5c31af7Sopenharmony_ci RGBA m_clearColor; 89e5c31af7Sopenharmony_ci int m_numIters; 90e5c31af7Sopenharmony_ci int m_curIter; 91e5c31af7Sopenharmony_ci}; 92e5c31af7Sopenharmony_ci 93e5c31af7Sopenharmony_ciClearColorCase::ClearColorCase (Context& context) 94e5c31af7Sopenharmony_ci : TestCase (context, "clear_color", "glClearColor test") 95e5c31af7Sopenharmony_ci , m_numIters (10) 96e5c31af7Sopenharmony_ci , m_curIter (0) 97e5c31af7Sopenharmony_ci{ 98e5c31af7Sopenharmony_ci} 99e5c31af7Sopenharmony_ci 100e5c31af7Sopenharmony_ciClearColorCase::~ClearColorCase (void) 101e5c31af7Sopenharmony_ci{ 102e5c31af7Sopenharmony_ci} 103e5c31af7Sopenharmony_ci 104e5c31af7Sopenharmony_ciTestCase::IterateResult ClearColorCase::iterate (void) 105e5c31af7Sopenharmony_ci{ 106e5c31af7Sopenharmony_ci int r = 0; 107e5c31af7Sopenharmony_ci int g = 0; 108e5c31af7Sopenharmony_ci int b = 0; 109e5c31af7Sopenharmony_ci int a = 255; 110e5c31af7Sopenharmony_ci 111e5c31af7Sopenharmony_ci switch (m_curIter) 112e5c31af7Sopenharmony_ci { 113e5c31af7Sopenharmony_ci case 0: 114e5c31af7Sopenharmony_ci // Black, skip 115e5c31af7Sopenharmony_ci break; 116e5c31af7Sopenharmony_ci case 1: 117e5c31af7Sopenharmony_ci r = 255; 118e5c31af7Sopenharmony_ci g = 255; 119e5c31af7Sopenharmony_ci b = 255; 120e5c31af7Sopenharmony_ci break; 121e5c31af7Sopenharmony_ci case 2: 122e5c31af7Sopenharmony_ci r = 255; 123e5c31af7Sopenharmony_ci break; 124e5c31af7Sopenharmony_ci case 3: 125e5c31af7Sopenharmony_ci g = 255; 126e5c31af7Sopenharmony_ci break; 127e5c31af7Sopenharmony_ci case 4: 128e5c31af7Sopenharmony_ci b = 255; 129e5c31af7Sopenharmony_ci break; 130e5c31af7Sopenharmony_ci default: 131e5c31af7Sopenharmony_ci deRandom rnd; 132e5c31af7Sopenharmony_ci deRandom_init(&rnd, deInt32Hash(m_curIter)); 133e5c31af7Sopenharmony_ci r = (int)(deRandom_getUint32(&rnd) & 0xFF); 134e5c31af7Sopenharmony_ci g = (int)(deRandom_getUint32(&rnd) & 0xFF); 135e5c31af7Sopenharmony_ci b = (int)(deRandom_getUint32(&rnd) & 0xFF); 136e5c31af7Sopenharmony_ci a = (int)(deRandom_getUint32(&rnd) & 0xFF); 137e5c31af7Sopenharmony_ci break; 138e5c31af7Sopenharmony_ci 139e5c31af7Sopenharmony_ci } 140e5c31af7Sopenharmony_ci 141e5c31af7Sopenharmony_ci glClearColor(float(r)/255.0f, float(g)/255.0f, float(b)/255.0f, float(a)/255.0f); 142e5c31af7Sopenharmony_ci glClear(GL_COLOR_BUFFER_BIT); 143e5c31af7Sopenharmony_ci 144e5c31af7Sopenharmony_ci GLU_CHECK_MSG("CLES2 ClearColor failed."); 145e5c31af7Sopenharmony_ci 146e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 147e5c31af7Sopenharmony_ci 148e5c31af7Sopenharmony_ci return (++m_curIter < m_numIters) ? CONTINUE : STOP; 149e5c31af7Sopenharmony_ci} 150e5c31af7Sopenharmony_ci 151e5c31af7Sopenharmony_ciclass ReadPixelsCase : public TestCase 152e5c31af7Sopenharmony_ci{ 153e5c31af7Sopenharmony_cipublic: 154e5c31af7Sopenharmony_ci ReadPixelsCase (Context& context); 155e5c31af7Sopenharmony_ci virtual ~ReadPixelsCase (void); 156e5c31af7Sopenharmony_ci virtual TestCase::IterateResult iterate (void); 157e5c31af7Sopenharmony_ci 158e5c31af7Sopenharmony_ciprivate: 159e5c31af7Sopenharmony_ci int m_numIters; 160e5c31af7Sopenharmony_ci int m_curIter; 161e5c31af7Sopenharmony_ci}; 162e5c31af7Sopenharmony_ci 163e5c31af7Sopenharmony_ciReadPixelsCase::ReadPixelsCase (Context& context) 164e5c31af7Sopenharmony_ci : TestCase(context, "read_pixels", "Read pixels test") 165e5c31af7Sopenharmony_ci , m_numIters(20) 166e5c31af7Sopenharmony_ci , m_curIter(0) 167e5c31af7Sopenharmony_ci{ 168e5c31af7Sopenharmony_ci} 169e5c31af7Sopenharmony_ci 170e5c31af7Sopenharmony_ciReadPixelsCase::~ReadPixelsCase (void) 171e5c31af7Sopenharmony_ci{ 172e5c31af7Sopenharmony_ci} 173e5c31af7Sopenharmony_ci 174e5c31af7Sopenharmony_ciTestCase::IterateResult ReadPixelsCase::iterate (void) 175e5c31af7Sopenharmony_ci{ 176e5c31af7Sopenharmony_ci const tcu::RenderTarget& renderTarget = m_context.getRenderTarget(); 177e5c31af7Sopenharmony_ci tcu::PixelFormat pixelFormat = renderTarget.getPixelFormat(); 178e5c31af7Sopenharmony_ci int targetWidth = renderTarget.getWidth(); 179e5c31af7Sopenharmony_ci int targetHeight = renderTarget.getHeight(); 180e5c31af7Sopenharmony_ci int x = 0; 181e5c31af7Sopenharmony_ci int y = 0; 182e5c31af7Sopenharmony_ci int imageWidth = 0; 183e5c31af7Sopenharmony_ci int imageHeight = 0; 184e5c31af7Sopenharmony_ci 185e5c31af7Sopenharmony_ci deRandom rnd; 186e5c31af7Sopenharmony_ci deRandom_init(&rnd, deInt32Hash(m_curIter)); 187e5c31af7Sopenharmony_ci 188e5c31af7Sopenharmony_ci switch (m_curIter) 189e5c31af7Sopenharmony_ci { 190e5c31af7Sopenharmony_ci case 0: 191e5c31af7Sopenharmony_ci // Fullscreen 192e5c31af7Sopenharmony_ci x = 0; 193e5c31af7Sopenharmony_ci y = 0; 194e5c31af7Sopenharmony_ci imageWidth = targetWidth; 195e5c31af7Sopenharmony_ci imageHeight = targetHeight; 196e5c31af7Sopenharmony_ci break; 197e5c31af7Sopenharmony_ci case 1: 198e5c31af7Sopenharmony_ci // Upper left corner 199e5c31af7Sopenharmony_ci x = 0; 200e5c31af7Sopenharmony_ci y = 0; 201e5c31af7Sopenharmony_ci imageWidth = targetWidth / 2; 202e5c31af7Sopenharmony_ci imageHeight = targetHeight / 2; 203e5c31af7Sopenharmony_ci break; 204e5c31af7Sopenharmony_ci case 2: 205e5c31af7Sopenharmony_ci // Lower right corner 206e5c31af7Sopenharmony_ci x = targetWidth / 2; 207e5c31af7Sopenharmony_ci y = targetHeight / 2; 208e5c31af7Sopenharmony_ci imageWidth = targetWidth - x; 209e5c31af7Sopenharmony_ci imageHeight = targetHeight - y; 210e5c31af7Sopenharmony_ci break; 211e5c31af7Sopenharmony_ci default: 212e5c31af7Sopenharmony_ci x = deRandom_getUint32(&rnd) % (targetWidth - 1); 213e5c31af7Sopenharmony_ci y = deRandom_getUint32(&rnd) % (targetHeight - 1); 214e5c31af7Sopenharmony_ci imageWidth = 1 + (deRandom_getUint32(&rnd) % (targetWidth - x - 1)); 215e5c31af7Sopenharmony_ci imageHeight = 1 + (deRandom_getUint32(&rnd) % (targetHeight - y - 1)); 216e5c31af7Sopenharmony_ci break; 217e5c31af7Sopenharmony_ci } 218e5c31af7Sopenharmony_ci 219e5c31af7Sopenharmony_ci Surface resImage(imageWidth, imageHeight); 220e5c31af7Sopenharmony_ci Surface refImage(imageWidth, imageHeight); 221e5c31af7Sopenharmony_ci Surface diffImage(imageWidth, imageHeight); 222e5c31af7Sopenharmony_ci 223e5c31af7Sopenharmony_ci int r = (int)(deRandom_getUint32(&rnd) & 0xFF); 224e5c31af7Sopenharmony_ci int g = (int)(deRandom_getUint32(&rnd) & 0xFF); 225e5c31af7Sopenharmony_ci int b = (int)(deRandom_getUint32(&rnd) & 0xFF); 226e5c31af7Sopenharmony_ci 227e5c31af7Sopenharmony_ci tcu::clear(refImage.getAccess(), tcu::IVec4(r, g, b, 255)); 228e5c31af7Sopenharmony_ci glClearColor(float(r)/255.0f, float(g)/255.0f, float(b)/255.0f, 1.0f); 229e5c31af7Sopenharmony_ci glClear(GL_COLOR_BUFFER_BIT); 230e5c31af7Sopenharmony_ci 231e5c31af7Sopenharmony_ci glu::readPixels(m_context.getRenderContext(), x, y, resImage.getAccess()); 232e5c31af7Sopenharmony_ci GLU_CHECK_MSG("glReadPixels() failed."); 233e5c31af7Sopenharmony_ci 234e5c31af7Sopenharmony_ci RGBA colorThreshold = pixelFormat.getColorThreshold(); 235e5c31af7Sopenharmony_ci RGBA matchColor(0, 255, 0, 255); 236e5c31af7Sopenharmony_ci RGBA diffColor(255, 0, 0, 255); 237e5c31af7Sopenharmony_ci bool isImageOk = true; 238e5c31af7Sopenharmony_ci 239e5c31af7Sopenharmony_ci for (int j = 0; j < imageHeight; j++) 240e5c31af7Sopenharmony_ci { 241e5c31af7Sopenharmony_ci for (int i = 0; i < imageWidth; i++) 242e5c31af7Sopenharmony_ci { 243e5c31af7Sopenharmony_ci RGBA resRGBA = resImage.getPixel(i, j); 244e5c31af7Sopenharmony_ci RGBA refRGBA = refImage.getPixel(i, j); 245e5c31af7Sopenharmony_ci bool isPixelOk = compareThreshold(refRGBA, resRGBA, colorThreshold); 246e5c31af7Sopenharmony_ci diffImage.setPixel(i, j, isPixelOk ? matchColor : diffColor); 247e5c31af7Sopenharmony_ci 248e5c31af7Sopenharmony_ci isImageOk = isImageOk && isPixelOk; 249e5c31af7Sopenharmony_ci } 250e5c31af7Sopenharmony_ci } 251e5c31af7Sopenharmony_ci 252e5c31af7Sopenharmony_ci if (isImageOk) 253e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 254e5c31af7Sopenharmony_ci else 255e5c31af7Sopenharmony_ci { 256e5c31af7Sopenharmony_ci m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 257e5c31af7Sopenharmony_ci 258e5c31af7Sopenharmony_ci m_testCtx.getLog() << TestLog::ImageSet("Result", "Resulting framebuffer") 259e5c31af7Sopenharmony_ci << TestLog::Image("Result", "Resulting framebuffer", resImage) 260e5c31af7Sopenharmony_ci << TestLog::Image("Reference", "Reference image", refImage) 261e5c31af7Sopenharmony_ci << TestLog::Image("DiffMask", "Failing pixels", diffImage) 262e5c31af7Sopenharmony_ci << TestLog::EndImageSet; 263e5c31af7Sopenharmony_ci } 264e5c31af7Sopenharmony_ci 265e5c31af7Sopenharmony_ci return (++m_curIter < m_numIters) ? CONTINUE : STOP; 266e5c31af7Sopenharmony_ci} 267e5c31af7Sopenharmony_ci 268e5c31af7Sopenharmony_ciPrerequisiteTests::PrerequisiteTests (Context& context) 269e5c31af7Sopenharmony_ci : TestCaseGroup(context, "prerequisite", "Prerequisite Test Cases") 270e5c31af7Sopenharmony_ci{ 271e5c31af7Sopenharmony_ci} 272e5c31af7Sopenharmony_ci 273e5c31af7Sopenharmony_ciPrerequisiteTests::~PrerequisiteTests (void) 274e5c31af7Sopenharmony_ci{ 275e5c31af7Sopenharmony_ci} 276e5c31af7Sopenharmony_ci 277e5c31af7Sopenharmony_civoid PrerequisiteTests::init (void) 278e5c31af7Sopenharmony_ci{ 279e5c31af7Sopenharmony_ci addChild(new StateResetCase(m_context)); 280e5c31af7Sopenharmony_ci addChild(new ClearColorCase(m_context)); 281e5c31af7Sopenharmony_ci addChild(new ReadPixelsCase(m_context)); 282e5c31af7Sopenharmony_ci} 283e5c31af7Sopenharmony_ci 284e5c31af7Sopenharmony_ci} // Functional 285e5c31af7Sopenharmony_ci} // gles3 286e5c31af7Sopenharmony_ci} // deqp 287