13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 2.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 size tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fTextureSizeTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluStrUtil.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Sampler; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glu; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::TextureTestUtil; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Texture2DSizeCase : public tcu::TestCase 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps); 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Texture2DSizeCase (void); 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSizeCase (const Texture2DSizeCase& other); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSizeCase& operator= (const Texture2DSizeCase& other); 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& m_renderCtx; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_format; 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_dataType; 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_width; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_height; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_useMipmaps; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::Texture2D* m_texture; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer m_renderer; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSizeCase::Texture2DSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, name, description) 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_dataType (dataType) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_useMipmaps (mipmaps) 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (DE_NULL) 85469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP) 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 893c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSizeCase::~Texture2DSizeCase (void) 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DSizeCase::deinit(); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DSizeCase::init (void) 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_texture); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = new Texture2D(m_renderCtx, m_format, m_dataType, m_width, m_height); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numLevels = m_useMipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill levels. 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->getRefTexture().allocLevel(levelNdx); 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_texture->getRefTexture().getLevel(levelNdx), tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f)); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Texture2DSizeCase::deinit (void) 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_texture; 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = DE_NULL; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.clear(); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexture2DSizeCase::IterateResult Texture2DSizeCase::iterate (void) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomViewport viewport (m_renderCtx.getRenderTarget(), 128, 128, deStringHash(getName())); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface renderedFrame (viewport.width, viewport.height); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceFrame (viewport.width, viewport.height); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(7,7,7,7); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 wrapS = GL_CLAMP_TO_EDGE; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 wrapT = GL_CLAMP_TO_EDGE; 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 minFilter = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 magFilter = GL_NEAREST; 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texCoord; 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f)); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup base viewport. 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload texture data to GL. 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->upload(); 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bind to unit 0. 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_2D, m_texture->getGLTexture()); 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS); 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT); 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state"); 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Draw. 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_2D); 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess()); 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute reference. 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()), m_texture->getRefTexture(), &texCoord[0], ReferenceParams(TEXTURETYPE_2D, mapGLSampler(wrapS, wrapT, minFilter, magFilter))); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = compareImages(log, referenceFrame, renderedFrame, threshold); 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : "Image comparison failed"); 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TextureCubeSizeCase : public tcu::TestCase 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~TextureCubeSizeCase (void); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeSizeCase (const TextureCubeSizeCase& other); 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeSizeCase& operator= (const TextureCubeSizeCase& other); 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool testFace (tcu::CubeFace face); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& m_renderCtx; 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_format; 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_dataType; 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_width; 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_height; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_useMipmaps; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureCube* m_texture; 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureRenderer m_renderer; 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_curFace; 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_isOk; 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeSizeCase::TextureCubeSizeCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description, deUint32 format, deUint32 dataType, int width, int height, bool mipmaps) 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, name, description) 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_renderCtx (renderCtx) 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_dataType (dataType) 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_useMipmaps (mipmaps) 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_texture (DE_NULL) 205469002caa1ccd58f59f53a1bf3dbac4cf6a5d817Jarkko Pöyry , m_renderer (renderCtx, testCtx.getLog(), glu::GLSL_VERSION_100_ES, glu::PRECISION_MEDIUMP) 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_curFace (0) 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_isOk (false) 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2113c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeSizeCase::~TextureCubeSizeCase (void) 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureCubeSizeCase::deinit(); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeSizeCase::init (void) 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_texture); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_width == m_height); 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = new TextureCube(m_renderCtx, m_format, m_dataType, m_width); 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const tcu::Vec4 gradients[tcu::CUBEFACE_LAST][2] = 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4( 0.0f, -1.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, 0.0f, -1.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4(-1.0f, -1.0f, -1.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { tcu::Vec4( 0.0f, 0.0f, 0.0f, 2.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numLevels = m_useMipmaps ? deLog2Floor32(de::max(m_width, m_height))+1 : 1; 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill levels. 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithComponentGradients(m_texture->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0], gradients[face][1]); 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload texture data to GL. 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture->upload(); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Initialize iteration state. 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_curFace = 0; 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_isOk = true; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureCubeSizeCase::deinit (void) 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_texture; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texture = DE_NULL; 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.clear(); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool TextureCubeSizeCase::testFace (tcu::CubeFace face) 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_renderCtx.getFunctions(); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry RandomViewport viewport (m_renderCtx.getRenderTarget(), 128, 128, deStringHash(getName())+(deUint32)face); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface renderedFrame (viewport.width, viewport.height); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface referenceFrame (viewport.width, viewport.height); 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA threshold = m_renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(7,7,7,7); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 wrapS = GL_CLAMP_TO_EDGE; 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 wrapT = GL_CLAMP_TO_EDGE; 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 minFilter = m_useMipmaps ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 magFilter = GL_NEAREST; 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texCoord; 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoordCube(texCoord, face); 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \todo [2011-10-28 pyry] Image set name / section? 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << TestLog::Message << face << TestLog::EndMessage; 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup base viewport. 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Bind to unit 0. 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.activeTexture(GL_TEXTURE0); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.bindTexture(GL_TEXTURE_CUBE_MAP, m_texture->getGLTexture()); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrapS); 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrapT); 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, minFilter); 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, magFilter); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state"); 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_renderer.renderQuad(0, &texCoord[0], TEXTURETYPE_CUBE); 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_renderCtx, viewport.x, viewport.y, renderedFrame.getAccess()); 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute reference. 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Sampler sampler = mapGLSampler(wrapS, wrapT, minFilter, magFilter); 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampler.seamlessCubeMap = false; 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sampleTexture(SurfaceAccess(referenceFrame, m_renderCtx.getRenderTarget().getPixelFormat()), m_texture->getRefTexture(), &texCoord[0], ReferenceParams(TEXTURETYPE_CUBE, sampler)); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return compareImages(log, referenceFrame, renderedFrame, threshold); 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3043c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureCubeSizeCase::IterateResult TextureCubeSizeCase::iterate (void) 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute test for all faces. 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!testFace((tcu::CubeFace)m_curFace)) 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_isOk = false; 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_curFace += 1; 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_curFace == tcu::CUBEFACE_LAST) 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(m_isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_isOk ? "Pass" : "Image comparison failed"); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return CONTINUE; 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSizeTests::TextureSizeTests (Context& context) 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "size", "Texture Size Tests") 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureSizeTests::~TextureSizeTests (void) 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid TextureSizeTests::init (void) 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width; 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height; 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } sizes2D[] = 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 64, 64 }, // Spec-mandated minimum. 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 65, 63 }, 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 512, 512 }, 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1024, 1024 }, 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2048, 2048 } 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width; 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height; 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } sizesCube[] = 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 15, 15 }, 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 16, 16 }, // Spec-mandated minimum 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 64, 64 }, 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 128, 128 }, 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 256, 256 }, 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 512, 512 } 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 format; 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 dataType; 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } formats[] = 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "l8", GL_LUMINANCE, GL_UNSIGNED_BYTE }, 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgba4444", GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 }, 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgb888", GL_RGB, GL_UNSIGNED_BYTE }, 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "rgba8888", GL_RGBA, GL_UNSIGNED_BYTE } 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // 2D cases. 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* group2D = new tcu::TestCaseGroup(m_testCtx, "2d", "2D Texture Size Tests"); 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(group2D); 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes2D); sizeNdx++) 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = sizes2D[sizeNdx].width; 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = sizes2D[sizeNdx].height; 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isPOT = deIsPowerOfTwo32(width) && deIsPowerOfTwo32(height); 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++) 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int mipmap = 0; mipmap < (isPOT ? 2 : 1); mipmap++) 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream name; 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name << width << "x" << height << "_" << formats[formatNdx].name << (mipmap ? "_mipmap" : ""); 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry group2D->addChild(new Texture2DSizeCase(m_testCtx, m_context.getRenderContext(), name.str().c_str(), "", 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry formats[formatNdx].format, formats[formatNdx].dataType, 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry width, height, mipmap != 0)); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Cubemap cases. 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* groupCube = new tcu::TestCaseGroup(m_testCtx, "cube", "Cubemap Texture Size Tests"); 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(groupCube); 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizesCube); sizeNdx++) 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = sizesCube[sizeNdx].width; 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = sizesCube[sizeNdx].height; 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isPOT = deIsPowerOfTwo32(width) && deIsPowerOfTwo32(height); 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++) 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int mipmap = 0; mipmap < (isPOT ? 2 : 1); mipmap++) 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::ostringstream name; 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name << width << "x" << height << "_" << formats[formatNdx].name << (mipmap ? "_mipmap" : ""); 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupCube->addChild(new TextureCubeSizeCase(m_testCtx, m_context.getRenderContext(), name.str().c_str(), "", 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry formats[formatNdx].format, formats[formatNdx].dataType, 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry width, height, mipmap != 0)); 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 423