Panda3D
 All Classes Functions Variables Enumerations
Public Types | Public Member Functions | Static Public Member Functions | 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
 Returns the degree of anisotropic filtering that should be applied to the texture. More...
 
const LColorget_border_color () const
 Returns the solid color of the texture's border. More...
 
int get_effective_anisotropic_degree () const
 Returns the degree of anisotropic filtering that should be applied to the texture. More...
 
FilterType get_effective_magfilter () const
 Returns the filter mode of the texture for magnification, with special treatment for FT_default. More...
 
FilterType get_effective_minfilter () const
 Returns the filter mode of the texture for minification, with special treatment for FT_default. More...
 
PN_stdfloat get_lod_bias () const
 Returns the bias that will be added to the texture level of detail when sampling this texture. More...
 
FilterType get_magfilter () const
 Returns the filter mode of the texture for magnification. More...
 
PN_stdfloat get_max_lod () const
 Returns the maximum level of detail that will be observed when sampling this texture. More...
 
PN_stdfloat get_min_lod () const
 Returns the minimum level of detail that will be observed when sampling this texture. More...
 
FilterType get_minfilter () const
 Returns the filter mode of the texture for minification. More...
 
WrapMode get_wrap_u () const
 Returns the wrap mode of the texture in the U direction. More...
 
WrapMode get_wrap_v () const
 Returns the wrap mode of the texture in the V direction. More...
 
WrapMode get_wrap_w () const
 Returns the wrap mode of the texture in the W direction. More...
 
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 (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)
 Specifies the level of anisotropic filtering to apply to the SamplerState. More...
 
void set_border_color (const LColor &color)
 Specifies the solid color of the SamplerState's border. More...
 
void set_lod_bias (PN_stdfloat lod_bias)
 Sets the value that will be added to the level of detail when sampling the texture. More...
 
void set_magfilter (FilterType filter)
 Sets the filtering method that should be used when viewing the SamplerState up close. More...
 
void set_max_lod (PN_stdfloat max_lod)
 Sets the maximum level of detail that will be used when sampling this texture. More...
 
void set_min_lod (PN_stdfloat min_lod)
 Sets the minimum level of detail that will be used when sampling this texture. More...
 
void set_minfilter (FilterType filter)
 Sets the filtering method that should be used when viewing the SamplerState from a distance. More...
 
void set_wrap_u (WrapMode wrap)
 This setting determines what happens when the SamplerState is sampled with a U value outside the range 0.0-1.0. More...
 
void set_wrap_v (WrapMode wrap)
 This setting determines what happens when the SamplerState is sampled with a V value outside the range 0.0-1.0. More...
 
void set_wrap_w (WrapMode wrap)
 The W wrap direction is only used for 3-d SamplerStates. More...
 
bool uses_mipmaps () const
 Returns true if the minfilter settings on this sampler indicate the use of mipmapping, false otherwise. More...
 
void write (ostream &out, int indent) const
 
void write_datagram (Datagram &destination) const
 Encodes the sampler state into a datagram. More...
 

Static Public Member Functions

static string format_filter_type (FilterType ft)
 Returns the indicated FilterType converted to a string word. More...
 
static 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 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 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...
 

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 39 of file samplerState.h.

Constructor & Destructor Documentation

SamplerState::SamplerState ( )
inline

Creates a new SamplerState initialized to the default values.

Definition at line 23 of file samplerState.I.

Member Function Documentation

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 282 of file samplerState.cxx.

string SamplerState::format_filter_type ( FilterType  ft)
static

Returns the indicated FilterType converted to a string word.

Definition at line 96 of file samplerState.cxx.

string SamplerState::format_wrap_mode ( WrapMode  wm)
static

Returns the indicated WrapMode converted to a string word.

Definition at line 163 of file samplerState.cxx.

int SamplerState::get_anisotropic_degree ( ) const
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 244 of file samplerState.I.

const LColor & SamplerState::get_border_color ( ) const
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 273 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

