tcuTextureUtil.hpp revision 2925635ad62614cb6c5f824c22e31e8ca6bbb03e
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 42// sRGB - linear conversion. 43Vec4 sRGBToLinear (const Vec4& cs); 44Vec4 linearToSRGB (const Vec4& cl); 45 46/*--------------------------------------------------------------------*//*! 47 * \brief Color channel storage type 48 *//*--------------------------------------------------------------------*/ 49enum TextureChannelClass 50{ 51 TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0, 52 TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT, 53 TEXTURECHANNELCLASS_SIGNED_INTEGER, 54 TEXTURECHANNELCLASS_UNSIGNED_INTEGER, 55 TEXTURECHANNELCLASS_FLOATING_POINT, 56 57 TEXTURECHANNELCLASS_LAST 58}; 59 60TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType); 61 62/*--------------------------------------------------------------------*//*! 63 * \brief Standard parameters for texture format testing 64 *//*--------------------------------------------------------------------*/ 65struct TextureFormatInfo 66{ 67 Vec4 valueMin; 68 Vec4 valueMax; 69 Vec4 lookupScale; 70 Vec4 lookupBias; 71 72 TextureFormatInfo (const Vec4& valueMin_, const Vec4& valueMax_, const Vec4& lookupScale_, const Vec4& lookupBias_) 73 : valueMin (valueMin_) 74 , valueMax (valueMax_) 75 , lookupScale (lookupScale_) 76 , lookupBias (lookupBias_) 77 { 78 } 79}; 80 81TextureFormatInfo getTextureFormatInfo (const TextureFormat& format); 82IVec4 getTextureFormatBitDepth (const TextureFormat& format); 83IVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format); 84 85// Texture fill. 86void clear (const PixelBufferAccess& access, const Vec4& color); 87void clear (const PixelBufferAccess& access, const IVec4& color); 88void clearDepth (const PixelBufferAccess& access, float depth); 89void clearStencil (const PixelBufferAccess& access, int stencil); 90void fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 91void fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB); 92void fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB); 93void fillWithMetaballs (const PixelBufferAccess& access, int numMetaballs, deUint32 seed); 94void fillWithRGBAQuads (const PixelBufferAccess& access); 95 96void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); 97void scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter); 98 99// Copy raw pixel data between buffers. Both buffers must have same pixel size. 100void copyRawPixels (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); 101 102void estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal); 103void computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias); 104 105int getCubeArrayFaceIndex (CubeFace face); 106 107//! FP32->U8 with RTE rounding (extremely fast, always accurate). 108inline deUint8 floatToU8 (float fv) 109{ 110 union { float fv; deUint32 uv; deInt32 iv; } v; 111 v.fv = fv; 112 113 const deUint32 e = (deUint32)(126-(v.iv>>23)); 114 deUint32 m = v.uv; 115 116 m &= 0x00ffffffu; 117 m |= 0x00800000u; 118 m = (m << 8) - m; 119 m = 0x00800000u + (m >> e); 120 121 if (e > 8) 122 m = e; 123 124 return (deUint8)(m>>24); 125} 126 127deUint32 packRGB999E5 (const tcu::Vec4& color); 128 129} // tcu 130 131#endif // _TCUTEXTUREUTIL_HPP 132