Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
SamplerState Class Reference

Represents a set of settings that indicate how a texture is sampled. More...

#include "samplerState.h"

Public Types

enum  FilterType {
  FT_nearest, FT_linear, FT_nearest_mipmap_nearest, FT_linear_mipmap_nearest,
  FT_nearest_mipmap_linear, FT_linear_mipmap_linear, FT_shadow, FT_default,
  FT_invalid
}
 
enum  WrapMode {
  WM_clamp, WM_repeat, WM_mirror, WM_mirror_once,
  WM_border_color, WM_invalid
}
 

Public Member Functions

 SamplerState ()
 Creates a new SamplerState initialized to the default values. More...
 
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 sorts after, or zero if they are equivalent. More...
 
int get_anisotropic_degree () const
 
const LColor & get_border_color () const
 
int get_effective_anisotropic_degree () const
 
FilterType get_effective_magfilter () const
 
FilterType get_effective_minfilter () const
 
PN_stdfloat get_lod_bias () const
 
FilterType get_magfilter () const
 
PN_stdfloat get_max_lod () const
 
PN_stdfloat get_min_lod () const
 
FilterType get_minfilter () const
 
WrapMode get_wrap_u () const
 
WrapMode get_wrap_v () const
 
WrapMode get_wrap_w () const
 
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. More...
 
bool operator != (const SamplerState &other) const
 
bool operator< (const SamplerState &other) const
 
bool operator== (const SamplerState &other) const
 
void output (std::ostream &out) const
 
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. More...
 
SamplerContextprepare_now (PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg) const
 Creates a context for the sampler on the particular GSG, if it does not already exist. More...
 
void read_datagram (DatagramIterator &source, BamReader *manager)
 Reads the sampler state from the datagram that has been previously written using write_datagram. More...
 
void release (PreparedGraphicsObjects *prepared_objects) const
 Frees the texture context only on the indicated object, if it exists there. More...
 
void set_anisotropic_degree (int anisotropic_degree)
 
void set_border_color (const LColor &color)
 
void set_lod_bias (PN_stdfloat lod_bias)
 
void set_magfilter (FilterType filter)
 
void set_max_lod (PN_stdfloat max_lod)
 
void set_min_lod (PN_stdfloat min_lod)
 
void set_minfilter (FilterType filter)
 
void set_wrap_u (WrapMode wrap)
 
void set_wrap_v (WrapMode wrap)
 
void set_wrap_w (WrapMode wrap)
 
bool uses_mipmaps () const
 Returns true if the minfilter settings on this sampler indicate the use of mipmapping, false otherwise. More...
 
void write (std::ostream &out, int indent) const
 
void write_datagram (Datagram &destination) const
 Encodes the sampler state into a datagram. More...
 

Static Public Member Functions

static std::string format_filter_type (FilterType ft)
 Returns the indicated FilterType converted to a string word. More...
 
static std::string format_wrap_mode (WrapMode wm)
 Returns the indicated WrapMode converted to a string word. More...
 
static TypeHandle get_class_type ()
 
static const SamplerStateget_default ()
 Returns a reference to the global default immutable SamplerState object. More...
 
static void init_type ()
 
static bool is_mipmap (FilterType type)
 Returns true if the indicated filter type requires the use of mipmaps, or false if it does not. More...
 
static FilterType string_filter_type (const std::string &str)
 Returns the FilterType value associated with the given string representation, or FT_invalid if the string does not match any known FilterType value. More...
 
static WrapMode string_wrap_mode (const std::string &str)
 Returns the WrapMode value associated with the given string representation, or WM_invalid if the string does not match any known WrapMode value. More...
 

