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
29 namespace tcu
30 {
31
32 // PixelBufferAccess utilities.
33 PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth);
34 ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth);
35
36 PixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height);
37 ConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height);
38
39 PixelBufferAccess flipYAccess (const PixelBufferAccess& access);
40 ConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access);
41
42 // sRGB - linear conversion.
43 Vec4 sRGBToLinear (const Vec4& cs);
44 Vec4 linearToSRGB (const Vec4& cl);
45
46 /*--------------------------------------------------------------------*//*!
47 * \brief Color channel storage type
48 *//*--------------------------------------------------------------------*/
49 enum 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
60 TextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType);
61
62 /*--------------------------------------------------------------------*//*!
63 * \brief Standard parameters for texture format testing
64 *//*--------------------------------------------------------------------*/
65 struct TextureFormatInfo
66 {
67 Vec4 valueMin;
68 Vec4 valueMax;
69 Vec4 lookupScale;
70 Vec4 lookupBias;
71
TextureFormatInfotcu::TextureFormatInfo72 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
81 TextureFormatInfo getTextureFormatInfo (const TextureFormat& format);
82 IVec4 getTextureFormatBitDepth (const TextureFormat& format);
83 IVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format);
84
85 // Texture fill.
86 void clear (const PixelBufferAccess& access, const Vec4& color);
87 void clear (const PixelBufferAccess& access, const IVec4& color);
88 void clearDepth (const PixelBufferAccess& access, float depth);
89 void clearStencil (const PixelBufferAccess& access, int stencil);
90 void fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal);
91 void fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB);
92 void fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB);
93 void fillWithMetaballs (const PixelBufferAccess& access, int numMetaballs, deUint32 seed);
94 void fillWithRGBAQuads (const PixelBufferAccess& access);
95
96 void copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src);
97 void scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter);
98
99 void estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal);
100 void computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias);
101
102 int getCubeArrayFaceIndex (CubeFace face);
103
104 //! FP32->U8 with RTE rounding (extremely fast, always accurate).
floatToU8(float fv)105 inline deUint8 floatToU8 (float fv)
106 {
107 union { float fv; deUint32 uv; deInt32 iv; } v;
108 v.fv = fv;
109
110 const deUint32 e = (deUint32)(126-(v.iv>>23));
111 deUint32 m = v.uv;
112
113 m &= 0x00ffffffu;
114 m |= 0x00800000u;
115 m = (m << 8) - m;
116 m = 0x00800000u + (m >> e);
117
118 if (e > 8)
119 m = e;
120
121 return (deUint8)(m>>24);
122 }
123
124 } // tcu
125
126 #endif // _TCUTEXTUREUTIL_HPP
127