15 #include "samplerState.h"
18 #include "datagramIterator.h"
19 #include "bamReader.h"
20 #include "bamWriter.h"
21 #include "samplerContext.h"
22 #include "preparedGraphicsObjects.h"
28 (
"texture-minfilter", SamplerState::FT_linear,
29 PRC_DESC(
"This specifies the default minfilter that is applied to a texture "
30 "in the absence of a specific minfilter setting. Normally this "
31 "is either 'linear' to disable mipmapping by default, or "
32 "'mipmap', to enable trilinear mipmapping by default. This "
33 "does not apply to depth textures. Note if this variable is "
34 "changed at runtime, you may need to reload textures explicitly "
35 "in order to change their visible properties."));
38 (
"texture-magfilter", SamplerState::FT_linear,
39 PRC_DESC(
"This specifies the default magfilter that is applied to a texture "
40 "in the absence of a specific magfilter setting. Normally this "
41 "is 'linear' (since mipmapping does not apply to magfilters). This "
42 "does not apply to depth textures. Note if this variable is "
43 "changed at runtime, you may need to reload textures explicitly "
44 "in order to change their visible properties."));
47 (
"texture-anisotropic-degree", 1,
48 PRC_DESC(
"This specifies the default anisotropic degree that is applied "
49 "to a texture in the absence of a particular anisotropic degree "
50 "setting (that is, a texture for which the anisotropic degree "
51 "is 0, meaning the default setting). It should be 1 to disable "
52 "anisotropic filtering, or a higher number to enable it. "
53 "Note if this variable is "
54 "changed at runtime, you may need to reload textures explicitly "
55 "in order to change their visible properties."));
67 if (_minfilter != FT_default) {
70 return texture_minfilter;
83 if (_magfilter != FT_default) {
86 return texture_magfilter;
103 case FT_nearest_mipmap_nearest:
104 return "nearest_mipmap_nearest";
105 case FT_linear_mipmap_nearest:
106 return "linear_mipmap_nearest";
107 case FT_nearest_mipmap_linear:
108 return "nearest_mipmap_linear";
109 case FT_linear_mipmap_linear:
110 return "linear_mipmap_linear";
121 return "**invalid**";
133 if (cmp_nocase_uh(
string,
"nearest") == 0) {
135 }
else if (cmp_nocase_uh(
string,
"linear") == 0) {
137 }
else if (cmp_nocase_uh(
string,
"nearest_mipmap_nearest") == 0) {
138 return FT_nearest_mipmap_nearest;
139 }
else if (cmp_nocase_uh(
string,
"linear_mipmap_nearest") == 0) {
140 return FT_linear_mipmap_nearest;
141 }
else if (cmp_nocase_uh(
string,
"nearest_mipmap_linear") == 0) {
142 return FT_nearest_mipmap_linear;
143 }
else if (cmp_nocase_uh(
string,
"linear_mipmap_linear") == 0) {
144 return FT_linear_mipmap_linear;
145 }
else if (cmp_nocase_uh(
string,
"mipmap") == 0) {
146 return FT_linear_mipmap_linear;
147 }
else if (cmp_nocase_uh(
string,
"shadow") == 0) {
149 }
else if (cmp_nocase_uh(
string,
"default") == 0) {
172 return "mirror_once";
173 case WM_border_color:
174 return "border_color";
180 return "**invalid**";
192 if (cmp_nocase_uh(
string,
"repeat") == 0 ||
193 cmp_nocase_uh(
string,
"wrap") == 0) {
195 }
else if (cmp_nocase_uh(
string,
"clamp") == 0) {
197 }
else if (cmp_nocase_uh(
string,
"mirror") == 0 ||
198 cmp_nocase_uh(
string,
"mirrored_repeat") == 0) {
200 }
else if (cmp_nocase_uh(
string,
"mirror_once") == 0) {
201 return WM_mirror_once;
202 }
else if (cmp_nocase_uh(
string,
"border_color") == 0 ||
203 cmp_nocase_uh(
string,
"border") == 0) {
204 return WM_border_color;
283 if (_wrap_u != other._wrap_u) {
284 return (_wrap_u < other._wrap_u) ? -1 : 1;
286 if (_wrap_v != other._wrap_v) {
287 return (_wrap_v < other._wrap_v) ? -1 : 1;
289 if (_wrap_w != other._wrap_w) {
290 return (_wrap_w < other._wrap_w) ? -1 : 1;
292 if (_minfilter != other._minfilter) {
293 return (_minfilter < other._minfilter) ? -1 : 1;
295 if (_magfilter != other._magfilter) {
296 return (_magfilter < other._magfilter) ? -1 : 1;
298 if (_anisotropic_degree != other._anisotropic_degree) {
299 return (_anisotropic_degree < other._anisotropic_degree) ? -1 : 1;
301 if (_border_color != other._border_color) {
302 return (_border_color < other._border_color) ? -1 : 1;
304 if (_min_lod != other._min_lod) {
305 return (_min_lod < other._min_lod) ? -1 : 1;
307 if (_max_lod != other._max_lod) {
308 return (_max_lod < other._max_lod) ? -1 : 1;
310 if (_lod_bias != other._lod_bias) {
311 return (_lod_bias < other._lod_bias) ? -1 : 1;
323 output(ostream &out)
const {
326 <<
" wrap(u=" << _wrap_u <<
", v=" << _wrap_v <<
", w=" << _wrap_w
327 <<
", border=" << _border_color <<
")"
328 <<
" filter(min=" << _minfilter <<
", mag=" << _magfilter
329 <<
", aniso=" << _anisotropic_degree <<
")"
330 <<
" lod(min=" << _min_lod <<
", max=" << _max_lod
331 <<
", bias=" << _lod_bias <<
")";
340 write(ostream &out,
int indent_level)
const {
341 indent(out, indent_level) <<
"SamplerState\n";
342 indent(out, indent_level) <<
" wrap_u = " << _wrap_u <<
"\n";
343 indent(out, indent_level) <<
" wrap_v = " << _wrap_v <<
"\n";
344 indent(out, indent_level) <<
" wrap_w = " << _wrap_w <<
"\n";
345 indent(out, indent_level) <<
" minfilter = " << _minfilter <<
"\n";
346 indent(out, indent_level) <<
" magfilter = " << _magfilter <<
"\n";
347 indent(out, indent_level) <<
" anisotropic_degree = " << _anisotropic_degree <<
"\n";
348 indent(out, indent_level) <<
" border_color = " << _border_color <<
"\n";
349 indent(out, indent_level) <<
" min_lod = " << _min_lod <<
"\n";
350 indent(out, indent_level) <<
" max_lod = " << _max_lod <<
"\n";
351 indent(out, indent_level) <<
" lod_bias = " << _lod_bias <<
"\n";
384 _minfilter = (FilterType)scan.
get_uint8();
385 _magfilter = (FilterType)scan.
get_uint8();
bool is_sampler_queued(const SamplerState &sampler) const
Returns true if the sampler has been queued on this GSG, false otherwise.
FilterType get_effective_magfilter() const
Returns the filter mode of the texture for magnification, with special treatment for FT_default...
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
PN_stdfloat get_stdfloat()
Extracts either a 32-bit or a 64-bit floating-point number, according to Datagram::set_stdfloat_doubl...
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...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void prepare(PreparedGraphicsObjects *prepared_objects) const
Indicates that the sampler should be enqueued to be prepared in the indicated prepared_objects at the...
void write_datagram(Datagram &destination) const
Encodes the sampler state into a datagram.
static string format_wrap_mode(WrapMode wm)
Returns the indicated WrapMode converted to a string word.
void read_datagram(DatagramIterator &source, BamReader *manager)
Reads the sampler state from the datagram that has been previously written using write_datagram.
static string format_filter_type(FilterType ft)
Returns the indicated FilterType converted to a string word.
void enqueue_sampler(const SamplerState &sampler)
Indicates that a sampler would like to be put on the list to be prepared when the GSG is next ready t...
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
SamplerContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg) const
Creates a context for the sampler on the particular GSG, if it does not already exist.
A table of objects that are saved within the graphics context for reference by handle later...
void release(PreparedGraphicsObjects *prepared_objects) const
Frees the texture context only on the indicated object, if it exists there.
PN_int16 get_int16()
Extracts a signed 16-bit integer.
static FilterType string_filter_type(const string &str)
Returns the FilterType value associated with the given string representation, or FT_invalid if the st...
void add_stdfloat(PN_stdfloat value)
Adds either a 32-bit or a 64-bit floating-point number, according to set_stdfloat_double().
void add_int16(PN_int16 value)
Adds a signed 16-bit integer to the datagram.
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
SamplerContext * prepare_sampler_now(const SamplerState &sampler, GraphicsStateGuardianBase *gsg)
Immediately creates a new SamplerContext for the indicated sampler and returns it.
This class specializes ConfigVariable as an enumerated type.
Represents a set of settings that indicate how a texture is sampled.
This is a special class object that holds a handle to the sampler state object given by the graphics ...
bool is_sampler_prepared(const SamplerState &sampler) const
Returns true if the sampler has been prepared on this GSG, false otherwise.
void write_datagram(Datagram &destination) const
Writes the vector to the Datagram using add_stdfloat().
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is a convenience class to specialize ConfigVariable as an integer type.
FilterType get_effective_minfilter() const
Returns the filter mode of the texture for minification, with special treatment for FT_default...
A class to retrieve the individual data elements previously stored in a Datagram. ...
void release_sampler(SamplerContext *sc)
Indicates that a sampler context, created by a previous call to prepare_sampler(), is no longer needed.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
TypeHandle is the identifier used to differentiate C++ class types.
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const
Returns true if the sampler has already been prepared or enqueued for preparation on the indicated GS...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
static WrapMode string_wrap_mode(const string &str)
Returns the WrapMode value associated with the given string representation, or WM_invalid if the stri...