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