Public Attributes

 get_anisotropic_degree
 Returns the degree of anisotropic filtering that should be applied to the texture. More...
 
 get_border_color
 Returns the solid color of the texture's border. More...
 
 get_effective_anisotropic_degree
 Returns the degree of anisotropic filtering that should be applied to the texture. More...
 
 get_effective_magfilter
 Returns the filter mode of the texture for magnification, with special treatment for FT_default. More...
 
 get_effective_minfilter
 Returns the filter mode of the texture for minification, with special treatment for FT_default. More...
 
 get_lod_bias
 Returns the bias that will be added to the texture level of detail when sampling this texture. More...
 
 get_magfilter
 Returns the filter mode of the texture for magnification. More...
 
 get_max_lod
 Returns the maximum level of detail that will be observed when sampling this texture. More...
 
 get_min_lod
 Returns the minimum level of detail that will be observed when sampling this texture. More...
 
 get_minfilter
 Returns the filter mode of the texture for minification. More...
 
 get_wrap_u
 Returns the wrap mode of the texture in the U direction. More...
 
 get_wrap_v
 Returns the wrap mode of the texture in the V direction. More...
 
 get_wrap_w
 Returns the wrap mode of the texture in the W direction. More...
 
 set_anisotropic_degree
 Specifies the level of anisotropic filtering to apply to the SamplerState. More...
 
 set_border_color
 Specifies the solid color of the SamplerState's border. More...
 
 set_lod_bias
 Sets the value that will be added to the level of detail when sampling the texture. More...
 
 set_magfilter
 Sets the filtering method that should be used when viewing the SamplerState up close. More...
 
 set_max_lod
 Sets the maximum level of detail that will be used when sampling this texture. More...
 
 set_min_lod
 Sets the minimum level of detail that will be used when sampling this texture. More...
 
 set_minfilter
 Sets the filtering method that should be used when viewing the SamplerState from a distance. More...
 
 set_wrap_u
 This setting determines what happens when the SamplerState is sampled with a U value outside the range 0.0-1.0. More...
 
 set_wrap_v
 This setting determines what happens when the SamplerState is sampled with a V value outside the range 0.0-1.0. More...
 
 set_wrap_w
 The W wrap direction is only used for 3-d SamplerStates. More...
 

Detailed Description

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.

Definition at line 36 of file samplerState.h.

Constructor & Destructor Documentation

◆ SamplerState()

SamplerState::SamplerState ( )
inline

Creates a new SamplerState initialized to the default values.

Definition at line 18 of file samplerState.I.

Member Function Documentation

◆ compare_to()

int SamplerState::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 sorts after, or zero if they are equivalent.

The sorting order is arbitrary and largely meaningless, except to differentiate different sampler states.

Definition at line 249 of file samplerState.cxx.

◆ format_filter_type()

string SamplerState::format_filter_type ( FilterType  ft)
static

Returns the indicated FilterType converted to a string word.

Definition at line 88 of file samplerState.cxx.

◆ format_wrap_mode()

string SamplerState::format_wrap_mode ( WrapMode  wm)
static

Returns the indicated WrapMode converted to a string word.

Definition at line 150 of file samplerState.cxx.

◆ get_default()

const SamplerState & SamplerState::get_default ( )
inlinestatic

Returns a reference to the global default immutable SamplerState object.

Definition at line 36 of file samplerState.I.

◆ is_mipmap()

bool SamplerState::is_mipmap ( FilterType  type)
inlinestatic

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

Definition at line 257 of file samplerState.I.

Referenced by uses_mipmaps(), and Texture::uses_mipmaps().

◆ is_prepared()

bool SamplerState::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.

Definition at line 211 of file samplerState.cxx.

References PreparedGraphicsObjects::is_sampler_prepared(), and PreparedGraphicsObjects::is_sampler_queued().

◆ prepare()

void SamplerState::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.

Definition at line 202 of file samplerState.cxx.

References PreparedGraphicsObjects::enqueue_sampler().

◆ prepare_now()

SamplerContext * SamplerState::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.

Definition at line 237 of file samplerState.cxx.

References PreparedGraphicsObjects::prepare_sampler_now().

Referenced by PreparedGraphicsObjects::begin_frame().

◆ read_datagram()

void SamplerState::read_datagram ( DatagramIterator source,
BamReader manager 
)

Reads the sampler state from the datagram that has been previously written using write_datagram.

Definition at line 339 of file samplerState.cxx.

References BamReader::get_file_minor_ver(), DatagramIterator::get_int16(), DatagramIterator::get_stdfloat(), and DatagramIterator::get_uint8().

◆ release()

void SamplerState::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.

