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 Vertex texture tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es2fVertexTextureTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glsTextureTestUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTexture.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuMatrix.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits> 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glw.h" 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec3; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Mat3; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace gls::TextureTestUtil; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::TextureTestUtil::TEXTURETYPE_2D; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing gls::TextureTestUtil::TEXTURETYPE_CUBE; 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles2 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// The 2D case draws four images. 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_2D_RENDER_WIDTH = 128*2; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_2D_RENDER_HEIGHT = 128*2; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// The cube map case draws four 3-by-2 image groups. 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_CUBE_RENDER_WIDTH = 28*2*3; 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int MAX_CUBE_RENDER_HEIGHT = 28*2*2; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int GRID_SIZE_2D = 127; 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic const int GRID_SIZE_CUBE = 63; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Helpers for making texture coordinates "safe", i.e. move them further from coordinate bounary. 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Moves x towards the closest K+targetFraction, where K is an integer. 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// E.g. moveTowardsFraction(x, 0.5f) moves x away from integer boundaries. 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float moveTowardsFraction (float x, float targetFraction) 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float strictness = 0.5f; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(0.0f < strictness && strictness <= 1.0f); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(targetFraction, 0.0f, 1.0f)); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float y = x + 0.5f - targetFraction; 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return deFloatFloor(y) + deFloatFrac(y)*(1.0f-strictness) + strictness*0.5f - 0.5f + targetFraction; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float safeCoord (float raw, int scale, float fraction) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float scaleFloat = (float)scale; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return moveTowardsFraction(raw*scaleFloat, fraction) / scaleFloat; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <int Size> 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline tcu::Vector<float, Size> safeCoords (const tcu::Vector<float, Size>& raw, const tcu::Vector<int, Size>& scale, const tcu::Vector<float, Size>& fraction) 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vector<float, Size> result; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < Size; i++) 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry result[i] = safeCoord(raw[i], scale[i], fraction[i]); 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return result; 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline Vec2 safe2DTexCoords (const Vec2& raw, const IVec2& textureSize) 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return safeCoords(raw, textureSize, Vec2(0.5f)); 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct Rect 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Rect (int x_, int y_, int w_, int h_) : x(x_), y(y_), w(w_), h(h_) {} 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVec2 pos (void) const { return IVec2(x, y); } 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVec2 size (void) const { return IVec2(w, h); } 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int x; 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int y; 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int w; 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int h; 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType> struct TexTypeTcuClass; 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeTcuClass<TEXTURETYPE_2D> { typedef tcu::Texture2D t; }; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeTcuClass<TEXTURETYPE_CUBE> { typedef tcu::TextureCube t; }; 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType> struct TexTypeSizeDims; 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeSizeDims<TEXTURETYPE_2D> { enum { V = 2 }; }; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeSizeDims<TEXTURETYPE_CUBE> { enum { V = 2 }; }; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType> struct TexTypeCoordDims; 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeCoordDims<TEXTURETYPE_2D> { enum { V = 2 }; }; 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct TexTypeCoordDims<TEXTURETYPE_CUBE> { enum { V = 3 }; }; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> struct TexTypeSizeIVec { typedef tcu::Vector<int, TexTypeSizeDims<TexType>::V> t; }; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> struct TexTypeCoordVec { typedef tcu::Vector<float, TexTypeCoordDims<TexType>::V> t; }; 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType> struct TexTypeCoordParams; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct 1443c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexTypeCoordParams<TEXTURETYPE_2D> 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 scale; 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 bias; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TexTypeCoordParams (const Vec2& scale_, const Vec2& bias_) : scale(scale_), bias(bias_) {} 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> struct 1533c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTexTypeCoordParams<TEXTURETYPE_CUBE> 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 scale; 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 bias; 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::CubeFace face; 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TexTypeCoordParams (const Vec2& scale_, const Vec2& bias_, tcu::CubeFace face_) : scale(scale_), bias(bias_), face(face_) {} 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Quad grid class containing position and texture coordinate data. 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * A quad grid of size S means a grid consisting of S*S quads (S rows and 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * S columns). The quads are rectangles with main axis aligned sides, and 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * each consists of two triangles. Note that although there are only 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * (S+1)*(S+1) distinct vertex positions, there are S*S*4 distinct vertices 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * because we want texture coordinates to be constant across the vertices 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * of a quad (to avoid interpolation issues), and thus each quad needs its 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * own 4 vertices. 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Pointers returned by get*Ptr() are suitable for gl calls such as 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * glVertexAttribPointer() (for position and tex coord) or glDrawElements() 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * (for indices). 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass PosTexCoordQuadGrid 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum { TEX_COORD_DIMS = TexTypeCoordDims <TexType>::V }; 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef typename TexTypeCoordVec<TexType>::t TexCoordVec; 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef typename TexTypeSizeIVec<TexType>::t TexSizeIVec; 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef TexTypeCoordParams<TexType> TexCoordParams; 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PosTexCoordQuadGrid (int gridSize, const IVec2& renderSize, const TexSizeIVec& textureSize, const TexCoordParams& texCoordParams, bool useSafeTexCoords); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getSize (void) const { return m_gridSize; } 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 getQuadLDRU (int col, int row) const; //!< Vec4(leftX, downY, rightX, upY) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const TexCoordVec& getQuadTexCoord (int col, int row) const; 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumIndices (void) const { return m_gridSize*m_gridSize*3*2; } 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float* getPositionPtr (void) const { DE_STATIC_ASSERT(sizeof(Vec2) == 2*sizeof(float)); return (float*)&m_positions[0]; } 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float* getTexCoordPtr (void) const { DE_STATIC_ASSERT(sizeof(TexCoordVec) == TEX_COORD_DIMS*(int)sizeof(float)); return (float*)&m_texCoords[0]; } 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint16* getIndexPtr (void) const { return &m_indices[0]; } 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void initializeTexCoords (const TexSizeIVec& textureSize, const TexCoordParams& texCoordParams, bool useSafeTexCoords); 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_gridSize; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<Vec2> m_positions; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<TexCoordVec> m_texCoords; 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<deUint16> m_indices; 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 2083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVec4 PosTexCoordQuadGrid<TexType>::getQuadLDRU (int col, int row) const 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int ndx00 = (row*m_gridSize + col) * 4; 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int ndx11 = ndx00 + 3; 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return Vec4(m_positions[ndx00].x(), 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_positions[ndx00].y(), 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_positions[ndx11].x(), 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_positions[ndx11].y()); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst typename TexTypeCoordVec<TexType>::t& PosTexCoordQuadGrid<TexType>::getQuadTexCoord (int col, int row) const 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_texCoords[(row*m_gridSize + col) * 4]; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 2263c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPosTexCoordQuadGrid<TexType>::PosTexCoordQuadGrid (int gridSize, const IVec2& renderSize, const TexSizeIVec& textureSize, const TexCoordParams& texCoordParams, bool useSafeTexCoords) 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_gridSize(gridSize) 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_gridSize > 0 && m_gridSize*m_gridSize <= (int)std::numeric_limits<deUint16>::max() + 1); 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float gridSizeFloat = (float)m_gridSize; 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_positions.reserve(m_gridSize*m_gridSize*4); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.reserve(m_gridSize*m_gridSize*3*2); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize; y++) 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize; x++) 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float fx0 = (float)(x+0) / gridSizeFloat; 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float fx1 = (float)(x+1) / gridSizeFloat; 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float fy0 = (float)(y+0) / gridSizeFloat; 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float fy1 = (float)(y+1) / gridSizeFloat; 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 quadVertices[4] = { Vec2(fx0, fy0), Vec2(fx1, fy0), Vec2(fx0, fy1), Vec2(fx1, fy1) }; 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int firstNdx = (int)m_positions.size(); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < DE_LENGTH_OF_ARRAY(quadVertices); i++) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_positions.push_back(safeCoords(quadVertices[i], renderSize, Vec2(0.0f)) * 2.0f - 1.0f); 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 0); 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 1); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 2); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 1); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 3); 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_indices.push_back(firstNdx + 2); 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texCoords.reserve(m_gridSize*m_gridSize*4); 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry initializeTexCoords(textureSize, texCoordParams, useSafeTexCoords); 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((int)m_positions.size() == m_gridSize*m_gridSize*4); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((int)m_indices.size() == m_gridSize*m_gridSize*3*2); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT((int)m_texCoords.size() == m_gridSize*m_gridSize*4); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PosTexCoordQuadGrid<TEXTURETYPE_2D>::initializeTexCoords (const IVec2& textureSize, const TexCoordParams& texCoordParams, bool useSafeTexCoords) 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_texCoords.empty()); 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float gridSizeFloat = (float)m_gridSize; 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize; y++) 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize; x++) 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 rawCoord = Vec2((float)x / gridSizeFloat, (float)y / gridSizeFloat) * texCoordParams.scale + texCoordParams.bias; 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 4; i++) 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texCoords.push_back(useSafeTexCoords ? safe2DTexCoords(rawCoord, textureSize) : rawCoord); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <> 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid PosTexCoordQuadGrid<TEXTURETYPE_CUBE>::initializeTexCoords (const IVec2& textureSize, const TexCoordParams& texCoordParams, bool useSafeTexCoords) 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_texCoords.empty()); 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float gridSizeFloat = (float)m_gridSize; 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<float> texBoundaries; 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeQuadTexCoordCube(texBoundaries, texCoordParams.face); 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 coordA = Vec3(texBoundaries[0], texBoundaries[1], texBoundaries[2]); 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 coordB = Vec3(texBoundaries[3], texBoundaries[4], texBoundaries[5]); 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 coordC = Vec3(texBoundaries[6], texBoundaries[7], texBoundaries[8]); 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 coordAB = coordB - coordA; 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 coordAC = coordC - coordA; 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < m_gridSize; y++) 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < m_gridSize; x++) 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 rawFaceCoord = texCoordParams.scale * Vec2((float)x / gridSizeFloat, (float)y / gridSizeFloat) + texCoordParams.bias; 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 safeFaceCoord = useSafeTexCoords ? safe2DTexCoords(rawFaceCoord, textureSize) : rawFaceCoord; 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec3 texCoord = coordA + coordAC*safeFaceCoord.x() + coordAB*safeFaceCoord.y(); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 4; i++) 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_texCoords.push_back(texCoord); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline bool isLevelNearest (deUint32 filter) 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return filter == GL_NEAREST || filter == GL_NEAREST_MIPMAP_NEAREST || filter == GL_NEAREST_MIPMAP_LINEAR; 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline IVec2 getTextureSize (const glu::Texture2D& tex) 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Texture2D& ref = tex.getRefTexture(); 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return IVec2(ref.getWidth(), ref.getHeight()); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline IVec2 getTextureSize (const glu::TextureCube& tex) 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureCube& ref = tex.getRefTexture(); 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return IVec2(ref.getSize(), ref.getSize()); 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void setPixelColors (const vector<Vec4>& quadColors, const Rect& region, const PosTexCoordQuadGrid<TexType>& grid, tcu::Surface& dst) 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int gridSize = grid.getSize(); 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < gridSize; y++) 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < gridSize; x++) 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 color = quadColors[y*gridSize + x]; 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 ldru = grid.getQuadLDRU(x, y) * 0.5f + 0.5f; // [-1, 1] -> [0, 1] 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ix0 = deCeilFloatToInt32(ldru.x() * (float)region.w - 0.5f); 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ix1 = deCeilFloatToInt32(ldru.z() * (float)region.w - 0.5f); 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int iy0 = deCeilFloatToInt32(ldru.y() * (float)region.h - 0.5f); 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int iy1 = deCeilFloatToInt32(ldru.w() * (float)region.h - 0.5f); 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int iy = iy0; iy < iy1; iy++) 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ix = ix0; ix < ix1; ix++) 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(deInBounds32(ix + region.x, 0, dst.getWidth())); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(deInBounds32(iy + region.y, 0, dst.getHeight())); 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(ix + region.x, iy + region.y, toRGBA(color)); 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline Vec4 sample (const tcu::Texture2D& tex, const Vec2& coord, float lod, const tcu::Sampler& sam) { return tex.sample(sam, coord.x(), coord.y(), lod); } 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline Vec4 sample (const tcu::TextureCube& tex, const Vec3& coord, float lod, const tcu::Sampler& sam) { return tex.sample(sam, coord.x(), coord.y(), coord.z(), lod); } 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <TextureType TexType> 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid computeReference (const typename TexTypeTcuClass<TexType>::t& texture, float lod, const tcu::Sampler& sampler, const PosTexCoordQuadGrid<TexType>& grid, tcu::Surface& dst, const Rect& dstRegion) 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int gridSize = grid.getSize(); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<Vec4> quadColors (gridSize*gridSize); 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < gridSize; y++) 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < gridSize; x++) 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int ndx = y*gridSize + x; 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const typename TexTypeCoordVec<TexType>::t& coord = grid.getQuadTexCoord(x, y); 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry quadColors[ndx] = sample(texture, coord, lod, sampler); 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry setPixelColors(quadColors, dstRegion, grid, dst); 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic bool compareImages (const glu::RenderContext& renderCtx, tcu::TestLog& log, const tcu::Surface& ref, const tcu::Surface& res) 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(renderCtx.getRenderTarget().getNumSamples() == 0); 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RGBA threshold = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(15,15,15,15); 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return tcu::pixelThresholdCompare(log, "Result", "Image compare result", ref, res, threshold, tcu::COMPARE_LOG_RESULT); 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Vertex2DTextureCase : public TestCase 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vertex2DTextureCase (Context& testCtx, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT); 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Vertex2DTextureCase (void); 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef PosTexCoordQuadGrid<TEXTURETYPE_2D> Grid; 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vertex2DTextureCase (const Vertex2DTextureCase& other); 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vertex2DTextureCase& operator= (const Vertex2DTextureCase& other); 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float calculateLod (const Vec2& texScale, const Vec2& dstSize, int textureNdx) const; 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setupShaderInputs (int textureNdx, float lod, const Grid& grid) const; 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderCell (int textureNdx, float lod, const Grid& grid) const; 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void computeReferenceCell (int textureNdx, float lod, const Grid& grid, tcu::Surface& dst, const Rect& dstRegion) const; 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_minFilter; 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_magFilter; 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_wrapS; 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_wrapT; 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ShaderProgram* m_program; 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::Texture2D* m_textures[2]; // 2 textures, a gradient texture and a grid texture. 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertex2DTextureCase::Vertex2DTextureCase (Context& testCtx, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT) 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_SELF_VALIDATE, name, desc) 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_program (DE_NULL) 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0] = DE_NULL; 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1] = DE_NULL; 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertex2DTextureCase::~Vertex2DTextureCase(void) 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vertex2DTextureCase::deinit(); 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Vertex2DTextureCase::init (void) 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const vertexShader = 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec2 a_position;\n" 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec2 a_texCoord;\n" 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform highp sampler2D u_texture;\n" 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform highp float u_lod;\n" 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main()\n" 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = vec4(a_position, 0.0, 1.0);\n" 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = texture2DLod(u_texture, a_texCoord, u_lod);\n" 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const fragmentShader = 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main()\n" 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_FragColor = v_color;\n" 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_context.getRenderTarget().getNumSamples() != 0) 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("MSAA config not supported by this test"); 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_program); 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShader, fragmentShader)); 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if(!m_program->isOk()) 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_program; 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLint maxVertexTextures; 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxVertexTextures); 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (maxVertexTextures < 1) 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Vertex texture image units not supported", "", __FILE__, __LINE__); 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Failed to compile shader"); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Make the textures. 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute suitable power-of-two sizes (for mipmaps). 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texWidth = 1 << deLog2Ceil32(MAX_2D_RENDER_WIDTH / 2); 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texHeight = 1 << deLog2Ceil32(MAX_2D_RENDER_HEIGHT / 2); 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_textures[i]); 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i] = new glu::Texture2D(m_context.getRenderContext(), GL_RGB, GL_UNSIGNED_BYTE, texWidth, texHeight); 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool mipmaps = (deIsPowerOfTwo32(texWidth) && deIsPowerOfTwo32(texHeight)); 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numLevels = mipmaps ? deLog2Floor32(de::max(texWidth, texHeight))+1 : 1; 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat()); 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 cBias = fmtInfo.valueMin; 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin; 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill first with gradient texture. 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 gMin = Vec4(-0.5f, -0.5f, -0.5f, 2.0f)*cScale + cBias; 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 gMax = Vec4( 1.0f, 1.0f, 1.0f, 0.0f)*cScale + cBias; 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0]->getRefTexture().allocLevel(levelNdx); 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevel(levelNdx), gMin, gMax); 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill second with grid texture. 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 step = 0x00ffffff / numLevels; 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 rgb = step*levelNdx; 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorA = 0xff000000 | rgb; 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorB = 0xff000000 | ~rgb; 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1]->getRefTexture().allocLevel(levelNdx); 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevel(levelNdx), 4, toVec4(tcu::RGBA(colorA))*cScale + cBias, toVec4(tcu::RGBA(colorB))*cScale + cBias); 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload. 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i]->upload(); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clean up to save memory. 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vertex2DTextureCase::deinit(); 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Vertex2DTextureCase::deinit (void) 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_textures[i]; 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i] = DE_NULL; 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_program; 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = DE_NULL; 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryfloat Vertex2DTextureCase::calculateLod (const Vec2& texScale, const Vec2& dstSize, int textureNdx) const 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Texture2D& refTexture = m_textures[textureNdx]->getRefTexture(); 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 srcSize = Vec2((float)refTexture.getWidth(), (float)refTexture.getHeight()); 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 sizeRatio = texScale*srcSize / dstSize; 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note In this particular case dv/dx and du/dy are zero, simplifying the expression. 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return deFloatLog2(de::max(sizeRatio.x(), sizeRatio.y())); 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5493c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertex2DTextureCase::IterateResult Vertex2DTextureCase::iterate (void) 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportWidth = deMin32(m_context.getRenderTarget().getWidth(), MAX_2D_RENDER_WIDTH); 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportHeight = deMin32(m_context.getRenderTarget().getHeight(), MAX_2D_RENDER_HEIGHT); 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportXOffsetMax = m_context.getRenderTarget().getWidth() - viewportWidth; 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportYOffsetMax = m_context.getRenderTarget().getHeight() - viewportHeight; 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd (deStringHash(getName())); 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportXOffset = rnd.getInt(0, viewportXOffsetMax); 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportYOffset = rnd.getInt(0, viewportYOffsetMax); 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUseProgram(m_program->getProgram()); 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Divide viewport into 4 cells. 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int leftWidth = viewportWidth / 2; 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int rightWidth = viewportWidth - leftWidth; 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bottomHeight = viewportHeight / 2; 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int topHeight = viewportHeight - bottomHeight; 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear. 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClearColor(0.125f, 0.25f, 0.5f, 1.0f); 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClear(GL_COLOR_BUFFER_BIT); 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Texture scaling and offsetting vectors. 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMinScale (+1.8f, +1.8f); 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMinOffset (-0.3f, -0.2f); 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMagScale (+0.3f, +0.3f); 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMagOffset (+0.9f, +0.8f); 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Surface for the reference image. 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface refImage(viewportWidth, viewportHeight); 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct Render 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Rect region; 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int textureNdx; 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texCoordScale; 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texCoordOffset; 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render (const Rect& r, int tN, const Vec2& tS, const Vec2& tO) : region(r), textureNdx(tN), texCoordScale(tS), texCoordOffset(tO) {} 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } renders[] = 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(0, 0, leftWidth, bottomHeight), 0, texMinScale, texMinOffset), 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(leftWidth, 0, rightWidth, bottomHeight), 0, texMagScale, texMagOffset), 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(0, bottomHeight, leftWidth, topHeight), 1, texMinScale, texMinOffset), 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(leftWidth, bottomHeight, rightWidth, topHeight), 1, texMagScale, texMagOffset) 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int renderNdx = 0; renderNdx < DE_LENGTH_OF_ARRAY(renders); renderNdx++) 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Render& rend = renders[renderNdx]; 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float lod = calculateLod(rend.texCoordScale, rend.region.size().asFloat(), rend.textureNdx); 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool useSafeTexCoords = isLevelNearest(lod > 0.0f ? m_minFilter : m_magFilter); 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Grid grid (GRID_SIZE_2D, rend.region.size(), getTextureSize(*m_textures[rend.textureNdx]), 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TexTypeCoordParams<TEXTURETYPE_2D>(rend.texCoordScale, rend.texCoordOffset), useSafeTexCoords); 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glViewport(viewportXOffset + rend.region.x, viewportYOffset + rend.region.y, rend.region.w, rend.region.h); 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderCell (rend.textureNdx, lod, grid); 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeReferenceCell (rend.textureNdx, lod, grid, refImage, rend.region); 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read back rendered results. 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface resImage(viewportWidth, viewportHeight); 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), viewportXOffset, viewportYOffset, resImage.getAccess()); 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUseProgram(0); 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool isOk = compareImages(m_context.getRenderContext(), m_testCtx.getLog(), refImage, resImage); 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : "Image comparison failed"); 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Vertex2DTextureCase::setupShaderInputs (int textureNdx, float lod, const Grid& grid) const 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 programID = m_program->getProgram(); 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // SETUP ATTRIBUTES. 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int positionLoc = glGetAttribLocation(programID, "a_position"); 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (positionLoc != -1) 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnableVertexAttribArray(positionLoc); 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glVertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 0, grid.getPositionPtr()); 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texCoordLoc = glGetAttribLocation(programID, "a_texCoord"); 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (texCoordLoc != -1) 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnableVertexAttribArray(texCoordLoc); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glVertexAttribPointer(texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, grid.getTexCoordPtr()); 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // SETUP UNIFORMS. 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int lodLoc = glGetUniformLocation(programID, "u_lod"); 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (lodLoc != -1) 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUniform1f(lodLoc, lod); 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glActiveTexture(GL_TEXTURE0); 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindTexture(GL_TEXTURE_2D, m_textures[textureNdx]->getGLTexture()); 6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrapS); 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrapT); 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter); 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter); 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texLoc = glGetUniformLocation(programID, "u_texture"); 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (texLoc != -1) 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUniform1i(texLoc, 0); 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Renders one sub-image with given parameters. 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Vertex2DTextureCase::renderCell (int textureNdx, float lod, const Grid& grid) const 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry setupShaderInputs(textureNdx, lod, grid); 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDrawElements(GL_TRIANGLES, grid.getNumIndices(), GL_UNSIGNED_SHORT, grid.getIndexPtr()); 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid Vertex2DTextureCase::computeReferenceCell (int textureNdx, float lod, const Grid& grid, tcu::Surface& dst, const Rect& dstRegion) const 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeReference(m_textures[textureNdx]->getRefTexture(), lod, glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter), grid, dst, dstRegion); 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass VertexCubeTextureCase : public TestCase 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexCubeTextureCase (Context& testCtx, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT); 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~VertexCubeTextureCase (void); 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef PosTexCoordQuadGrid<TEXTURETYPE_CUBE> Grid; 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexCubeTextureCase (const VertexCubeTextureCase& other); 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexCubeTextureCase& operator= (const VertexCubeTextureCase& other); 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float calculateLod (const Vec2& texScale, const Vec2& dstSize, int textureNdx) const; 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setupShaderInputs (int textureNdx, float lod, const Grid& grid) const; 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderCell (int textureNdx, float lod, const Grid& grid) const; 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void computeReferenceCell (int textureNdx, float lod, const Grid& grid, tcu::Surface& dst, const Rect& dstRegion) const; 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_minFilter; 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_magFilter; 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_wrapS; 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_wrapT; 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glu::ShaderProgram* m_program; 7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TextureCube* m_textures[2]; // 2 textures, a gradient texture and a grid texture. 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7183c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexCubeTextureCase::VertexCubeTextureCase (Context& testCtx, const char* name, const char* desc, deUint32 minFilter, deUint32 magFilter, deUint32 wrapS, deUint32 wrapT) 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (testCtx, tcu::NODETYPE_SELF_VALIDATE, name, desc) 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_minFilter (minFilter) 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_magFilter (magFilter) 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapS (wrapS) 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_wrapT (wrapT) 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_program (DE_NULL) 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0] = DE_NULL; 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1] = DE_NULL; 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7303c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexCubeTextureCase::~VertexCubeTextureCase(void) 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexCubeTextureCase::deinit(); 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexCubeTextureCase::init (void) 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const vertexShader = 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec2 a_position;\n" 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "attribute highp vec3 a_texCoord;\n" 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform highp samplerCube u_texture;\n" 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform highp float u_lod;\n" 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main()\n" 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = vec4(a_position, 0.0, 1.0);\n" 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " v_color = textureCubeLod(u_texture, a_texCoord, u_lod);\n" 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* const fragmentShader = 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "varying mediump vec4 v_color;\n" 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "\n" 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main()\n" 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_FragColor = v_color;\n" 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n"; 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_context.getRenderTarget().getNumSamples() != 0) 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("MSAA config not supported by this test"); 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_program); 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(vertexShader, fragmentShader)); 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if(!m_program->isOk()) 7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.getLog() << *m_program; 7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLint maxVertexTextures; 7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxVertexTextures); 7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (maxVertexTextures < 1) 7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("Vertex texture image units not supported", "", __FILE__, __LINE__); 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Failed to compile shader"); 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Make the textures. 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry try 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute suitable power-of-two sizes (for mipmaps). 7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texWidth = 1 << deLog2Ceil32(MAX_CUBE_RENDER_WIDTH / 3 / 2); 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texHeight = 1 << deLog2Ceil32(MAX_CUBE_RENDER_HEIGHT / 2 / 2); 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(texWidth == texHeight); 7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(texHeight); 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(!m_textures[i]); 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i] = new glu::TextureCube(m_context.getRenderContext(), GL_RGB, GL_UNSIGNED_BYTE, texWidth); 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool mipmaps = deIsPowerOfTwo32(texWidth) != DE_FALSE; 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int numLevels = mipmaps ? deLog2Floor32(texWidth)+1 : 1; 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(m_textures[0]->getRefTexture().getFormat()); 7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 cBias = fmtInfo.valueMin; 7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec4 cScale = fmtInfo.valueMax-fmtInfo.valueMin; 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill first with gradient texture. 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const Vec4 gradients[tcu::CUBEFACE_LAST][2] = 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4(-1.0f, -1.0f, -1.0f, 2.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative x 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4( 0.0f, -1.0f, -1.0f, 2.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive x 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4(-1.0f, 0.0f, -1.0f, 2.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // negative y 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4(-1.0f, -1.0f, 0.0f, 2.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f) }, // positive y 8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4(-1.0f, -1.0f, -1.0f, 0.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f) }, // negative z 8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { Vec4( 0.0f, 0.0f, 0.0f, 2.0f), Vec4(1.0f, 1.0f, 1.0f, 0.0f) } // positive z 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[0]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx); 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithComponentGradients(m_textures[0]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), gradients[face][0]*cScale + cBias, gradients[face][1]*cScale + cBias); 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fill second with grid texture. 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int face = 0; face < tcu::CUBEFACE_LAST; face++) 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int levelNdx = 0; levelNdx < numLevels; levelNdx++) 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 step = 0x00ffffff / (numLevels*tcu::CUBEFACE_LAST); 8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 rgb = step*levelNdx*face; 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorA = 0xff000000 | rgb; 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorB = 0xff000000 | ~rgb; 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[1]->getRefTexture().allocLevel((tcu::CubeFace)face, levelNdx); 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithGrid(m_textures[1]->getRefTexture().getLevelFace(levelNdx, (tcu::CubeFace)face), 4, toVec4(tcu::RGBA(colorA))*cScale + cBias, toVec4(tcu::RGBA(colorB))*cScale + cBias); 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Upload. 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i]->upload(); 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry catch (const std::exception&) 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clean up to save memory. 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VertexCubeTextureCase::deinit(); 8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw; 8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexCubeTextureCase::deinit (void) 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < 2; i++) 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_textures[i]; 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_textures[i] = DE_NULL; 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_program; 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_program = DE_NULL; 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryfloat VertexCubeTextureCase::calculateLod (const Vec2& texScale, const Vec2& dstSize, int textureNdx) const 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::TextureCube& refTexture = m_textures[textureNdx]->getRefTexture(); 8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 srcSize = Vec2((float)refTexture.getSize(), (float)refTexture.getSize()); 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 sizeRatio = texScale*srcSize / dstSize; 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note In this particular case, dv/dx and du/dy are zero, simplifying the expression. 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return deFloatLog2(de::max(sizeRatio.x(), sizeRatio.y())); 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8673c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexCubeTextureCase::IterateResult VertexCubeTextureCase::iterate (void) 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportWidth = deMin32(m_context.getRenderTarget().getWidth(), MAX_CUBE_RENDER_WIDTH); 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportHeight = deMin32(m_context.getRenderTarget().getHeight(), MAX_CUBE_RENDER_HEIGHT); 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportXOffsetMax = m_context.getRenderTarget().getWidth() - viewportWidth; 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportYOffsetMax = m_context.getRenderTarget().getHeight() - viewportHeight; 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd (deStringHash(getName())); 8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportXOffset = rnd.getInt(0, viewportXOffsetMax); 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int viewportYOffset = rnd.getInt(0, viewportYOffsetMax); 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUseProgram(m_program->getProgram()); 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Divide viewport into 4 areas. 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int leftWidth = viewportWidth / 2; 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int rightWidth = viewportWidth - leftWidth; 8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bottomHeight = viewportHeight / 2; 8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int topHeight = viewportHeight - bottomHeight; 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear. 8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClearColor(0.125f, 0.25f, 0.5f, 1.0f); 8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClear(GL_COLOR_BUFFER_BIT); 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Texture scaling and offsetting vectors. 8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMinScale (1.0f, 1.0f); 8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMinOffset (0.0f, 0.0f); 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMagScale (0.3f, 0.3f); 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texMagOffset (0.5f, 0.3f); 8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Surface for the reference image. 8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface refImage(viewportWidth, viewportHeight); 9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Each of the four areas is divided into 6 cells. 9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defCellWidth = viewportWidth / 2 / 3; 9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int defCellHeight = viewportHeight / 2 / 2; 9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < tcu::CUBEFACE_LAST; i++) 9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int cellOffsetX = defCellWidth * (i % 3); 9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int cellOffsetY = defCellHeight * (i / 3); 9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool isRightmostCell = i == 2 || i == 5; 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool isTopCell = i >= 3; 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int leftCellWidth = isRightmostCell ? leftWidth - cellOffsetX : defCellWidth; 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int rightCellWidth = isRightmostCell ? rightWidth - cellOffsetX : defCellWidth; 9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int bottomCellHeight = isTopCell ? bottomHeight - cellOffsetY : defCellHeight; 9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int topCellHeight = isTopCell ? topHeight - cellOffsetY : defCellHeight; 9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const struct Render 9173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Rect region; 9193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int textureNdx; 9203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texCoordScale; 9213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Vec2 texCoordOffset; 9223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render (const Rect& r, int tN, const Vec2& tS, const Vec2& tO) : region(r), textureNdx(tN), texCoordScale(tS), texCoordOffset(tO) {} 9233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } renders[] = 9243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(cellOffsetX + 0, cellOffsetY + 0, leftCellWidth, bottomCellHeight), 0, texMinScale, texMinOffset), 9263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(cellOffsetX + leftWidth, cellOffsetY + 0, rightCellWidth, bottomCellHeight), 0, texMagScale, texMagOffset), 9273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(cellOffsetX + 0, cellOffsetY + bottomHeight, leftCellWidth, topCellHeight), 1, texMinScale, texMinOffset), 9283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Render(Rect(cellOffsetX + leftWidth, cellOffsetY + bottomHeight, rightCellWidth, topCellHeight), 1, texMagScale, texMagOffset) 9293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 9303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int renderNdx = 0; renderNdx < DE_LENGTH_OF_ARRAY(renders); renderNdx++) 9323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Render& rend = renders[renderNdx]; 9343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float lod = calculateLod(rend.texCoordScale, rend.region.size().asFloat(), rend.textureNdx); 9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool useSafeTexCoords = isLevelNearest(lod > 0.0f ? m_minFilter : m_magFilter); 9363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Grid grid (GRID_SIZE_CUBE, rend.region.size(), getTextureSize(*m_textures[rend.textureNdx]), 9373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TexTypeCoordParams<TEXTURETYPE_CUBE>(rend.texCoordScale, rend.texCoordOffset, (tcu::CubeFace)i), useSafeTexCoords); 9383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glViewport(viewportXOffset + rend.region.x, viewportYOffset + rend.region.y, rend.region.w, rend.region.h); 9403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderCell (rend.textureNdx, lod, grid); 9413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeReferenceCell (rend.textureNdx, lod, grid, refImage, rend.region); 9423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read back rendered results. 9463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface resImage(viewportWidth, viewportHeight); 9473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), viewportXOffset, viewportYOffset, resImage.getAccess()); 9483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUseProgram(0); 9503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare and log. 9523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const bool isOk = compareImages(m_context.getRenderContext(), m_testCtx.getLog(), refImage, resImage); 9543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 9563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : "Image comparison failed"); 9573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 9603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexCubeTextureCase::setupShaderInputs (int textureNdx, float lod, const Grid& grid) const 9633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 9643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 programID = m_program->getProgram(); 9653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // SETUP ATTRIBUTES. 9673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int positionLoc = glGetAttribLocation(programID, "a_position"); 9703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (positionLoc != -1) 9713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnableVertexAttribArray(positionLoc); 9733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glVertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 0, grid.getPositionPtr()); 9743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texCoordLoc = glGetAttribLocation(programID, "a_texCoord"); 9793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (texCoordLoc != -1) 9803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnableVertexAttribArray(texCoordLoc); 9823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glVertexAttribPointer(texCoordLoc, 3, GL_FLOAT, GL_FALSE, 0, grid.getTexCoordPtr()); 9833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // SETUP UNIFORMS. 9873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int lodLoc = glGetUniformLocation(programID, "u_lod"); 9903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (lodLoc != -1) 9913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUniform1f(lodLoc, lod); 9923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glActiveTexture(GL_TEXTURE0); 9953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindTexture(GL_TEXTURE_CUBE_MAP, m_textures[textureNdx]->getGLTexture()); 9963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, m_wrapS); 9973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, m_wrapT); 9983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, m_minFilter); 9993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, m_magFilter); 10003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texLoc = glGetUniformLocation(programID, "u_texture"); 10033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (texLoc != -1) 10043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glUniform1i(texLoc, 0); 10053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Renders one cube face with given parameters. 10093c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexCubeTextureCase::renderCell (int textureNdx, float lod, const Grid& grid) const 10103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry setupShaderInputs(textureNdx, lod, grid); 10123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDrawElements(GL_TRIANGLES, grid.getNumIndices(), GL_UNSIGNED_SHORT, grid.getIndexPtr()); 10133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Computes reference for one cube face with given parameters. 10163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexCubeTextureCase::computeReferenceCell (int textureNdx, float lod, const Grid& grid, tcu::Surface& dst, const Rect& dstRegion) const 10173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Sampler sampler = glu::mapGLSampler(m_wrapS, m_wrapT, m_minFilter, m_magFilter); 10193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry computeReference(m_textures[textureNdx]->getRefTexture(), lod, sampler, grid, dst, dstRegion); 10203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10223c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexTextureTests::VertexTextureTests (Context& context) 10233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "vertex", "Vertex Texture Tests") 10243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10273c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVertexTextureTests::~VertexTextureTests(void) 10283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 10303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid VertexTextureTests::init (void) 10323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 10333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // 2D and cube map groups, and their filtering and wrap sub-groups. 10343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const group2D = new TestCaseGroup(m_context, "2d", "2D Vertex Texture Tests"); 10353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const groupCube = new TestCaseGroup(m_context, "cube", "Cube Map Vertex Texture Tests"); 10363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const filteringGroup2D = new TestCaseGroup(m_context, "filtering", "2D Vertex Texture Filtering Tests"); 10373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const wrapGroup2D = new TestCaseGroup(m_context, "wrap", "2D Vertex Texture Wrap Tests"); 10383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const filteringGroupCube = new TestCaseGroup(m_context, "filtering", "Cube Map Vertex Texture Filtering Tests"); 10393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup* const wrapGroupCube = new TestCaseGroup(m_context, "wrap", "Cube Map Vertex Texture Wrap Tests"); 10403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry group2D->addChild(filteringGroup2D); 10423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry group2D->addChild(wrapGroup2D); 10433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupCube->addChild(filteringGroupCube); 10443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupCube->addChild(wrapGroupCube); 10453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(group2D); 10473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(groupCube); 10483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 10503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 10523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum mode; 10533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } wrapModes[] = 10543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "clamp", GL_CLAMP_TO_EDGE }, 10563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "repeat", GL_REPEAT }, 10573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "mirror", GL_MIRRORED_REPEAT } 10583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 10593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 10613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 10633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum mode; 10643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } minFilterModes[] = 10653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest", GL_NEAREST }, 10673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear", GL_LINEAR }, 10683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest_mipmap_nearest", GL_NEAREST_MIPMAP_NEAREST }, 10693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear_mipmap_nearest", GL_LINEAR_MIPMAP_NEAREST }, 10703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest_mipmap_linear", GL_NEAREST_MIPMAP_LINEAR }, 10713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear_mipmap_linear", GL_LINEAR_MIPMAP_LINEAR } 10723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 10733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const struct 10753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* name; 10773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum mode; 10783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } magFilterModes[] = 10793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "nearest", GL_NEAREST }, 10813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { "linear", GL_LINEAR } 10823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 10833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define FOR_EACH(ITERATOR, ARRAY, BODY) \ 10853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ITERATOR = 0; ITERATOR < DE_LENGTH_OF_ARRAY(ARRAY); ITERATOR++) \ 10863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BODY 10873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // 2D cases. 10893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(minFilter, minFilterModes, 10913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(magFilter, magFilterModes, 10923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapMode, wrapModes, 10933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 10943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name; 10953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 10963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry filteringGroup2D->addChild(new Vertex2DTextureCase(m_context, 10973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 10983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minFilterModes[minFilter].mode, 10993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry magFilterModes[magFilter].mode, 11003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 11013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode)); 11023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }))); 11033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapSMode, wrapModes, 11053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapTMode, wrapModes, 11063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string name = string("") + wrapModes[wrapSMode].name + "_" + wrapModes[wrapTMode].name; 11083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapGroup2D->addChild(new Vertex2DTextureCase(m_context, 11103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 11113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_LINEAR_MIPMAP_LINEAR, 11123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_LINEAR, 11133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapSMode].mode, 11143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapTMode].mode)); 11153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry })); 11163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Cube map cases. 11183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(minFilter, minFilterModes, 11203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(magFilter, magFilterModes, 11213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapMode, wrapModes, 11223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string name = string("") + minFilterModes[minFilter].name + "_" + magFilterModes[magFilter].name + "_" + wrapModes[wrapMode].name; 11243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry filteringGroupCube->addChild(new VertexCubeTextureCase(m_context, 11263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 11273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minFilterModes[minFilter].mode, 11283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry magFilterModes[magFilter].mode, 11293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode, 11303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapMode].mode)); 11313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }))); 11323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapSMode, wrapModes, 11343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FOR_EACH(wrapTMode, wrapModes, 11353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 11363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const string name = string("") + wrapModes[wrapSMode].name + "_" + wrapModes[wrapTMode].name; 11373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapGroupCube->addChild(new VertexCubeTextureCase(m_context, 11393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry name.c_str(), "", 11403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_LINEAR_MIPMAP_LINEAR, 11413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_LINEAR, 11423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapSMode].mode, 11433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry wrapModes[wrapTMode].mode)); 11443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry })); 11453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 11463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 11473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 11483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles2 11493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 1150