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