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 Texture filtering accuracy tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3aTextureFilteringTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deStringUtil.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Accuracy 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::TextureTestUtil; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Texture2DFilteringCase : public tcu::TestCase 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 internalFormat, int width, int height); 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Texture2DFilteringCase (void); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DFilteringCase (const Texture2DFilteringCase& other); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DFilteringCase& operator= (const Texture2DFilteringCase& other); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& m_renderCtx; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ContextInfo& m_renderCtxInfo; 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_minFilter; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_magFilter; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_wrapS; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_wrapT; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_internalFormat; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_width; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_height; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<std::string> m_filenames; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<glu::Texture2D*> m_textures; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer m_renderer; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 823c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DFilteringCase::Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, deUint32 internalFormat, int width, int height) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_ACCURACY, name, desc) 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtxInfo (ctxInfo) 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_internalFormat (internalFormat) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 93469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DFilteringCase::Texture2DFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, const std::vector<std::string>& filenames) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_ACCURACY, name, desc) 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtxInfo (ctxInfo) 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_internalFormat (GL_NONE) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (0) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (0) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_filenames (filenames) 109469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_HIGHP) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1133c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DFilteringCase::~Texture2DFilteringCase (void) 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DFilteringCase::init (void) 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_filenames.empty()) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.reserve(1); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.push_back(glu::Texture2D::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size(), m_filenames)); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Create 2 textures. 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.reserve(2); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < 2; ndx++) 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.push_back(new glu::Texture2D(m_renderCtx, m_internalFormat, m_width, m_height)); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numLevels = deLog2Floor32(de::max(m_width, m_height))+1; 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat()); 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 cBias = fmtInfo.valueMin; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill first gradient texture. 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 gMin = tcu::Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias; 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 gMax = tcu::Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias; 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0]->getRefTexture().allocLevel(levelNdx); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevel(levelNdx), gMin, gMax); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill second with grid texture. 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 step = 0x00ffffff / numLevels; 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 rgb = step*levelNdx; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorA = 0xff000000 | rgb; 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorB = 0xff000000 | ~rgb; 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1]->getRefTexture().allocLevel(levelNdx); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevel(levelNdx), 4, toVec4(tcu::RGBA(colorA))*cScale + cBias, toVec4(tcu::RGBA(colorB))*cScale + cBias); 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload. 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++) 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (*i)->upload(); 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (...) 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clean up to save memory. 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DFilteringCase::deinit(); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DFilteringCase::deinit (void) 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<glu::Texture2D*>::iterator i = m_textures.begin(); i != m_textures.end(); i++) 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete *i; 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.clear(); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.clear(); 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1833c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DFilteringCase::IterateResult Texture2DFilteringCase::iterate (void) 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defViewportWidth = 256; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defViewportHeight = 256; 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomViewport viewport (m_renderCtx.getRenderTarget(), defViewportWidth, defViewportHeight, deStringHash(getName())); 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface renderedFrame (viewport.width, viewport.height); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceFrame (viewport.width, viewport.height); 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureFormat& texFmt = m_textures[0]->getRefTexture().getFormat(); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceParams refParams (TEXTURETYPE_2D); 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texCoord; 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Accuracy measurements are off unless viewport size is 256x256 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (viewport.width < defViewportWidth || viewport.height < defViewportHeight) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__); 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Viewport is divided into 4 sections. 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int leftWidth = viewport.width / 2; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int rightWidth = viewport.width - leftWidth; 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int bottomHeight = viewport.height / 2; 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int topHeight = viewport.height - bottomHeight; 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curTexNdx = 0; 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Use unit 0. 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bind gradient texture and setup sampler parameters. 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_textures[curTexNdx]->getGLTexture()); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS); 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT); 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter); 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup params for reference. 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refParams.sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter); 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refParams.samplerType = getSamplerType(texFmt); 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refParams.lodMode = LODMODE_EXACT; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refParams.colorBias = fmtInfo.lookupBias; 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry refParams.colorScale = fmtInfo.lookupScale; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bottom left: Minification 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x, viewport.y, leftWidth, bottomHeight); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(-4.0f, -4.5f), tcu::Vec2(4.0f, 2.5f)); 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], refParams); 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, bottomHeight), 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), &texCoord[0], refParams); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bottom right: Magnification 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x+leftWidth, viewport.y, rightWidth, bottomHeight); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f)); 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], refParams); 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, bottomHeight), 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), &texCoord[0], refParams); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_textures.size() >= 2) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry curTexNdx += 1; 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup second texture. 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_textures[curTexNdx]->getGLTexture()); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS); 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter); 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Top left: Minification 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note Minification is chosen so that 0.0 < lod <= 0.5. This way special minification threshold rule will be triggered. 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x, viewport.y+bottomHeight, leftWidth, topHeight); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sMin = -0.5f; 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float tMin = -0.2f; 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sRange = ((float)leftWidth * 1.2f) / (float)m_textures[curTexNdx]->getRefTexture().getWidth(); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float tRange = ((float)topHeight * 1.1f) / (float)m_textures[curTexNdx]->getRefTexture().getHeight(); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(sMin, tMin), tcu::Vec2(sMin+sRange, tMin+tRange)); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], refParams); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, bottomHeight, leftWidth, topHeight), 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), &texCoord[0], refParams); 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Top right: Magnification 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x+leftWidth, viewport.y+bottomHeight, rightWidth, topHeight); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(-0.5f, 0.75f), tcu::Vec2(0.25f, 1.25f)); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], refParams); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, bottomHeight, rightWidth, topHeight), 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), &texCoord[0], refParams); 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read result. 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess()); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bestScoreDiff = 16; 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int worstScoreDiff = 3200; 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int score = measureAccuracy(log, referenceFrame, renderedFrame, bestScoreDiff, worstScoreDiff); 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str()); 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureCubeFilteringCase : public tcu::TestCase 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, bool onlySampleFaceInterior, deUint32 internalFormat, int width, int height); 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, bool onlySampleFaceInterior, const std::vector<std::string>& filenames); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~TextureCubeFilteringCase (void); 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeFilteringCase (const TextureCubeFilteringCase& other); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeFilteringCase& operator= (const TextureCubeFilteringCase& other); 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& m_renderCtx; 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ContextInfo& m_renderCtxInfo; 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_minFilter; 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_magFilter; 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_wrapS; 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_wrapT; 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_onlySampleFaceInterior; //!< If true, we avoid sampling anywhere near a face's edges. 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_internalFormat; 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_width; 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_height; 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<std::string> m_filenames; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<glu::TextureCube*> m_textures; 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer m_renderer; 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeFilteringCase::TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, bool onlySampleFaceInterior, deUint32 internalFormat, int width, int height) 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_ACCURACY, name, desc) 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtxInfo (ctxInfo) 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_onlySampleFaceInterior (onlySampleFaceInterior) 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_internalFormat (internalFormat) 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 349469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP) 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3533c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeFilteringCase::TextureCubeFilteringCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const glu::ContextInfo& ctxInfo, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT, bool onlySampleFaceInterior, const std::vector<std::string>& filenames) 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_ACCURACY, name, desc) 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtxInfo (ctxInfo) 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_onlySampleFaceInterior (onlySampleFaceInterior) 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_internalFormat (GL_NONE) 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (0) 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (0) 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_filenames (filenames) 366469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_300_ES, glu::PRECISION_HIGHP) 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3703c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeFilteringCase::~TextureCubeFilteringCase (void) 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deinit(); 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeFilteringCase::init (void) 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_filenames.empty()) 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.reserve(1); 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.push_back(glu::TextureCube::create(m_renderCtx, m_renderCtxInfo, m_testCtx.getArchive(), (int)m_filenames.size() / 6, m_filenames)); 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.reserve(2); 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_width == m_height); 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < 2; ndx++) 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.push_back(new glu::TextureCube(m_renderCtx, m_internalFormat, m_width)); 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numLevels = deLog2Floor32(de::max(m_width, m_height))+1; 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat()); 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 cBias = fmtInfo.valueMin; 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin; 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill first with gradient texture. 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] = 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, 0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4( 0.0f, 0.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx); 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias); 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill second with grid texture. 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST); 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 rgb = step*levelNdx*face; 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorA = 0xff000000 | rgb; 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorB = 0xff000000 | ~rgb; 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx); 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), 4, toVec4(tcu::RGBA(colorA))*cScale + cBias, toVec4(tcu::RGBA(colorB))*cScale + cBias); 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_magFilter == GL_LINEAR || m_minFilter == GL_LINEAR || m_minFilter == GL_LINEAR_MIPMAP_NEAREST || m_minFilter == GL_LINEAR_MIPMAP_LINEAR) 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Using seamless linear cube map filtering - set all corner texels to the same color, because cube corner sampling in this case is not very well defined by the spec. 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo Probably should also do this for cases where textures are loaded from files. 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int texNdx = 0; texNdx < (int)m_textures.size(); texNdx++) 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const tcu::Vec4 color(0.0f, 0.0f, 0.0f, 1.0f); 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess access = m_textures[texNdx]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face); 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, 0, 0); 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, access.getWidth()-1, 0); 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, 0, access.getHeight()-1); 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, access.getWidth()-1, access.getHeight()-1); 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload. 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<glu::TextureCube*>::iterator i = m_textures.begin(); i != m_textures.end(); i++) 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (*i)->upload(); 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clean up to save memory. 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeFilteringCase::deinit(); 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeFilteringCase::deinit (void) 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<glu::TextureCube*>::iterator i = m_textures.begin(); i != m_textures.end(); i++) 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete *i; 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures.clear(); 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.clear(); 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void renderFaces ( 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl, 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const SurfaceAccess& dstRef, 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureCube& refTexture, 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ReferenceParams& params, 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer& renderer, 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int x, 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int y, 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width, 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height, 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec2& bottomLeft, 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec2& topRight, 487d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry const tcu::Vec2& texCoordTopRightFactor) 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(width == dstRef.getWidth() && height == dstRef.getHeight()); 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texCoord; 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(tcu::CUBEFACE_LAST == 6); 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isRightmost = (face == 2) || (face == 5); 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isTop = face >= 3; 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curX = (face % 3) * (width / 3); 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curY = (face / 3) * (height / 2); 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curW = isRightmost ? (width-curX) : (width / 3); 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curH = isTop ? (height-curY) : (height / 2); 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoordCube(texCoord, (tcu::CubeFace)face, bottomLeft, topRight); 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Move the top and right edges of the texture coord quad. This is useful when we want a cube edge visible. 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int texCoordSRow = face == tcu::CUBEFACE_NEGATIVE_X || face == tcu::CUBEFACE_POSITIVE_X ? 2 : 0; 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int texCoordTRow = face == tcu::CUBEFACE_NEGATIVE_Y || face == tcu::CUBEFACE_POSITIVE_Y ? 2 : 1; 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texCoord[6 + texCoordSRow] *= texCoordTopRightFactor.x(); 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texCoord[9 + texCoordSRow] *= texCoordTopRightFactor.x(); 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texCoord[3 + texCoordTRow] *= texCoordTopRightFactor.y(); 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texCoord[9 + texCoordTRow] *= texCoordTopRightFactor.y(); 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(x+curX, y+curY, curW, curH); 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderer.renderQuad(0, &texCoord[0], params); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 519d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry sampleTexture(SurfaceAccess(dstRef, curX, curY, curW, curH), refTexture, &texCoord[0], params); 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Post render"); 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5253c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeFilteringCase::IterateResult TextureCubeFilteringCase::iterate (void) 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int cellSize = 28; 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defViewportWidth = cellSize*6; 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defViewportHeight = cellSize*4; 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomViewport viewport (m_renderCtx.getRenderTarget(), cellSize*6, cellSize*4, deStringHash(getName())); 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface renderedFrame (viewport.width, viewport.height); 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceFrame (viewport.width, viewport.height); 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReferenceParams sampleParams (TEXTURETYPE_CUBE); 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureFormat& texFmt = m_textures[0]->getRefTexture().getFormat(); 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(texFmt); 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Accuracy measurements are off unless viewport size is exactly as expected. 540ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry if (getNodeType() == tcu::NODETYPE_ACCURACY && (viewport.width < defViewportWidth || viewport.height < defViewportHeight)) 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Too small viewport", "", __FILE__, __LINE__); 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Viewport is divided into 4 sections. 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int leftWidth = viewport.width / 2; 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int rightWidth = viewport.width - leftWidth; 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int bottomHeight = viewport.height / 2; 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int topHeight = viewport.height - bottomHeight; 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int curTexNdx = 0; 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Sampling parameters. 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter); 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.sampler.seamlessCubeMap = true; 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.samplerType = getSamplerType(texFmt); 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.colorBias = fmtInfo.lookupBias; 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.colorScale = fmtInfo.lookupScale; 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleParams.lodMode = LODMODE_EXACT; 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Use unit 0. 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup gradient texture. 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_textures[curTexNdx]->getGLTexture()); 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS); 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT); 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter); 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, m_magFilter); 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bottom left: Minification 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderFaces(gl, 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, 0, leftWidth, bottomHeight), 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), sampleParams, 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer, 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry viewport.x, viewport.y, leftWidth, bottomHeight, 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_onlySampleFaceInterior ? tcu::Vec2(-0.81f, -0.81f) : tcu::Vec2(-0.975f, -0.975f), 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_onlySampleFaceInterior ? tcu::Vec2( 0.8f, 0.8f) : tcu::Vec2( 0.975f, 0.975f), 577d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry !m_onlySampleFaceInterior ? tcu::Vec2(1.3f, 1.25f) : tcu::Vec2(1.0f, 1.0f)); 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bottom right: Magnification 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderFaces(gl, 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, 0, rightWidth, bottomHeight), 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), sampleParams, 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer, 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry viewport.x+leftWidth, viewport.y, rightWidth, bottomHeight, 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec2(0.5f, 0.65f), m_onlySampleFaceInterior ? tcu::Vec2(0.8f, 0.8f) : tcu::Vec2(0.975f, 0.975f), 586d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry !m_onlySampleFaceInterior ? tcu::Vec2(1.1f, 1.06f) : tcu::Vec2(1.0f, 1.0f)); 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_textures.size() >= 2) 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry curTexNdx += 1; 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup second texture. 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_textures[curTexNdx]->getGLTexture()); 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS); 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT); 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter); 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, m_magFilter); 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Top left: Minification 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderFaces(gl, 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), 0, bottomHeight, leftWidth, topHeight), 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), sampleParams, 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer, 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry viewport.x, viewport.y+bottomHeight, leftWidth, topHeight, 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_onlySampleFaceInterior ? tcu::Vec2(-0.81f, -0.81f) : tcu::Vec2(-0.975f, -0.975f), 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_onlySampleFaceInterior ? tcu::Vec2( 0.8f, 0.8f) : tcu::Vec2( 0.975f, 0.975f), 608d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry !m_onlySampleFaceInterior ? tcu::Vec2(1.3f, 1.25f) : tcu::Vec2(1.0f, 1.0f)); 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Top right: Magnification 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderFaces(gl, 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat(), leftWidth, bottomHeight, rightWidth, topHeight), 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[curTexNdx]->getRefTexture(), sampleParams, 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer, 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry viewport.x+leftWidth, viewport.y+bottomHeight, rightWidth, topHeight, 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec2(0.5f, -0.65f), m_onlySampleFaceInterior ? tcu::Vec2(0.8f, -0.8f) : tcu::Vec2(0.975f, -0.975f), 617d81a5c316e936b6ff090e37743afbde12cfa3321Jarkko Pöyry !m_onlySampleFaceInterior ? tcu::Vec2(1.1f, 1.06f) : tcu::Vec2(1.0f, 1.0f)); 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read result. 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess()); 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bestScoreDiff = 16; 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int worstScoreDiff = 10000; 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int score = measureAccuracy(log, referenceFrame, renderedFrame, bestScoreDiff, worstScoreDiff); 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::toString(score).c_str()); 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureFilteringTests::TextureFilteringTests (Context& context) 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "filter", "Texture Filtering Accuracy Tests") 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6393c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureFilteringTests::~TextureFilteringTests (void) 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureFilteringTests::init (void) 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* group2D = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Filtering"); 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cube Map Filtering"); 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(group2D); 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(groupCube); 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 mode; 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } wrapModes[] = 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "clamp", GL_CLAMP_TO_EDGE }, 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "repeat", GL_REPEAT }, 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "mirror", GL_MIRRORED_REPEAT } 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 mode; 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } minFilterModes[] = 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest", GL_NEAREST }, 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear", GL_LINEAR }, 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest_mipmap_nearest", GL_NEAREST_MIPMAP_NEAREST }, 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear_mipmap_nearest", GL_LINEAR_MIPMAP_NEAREST }, 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest_mipmap_linear", GL_NEAREST_MIPMAP_LINEAR }, 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear_mipmap_linear", GL_LINEAR_MIPMAP_LINEAR } 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 mode; 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } magFilterModes[] = 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest", GL_NEAREST }, 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear", GL_LINEAR } 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width; 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height; 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } sizes2D[] = 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "pot", 32, 64 }, 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "npot", 31, 55 } 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width; 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height; 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } sizesCube[] = 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "pot", 64, 64 }, 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "npot", 63, 63 } 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format; 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } formats[] = 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgba8", GL_RGBA8 } 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define FOR_EACH(ITERATOR, ARRAY, BODY) \ 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++) \ 7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BODY 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // 2D cases. 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(minFilter, minFilterModes, 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(magFilter, magFilterModes, 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapMode, wrapModes, 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(format, formats, 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(size, sizes2D, 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name + "_" + formats[format].name + string("_") + sizes2D[size].name; 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry group2D->addChild(new Texture2DFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), 7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minFilterModes[minFilter].mode, 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry magFilterModes[magFilter].mode, 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry formats[format].format, 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sizes2D[size].width, sizes2D[size].height)); 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }))))); 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Cubemap cases. 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(minFilter, minFilterModes, 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(magFilter, magFilterModes, 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapMode, wrapModes, 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(format, formats, 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(size, sizesCube, 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name + "_" + formats[format].name + string("_") + sizesCube[size].name; 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupCube->addChild(new TextureCubeFilteringCase(m_testCtx, m_context.getRenderContext(), m_context.getContextInfo(), 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minFilterModes[minFilter].mode, 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry magFilterModes[magFilter].mode, 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry false, 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry formats[format].format, 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sizesCube[size].width, sizesCube[size].height)); 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }))))); 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Accuracy 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 763