HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_TextureFilter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_TextureFilter.h ( RE Library, C++)
7  *
8  * COMMENTS:
9  * This class contains simple filter information used for textures.
10  * The GPU does the actual filtering.
11  */
12 #ifndef RE_TextureFilter_h
13 #define RE_TextureFilter_h
14 
15 #include "RE_API.h"
16 #include "RE_TextureTypes.h"
17 #include <UT/UT_Assert.h>
18 #include <UT/UT_Vector4.h>
19 
20 
22 {
23 public:
25 
27  RE_TextureFilter &operator=(const RE_TextureFilter &filter);
28  bool operator==(const RE_TextureFilter &filter) const;
29 
30  void setMinFilter(RE_TexFiltType t );
31  RE_TexFiltType getMinFilter() const;
32 
33  // Filter to use when displaying the texture at greater than 100% zoom
34  void setMagFilter(RE_TexFiltType t );
35  RE_TexFiltType getMagFilter() const;
36 
37  // Anisotropic filtering. Acceptable values are pow2 up to the GL max.
38  void setMaxAnisotropy(int atf);
39  int getMaxAnisotropy() const;
40 
41  // Fixed bias value that is added to the level-of-detail parameter for
42  // the texture before texture sampling (when mipmapping).
43  void setLodBias(float bias);
44  float getLodBias() const;
45 
46  // Texture wrapping - clamp or repeat (true). Not all dimension may be used.
47  void setTextureWrap(RE_TexClampType wrap_s,
50  RE_TexClampType getWrapS() const;
51  RE_TexClampType getWrapT() const;
52  RE_TexClampType getWrapR() const;
53  bool isWrapSet() const;
54 
55  // For RE_CLAMP_BORDER, this defines the border color, normally (0,0,0,0).
56  void setBorder(RE_TextureBorder border,
57  const UT_Vector4F *color_alpha = nullptr);
58  const UT_Vector4F &getBorderColor() const;
59 
60  // Sets all the filtering options to invalid values.
61  void invalidate();
62 
63 private:
64  RE_TexFiltType myMinFilter;
65  RE_TexFiltType myMagFilter;
66  int myTextureAnisotropy;
67  UT_Vector4F myBorder;
68  float myLodBias;
69  unsigned short myWrapS:3, myWrapT:3, myWrapR:3;
70 };
71 
73  : myMinFilter(RE_FILT_LINEAR),
74  myMagFilter(RE_FILT_LINEAR),
75  myWrapS(RE_CLAMP_REPEAT),
76  myWrapT(RE_CLAMP_REPEAT),
77  myWrapR(RE_CLAMP_REPEAT),
78  myTextureAnisotropy(1),
79  myBorder(0,0,0,0),
80  myLodBias(0.0f)
81 {
82 }
83 
84 inline void
86 {
87  myMinFilter = t;
88 }
89 
90 inline RE_TexFiltType
92 {
93  return myMinFilter;
94 }
95 
96 inline void
98 {
99  myMagFilter = t;
100 }
101 
102 inline RE_TexFiltType
104 {
105  return myMagFilter;
106 }
107 
108 inline void
110 {
111  myTextureAnisotropy = ta;
112 }
113 
114 inline int
116 {
117  return myTextureAnisotropy;
118 }
119 
120 inline void
122 {
123  myLodBias = bias;
124 }
125 
126 inline float
128 {
129  return myLodBias;
130 }
131 
132 inline void
136 {
137  myWrapS = s;
138  myWrapT = t;
139  myWrapR = r;
140 }
141 
142 inline RE_TexClampType
144 {
145  return RE_TexClampType(myWrapS);
146 }
147 
148 inline RE_TexClampType
150 {
151  return RE_TexClampType(myWrapT);
152 }
153 
154 inline RE_TexClampType
156 {
157  return RE_TexClampType(myWrapR);
158 }
159 
161 {
162  myLodBias = 0.0;
163  *this = filter;
164 }
165 
166 inline RE_TextureFilter &
168 {
169  myWrapS = filter.myWrapS;
170  myWrapT = filter.myWrapT;
171  myWrapR = filter.myWrapR;
172  myMinFilter = filter.myMinFilter;
173  myMagFilter = filter.myMagFilter;
174  myTextureAnisotropy = filter.myTextureAnisotropy;
175  myBorder = filter.myBorder;
176 
177  return *this;
178 }
179 
180 inline bool
182 {
183  return (myWrapS == filter.myWrapS &&
184  myWrapT == filter.myWrapT &&
185  myWrapR == filter.myWrapR &&
186  myMinFilter == filter.myMinFilter &&
187  myMagFilter == filter.myMagFilter &&
188  myBorder == filter.myBorder &&
189  myTextureAnisotropy == filter.myTextureAnisotropy);
190 }
191 
192 inline void
194 {
195  myMinFilter = RE_FILT_MAX_FILTERS;
196  myMagFilter = RE_FILT_MAX_FILTERS;
197  myWrapS = RE_TEXTURE_BAD_WRAPPING;
198  myWrapT = RE_TEXTURE_BAD_WRAPPING;
199  myWrapR = RE_TEXTURE_BAD_WRAPPING;
200  myBorder.assign(-1,-1,-1,-1);
201  myTextureAnisotropy = 0;
202 }
203 
204 inline bool
206 {
207  return (myWrapS != RE_TEXTURE_BAD_WRAPPING &&
208  myWrapT != RE_TEXTURE_BAD_WRAPPING &&
209  myWrapR != RE_TEXTURE_BAD_WRAPPING);
210 }
211 
212 inline void
214  const UT_Vector4F *color)
215 {
216  switch(border)
217  {
218  case RE_TEX_BORDER_ZERO:
219  myBorder.assign(0,0,0,0); break;
220  case RE_TEX_BORDER_BLACK:
221  myBorder.assign(0,0,0,1); break;
222  case RE_TEX_BORDER_WHITE:
223  myBorder.assign(1,1,1,1); break;
224  case RE_TEX_BORDER_COLOR:
225  UT_ASSERT(color);
226  myBorder = *color;
227  break;
228  }
229 }
230 
231 inline const UT_Vector4F &
233 {
234  return myBorder;
235 }
236 
237 #endif
#define RE_API
Definition: RE_API.h:10
RE_TextureFilter & operator=(const RE_TextureFilter &filter)
GLdouble s
Definition: glad.h:3009
void setMaxAnisotropy(int atf)
float getLodBias() const
RE_TexFiltType getMagFilter() const
RE_TexFiltType
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLfloat f
Definition: glcorearb.h:1926
#define RE_TEXTURE_BAD_WRAPPING
void setMinFilter(RE_TexFiltType t)
void setLodBias(float bias)
RE_TexClampType
void setTextureWrap(RE_TexClampType wrap_s, RE_TexClampType wrap_t=RE_CLAMP_EDGE, RE_TexClampType wrap_r=RE_CLAMP_EDGE)
RE_TextureBorder
int getMaxAnisotropy() const
GLdouble t
Definition: glad.h:2397
void setBorder(RE_TextureBorder border, const UT_Vector4F *color_alpha=nullptr)
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f, T ww=1.0f)
Set the values of the vector components.
Definition: UT_Vector4.h:523
GLint GLint GLsizei GLint border
Definition: glcorearb.h:108
RE_TexClampType getWrapR() const
RE_TexClampType getWrapS() const
GLuint color
Definition: glcorearb.h:1261
void setMagFilter(RE_TexFiltType t)
RE_TexFiltType getMinFilter() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GLboolean r
Definition: glcorearb.h:1222
bool operator==(const RE_TextureFilter &filter) const
const UT_Vector4F & getBorderColor() const
RE_TexClampType getWrapT() const
bool isWrapSet() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297