SamplerState

class SamplerState

Represents a set of settings that indicate how a texture is sampled. This can be used to sample the same texture using different settings in different places.

Inheritance diagram

Inheritance diagram of SamplerState

enum FilterType
enumerator FT_nearest = 0

Point sample the pixel

enumerator FT_linear = 1

Bilinear filtering of four neighboring pixels

enumerator FT_nearest_mipmap_nearest = 2

Point sample the pixel from the nearest mipmap level

enumerator FT_linear_mipmap_nearest = 3

Bilinear filter the pixel from the nearest mipmap level

enumerator FT_nearest_mipmap_linear = 4

Point sample the pixel from two mipmap levels, and linearly blend

enumerator FT_linear_mipmap_linear = 5

A.k.a. trilinear filtering: Bilinear filter the pixel from two mipmap levels, and linearly blend the results.

enumerator FT_shadow = 6

The OpenGL ARB_shadow extension can be thought of as a kind of filtering.

enumerator FT_default = 7

Default is usually linear, but it depends on format. This was added at the end of the list to avoid bumping TXO version #.

enumerator FT_invalid = 8

Returned by string_filter_type() for an invalid match.

enum WrapMode
enumerator WM_clamp = 0

coords that would be outside [0-1] are clamped to 0 or 1

enumerator WM_repeat = 1
enumerator WM_mirror = 2
enumerator WM_mirror_once = 3

mirror once, then clamp

enumerator WM_border_color = 4

coords outside [0-1] use explicit border color Returned by string_wrap_mode() for an invalid match.

enumerator WM_invalid = 5

coords outside [0-1] use explicit border color Returned by string_wrap_mode() for an invalid match.

SamplerState(void)
SamplerState(SamplerState const&) = default

Creates a new SamplerState initialized to the default values.

static std::string format_filter_type(SamplerState::FilterType ft)

Returns the indicated FilterType converted to a string word.

static std::string format_wrap_mode(SamplerState::WrapMode wm)

Returns the indicated WrapMode converted to a string word.

int get_anisotropic_degree(void) const

Returns the degree of anisotropic filtering that should be applied to the texture. This value may return 0, indicating the default value; see also get_effective_anisotropic_degree.

LColor const &get_border_color(void) const

Returns the solid color of the texture’s border. Some OpenGL implementations use a border for tiling textures; in Panda, it is only used for specifying the clamp color.

static TypeHandle get_class_type(void)
SamplerState const &get_default(void)

Returns a reference to the global default immutable SamplerState object.

int get_effective_anisotropic_degree(void) const

Returns the degree of anisotropic filtering that should be applied to the texture. This value will normally not return 0, unless there is an error in the config file.

FilterType get_effective_magfilter(void) const

Returns the filter mode of the texture for magnification, with special treatment for FT_default. This will normally not return FT_default, unless there is an error in the config file.

FilterType get_effective_minfilter(void) const

Returns the filter mode of the texture for minification, with special treatment for FT_default. This will normally not return FT_default, unless there is an error in the config file.

PN_stdfloat get_lod_bias(void) const

Returns the bias that will be added to the texture level of detail when sampling this texture.

FilterType get_magfilter(void) const

Returns the filter mode of the texture for magnification. The mipmap constants are invalid here. This may return FT_default; see also get_effective_minfilter().

PN_stdfloat get_max_lod(void) const

Returns the maximum level of detail that will be observed when sampling this texture.

PN_stdfloat get_min_lod(void) const

Returns the minimum level of detail that will be observed when sampling this texture.

FilterType get_minfilter(void) const

Returns the filter mode of the texture for minification. If this is one of the mipmap constants, then the texture requires mipmaps. This may return FT_default; see also get_effective_minfilter().

WrapMode get_wrap_u(void) const

Returns the wrap mode of the texture in the U direction.

WrapMode get_wrap_v(void) const

Returns the wrap mode of the texture in the V direction.

WrapMode get_wrap_w(void) const

Returns the wrap mode of the texture in the W direction. This is the depth direction of 3-d textures.

bool is_mipmap(SamplerState::FilterType type)

Returns true if the indicated filter type requires the use of mipmaps, or false if it does not.

bool is_prepared(PreparedGraphicsObjects *prepared_objects) const

Returns true if the sampler has already been prepared or enqueued for preparation on the indicated GSG, false otherwise.

void prepare(PreparedGraphicsObjects *prepared_objects) const

Indicates that the sampler should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame.

Use this function instead of prepare_now() to preload samplers from a user interface standpoint.

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. Returns the new (or old) SamplerContext. This assumes that the GraphicsStateGuardian is the currently active rendering context and that it is ready to accept new textures. If this is not necessarily the case, you should use prepare() instead.

Normally, this is not called directly except by the GraphicsStateGuardian; a sampler does not need to be explicitly prepared by the user before it may be rendered.

void release(PreparedGraphicsObjects *prepared_objects) const

Frees the texture context only on the indicated object, if it exists there. Returns true if it was released, false if it had not been prepared.

void set_anisotropic_degree(int anisotropic_degree)

Specifies the level of anisotropic filtering to apply to the SamplerState. Set this 0 to indicate the default value, which is specified in the SamplerState-anisotropic-degree config variable.

To explicitly disable anisotropic filtering, set this value to 1. To explicitly enable anisotropic filtering, set it to a value higher than 1; larger numbers indicate greater degrees of filtering.

void set_border_color(LColor const &color)

Specifies the solid color of the SamplerState’s border. Some OpenGL implementations use a border for tiling SamplerStates; in Panda, it is only used for specifying the clamp color.

void set_lod_bias(PN_stdfloat lod_bias)

Sets the value that will be added to the level of detail when sampling the texture. This may be a negative value, although some graphics hardware may not support the use of negative LOD values.

void set_magfilter(SamplerState::FilterType filter)

Sets the filtering method that should be used when viewing the SamplerState up close.

void set_max_lod(PN_stdfloat max_lod)

Sets the maximum level of detail that will be used when sampling this texture. This may exceed the number of mipmap levels that the texture has.

void set_min_lod(PN_stdfloat min_lod)

Sets the minimum level of detail that will be used when sampling this texture. This may be a negative value.

void set_minfilter(SamplerState::FilterType filter)

Sets the filtering method that should be used when viewing the SamplerState from a distance.

void set_wrap_u(SamplerState::WrapMode wrap)

This setting determines what happens when the SamplerState is sampled with a U value outside the range 0.0-1.0. The default is WM_repeat, which indicates that the SamplerState should repeat indefinitely.

void set_wrap_v(SamplerState::WrapMode wrap)

This setting determines what happens when the SamplerState is sampled with a V value outside the range 0.0-1.0. The default is WM_repeat, which indicates that the SamplerState should repeat indefinitely.

void set_wrap_w(SamplerState::WrapMode wrap)

The W wrap direction is only used for 3-d SamplerStates.

static FilterType string_filter_type(std::string const &str)

Returns the FilterType value associated with the given string representation, or FT_invalid if the string does not match any known FilterType value.

static WrapMode string_wrap_mode(std::string const &str)

Returns the WrapMode value associated with the given string representation, or WM_invalid if the string does not match any known WrapMode value.

bool uses_mipmaps(void) const

Returns true if the minfilter settings on this sampler indicate the use of mipmapping, false otherwise.