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