OSDN Git Service

Fix resetting current display when no current context.
[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                 int sliceP[2];
40         };
41
42         struct Texture
43         {
44                 Mipmap mipmap[MIPMAP_LEVELS];
45
46                 float LOD;
47                 float4 widthHeightLOD;
48                 float4 widthLOD;
49                 float4 heightLOD;
50                 float4 depthLOD;
51
52                 word4 borderColor4[4];
53                 float4 borderColorF[4];
54                 float maxAnisotropy;
55                 int baseLevel;
56                 int maxLevel;
57                 float minLod;
58                 float maxLod;
59         };
60
61         enum SamplerType
62         {
63                 SAMPLER_PIXEL,
64                 SAMPLER_VERTEX
65         };
66
67         enum TextureType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
68         {
69                 TEXTURE_NULL,
70                 TEXTURE_2D,
71                 TEXTURE_CUBE,
72                 TEXTURE_3D,
73                 TEXTURE_2D_ARRAY,
74
75                 TEXTURE_LAST = TEXTURE_2D_ARRAY
76         };
77
78         enum FilterType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
79         {
80                 FILTER_POINT,
81                 FILTER_GATHER,
82                 FILTER_MIN_POINT_MAG_LINEAR,
83                 FILTER_MIN_LINEAR_MAG_POINT,
84                 FILTER_LINEAR,
85                 FILTER_ANISOTROPIC,
86
87                 FILTER_LAST = FILTER_ANISOTROPIC
88         };
89
90         enum MipmapType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
91         {
92                 MIPMAP_NONE,
93                 MIPMAP_POINT,
94                 MIPMAP_LINEAR,
95
96                 MIPMAP_LAST = MIPMAP_LINEAR
97         };
98
99         enum AddressingMode ENUM_UNDERLYING_TYPE_UNSIGNED_INT
100         {
101                 ADDRESSING_WRAP,
102                 ADDRESSING_CLAMP,
103                 ADDRESSING_MIRROR,
104                 ADDRESSING_MIRRORONCE,
105                 ADDRESSING_BORDER,
106                 ADDRESSING_LAYER,
107                 ADDRESSING_TEXELFETCH,
108
109                 ADDRESSING_LAST = ADDRESSING_TEXELFETCH
110         };
111
112         enum SwizzleType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
113         {
114                 SWIZZLE_RED,
115                 SWIZZLE_GREEN,
116                 SWIZZLE_BLUE,
117                 SWIZZLE_ALPHA,
118                 SWIZZLE_ZERO,
119                 SWIZZLE_ONE,
120
121                 SWIZZLE_LAST = SWIZZLE_ONE
122         };
123
124         class Sampler
125         {
126         public:
127                 struct State
128                 {
129                         State();
130
131                         TextureType textureType        : BITS(TEXTURE_LAST);
132                         Format textureFormat           : BITS(FORMAT_LAST);
133                         FilterType textureFilter       : BITS(FILTER_LAST);
134                         AddressingMode addressingModeU : BITS(ADDRESSING_LAST);
135                         AddressingMode addressingModeV : BITS(ADDRESSING_LAST);
136                         AddressingMode addressingModeW : BITS(ADDRESSING_LAST);
137                         MipmapType mipmapFilter        : BITS(FILTER_LAST);
138                         bool sRGB                      : 1;
139                         SwizzleType swizzleR           : BITS(SWIZZLE_LAST);
140                         SwizzleType swizzleG           : BITS(SWIZZLE_LAST);
141                         SwizzleType swizzleB           : BITS(SWIZZLE_LAST);
142                         SwizzleType swizzleA           : BITS(SWIZZLE_LAST);
143
144                         #if PERF_PROFILE
145                         bool compressedFormat          : 1;
146                         #endif
147                 };
148
149                 Sampler();
150
151                 ~Sampler();
152
153                 State samplerState() const;
154
155                 void setTextureLevel(int face, int level, Surface *surface, TextureType type);
156
157                 void setTextureFilter(FilterType textureFilter);
158                 void setMipmapFilter(MipmapType mipmapFilter);
159                 void setGatherEnable(bool enable);
160                 void setAddressingModeU(AddressingMode addressingMode);
161                 void setAddressingModeV(AddressingMode addressingMode);
162                 void setAddressingModeW(AddressingMode addressingMode);
163                 void setReadSRGB(bool sRGB);
164                 void setBorderColor(const Color<float> &borderColor);
165                 void setMaxAnisotropy(float maxAnisotropy);
166                 void setSwizzleR(SwizzleType swizzleR);
167                 void setSwizzleG(SwizzleType swizzleG);
168                 void setSwizzleB(SwizzleType swizzleB);
169                 void setSwizzleA(SwizzleType swizzleA);
170                 void setBaseLevel(int baseLevel);
171                 void setMaxLevel(int maxLevel);
172                 void setMinLod(float minLod);
173                 void setMaxLod(float maxLod);
174
175                 static void setFilterQuality(FilterType maximumFilterQuality);
176                 static void setMipmapQuality(MipmapType maximumFilterQuality);
177                 void setMipmapLOD(float lod);
178
179                 bool hasTexture() const;
180                 bool hasUnsignedTexture() const;
181                 bool hasCubeTexture() const;
182                 bool hasVolumeTexture() const;
183
184                 const Texture &getTextureData();
185
186         private:
187                 MipmapType mipmapFilter() const;
188                 TextureType getTextureType() const;
189                 FilterType getTextureFilter() const;
190                 AddressingMode getAddressingModeU() const;
191                 AddressingMode getAddressingModeV() const;
192                 AddressingMode getAddressingModeW() const;
193
194                 Format externalTextureFormat;
195                 Format internalTextureFormat;
196                 TextureType textureType;
197
198                 FilterType textureFilter;
199                 AddressingMode addressingModeU;
200                 AddressingMode addressingModeV;
201                 AddressingMode addressingModeW;
202                 MipmapType mipmapFilterState;
203                 bool sRGB;
204                 bool gather;
205
206                 SwizzleType swizzleR;
207                 SwizzleType swizzleG;
208                 SwizzleType swizzleB;
209                 SwizzleType swizzleA;
210                 Texture texture;
211                 float exp2LOD;
212
213                 static FilterType maximumTextureFilterQuality;
214                 static MipmapType maximumMipmapFilterQuality;
215         };
216 }
217
218 #endif   // sw_Sampler_hpp