OSDN Git Service

Compute texture coordinates using floating point operations
[android-x86/external-swiftshader.git] / src / Renderer / Sampler.hpp
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef sw_Sampler_hpp
16 #define sw_Sampler_hpp
17
18 #include "Main/Config.hpp"
19 #include "Renderer/Surface.hpp"
20 #include "Common/Types.hpp"
21
22 namespace sw
23 {
24         struct Mipmap
25         {
26                 const void *buffer[6];
27
28                 float4 fWidth;
29                 float4 fHeight;
30                 float4 fDepth;
31
32                 short uHalf[4];
33                 short vHalf[4];
34                 short wHalf[4];
35                 short width[4];
36                 short height[4];
37                 short depth[4];
38                 short onePitchP[4];
39                 int4 pitchP;
40                 int4 sliceP;
41         };
42
43         struct Texture
44         {
45                 Mipmap mipmap[MIPMAP_LEVELS];
46
47                 float LOD;
48                 float4 widthHeightLOD;
49                 float4 widthLOD;
50                 float4 heightLOD;
51                 float4 depthLOD;
52
53                 word4 borderColor4[4];
54                 float4 borderColorF[4];
55                 float maxAnisotropy;
56                 int baseLevel;
57                 int maxLevel;
58                 float minLod;
59                 float maxLod;
60         };
61
62         enum SamplerType
63         {
64                 SAMPLER_PIXEL,
65                 SAMPLER_VERTEX
66         };
67
68         enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
69         {
70                 TEXTURE_NULL,
71                 TEXTURE_2D,
72                 TEXTURE_CUBE,
73                 TEXTURE_3D,
74                 TEXTURE_2D_ARRAY,
75
76                 TEXTURE_LAST = TEXTURE_2D_ARRAY
77         };
78
79         enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
80         {
81                 FILTER_POINT,
82                 FILTER_GATHER,
83                 FILTER_MIN_POINT_MAG_LINEAR,
84                 FILTER_MIN_LINEAR_MAG_POINT,
85                 FILTER_LINEAR,
86                 FILTER_ANISOTROPIC,
87
88                 FILTER_LAST = FILTER_ANISOTROPIC
89         };
90
91         enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
92         {
93                 MIPMAP_NONE,
94                 MIPMAP_POINT,
95                 MIPMAP_LINEAR,
96
97                 MIPMAP_LAST = MIPMAP_LINEAR
98         };
99
100         enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
101         {
102                 ADDRESSING_WRAP,
103                 ADDRESSING_CLAMP,
104                 ADDRESSING_MIRROR,
105                 ADDRESSING_MIRRORONCE,
106                 ADDRESSING_BORDER,
107                 ADDRESSING_LAYER,
108                 ADDRESSING_TEXELFETCH,
109
110                 ADDRESSING_LAST = ADDRESSING_TEXELFETCH
111         };
112
113         enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
114         {
115                 SWIZZLE_RED,
116                 SWIZZLE_GREEN,
117                 SWIZZLE_BLUE,
118                 SWIZZLE_ALPHA,
119                 SWIZZLE_ZERO,
120                 SWIZZLE_ONE,
121
122                 SWIZZLE_LAST = SWIZZLE_ONE
123         };
124
125         class Sampler
126         {
127         public:
128                 struct State
129                 {
130                         State();
131
132                         TextureType textureType        : BITS(TEXTURE_LAST);
133                         Format textureFormat           : BITS(FORMAT_LAST);
134                         FilterType textureFilter       : BITS(FILTER_LAST);
135                         AddressingMode addressingModeU : BITS(ADDRESSING_LAST);
136                         AddressingMode addressingModeV : BITS(ADDRESSING_LAST);
137                         AddressingMode addressingModeW : BITS(ADDRESSING_LAST);
138                         MipmapType mipmapFilter        : BITS(FILTER_LAST);
139                         bool sRGB                      : 1;
140                         SwizzleType swizzleR           : BITS(SWIZZLE_LAST);
141                         SwizzleType swizzleG           : BITS(SWIZZLE_LAST);
142                         SwizzleType swizzleB           : BITS(SWIZZLE_LAST);
143                         SwizzleType swizzleA           : BITS(SWIZZLE_LAST);
144                         bool highPrecisionFiltering    : 1;
145
146                         #if PERF_PROFILE
147                         bool compressedFormat          : 1;
148                         #endif
149                 };
150
151                 Sampler();
152
153                 ~Sampler();
154
155                 State samplerState() const;
156
157                 void setTextureLevel(int face, int level, Surface *surface, TextureType type);
158
159                 void setTextureFilter(FilterType textureFilter);
160                 void setMipmapFilter(MipmapType mipmapFilter);
161                 void setGatherEnable(bool enable);
162                 void setAddressingModeU(AddressingMode addressingMode);
163                 void setAddressingModeV(AddressingMode addressingMode);
164                 void setAddressingModeW(AddressingMode addressingMode);
165                 void setReadSRGB(bool sRGB);
166                 void setBorderColor(const Color<float> &borderColor);
167                 void setMaxAnisotropy(float maxAnisotropy);
168                 void setHighPrecisionFiltering(bool highPrecisionFiltering);
169                 void setSwizzleR(SwizzleType swizzleR);
170                 void setSwizzleG(SwizzleType swizzleG);
171                 void setSwizzleB(SwizzleType swizzleB);
172                 void setSwizzleA(SwizzleType swizzleA);
173                 void setBaseLevel(int baseLevel);
174                 void setMaxLevel(int maxLevel);
175                 void setMinLod(float minLod);
176                 void setMaxLod(float maxLod);
177
178                 static void setFilterQuality(FilterType maximumFilterQuality);
179                 static void setMipmapQuality(MipmapType maximumFilterQuality);
180                 void setMipmapLOD(float lod);
181
182                 bool hasTexture() const;
183                 bool hasUnsignedTexture() const;
184                 bool hasCubeTexture() const;
185                 bool hasVolumeTexture() const;
186
187                 const Texture &getTextureData();
188
189         private:
190                 MipmapType mipmapFilter() const;
191                 TextureType getTextureType() const;
192                 FilterType getTextureFilter() const;
193                 AddressingMode getAddressingModeU() const;
194                 AddressingMode getAddressingModeV() const;
195                 AddressingMode getAddressingModeW() const;
196
197                 Format externalTextureFormat;
198                 Format internalTextureFormat;
199                 TextureType textureType;
200
201                 FilterType textureFilter;
202                 AddressingMode addressingModeU;
203                 AddressingMode addressingModeV;
204                 AddressingMode addressingModeW;
205                 MipmapType mipmapFilterState;
206                 bool sRGB;
207                 bool gather;
208                 bool highPrecisionFiltering;
209
210                 SwizzleType swizzleR;
211                 SwizzleType swizzleG;
212                 SwizzleType swizzleB;
213                 SwizzleType swizzleA;
214                 Texture texture;
215                 float exp2LOD;
216
217                 static FilterType maximumTextureFilterQuality;
218                 static MipmapType maximumMipmapFilterQuality;
219         };
220 }
221
222 #endif   // sw_Sampler_hpp