Panda3D
samplerState.I
1 // Filename: samplerState.I
2 // Created by: rdb (09Dec14)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: SamplerState::Constructor
18 // Access: Published
19 // Description: Creates a new SamplerState initialized to the
20 // default values.
21 ////////////////////////////////////////////////////////////////////
22 INLINE SamplerState::
24  _border_color(0, 0, 0, 1),
25  _wrap_u(WM_repeat),
26  _wrap_v(WM_repeat),
27  _wrap_w(WM_repeat),
28  _minfilter(FT_default),
29  _magfilter(FT_default),
30  _min_lod(-1000),
31  _max_lod(1000),
32  _lod_bias(0),
33  _anisotropic_degree(0)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: SamplerState::get_default
39 // Access: Published, Static
40 // Description: Returns a reference to the global default immutable
41 // SamplerState object.
42 ////////////////////////////////////////////////////////////////////
43 INLINE const SamplerState &SamplerState::
45  return _default;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: SamplerState::set_wrap_u
50 // Access: Published
51 // Description: This setting determines what happens when the
52 // SamplerState is sampled with a U value outside the range
53 // 0.0-1.0. The default is WM_repeat, which indicates
54 // that the SamplerState should repeat indefinitely.
55 ////////////////////////////////////////////////////////////////////
56 INLINE void SamplerState::
57 set_wrap_u(SamplerState::WrapMode wrap) {
58  _wrap_u = wrap;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: SamplerState::set_wrap_v
63 // Access: Published
64 // Description: This setting determines what happens when the
65 // SamplerState is sampled with a V value outside the range
66 // 0.0-1.0. The default is WM_repeat, which indicates
67 // that the SamplerState should repeat indefinitely.
68 ////////////////////////////////////////////////////////////////////
69 INLINE void SamplerState::
70 set_wrap_v(SamplerState::WrapMode wrap) {
71  _wrap_v = wrap;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: SamplerState::set_wrap_w
76 // Access: Published
77 // Description: The W wrap direction is only used for 3-d SamplerStates.
78 ////////////////////////////////////////////////////////////////////
79 INLINE void SamplerState::
80 set_wrap_w(SamplerState::WrapMode wrap) {
81  _wrap_w = wrap;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: SamplerState::set_minfilter
86 // Access: Published
87 // Description: Sets the filtering method that should be used when
88 // viewing the SamplerState from a distance.
89 ////////////////////////////////////////////////////////////////////
90 INLINE void SamplerState::
91 set_minfilter(SamplerState::FilterType filter) {
92  _minfilter = filter;
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: SamplerState::set_magfilter
97 // Access: Published
98 // Description: Sets the filtering method that should be used when
99 // viewing the SamplerState up close.
100 ////////////////////////////////////////////////////////////////////
101 INLINE void SamplerState::
102 set_magfilter(SamplerState::FilterType filter) {
103  _magfilter = filter;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: SamplerState::set_anisotropic_degree
108 // Access: Published
109 // Description: Specifies the level of anisotropic filtering to apply
110 // to the SamplerState. Set this 0 to indicate the default
111 // value, which is specified in the
112 // SamplerState-anisotropic-degree config variable.
113 //
114 // To explicitly disable anisotropic filtering, set this
115 // value to 1. To explicitly enable anisotropic
116 // filtering, set it to a value higher than 1; larger
117 // numbers indicate greater degrees of filtering.
118 ////////////////////////////////////////////////////////////////////
119 INLINE void SamplerState::
120 set_anisotropic_degree(int anisotropic_degree) {
121  _anisotropic_degree = anisotropic_degree;
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: SamplerState::set_border_color
126 // Access: Published
127 // Description: Specifies the solid color of the SamplerState's border.
128 // Some OpenGL implementations use a border for tiling
129 // SamplerStates; in Panda, it is only used for specifying
130 // the clamp color.
131 ////////////////////////////////////////////////////////////////////
132 INLINE void SamplerState::
134  _border_color = color;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: SamplerState::set_min_lod
139 // Access: Published
140 // Description: Sets the minimum level of detail that will be used
141 // when sampling this texture. This may be a negative
142 // value.
143 ////////////////////////////////////////////////////////////////////
144 INLINE void SamplerState::
145 set_min_lod(PN_stdfloat min_lod) {
146  _min_lod = min_lod;
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: SamplerState::set_max_lod
151 // Access: Published
152 // Description: Sets the maximum level of detail that will be used
153 // when sampling this texture. This may exceed the
154 // number of mipmap levels that the texture has.
155 ////////////////////////////////////////////////////////////////////
156 INLINE void SamplerState::
157 set_max_lod(PN_stdfloat max_lod) {
158  _max_lod = max_lod;
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: SamplerState::set_lod_bias
163 // Access: Published
164 // Description: Sets the value that will be added to the level of
165 // detail when sampling the texture. This may be a
166 // negative value, although some graphics hardware may
167 // not support the use of negative LOD values.
168 ////////////////////////////////////////////////////////////////////
169 INLINE void SamplerState::
170 set_lod_bias(PN_stdfloat lod_bias) {
171  _lod_bias = lod_bias;
172 }
173 
174 ////////////////////////////////////////////////////////////////////
175 // Function: SamplerState::get_wrap_u
176 // Access: Published
177 // Description: Returns the wrap mode of the texture in the U
178 // direction.
179 ////////////////////////////////////////////////////////////////////
180 INLINE SamplerState::WrapMode SamplerState::
181 get_wrap_u() const {
182  return _wrap_u;
183 }
184 
185 ////////////////////////////////////////////////////////////////////
186 // Function: SamplerState::get_wrap_v
187 // Access: Published
188 // Description: Returns the wrap mode of the texture in the V
189 // direction.
190 ////////////////////////////////////////////////////////////////////
191 INLINE SamplerState::WrapMode SamplerState::
192 get_wrap_v() const {
193  return _wrap_v;
194 }
195 
196 ////////////////////////////////////////////////////////////////////
197 // Function: SamplerState::get_wrap_w
198 // Access: Published
199 // Description: Returns the wrap mode of the texture in the W
200 // direction. This is the depth direction of 3-d
201 // textures.
202 ////////////////////////////////////////////////////////////////////
203 INLINE SamplerState::WrapMode SamplerState::
204 get_wrap_w() const {
205  return _wrap_w;
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: SamplerState::get_minfilter
210 // Access: Published
211 // Description: Returns the filter mode of the texture for
212 // minification. If this is one of the mipmap
213 // constants, then the texture requires mipmaps. This
214 // may return FT_default; see also
215 // get_effective_minfilter().
216 ////////////////////////////////////////////////////////////////////
217 INLINE SamplerState::FilterType SamplerState::
218 get_minfilter() const {
219  return _minfilter;
220 }
221 
222 ////////////////////////////////////////////////////////////////////
223 // Function: SamplerState::get_magfilter
224 // Access: Published
225 // Description: Returns the filter mode of the texture for
226 // magnification. The mipmap constants are invalid
227 // here. This may return FT_default; see also
228 // get_effective_minfilter().
229 ////////////////////////////////////////////////////////////////////
230 INLINE SamplerState::FilterType SamplerState::
231 get_magfilter() const {
232  return _magfilter;
233 }
234 
235 ////////////////////////////////////////////////////////////////////
236 // Function: SamplerState::get_anisotropic_degree
237 // Access: Published
238 // Description: Returns the degree of anisotropic filtering that
239 // should be applied to the texture. This value may
240 // return 0, indicating the default value; see also
241 // get_effective_anisotropic_degree.
242 ////////////////////////////////////////////////////////////////////
243 INLINE int SamplerState::
245  return _anisotropic_degree;
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: SamplerState::get_effective_anisotropic_degree
250 // Access: Published
251 // Description: Returns the degree of anisotropic filtering that
252 // should be applied to the texture. This value will
253 // normally not return 0, unless there is an error in
254 // the config file.
255 ////////////////////////////////////////////////////////////////////
256 INLINE int SamplerState::
258  if (_anisotropic_degree != 0) {
259  return _anisotropic_degree;
260  }
261  return texture_anisotropic_degree;
262 }
263 
264 ////////////////////////////////////////////////////////////////////
265 // Function: SamplerState::get_border_color
266 // Access: Published
267 // Description: Returns the solid color of the texture's border.
268 // Some OpenGL implementations use a border for tiling
269 // textures; in Panda, it is only used for specifying
270 // the clamp color.
271 ////////////////////////////////////////////////////////////////////
272 INLINE const LColor &SamplerState::
274  return _border_color;
275 }
276 
277 ////////////////////////////////////////////////////////////////////
278 // Function: SamplerState::get_min_lod
279 // Access: Published
280 // Description: Returns the minimum level of detail that will be
281 // observed when sampling this texture.
282 ////////////////////////////////////////////////////////////////////
283 INLINE PN_stdfloat SamplerState::
284 get_min_lod() const {
285  return _min_lod;
286 }
287 
288 ////////////////////////////////////////////////////////////////////
289 // Function: SamplerState::get_max_lod
290 // Access: Published
291 // Description: Returns the maximum level of detail that will be
292 // observed when sampling this texture.
293 ////////////////////////////////////////////////////////////////////
294 INLINE PN_stdfloat SamplerState::
295 get_max_lod() const {
296  return _max_lod;
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: SamplerState::get_lod_bias
301 // Access: Published
302 // Description: Returns the bias that will be added to the texture
303 // level of detail when sampling this texture.
304 ////////////////////////////////////////////////////////////////////
305 INLINE PN_stdfloat SamplerState::
306 get_lod_bias() const {
307  return _lod_bias;
308 }
309 
310 ////////////////////////////////////////////////////////////////////
311 // Function: SamplerState::uses_mipmaps
312 // Access: Public
313 // Description: Returns true if the minfilter settings on this
314 // sampler indicate the use of mipmapping, false
315 // otherwise.
316 ////////////////////////////////////////////////////////////////////
317 INLINE bool SamplerState::
318 uses_mipmaps() const {
320 }
321 
322 ////////////////////////////////////////////////////////////////////
323 // Function: SamplerState::is_mipmap
324 // Access: Published, Static
325 // Description: Returns true if the indicated filter type requires
326 // the use of mipmaps, or false if it does not.
327 ////////////////////////////////////////////////////////////////////
328 INLINE bool SamplerState::
329 is_mipmap(FilterType filter_type) {
330  switch (filter_type) {
331  case SamplerState::FT_nearest_mipmap_nearest:
332  case SamplerState::FT_linear_mipmap_nearest:
333  case SamplerState::FT_nearest_mipmap_linear:
334  case SamplerState::FT_linear_mipmap_linear:
335  return true;
336 
337  default:
338  return false;
339  }
340 }
341 
342 ////////////////////////////////////////////////////////////////////
343 // Function: SamplerState::operator ==
344 // Access: Published
345 // Description:
346 ////////////////////////////////////////////////////////////////////
347 INLINE bool SamplerState::
348 operator == (const SamplerState &other) const {
349  return compare_to(other) == 0;
350 }
351 
352 ////////////////////////////////////////////////////////////////////
353 // Function: SamplerState::operator !=
354 // Access: Published
355 // Description:
356 ////////////////////////////////////////////////////////////////////
357 INLINE bool SamplerState::
358 operator != (const SamplerState &other) const {
359  return compare_to(other) != 0;
360 }
361 
362 ////////////////////////////////////////////////////////////////////
363 // Function: SamplerState::operator <
364 // Access: Published
365 // Description:
366 ////////////////////////////////////////////////////////////////////
367 INLINE bool SamplerState::
368 operator < (const SamplerState &other) const {
369  return compare_to(other) < 0;
370 }
void set_max_lod(PN_stdfloat max_lod)
Sets the maximum level of detail that will be used when sampling this texture.
Definition: samplerState.I:157
void set_wrap_u(WrapMode wrap)
This setting determines what happens when the SamplerState is sampled with a U value outside the rang...
Definition: samplerState.I:57
PN_stdfloat get_max_lod() const
Returns the maximum level of detail that will be observed when sampling this texture.
Definition: samplerState.I:295
void set_magfilter(FilterType filter)
Sets the filtering method that should be used when viewing the SamplerState up close.
Definition: samplerState.I:102
static bool is_mipmap(FilterType type)
Returns true if the indicated filter type requires the use of mipmaps, or false if it does not...
Definition: samplerState.I:329
void set_minfilter(FilterType filter)
Sets the filtering method that should be used when viewing the SamplerState from a distance...
Definition: samplerState.I:91
FilterType get_magfilter() const
Returns the filter mode of the texture for magnification.
Definition: samplerState.I:231
void set_anisotropic_degree(int anisotropic_degree)
Specifies the level of anisotropic filtering to apply to the SamplerState.
Definition: samplerState.I:120
void set_wrap_w(WrapMode wrap)
The W wrap direction is only used for 3-d SamplerStates.
Definition: samplerState.I:80
FilterType get_effective_minfilter() const
Returns the filter mode of the texture for minification, with special treatment for FT_default...
bool uses_mipmaps() const
Returns true if the minfilter settings on this sampler indicate the use of mipmapping, false otherwise.
Definition: samplerState.I:318
int get_effective_anisotropic_degree() const
Returns the degree of anisotropic filtering that should be applied to the texture.
Definition: samplerState.I:257
FilterType get_minfilter() const
Returns the filter mode of the texture for minification.
Definition: samplerState.I:218
void set_wrap_v(WrapMode wrap)
This setting determines what happens when the SamplerState is sampled with a V value outside the rang...
Definition: samplerState.I:70
void set_min_lod(PN_stdfloat min_lod)
Sets the minimum level of detail that will be used when sampling this texture.
Definition: samplerState.I:145
int get_anisotropic_degree() const
Returns the degree of anisotropic filtering that should be applied to the texture.
Definition: samplerState.I:244
const LColor & get_border_color() const
Returns the solid color of the texture&#39;s border.
Definition: samplerState.I:273
Represents a set of settings that indicate how a texture is sampled.
Definition: samplerState.h:39
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
static const SamplerState & get_default()
Returns a reference to the global default immutable SamplerState object.
Definition: samplerState.I:44
int compare_to(const SamplerState &other) const
Returns a number less than zero if this sampler sorts before the other one, greater than zero if it s...
SamplerState()
Creates a new SamplerState initialized to the default values.
Definition: samplerState.I:23
PN_stdfloat get_min_lod() const
Returns the minimum level of detail that will be observed when sampling this texture.
Definition: samplerState.I:284
WrapMode get_wrap_w() const
Returns the wrap mode of the texture in the W direction.
Definition: samplerState.I:204
PN_stdfloat get_lod_bias() const
Returns the bias that will be added to the texture level of detail when sampling this texture...
Definition: samplerState.I:306
void set_lod_bias(PN_stdfloat lod_bias)
Sets the value that will be added to the level of detail when sampling the texture.
Definition: samplerState.I:170
WrapMode get_wrap_v() const
Returns the wrap mode of the texture in the V direction.
Definition: samplerState.I:192
void set_border_color(const LColor &color)
Specifies the solid color of the SamplerState&#39;s border.
Definition: samplerState.I:133
WrapMode get_wrap_u() const
Returns the wrap mode of the texture in the U direction.
Definition: samplerState.I:181