13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture utilities. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVectorUtil.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMemory.h" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <limits> 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float sRGBChannelToLinear (float cs) 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cs <= 0.04045) 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return cs / 12.92f; 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return deFloatPow((cs + 0.055f) / 1.055f, 2.4f); 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float linearChannelToSRGB (float cl) 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (cl <= 0.0f) 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 0.0f; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (cl < 0.0031308f) 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 12.92f*cl; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (cl < 1.0f) 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 1.055f*deFloatPow(cl, 0.41666f) - 0.055f; 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return 1.0f; 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Convert sRGB to linear colorspace 563c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVec4 sRGBToLinear (const Vec4& cs) 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return Vec4(sRGBChannelToLinear(cs[0]), 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sRGBChannelToLinear(cs[1]), 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sRGBChannelToLinear(cs[2]), 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry cs[3]); 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Convert from linear to sRGB colorspace 653c827367444ee418f129b2c238299f49d3264554Jarkko PoyryVec4 linearToSRGB (const Vec4& cl) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return Vec4(linearChannelToSRGB(cl[0]), 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry linearChannelToSRGB(cl[1]), 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry linearChannelToSRGB(cl[2]), 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry cl[3]); 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Get texture channel class for format 743c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (channelType) 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT8: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT16: return TEXTURECHANNELCLASS_SIGNED_FIXED_POINT; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT8: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT16: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_565: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_555: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_4444: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_5551: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_101010: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_1010102_REV: return TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT; 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_1010102_REV: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return TEXTURECHANNELCLASS_FLOATING_POINT; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_999_E5_REV: return TEXTURECHANNELCLASS_FLOATING_POINT; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT8: return TEXTURECHANNELCLASS_SIGNED_INTEGER; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT16: return TEXTURECHANNELCLASS_SIGNED_INTEGER; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT32: return TEXTURECHANNELCLASS_SIGNED_INTEGER; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT8: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT16: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT32: return TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::HALF_FLOAT: return TEXTURECHANNELCLASS_FLOATING_POINT; 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::FLOAT: return TEXTURECHANNELCLASS_FLOATING_POINT; 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: return TEXTURECHANNELCLASS_LAST; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Get access to subregion of pixel buffer 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Parent access object 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param x X offset 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param y Y offset 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param z Z offset 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param width Width 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param height Height 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param depth Depth 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Access object that targets given subregion of parent access object 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1143c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(x, 0, access.getWidth()) && de::inRange(x+width, x, access.getWidth())); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(y, 0, access.getHeight()) && de::inRange(y+height, y, access.getHeight())); 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(z, 0, access.getDepth()) && de::inRange(z+depth, z, access.getDepth())); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ConstPixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(), 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (const deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Get access to subregion of pixel buffer 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Parent access object 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param x X offset 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param y Y offset 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param z Z offset 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param width Width 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param height Height 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param depth Depth 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Access object that targets given subregion of parent access object 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1343c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth) 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(x, 0, access.getWidth()) && de::inRange(x+width, x, access.getWidth())); 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(y, 0, access.getHeight()) && de::inRange(y+height, y, access.getHeight())); 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(de::inBounds(z, 0, access.getDepth()) && de::inRange(z+depth, z, access.getDepth())); 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return PixelBufferAccess(access.getFormat(), width, height, depth, access.getRowPitch(), access.getSlicePitch(), 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (deUint8*)access.getDataPtr() + access.getFormat().getPixelSize()*x + access.getRowPitch()*y + access.getSlicePitch()*z); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Get access to subregion of pixel buffer 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Parent access object 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param x X offset 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param y Y offset 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param width Width 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param height Height 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Access object that targets given subregion of parent access object 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1523c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height) 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return getSubregion(access, x, y, 0, width, height, 1); 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Get access to subregion of pixel buffer 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Parent access object 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param x X offset 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param y Y offset 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param width Width 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param height Height 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Access object that targets given subregion of parent access object 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1663c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height) 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return getSubregion(access, x, y, 0, width, height, 1); 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Flip rows in Y direction 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Access object 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Modified access object where Y coordinates are reversed 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1763c827367444ee418f129b2c238299f49d3264554Jarkko PoyryPixelBufferAccess flipYAccess (const PixelBufferAccess& access) 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int rowPitch = access.getRowPitch(); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int offsetToLast = rowPitch*(access.getHeight()-1); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return PixelBufferAccess(access.getFormat(), access.getWidth(), access.getHeight(), access.getDepth(), 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -rowPitch, access.getSlicePitch(), (deUint8*)access.getDataPtr() + offsetToLast); 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Flip rows in Y direction 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \param access Access object 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \return Modified access object where Y coordinates are reversed 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int rowPitch = access.getRowPitch(); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int offsetToLast = rowPitch*(access.getHeight()-1); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ConstPixelBufferAccess(access.getFormat(), access.getWidth(), access.getHeight(), access.getDepth(), 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -rowPitch, access.getSlicePitch(), (const deUint8*)access.getDataPtr() + offsetToLast); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic Vec2 getChannelValueRange (TextureFormat::ChannelType channelType) 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float cMin = 0.0f; 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float cMax = 0.0f; 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (channelType) 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Signed normalized formats. 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT8: 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT16: cMin = -1.0f; cMax = 1.0f; break; 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Unsigned normalized formats. 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT8: 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT16: 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_565: 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_4444: 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_101010: 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_1010102_REV: cMin = 0.0f; cMax = 1.0f; break; 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Misc formats. 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT8: cMin = -128.0f; cMax = 127.0f; break; 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT16: cMin = -32768.0f; cMax = 32767.0f; break; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT32: cMin = -2147483648.0f; cMax = 2147483647.0f; break; 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT8: cMin = 0.0f; cMax = 255.0f; break; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT16: cMin = 0.0f; cMax = 65535.0f; break; 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT32: cMin = 0.0f; cMax = 4294967295.f; break; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::HALF_FLOAT: cMin = -1e3f; cMax = 1e3f; break; 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::FLOAT: cMin = -1e5f; cMax = 1e5f; break; 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: cMin = 0.0f; cMax = 1e4f; break; 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_999_E5_REV: cMin = 0.0f; cMax = 1e5f; break; 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return Vec2(cMin, cMax); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Get standard parameters for testing texture format 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Returns TextureFormatInfo that describes good parameters for exercising 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * given TextureFormat. Parameters include value ranges per channel and 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * suitable lookup scaling and bias in order to reduce result back to 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 0..1 range. 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 2453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTextureFormatInfo getTextureFormatInfo (const TextureFormat& format) 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Special cases. 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::UNSIGNED_INT_1010102_REV)) 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TextureFormatInfo(Vec4( 0.0f, 0.0f, 0.0f, 0.0f), 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4( 1023.0f, 1023.0f, 1023.0f, 3.0f), 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(1.0f/1023.f, 1.0f/1023.0f, 1.0f/1023.0f, 1.0f/3.0f), 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4( 0.0f, 0.0f, 0.0f, 0.0f)); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (format.order == TextureFormat::D || format.order == TextureFormat::DS) 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TextureFormatInfo(Vec4(0.0f, 0.0f, 0.0f, 0.0f), 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(1.0f, 1.0f, 1.0f, 0.0f), 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(1.0f, 1.0f, 1.0f, 1.0f), 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(0.0f, 0.0f, 0.0f, 0.0f)); // Depth / stencil formats. 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (format == TextureFormat(TextureFormat::RGBA, TextureFormat::UNORM_SHORT_5551)) 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TextureFormatInfo(Vec4(0.0f, 0.0f, 0.0f, 0.5f), 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(1.0f, 1.0f, 1.0f, 1.5f), 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(1.0f, 1.0f, 1.0f, 1.0f), 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4(0.0f, 0.0f, 0.0f, 0.0f)); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 cRange = getChannelValueRange(format.type); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BVec4 chnMask = BVec4(false); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (format.order) 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::D: chnMask = BVec4(true, true, true, false); break; 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::DS: chnMask = BVec4(true, true, true, true); break; 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float scale = 1.0f / (cRange[1] - cRange[0]); 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float bias = -cRange[0] * scale; 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return TextureFormatInfo(select(cRange[0], 0.0f, chnMask), 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry select(cRange[1], 0.0f, chnMask), 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry select(scale, 1.0f, chnMask), 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry select(bias, 0.0f, chnMask)); 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic IVec4 getChannelBitDepth (TextureFormat::ChannelType channelType) 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (channelType) 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT8: return IVec4(8); 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT16: return IVec4(16); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT32: return IVec4(32); 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT8: return IVec4(8); 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT16: return IVec4(16); 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT32: return IVec4(32); 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_565: return IVec4(5,6,5,0); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_4444: return IVec4(4); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_555: return IVec4(5,5,5,0); 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_SHORT_5551: return IVec4(5,5,5,1); 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_101010: return IVec4(10,10,10,0); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT_1010102_REV: return IVec4(10,10,10,2); 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT8: return IVec4(8); 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT16: return IVec4(16); 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SIGNED_INT32: return IVec4(32); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT8: return IVec4(8); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT16: return IVec4(16); 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT32: return IVec4(32); 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_1010102_REV: return IVec4(10,10,10,2); 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_24_8: return IVec4(24,0,0,8); 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::HALF_FLOAT: return IVec4(16); 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::FLOAT: return IVec4(32); 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return IVec4(11,11,10,0); 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNSIGNED_INT_999_E5_REV: return IVec4(9,9,9,0); 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: return IVec4(32,0,0,8); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return IVec4(0); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3283c827367444ee418f129b2c238299f49d3264554Jarkko PoyryIVec4 getTextureFormatBitDepth (const TextureFormat& format) 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVec4 chnBits = getChannelBitDepth(format.type); 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BVec4 chnMask = BVec4(false); 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVec4 chnSwz (0,1,2,3); 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (format.order) 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RA: chnMask = BVec4(true, false, false, true); break; 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; 340ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::I: chnMask = BVec4(true, true, true, true); break; 341ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; 342ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; 343ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; 344ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; 345ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::BGRA: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(2, 1, 0, 3); break; 346ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::ARGB: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(1, 2, 3, 0); break; 347ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; 348ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; 349ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::D: chnMask = BVec4(true, false, false, false); break; 350ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::DS: chnMask = BVec4(true, false, false, true); break; 351ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::S: chnMask = BVec4(false, false, false, true); break; 352ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry default: 353ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry DE_ASSERT(false); 354ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry } 355ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 356ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); 357ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry} 358ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 359ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyrystatic IVec4 getChannelMantissaBitDepth (TextureFormat::ChannelType channelType) 360ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry{ 361ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry switch (channelType) 362ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry { 363ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SNORM_INT8: 364ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SNORM_INT16: 365ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SNORM_INT32: 366ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_INT8: 367ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_INT16: 368ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_INT32: 369ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_SHORT_565: 370ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_SHORT_4444: 371ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_SHORT_555: 372ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_SHORT_5551: 373ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_INT_101010: 374ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNORM_INT_1010102_REV: 375ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SIGNED_INT8: 376ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SIGNED_INT16: 377ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::SIGNED_INT32: 378ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT8: 379ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT16: 380ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT32: 381ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT_1010102_REV: 382ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT_24_8: 383ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT_999_E5_REV: 384ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry return getChannelBitDepth(channelType); 385ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 386ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::HALF_FLOAT: return IVec4(10); 387ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::FLOAT: return IVec4(23); 388ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::UNSIGNED_INT_11F_11F_10F_REV: return IVec4(6,6,5,0); 389ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV: return IVec4(23,0,0,8); 390ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry default: 391ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry DE_ASSERT(false); 392ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry return IVec4(0); 393ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry } 394ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry} 395ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 396ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryIVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format) 397ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry{ 398ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry IVec4 chnBits = getChannelMantissaBitDepth(format.type); 399ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry BVec4 chnMask = BVec4(false); 400ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry IVec4 chnSwz (0,1,2,3); 401ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry 402ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry switch (format.order) 403ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry { 404ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::R: chnMask = BVec4(true, false, false, false); break; 405ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::A: chnMask = BVec4(false, false, false, true); break; 406ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::RA: chnMask = BVec4(true, false, false, true); break; 407ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko Pöyry case TextureFormat::L: chnMask = BVec4(true, true, true, false); break; 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::I: chnMask = BVec4(true, true, true, true); break; 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::LA: chnMask = BVec4(true, true, true, true); break; 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RG: chnMask = BVec4(true, true, false, false); break; 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RGB: chnMask = BVec4(true, true, true, false); break; 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::RGBA: chnMask = BVec4(true, true, true, true); break; 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::BGRA: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(2, 1, 0, 3); break; 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::ARGB: chnMask = BVec4(true, true, true, true); chnSwz = IVec4(1, 2, 3, 0); break; 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::sRGB: chnMask = BVec4(true, true, true, false); break; 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::sRGBA: chnMask = BVec4(true, true, true, true); break; 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::D: chnMask = BVec4(true, false, false, false); break; 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::DS: chnMask = BVec4(true, false, false, true); break; 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::S: chnMask = BVec4(false, false, false, true); break; 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(false); 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return select(chnBits.swizzle(chnSwz.x(), chnSwz.y(), chnSwz.z(), chnSwz.w()), IVec4(0), chnMask); 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline float linearInterpolate (float t, float minVal, float maxVal) 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return minVal + (maxVal - minVal) * t; 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline Vec4 linearInterpolate (float t, const Vec4& a, const Vec4& b) 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return a + (b - a) * t; 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CLEAR_OPTIMIZE_THRESHOLD = 128, 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CLEAR_OPTIMIZE_MAX_PIXEL_SIZE = 8 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline void fillRow (const PixelBufferAccess& dst, int y, int z, int pixelSize, const deUint8* pixel) 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8* dstPtr = (deUint8*)dst.getDataPtr() + z*dst.getSlicePitch() + y*dst.getRowPitch(); 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = dst.getWidth(); 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (pixelSize == 8 && deIsAlignedPtr(dstPtr, pixelSize) && deIsAlignedPtr(dstPtr, pixelSize)) 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 val; 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry memcpy(&val, pixel, sizeof(val)); 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < width; i++) 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ((deUint64*)dstPtr)[i] = val; 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (pixelSize == 4 && deIsAlignedPtr(dstPtr, pixelSize) && deIsAlignedPtr(dstPtr, pixelSize)) 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 val; 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry memcpy(&val, pixel, sizeof(val)); 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < width; i++) 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ((deUint32*)dstPtr)[i] = val; 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < width; i++) 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int j = 0; j < pixelSize; j++) 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dstPtr[i*pixelSize+j] = pixel[j]; 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const PixelBufferAccess& access, const Vec4& color) 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = access.getFormat().getPixelSize(); 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE) 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Convert to destination format. 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 u64; // Forces 64-bit alignment. 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } pixel; 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixel(color, 0, 0); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillRow(access, y, z, pixelSize, &pixel.u8[0]); 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, x, y, z); 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const PixelBufferAccess& access, const IVec4& color) 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = access.getFormat().getPixelSize(); 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE) 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Convert to destination format. 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 u64; // Forces 64-bit alignment. 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } pixel; 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixel(color, 0, 0); 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillRow(access, y, z, pixelSize, &pixel.u8[0]); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(color, x, y, z); 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearDepth (const PixelBufferAccess& access, float depth) 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = access.getFormat().getPixelSize(); 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE) 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Convert to destination format. 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 u64; // Forces 64-bit alignment. 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } pixel; 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixDepth(depth, 0, 0); 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillRow(access, y, z, pixelSize, &pixel.u8[0]); 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixDepth(depth, x, y, z); 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearStencil (const PixelBufferAccess& access, int stencil) 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = access.getFormat().getPixelSize(); 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getWidth()*access.getHeight()*access.getDepth() >= CLEAR_OPTIMIZE_THRESHOLD && 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelSize < CLEAR_OPTIMIZE_MAX_PIXEL_SIZE) 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Convert to destination format. 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint8 u8[CLEAR_OPTIMIZE_MAX_PIXEL_SIZE]; 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint64 u64; // Forces 64-bit alignment. 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } pixel; 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_STATIC_ASSERT(sizeof(pixel) == CLEAR_OPTIMIZE_MAX_PIXEL_SIZE); 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry PixelBufferAccess(access.getFormat(), 1, 1, 1, 0, 0, &pixel.u8[0]).setPixStencil(stencil, 0, 0); 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillRow(access, y, z, pixelSize, &pixel.u8[0]); 5743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 5783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 5793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 5803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixStencil(stencil, x, y, z); 5813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5843c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void fillWithComponentGradients1D (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) 5853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(access.getHeight() == 1); 5873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 5883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float s = ((float)x + 0.5f) / (float)access.getWidth(); 5903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float r = linearInterpolate(s, minVal.x(), maxVal.x()); 5923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float g = linearInterpolate(s, minVal.y(), maxVal.y()); 5933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float b = linearInterpolate(s, minVal.z(), maxVal.z()); 5943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float a = linearInterpolate(s, minVal.w(), maxVal.w()); 5953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(tcu::Vec4(r, g, b, a), x, 0); 5973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void fillWithComponentGradients2D (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) 6013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 6033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 6053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float s = ((float)x + 0.5f) / (float)access.getWidth(); 6073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float t = ((float)y + 0.5f) / (float)access.getHeight(); 6083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float r = linearInterpolate(( s + t) *0.5f, minVal.x(), maxVal.x()); 6103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float g = linearInterpolate(( s + (1.0f-t))*0.5f, minVal.y(), maxVal.y()); 6113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float b = linearInterpolate(((1.0f-s) + t) *0.5f, minVal.z(), maxVal.z()); 6123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float a = linearInterpolate(((1.0f-s) + (1.0f-t))*0.5f, minVal.w(), maxVal.w()); 6133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(tcu::Vec4(r, g, b, a), x, y); 6153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic void fillWithComponentGradients3D (const PixelBufferAccess& dst, const Vec4& minVal, const Vec4& maxVal) 6203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < dst.getDepth(); z++) 6223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 6243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 6263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float s = ((float)x + 0.5f) / (float)dst.getWidth(); 6283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float t = ((float)y + 0.5f) / (float)dst.getHeight(); 6293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float p = ((float)z + 0.5f) / (float)dst.getDepth(); 6303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float r = linearInterpolate(s, minVal.x(), maxVal.x()); 6323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float g = linearInterpolate(t, minVal.y(), maxVal.y()); 6333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float b = linearInterpolate(p, minVal.z(), maxVal.z()); 6343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float a = linearInterpolate(1.0f - (s+t+p)/3.0f, minVal.w(), maxVal.w()); 6353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(tcu::Vec4(r, g, b, a), x, y, z); 6373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal) 6433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getHeight() == 1 && access.getDepth() == 1) 6453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithComponentGradients1D(access, minVal, maxVal); 6463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (access.getDepth() == 1) 6473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithComponentGradients2D(access, minVal, maxVal); 6483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithComponentGradients3D(access, minVal, maxVal); 6503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithGrid1D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) 6533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 6553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mx = (x / cellSize) % 2; 6573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (mx) 6593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorB, x, 0); 6603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorA, x, 0); 6623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6653c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithGrid2D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) 6663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 6683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 6703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mx = (x / cellSize) % 2; 6723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int my = (y / cellSize) % 2; 6733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (mx ^ my) 6753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorB, x, y); 6763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorA, x, y); 6783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 6813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithGrid3D (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) 6833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 6843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z++) 6853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 6873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 6893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 6903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mx = (x / cellSize) % 2; 6913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int my = (y / cellSize) % 2; 6923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mz = (z / cellSize) % 2; 6933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (mx ^ my ^ mz) 6953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorB, x, y, z); 6963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 6973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(colorA, x, y, z); 6983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 6993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7033c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB) 7043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (access.getHeight() == 1 && access.getDepth() == 1) 7063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithGrid1D(access, cellSize, colorA, colorB); 7073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (access.getDepth() == 1) 7083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithGrid2D(access, cellSize, colorA, colorB); 7093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 7103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry fillWithGrid3D(access, cellSize, colorA, colorB); 7113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB) 7143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y++) 7163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x++) 7183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float s = ((float)x + 0.5f) / (float)access.getWidth(); 7203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float t = ((float)y + 0.5f) / (float)access.getHeight(); 7213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float a = s > 0.5f ? (2.0f - 2.0f*s) : 2.0f*s; 7233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float b = t > 0.5f ? (2.0f - 2.0f*t) : 2.0f*t; 7243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float p = deFloatClamp(deFloatSqrt(a*a + b*b), 0.0f, 1.0f); 7263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry access.setPixel(linearInterpolate(p, colorA, colorB), x, y); 7273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7313c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithRGBAQuads (const PixelBufferAccess& dst) 7323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(dst.getDepth() == 1); 7343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = dst.getWidth(); 7353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = dst.getHeight(); 7363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int left = width/2; 7373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int top = height/2; 7383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear(getSubregion(dst, 0, 0, 0, left, top, 1), Vec4(1.0f, 0.0f, 0.0f, 1.0f)); 7403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear(getSubregion(dst, left, 0, 0, width-left, top, 1), Vec4(0.0f, 1.0f, 0.0f, 1.0f)); 7413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear(getSubregion(dst, 0, top, 0, left, height-top, 1), Vec4(0.0f, 0.0f, 1.0f, 0.0f)); 7423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear(getSubregion(dst, left, top, 0, width-left, height-top, 1), Vec4(0.5f, 0.5f, 0.5f, 1.0f)); 7433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2012-11-13 pyry] There is much better metaballs code in CL SIR value generators. 7463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithMetaballs (const PixelBufferAccess& dst, int numBalls, deUint32 seed) 7473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_CHECK_INTERNAL(dst.getDepth() == 1); 7493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Vec2> points(numBalls); 7503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd(seed); 7513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int i = 0; i < numBalls; i++) 7533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float x = rnd.getFloat(); 7553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float y = rnd.getFloat(); 7563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry points[i] = (Vec2(x, y)); 7573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 7603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 7613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 p((float)x/(float)dst.getWidth(), (float)y/(float)dst.getHeight()); 7633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sum = 0.0f; 7653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<Vec2>::const_iterator i = points.begin(); i != points.end(); i++) 7663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec2 d = p - *i; 7683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float f = 0.01f / (d.x()*d.x() + d.y()*d.y()); 7693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sum += f; 7713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(Vec4(sum), x, y); 7743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 7763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7773c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src) 7783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 7793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = dst.getWidth(); 7803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = dst.getHeight(); 7813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int depth = dst.getDepth(); 7823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(src.getWidth() == width && src.getHeight() == height && src.getDepth() == depth); 7843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (src.getFormat() == dst.getFormat()) 7863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fast-path for matching formats. 7883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int pixelSize = src.getFormat().getPixelSize(); 7893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 7903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < depth; z++) 7913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < height; y++) 7923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deMemcpy((deUint8*)dst.getDataPtr() + z*dst.getSlicePitch() + y*dst.getRowPitch(), 7933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (const deUint8*)src.getDataPtr() + z*src.getSlicePitch() + y*src.getRowPitch(), 7943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pixelSize*width); 7953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 7963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 7973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 7983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureChannelClass srcClass = getTextureChannelClass(src.getFormat().type); 7993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureChannelClass dstClass = getTextureChannelClass(dst.getFormat().type); 8003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool srcIsInt = srcClass == TEXTURECHANNELCLASS_SIGNED_INTEGER || srcClass == TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 8013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool dstIsInt = dstClass == TEXTURECHANNELCLASS_SIGNED_INTEGER || dstClass == TEXTURECHANNELCLASS_UNSIGNED_INTEGER; 8023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (srcIsInt && dstIsInt) 8043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < depth; z++) 8063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < height; y++) 8073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < width; x++) 8083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(src.getPixelInt(x, y, z), x, y, z); 8093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < depth; z++) 8133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < height; y++) 8143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < width; x++) 8153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(src.getPixel(x, y, z), x, y, z); 8163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter) 8213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(filter == Sampler::NEAREST || filter == Sampler::LINEAR); 8233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Sampler sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, 8253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry filter, filter, 0.0f, false); 8263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sX = (float)src.getWidth() / (float)dst.getWidth(); 8283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sY = (float)src.getHeight() / (float)dst.getHeight(); 8293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float sZ = (float)src.getDepth() / (float)dst.getDepth(); 8303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (dst.getDepth() == 1 && src.getDepth() == 1) 8323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 8343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 8353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(src.sample2D(sampler, filter, (x+0.5f)*sX, (y+0.5f)*sY, 0), x, y); 8363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 8383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < dst.getDepth(); z++) 8403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 8413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 8423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(src.sample3D(sampler, filter, (x+0.5f)*sX, (y+0.5f)*sY, (z+0.5f)*sZ), x, y, z); 8433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal) 8473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const TextureFormat& format = access.getFormat(); 8493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (format.type) 8513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT8: 8533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::UNORM_INT16: 8543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Normalized unsigned formats. 8553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal = Vec4(0.0f); 8563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal = Vec4(1.0f); 8573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 8583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT8: 8603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case TextureFormat::SNORM_INT16: 8613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Normalized signed formats. 8623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal = Vec4(-1.0f); 8633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal = Vec4(+1.0f); 8643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 8653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 8673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note Samples every 4/8th pixel. 8683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal = Vec4(std::numeric_limits<float>::max()); 8693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal = Vec4(std::numeric_limits<float>::min()); 8703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int z = 0; z < access.getDepth(); z += 2) 8723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < access.getHeight(); y += 2) 8743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < access.getWidth(); x += 2) 8763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 8773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 p = access.getPixel(x, y, z); 8783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal[0] = de::min(minVal[0], p[0]); 8803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal[1] = de::min(minVal[1], p[1]); 8813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal[2] = de::min(minVal[2], p[2]); 8823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry minVal[3] = de::min(minVal[3], p[3]); 8833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal[0] = de::max(maxVal[0], p[0]); 8853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal[1] = de::max(maxVal[1], p[1]); 8863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal[2] = de::max(maxVal[2], p[2]); 8873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry maxVal[3] = de::max(maxVal[3], p[3]); 8883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 8923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 8933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 8943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 8953c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias) 8963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 8973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 minVal, maxVal; 8983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry estimatePixelValueRange(access, minVal, maxVal); 8993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float eps = 0.0001f; 9013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int c = 0; c < 4; c++) 9033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (maxVal[c] - minVal[c] < eps) 9053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry scale[c] = (maxVal[c] < eps) ? 1.0f : (1.0f / maxVal[c]); 9073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bias[c] = (c == 3) ? (1.0f - maxVal[c]*scale[c]) : (0.0f - minVal[c]*scale[c]); 9083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 9103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 9113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry scale[c] = 1.0f / (maxVal[c] - minVal[c]); 9123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bias[c] = 0.0f - minVal[c]*scale[c]; 9133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 9153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 9163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 9178852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryint getCubeArrayFaceIndex (CubeFace face) 9188852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry{ 9198852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry DE_ASSERT((int)face >= 0 && face < CUBEFACE_LAST); 9208852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry 9218852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry switch (face) 9228852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry { 9238852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_POSITIVE_X: return 0; 9248852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_NEGATIVE_X: return 1; 9258852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_POSITIVE_Y: return 2; 9268852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_NEGATIVE_Y: return 3; 9278852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_POSITIVE_Z: return 4; 9288852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry case CUBEFACE_NEGATIVE_Z: return 5; 9298852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry 9308852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry default: 9318852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry return -1; 9328852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry } 9338852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry} 9348852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry 9353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 936