const SamplerState & SamplerState::get_default ( )
inlinestatic

Returns a reference to the global default immutable SamplerState object.

Definition at line 44 of file samplerState.I.

Referenced by TextureAttrib::get_on_sampler(), ShaderAttrib::get_shader_input_sampler(), and NodePath::get_texture_sampler().

int SamplerState::get_effective_anisotropic_degree ( ) const
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 257 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

SamplerState::FilterType SamplerState::get_effective_magfilter ( ) 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.

Definition at line 82 of file samplerState.cxx.

Referenced by DXGraphicsStateGuardian9::apply_texture().

SamplerState::FilterType SamplerState::get_effective_minfilter ( ) 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.

Definition at line 66 of file samplerState.cxx.

Referenced by DXGraphicsStateGuardian9::apply_texture(), and uses_mipmaps().

PN_stdfloat SamplerState::get_lod_bias ( ) const
inline

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

Definition at line 306 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

SamplerState::FilterType SamplerState::get_magfilter ( ) const
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 231 of file samplerState.I.

PN_stdfloat SamplerState::get_max_lod ( ) const
inline

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

Definition at line 295 of file samplerState.I.

PN_stdfloat SamplerState::get_min_lod ( ) const
inline

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

Definition at line 284 of file samplerState.I.

SamplerState::FilterType SamplerState::get_minfilter ( ) const
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 218 of file samplerState.I.

SamplerState::WrapMode SamplerState::get_wrap_u ( ) const
inline

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

Definition at line 181 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

SamplerState::WrapMode SamplerState::get_wrap_v ( ) const
inline

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

Definition at line 192 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

SamplerState::WrapMode SamplerState::get_wrap_w ( ) const
inline

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

This is the depth direction of 3-d textures.

Definition at line 204 of file samplerState.I.

Referenced by DXGraphicsStateGuardian9::apply_texture().

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 329 of file samplerState.I.

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

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 233 of file samplerState.cxx.

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

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 221 of file samplerState.cxx.

References PreparedGraphicsObjects::enqueue_sampler().

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 267 of file samplerState.cxx.

References PreparedGraphicsObjects::prepare_sampler_now().

Referenced by PreparedGraphicsObjects::begin_frame().

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 380 of file samplerState.cxx.

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

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 246 of file samplerState.cxx.

References PreparedGraphicsObjects::release_sampler().

void SamplerState::set_anisotropic_degree ( int  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 120 of file samplerState.I.

void SamplerState::set_border_color ( const LColor 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 133 of file samplerState.I.

void SamplerState::set_lod_bias ( PN_stdfloat  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 170 of file samplerState.I.

void SamplerState::set_magfilter ( SamplerState::FilterType  filter)
inline

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

Definition at line 102 of file samplerState.I.

void SamplerState::set_max_lod ( PN_stdfloat  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 157 of file samplerState.I.

void SamplerState::set_min_lod ( PN_stdfloat  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 145 of file samplerState.I.

void SamplerState::set_minfilter ( SamplerState::FilterType  filter)
inline

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

Definition at line 91 of file samplerState.I.

void SamplerState::set_wrap_u ( SamplerState::WrapMode  wrap)
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 57 of file samplerState.I.

void SamplerState::set_wrap_v ( SamplerState::WrapMode  wrap)
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 70 of file samplerState.I.

void SamplerState::set_wrap_w ( SamplerState::WrapMode  wrap)
inline

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

Definition at line 80 of file samplerState.I.

SamplerState::FilterType SamplerState::string_filter_type ( const 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 132 of file samplerState.cxx.

SamplerState::WrapMode SamplerState::string_wrap_mode ( const 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 191 of file samplerState.cxx.

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 318 of file samplerState.I.

References get_effective_minfilter(), and is_mipmap().

void SamplerState::write_datagram ( Datagram destination) const

Encodes the sampler state into a datagram.

Definition at line 360 of file samplerState.cxx.

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

Referenced by ParamTextureSampler::write_datagram().


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