13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Screen clearing test. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fColorClearTest.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRGBA.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deInt32.h" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::RGBA; 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Surface; 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace std; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ColorClearCase : public TestCase 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ColorClearCase(Context& context, const char* name, int numIters, int numClearsMin, int numClearsMax, bool testAlpha, bool testScissoring, bool testColorMasks, bool firstClearFull) 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, name) 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numIters (numIters) 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numClearsMin (numClearsMin) 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numClearsMax (numClearsMax) 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testAlpha (testAlpha) 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testScissoring (testScissoring) 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testColorMasks (testColorMasks) 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_firstClearFull (firstClearFull) 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_curIter = 0; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~ColorClearCase (void) 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual IterateResult iterate (void); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_numIters; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_numClearsMin; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_numClearsMax; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_testAlpha; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_testScissoring; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_testColorMasks; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool m_firstClearFull; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_curIter; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ClearInfo 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ClearInfo (const tcu::IVec4& rect, deUint8 colorMask, tcu::RGBA color) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_rect(rect), m_colorMask(colorMask), m_color(color) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::IVec4 m_rect; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 m_colorMask; 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA m_color; 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult ColorClearCase::iterate (void) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget& renderTarget = m_context.getRenderTarget(); 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::PixelFormat& pixelFormat = renderTarget.getPixelFormat(); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int targetWidth = renderTarget.getWidth(); 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int targetHeight = renderTarget.getHeight(); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numPixels = targetWidth * targetHeight; 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd (deInt32Hash(m_curIter)); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint8> pixelKnownChannelMask (numPixels, 0); 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Surface refImage (targetWidth, targetHeight); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Surface resImage (targetWidth, targetHeight); 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Surface diffImage (targetWidth, targetHeight); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numClears = rnd.getUint32() % (m_numClearsMax + 1 - m_numClearsMin) + m_numClearsMin; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ClearInfo> clearOps; 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testScissoring) 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable(GL_SCISSOR_TEST); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int clearNdx = 0; clearNdx < numClears; clearNdx++) 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Rectangle. 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int clearX; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int clearY; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int clearWidth; 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int clearHeight; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_testScissoring || (clearNdx == 0 && m_firstClearFull)) 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearX = 0; 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearY = 0; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearWidth = targetWidth; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearHeight = targetHeight; 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearX = (rnd.getUint32() % (2*targetWidth)) - targetWidth; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearY = (rnd.getUint32() % (2*targetHeight)) - targetHeight; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearWidth = (rnd.getUint32() % targetWidth); 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearHeight = (rnd.getUint32() % targetHeight); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.scissor(clearX, clearY, clearWidth, clearHeight); 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Color. 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int r = (int)(rnd.getUint32() & 0xFF); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int g = (int)(rnd.getUint32() & 0xFF); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int b = (int)(rnd.getUint32() & 0xFF); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int a = m_testAlpha ? (int)(rnd.getUint32() & 0xFF) : 0xFF; 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA clearCol(r, g, b, a); 15052572b88f63a1b260f3182d55e42b3c10b195b3aJarkko Pöyry gl.clearColor(float(r)/255.0f, float(g)/255.0f, float(b)/255.0f, float(a)/255.0f); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Mask. 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 clearMask; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_testColorMasks || (clearNdx == 0 && m_firstClearFull)) 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearMask = 0xF; 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearMask = (rnd.getUint32() & 0xF); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.colorMask((clearMask&0x1) != 0, (clearMask&0x2) != 0, (clearMask&0x4) != 0, (clearMask&0x8) != 0); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear & store op. 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear(GL_COLOR_BUFFER_BIT); 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clearOps.push_back(ClearInfo(tcu::IVec4(clearX, clearY, clearWidth, clearHeight), clearMask, clearCol)); 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Let watchdog know we're alive. 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.touchWatchdog(); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute reference image. 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < targetHeight; y++) 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ClearInfo> scanlineClearOps; 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Find all rectangles affecting this scanline. 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int opNdx = 0; opNdx < (int)clearOps.size(); opNdx++) 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ClearInfo& op = clearOps[opNdx]; 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (de::inBounds(y, op.m_rect.y(), op.m_rect.y()+op.m_rect.w())) 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry scanlineClearOps.push_back(op); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute reference for scanline. 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int x = 0; 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (x < targetWidth) 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA spanColor; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 spanKnownMask = 0; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int spanLength = (targetWidth - x); 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int opNdx = (int)scanlineClearOps.size() - 1; opNdx >= 0; opNdx--) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ClearInfo& op = scanlineClearOps[opNdx]; 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (de::inBounds(x, op.m_rect.x(), op.m_rect.x()+op.m_rect.z()) && 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::inBounds(y, op.m_rect.y(), op.m_rect.y()+op.m_rect.w())) 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute span length until end of given rectangle. 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spanLength = deMin32(spanLength, op.m_rect.x() + op.m_rect.z() - x); 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA clearCol = op.m_color; 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 clearMask = op.m_colorMask; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clearMask & 0x1) && !(spanKnownMask & 0x1)) spanColor.setRed(clearCol.getRed()); 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clearMask & 0x2) && !(spanKnownMask & 0x2)) spanColor.setGreen(clearCol.getGreen()); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clearMask & 0x4) && !(spanKnownMask & 0x4)) spanColor.setBlue(clearCol.getBlue()); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clearMask & 0x8) && !(spanKnownMask & 0x8)) spanColor.setAlpha(clearCol.getAlpha()); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spanKnownMask |= clearMask; 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Break if have all colors. 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (spanKnownMask == 0xF) 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (op.m_rect.x() > x) 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spanLength = deMin32(spanLength, op.m_rect.x() - x); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Set reference alpha channel to 0xFF, if no alpha in target. 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (pixelFormat.alphaBits == 0) 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry spanColor.setAlpha(0xFF); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill the span. 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < spanLength; ndx++) 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refImage.setPixel(x + ndx, y, spanColor); 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelKnownChannelMask[y*targetWidth + x + ndx] |= spanKnownMask; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry x += spanLength; 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), 0, 0, resImage.getAccess()); 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "glReadPixels"); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute difference image. 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA colorThreshold = pixelFormat.getColorThreshold(); 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA matchColor(0, 255, 0, 255); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA diffColor(255, 0, 0, 255); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA maxDiff(0, 0, 0, 0); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isImageOk = true; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (gl.isEnabled(GL_DITHER)) 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry colorThreshold.setRed(colorThreshold.getRed() + 1); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry colorThreshold.setGreen(colorThreshold.getGreen() + 1); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry colorThreshold.setBlue(colorThreshold.getBlue() + 1); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry colorThreshold.setAlpha(colorThreshold.getAlpha() + 1); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < targetHeight; y++) 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < targetWidth; x++) 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int offset = (y*targetWidth + x); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA refRGBA = refImage.getPixel(x, y); 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA resRGBA = resImage.getPixel(x, y); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 colMask = pixelKnownChannelMask[offset]; 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RGBA diff = computeAbsDiffMasked(refRGBA, resRGBA, colMask); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isPixelOk = diff.isBelowThreshold(colorThreshold); 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry diffImage.setPixel(x, y, isPixelOk ? matchColor : diffColor); 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isImageOk = isImageOk && isPixelOk; 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxDiff = max(maxDiff, diff); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (isImageOk) 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail"); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << tcu::TestLog::Message << "Image comparison failed, max diff = " << maxDiff << ", threshold = " << colorThreshold << tcu::TestLog::EndMessage; 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::ImageSet("Result", "Resulting framebuffer") 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("Result", "Resulting framebuffer", resImage) 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("Reference", "Reference image", refImage) 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("DiffMask", "Failing pixels", diffImage) 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::EndImageSet; 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TestCase::STOP; 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isFinal = (++m_curIter == m_numIters); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // On final frame, dump images. 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (isFinal) 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::ImageSet("Result", "Resulting framebuffer") 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::Image("Result", "Resulting framebuffer", resImage) 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << TestLog::EndImageSet; 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return isFinal ? TestCase::STOP : TestCase::CONTINUE; 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryColorClearTest::ColorClearTest (Context& context) : TestCaseGroup(context, "color_clear", "Color Clear Tests") 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko PoyryColorClearTest::~ColorClearTest (void) 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid ColorClearTest::init (void) 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // name iters, #..#, alpha?, scissor,masks, 1stfull? 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "single_rgb", 30, 1,3, false, false, false, true )); 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "single_rgba", 30, 1,3, true, false, false, true )); 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "multiple_rgb", 15, 4,20, false, false, false, true )); 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "multiple_rgba", 15, 4,20, true, false, false, true )); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "long_rgb", 2, 100,500, false, false, false, true )); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "long_rgba", 2, 100,500, true, false, false, true )); 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "subclears_rgb", 15, 4,30, false, false, false, false )); 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "subclears_rgba", 15, 4,30, true, false, false, false )); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "short_scissored_rgb", 30, 2,4, false, true, false, true )); 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "scissored_rgb", 15, 4,30, false, true, false, true )); 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "scissored_rgba", 15, 4,30, true, true, false, true )); 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "masked_rgb", 15, 4,30, false, true, false, true )); 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "masked_rgba", 15, 4,30, true, true, false, true )); 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "masked_scissored_rgb", 15, 4,30, false, true, true, true )); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "masked_scissored_rgba", 15, 4,30, true, true, true, true )); 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "complex_rgb", 15, 5,50, false, true, true, false )); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "complex_rgba", 15, 5,50, true, true, true, false )); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "long_masked_rgb", 2, 100,500, false, true, true, true )); 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new ColorClearCase(m_context, "long_masked_rgba", 2, 100,500, true, true, true, true )); 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 332