Definition at line 221 of file samplerState.cxx.

References PreparedGraphicsObjects::release_sampler().

◆ string_filter_type()

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

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

Definition at line 122 of file samplerState.cxx.

◆ string_wrap_mode()

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

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

Definition at line 175 of file samplerState.cxx.

◆ uses_mipmaps()

bool SamplerState::uses_mipmaps ( ) const
inline

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

Definition at line 248 of file samplerState.I.

References get_effective_minfilter, and is_mipmap().

◆ write_datagram()

void SamplerState::write_datagram ( Datagram destination) const

Encodes the sampler state into a datagram.

Definition at line 321 of file samplerState.cxx.

References Datagram::add_int16(), Datagram::add_stdfloat(), and Datagram::add_uint8().

Referenced by ParamTextureSampler::write_datagram().

Member Data Documentation

◆ get_anisotropic_degree

int SamplerState::get_anisotropic_degree
inline

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.

Definition at line 119 of file samplerState.h.

◆ get_border_color

const LColor & SamplerState::get_border_color
inline

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.

Definition at line 121 of file samplerState.h.

◆ get_effective_anisotropic_degree

int SamplerState::get_effective_anisotropic_degree
inline

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.

Definition at line 120 of file samplerState.h.

◆ get_effective_magfilter

SamplerState::FilterType SamplerState::get_effective_magfilter

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.

Definition at line 118 of file samplerState.h.

◆ get_effective_minfilter

SamplerState::FilterType SamplerState::get_effective_minfilter

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.

Definition at line 117 of file samplerState.h.

Referenced by uses_mipmaps().

◆ get_lod_bias

PN_stdfloat SamplerState::get_lod_bias
inline

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

Definition at line 124 of file samplerState.h.

◆ get_magfilter

SamplerState::FilterType SamplerState::get_magfilter
inline

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().

Definition at line 116 of file samplerState.h.

◆ get_max_lod

PN_stdfloat SamplerState::get_max_lod
inline

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

Definition at line 123 of file samplerState.h.

◆ get_min_lod

PN_stdfloat SamplerState::get_min_lod
inline

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

Definition at line 122 of file samplerState.h.

◆ get_minfilter

SamplerState::FilterType SamplerState::get_minfilter
inline

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().

Definition at line 115 of file samplerState.h.

◆ get_wrap_u

SamplerState::WrapMode SamplerState::get_wrap_u
inline

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

Definition at line 112 of file samplerState.h.

◆ get_wrap_v

SamplerState::WrapMode SamplerState::get_wrap_v
inline

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

Definition at line 113 of file samplerState.h.

◆ get_wrap_w

SamplerState::WrapMode SamplerState::get_wrap_w
inline

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

This is the depth direction of 3-d textures.

Definition at line 114 of file samplerState.h.

◆ set_anisotropic_degree

void SamplerState::set_anisotropic_degree
inline

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.

Definition at line 119 of file samplerState.h.

◆ set_border_color

void SamplerState::set_border_color
inline

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.

Definition at line 121 of file samplerState.h.

◆ set_lod_bias

void SamplerState::set_lod_bias
inline

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.

Definition at line 124 of file samplerState.h.

◆ set_magfilter

void SamplerState::set_magfilter
inline

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

Definition at line 116 of file samplerState.h.

◆ set_max_lod

void SamplerState::set_max_lod
inline

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.

Definition at line 123 of file samplerState.h.

◆ set_min_lod

void SamplerState::set_min_lod
inline

Sets the minimum level of detail that will be used when sampling this texture.

This may be a negative value.

Definition at line 122 of file samplerState.h.

◆ set_minfilter

void SamplerState::set_minfilter
inline

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

Definition at line 115 of file samplerState.h.

◆ set_wrap_u

void SamplerState::set_wrap_u
inline

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.

Definition at line 112 of file samplerState.h.

◆ set_wrap_v

void SamplerState::set_wrap_v
inline

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.

Definition at line 113 of file samplerState.h.

◆ set_wrap_w

void SamplerState::set_wrap_w
inline

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

Definition at line 114 of file samplerState.h.


The documentation for this class was generated from the following files: