1#ifndef _TCUTEXTUREUTIL_HPP 2#define _TCUTEXTUREUTIL_HPP 3/*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Texture utilities. 24 *//*--------------------------------------------------------------------*/ 25 26#include "tcuDefs.hpp" 27#include "tcuTexture.hpp" 28 29namespace tcu 30{ 31 32// PixelBufferAccess utilities. 33PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 34ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 35 36PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height); 37ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height); 38 39PixelBufferAccess flipYAccess (const PixelBufferAccess& access); 40ConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access); 41 42bool isCombinedDepthStencilType (TextureFormat::ChannelType type); 43 44// sRGB - linear conversion. 45Vec4 sRGBToLinear (const Vec4& cs); 46Vec4 linearToSRGB (const Vec4& cl); 47bool isSRGB (TextureFormat format); 48 49/*--------------------------------------------------------------------*//*! 50 * \brief Color channel storage type 51 *//*--------------------------------------------------------------------*/ 52enum TextureChannelClass 53{ 54 TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0, 55 TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT, 56 TEXTURECHANNELCLASS_SIGNED_INTEGER, 57 TEXTURECHANNELCLASS_UNSIGNED_INTEGER, 58 TEXTURECHANNELCLASS_FLOATING_POINT, 59 60 TEXTURECHANNELCLASS_LAST 61}; 62 63TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType); 64 65/*--------------------------------------------------------------------*//*! 66 * \brief Standard parameters for texture format testing 67 *//*--------------------------------------------------------------------*/ 68struct TextureFormatInfo 69{ 70 Vec4 valueMin; 71 Vec4 valueMax; 72 Vec4 lookupScale; 73 Vec4 lookupBias; 74 75 TextureFormatInfo (const Vec4& valueMin_, const Vec4& valueMax_, const Vec4& lookupScale_, const Vec4& lookupBias_) 76 : valueMin (valueMin_) 77 , valueMax (valueMax_) 78 , lookupScale (lookupScale_) 79 , lookupBias (lookupBias_) 80 { 81 } 82} DE_WARN_UNUSED_TYPE; 83 84TextureFormatInfo getTextureFormatInfo (const TextureFormat& format); 85IVec4 getTextureFormatBitDepth (const TextureFormat& format); 86IVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format); 87BVec4 getTextureFormatChannelMask (const TextureFormat& format); 88 89// Texture fill. 90void clear (const PixelBufferAccess& access, const Vec4& color); 91void clear (const PixelBufferAccess& access, const IVec4& color); 92void clear (const PixelBufferAccess& access, const UVec4& color); 93void clearDepth (const PixelBufferAccess& access, float depth); 94void clearStencil (const PixelBufferAccess& access, int stencil); 95void fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 96void fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB); 97void fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB); 98void fillWithMetaballs (const PixelBufferAccess& access, int numMetaballs, deUint32 seed); 99void fillWithRGBAQuads (const PixelBufferAccess& access); 100 101//! Copies contents of src to dst. If formats of dst and src are equal, a bit-exact copy is made. 102void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); 103 104void scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter); 105 106void estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal); 107void computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias); 108 109int getCubeArrayFaceIndex (CubeFace face); 110 111//! FP32->U8 with RTE rounding (extremely fast, always accurate). 112inline deUint8 floatToU8 (float fv) 113{ 114 union { float fv; deUint32 uv; deInt32 iv; } v; 115 v.fv = fv; 116 117 const deUint32 e = (deUint32)(126-(v.iv>>23)); 118 deUint32 m = v.uv; 119 120 m &= 0x00ffffffu; 121 m |= 0x00800000u; 122 m = (m << 8) - m; 123 m = 0x00800000u + (m >> e); 124 125 if (e > 8) 126 m = e; 127 128 return (deUint8)(m>>24); 129} 130 131deUint32 packRGB999E5 (const tcu::Vec4& color); 132 133/*--------------------------------------------------------------------*//*! 134 * \brief Depth-stencil utilities 135 *//*--------------------------------------------------------------------*/ 136 137TextureFormat getEffectiveDepthStencilTextureFormat (const TextureFormat& baseFormat, Sampler::DepthStencilMode mode); 138 139//! returns the currently effective access to an access with a given sampler mode, e.g. 140//! for combined depth stencil accesses and for sampler set to sample stencil returns 141//! stencil access. Identity for non-combined formats. 142PixelBufferAccess getEffectiveDepthStencilAccess (const PixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 143ConstPixelBufferAccess getEffectiveDepthStencilAccess (const ConstPixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 144 145//! returns the currently effective view to an texture with a given sampler mode. Uses 146//! storage for access storage storage 147 148tcu::Texture1DView getEffectiveTextureView (const tcu::Texture1DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 149tcu::Texture2DView getEffectiveTextureView (const tcu::Texture2DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 150tcu::Texture3DView getEffectiveTextureView (const tcu::Texture3DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 151tcu::Texture1DArrayView getEffectiveTextureView (const tcu::Texture1DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 152tcu::Texture2DArrayView getEffectiveTextureView (const tcu::Texture2DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 153tcu::TextureCubeView getEffectiveTextureView (const tcu::TextureCubeView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 154tcu::TextureCubeArrayView getEffectiveTextureView (const tcu::TextureCubeArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 155 156template <typename ScalarType> 157tcu::Vector<ScalarType, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); 158 159} // tcu 160 161#endif // _TCUTEXTUREUTIL_HPP 162