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

This represents a unique collection of RenderAttrib objects that correspond to a particular renderable state. More...

Inheritance diagram for RenderState:
NodeCachedReferenceCount CachedTypedWritableReferenceCount TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject

Public Member Functions

const RenderState addAttrib (const RenderAttrib attrib, int override)
 Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added. More...
 
const RenderState adjustAllPriorities (int adjustment)
 Returns a new RenderState object that represents the same as the source state, with all attributes' override values incremented (or decremented, if negative) by the indicated amount. More...
 
 cacheRef ()
 Overrides this method to update PStats appropriately. More...
 
bool cacheUnref ()
 Overrides this method to update PStats appropriately. More...
 
int compareMask (const RenderState other, RenderState::SlotMask compare_mask)
 This version of compare_to takes a slot mask that indicates which attributes to include in the comparison. More...
 
int compareSort (const RenderState other)
 Returns -1, 0, or 1 according to the relative sorting of these two RenderStates, with regards to rendering performance, so that "heavier" RenderAttribs (as defined by RenderAttribRegistry::get_slot_sort()) are more likely to be grouped together. More...
 
int compareTo (const RenderState other)
 Provides an arbitrary ordering among all unique RenderStates, so we can store the essentially different ones in a big set and throw away the rest. More...
 
const RenderState compose (const RenderState other)
 Returns a new RenderState object that represents the composition of this state with the other state. More...
 
bool cullCallback (CullTraverser trav, const CullTraverserData data)
 Calls cull_callback() on each attrib. More...
 
const RenderAttrib getAttrib (TypeHandle type)
 Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found, or NULL if it is not. More...
 
const RenderAttrib getAttrib (int slot)
 Returns the RenderAttrib with the indicated slot index, or NULL if there is no such RenderAttrib in the state. More...
 
const RenderAttrib getAttribDef (int slot)
 Returns the RenderAttrib with the indicated slot index, or the default attrib for that slot if there is no such RenderAttrib in the state. More...
 
int getBinIndex ()
 Returns the bin index indicated by the CullBinAttrib, if any, associated by this state (or the default bin index if there is no CullBinAttrib). More...
 
object getCompositionCache ()
 
int getCompositionCacheNumEntries ()
 Returns the number of entries in the composition cache for this RenderState. More...
 
const RenderState getCompositionCacheResult (int n)
 Returns the result RenderState of the nth element in the composition cache. More...
 
int getCompositionCacheSize ()
 Returns the number of slots in the composition cache for this RenderState. More...
 
const RenderState getCompositionCacheSource (int n)
 Returns the source RenderState of the nth element in the composition cache. More...
 
int getDrawOrder ()
 Returns the draw order indicated by the CullBinAttrib, if any, associated by this state (or 0 if there is no CullBinAttrib). More...
 
int getGeomRendering (int geom_rendering)
 Returns the union of the Geom::GeomRendering bits that will be required once this RenderState is applied to a geom which includes the indicated geom_rendering bits. More...
 
int getHash ()
 Returns a suitable hash value for phash_map. More...
 
object getInvertCompositionCache ()
 
int getInvertCompositionCacheNumEntries ()
 Returns the number of entries in the invert_composition cache for this RenderState. More...
 
const RenderState getInvertCompositionCacheResult (int n)
 Returns the result RenderState of the nth element in the invert composition cache. More...
 
int getInvertCompositionCacheSize ()
 Returns the number of slots in the composition cache for this RenderState. More...
 
const RenderState getInvertCompositionCacheSource (int n)
 Returns the source RenderState of the nth element in the invert composition cache. More...
 
int getOverride (TypeHandle type)
 Looks for a RenderAttrib of the indicated type in the state, and returns its override value if it is found, or 0 if it is not. More...
 
int getOverride (int slot)
 Looks for a RenderAttrib of the indicated type in the state, and returns its override value if it is found, or 0 if it is not. More...
 
const RenderState getUnique ()
 Returns the pointer to the unique RenderState in the cache that is equivalent to this one. More...
 
bool hasAttrib (TypeHandle type)
 Returns true if an attrib of the indicated type is present, false otherwise. More...
 
bool hasAttrib (int slot)
 Returns true if an attrib of the indicated type is present, false otherwise. More...
 
bool hasCullCallback ()
 Returns true if any of the RenderAttribs in this state request a cull_callback(), false if none of them do. More...
 
const RenderState invertCompose (const RenderState other)
 Returns a new RenderState object that represents the composition of this state's inverse with the other state. More...
 
bool isEmpty ()
 Returns true if the state is empty, false otherwise. More...
 
 nodeRef ()
 Overrides this method to update PStats appropriately. More...
 
bool nodeUnref ()
 Overrides this method to update PStats appropriately. More...
 
 output (Ostream out)
 
const RenderState removeAttrib (TypeHandle type)
 Returns a new RenderState object that represents the same as the source state, with the indicated RenderAttrib removed. More...
 
const RenderState removeAttrib (int slot)
 Returns a new RenderState object that represents the same as the source state, with the indicated RenderAttrib removed. More...
 
const RenderState setAttrib (const RenderAttrib attrib)
 Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added. More...
 
const RenderState setAttrib (const RenderAttrib attrib, int override)
 Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added. More...
 
 write (Ostream out, int indent_level)
 
- Public Member Functions inherited from NodeCachedReferenceCount
int getNodeRefCount ()
 Returns the current reference count. More...
 
int getReferencedBits ()
 Returns the union of the values defined in the Referenced enum that represents the various things that appear to be holding a pointer to this object. More...
 
 nodeRef ()
 Explicitly increments the reference count. More...
 
bool nodeUnref ()
 Explicitly decrements the node reference count and the normal reference count simultaneously. More...
 
bool testRefCountIntegrity ()
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
- Public Member Functions inherited from CachedTypedWritableReferenceCount
 cacheRef ()
 Explicitly increments the cache reference count and the normal reference count simultaneously. More...
 
bool cacheUnref ()
 Explicitly decrements the cache reference count and the normal reference count simultaneously. More...
 
int getCacheRefCount ()
 Returns the current reference count. More...
 
bool testRefCountIntegrity ()
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
- Public Member Functions inherited from TypedWritable
object __reduce__ ()
 
object __reduce_persist__ (object pickler)
 
VectorUchar encodeToBamStream ()
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More...
 
bool encodeToBamStream (VectorUchar data, BamWriter writer)
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More...
 
 fillin (DatagramIterator scan, BamReader manager)
 This internal function is intended to be called by each class's make_from_bam() method to read in all of the relevant data from the BamFile for the new object. More...
 
UpdateSeq getBamModified ()
 Returns the current bam_modified counter. More...
 
 markBamModified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More...
 
- Public Member Functions inherited from TypedObject
TypeHandle getType ()
 
int getTypeIndex ()
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool isExactType (TypeHandle handle)
 Returns true if the current object is the indicated type exactly. More...
 
bool isOfType (TypeHandle handle)
 Returns true if the current object is or derives from the indicated type. More...
 
- Public Member Functions inherited from ReferenceCount
int getRefCount ()
 Returns the current reference count. More...
 
 ref ()
 Explicitly increments the reference count. More...
 
bool testRefCountIntegrity ()
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool testRefCountNonzero ()
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
bool unref ()
 Explicitly decrements the reference count. More...
 

Static Public Member Functions

static int clearCache ()
 Empties the cache of composed RenderStates. More...
 
static clearMungerCache ()
 Completely empties the cache of state + gsg -> munger, for all states and all gsg's. More...
 
static int garbageCollect ()
 Performs a garbage-collection cycle. More...
 
static TypeHandle getClassType ()
 
static int getMaxPriority ()
 Returns the maximum priority number (sometimes called override) that may be set on any node. More...
 
static int getNumStates ()
 Returns the total number of unique RenderState objects allocated in the world. More...
 
static int getNumUnusedStates ()
 Returns the total number of RenderState objects that have been allocated but have no references outside of the internal RenderState cache. More...
 
static object getStates ()
 
static listCycles (Ostream out)
 Detects all of the reference-count cycles in the cache and reports them to standard output. More...
 
static listStates (Ostream out)
 Lists all of the RenderStates in the cache to the output stream, one per line. More...
 
static const RenderState make (const RenderAttrib attrib1, const RenderAttrib attrib2, const RenderAttrib attrib3, const RenderAttrib attrib4, const RenderAttrib attrib5, int override)
 Returns a RenderState with five attributes set. More...
 
static const RenderState make (const RenderAttrib attrib1, const RenderAttrib attrib2, const RenderAttrib attrib3, const RenderAttrib attrib4, int override)
 Returns a RenderState with four attributes set. More...
 
static const RenderState make (const RenderAttrib attrib1, const RenderAttrib attrib2, const RenderAttrib attrib3, int override)
 Returns a RenderState with three attributes set. More...
 
static const RenderState make (const RenderAttrib attrib1, const RenderAttrib attrib2, int override)
 Returns a RenderState with two attributes set. More...
 
static const RenderState make (const RenderAttrib attrib, int override)
 Returns a RenderState with one attribute set. More...
 
static const RenderState makeEmpty ()
 Returns a RenderState with no attributes set. More...
 
static bool validateStates ()
 Ensures that the cache is still stored in sorted order, and that none of the cache elements have been inadvertently deleted. More...
 
- Static Public Member Functions inherited from NodeCachedReferenceCount
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from CachedTypedWritableReferenceCount
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedWritableReferenceCount
static TypedWritableReferenceCount decodeFromBamStream (VectorUchar data, BamReader reader)
 Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts and returns the single object on those bytes. More...
 
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedWritable
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle getClassType ()
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle getClassType ()
 

Public Attributes

const RenderAttrib attribs []
 
- Public Attributes inherited from CachedTypedWritableReferenceCount
int cache_ref_count
 Returns the current reference count. More...
 
- Public Attributes inherited from TypedObject
TypeHandle type
 Returns the TypeHandle representing this object's type. More...
 
- Public Attributes inherited from ReferenceCount
int ref_count
 The current reference count. More...
 

Additional Inherited Members

- Public Types inherited from NodeCachedReferenceCount
enum  Referenced { R_node = 1, R_cache = 2 }
 

Detailed Description

This represents a unique collection of RenderAttrib objects that correspond to a particular renderable state.

You should not attempt to create or modify a RenderState object directly. Instead, call one of the make() functions to create one for you. And instead of modifying a RenderState object, create a new one.

Member Function Documentation

◆ addAttrib()

const RenderState addAttrib ( const RenderAttrib  attrib,
int  override 
)

Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added.

If there is already a RenderAttrib with the same type, it is replaced (unless the override is lower).

◆ adjustAllPriorities()

const RenderState adjustAllPriorities ( int  adjustment)

Returns a new RenderState object that represents the same as the source state, with all attributes' override values incremented (or decremented, if negative) by the indicated amount.

If the override would drop below zero, it is set to zero.

◆ cacheRef()

cacheRef ( )

Overrides this method to update PStats appropriately.

◆ cacheUnref()

bool cacheUnref ( )

Overrides this method to update PStats appropriately.

◆ clearCache()

static int clearCache ( )
static

Empties the cache of composed RenderStates.

This makes every RenderState forget what results when it is composed with other RenderStates.

This will eliminate any RenderState objects that have been allocated but have no references outside of the internal RenderState map. It will not eliminate RenderState objects that are still in use.

Nowadays, this method should not be necessary, as reference-count cycles in the composition cache should be automatically detected and broken.

The return value is the number of RenderStates freed by this operation.

◆ clearMungerCache()

static clearMungerCache ( )
static

Completely empties the cache of state + gsg -> munger, for all states and all gsg's.

Normally there is no need to empty this cache.

◆ compareMask()

int compareMask ( const RenderState  other,
RenderState::SlotMask  compare_mask 
)

This version of compare_to takes a slot mask that indicates which attributes to include in the comparison.

Unlike compare_to, this method compares the attributes by pointer.

◆ compareSort()

int compareSort ( const RenderState  other)

Returns -1, 0, or 1 according to the relative sorting of these two RenderStates, with regards to rendering performance, so that "heavier" RenderAttribs (as defined by RenderAttribRegistry::get_slot_sort()) are more likely to be grouped together.

This is not related to the sorting order defined by compare_to.

◆ compareTo()

int compareTo ( const RenderState  other)

Provides an arbitrary ordering among all unique RenderStates, so we can store the essentially different ones in a big set and throw away the rest.

This method is not needed outside of the RenderState class because all equivalent RenderState objects are guaranteed to share the same pointer; thus, a pointer comparison is always sufficient.

◆ compose()

const RenderState compose ( const RenderState  other)

Returns a new RenderState object that represents the composition of this state with the other state.

The result of this operation is cached, and will be retained as long as both this RenderState object and the other RenderState object continue to exist. Should one of them destruct, the cached entry will be removed, and its pointer will be allowed to destruct as well.

◆ cullCallback()

bool cullCallback ( CullTraverser  trav,
const CullTraverserData  data 
)

Calls cull_callback() on each attrib.

If any attrib returns false, interrupts the list and returns false immediately; otherwise, completes the list and returns true.

◆ garbageCollect()

static int garbageCollect ( )
static

Performs a garbage-collection cycle.

This must be called periodically if garbage-collect-states is true to ensure that RenderStates get cleaned up appropriately. It does no harm to call it even if this variable is not true, but there is probably no advantage in that case.

This automatically calls RenderAttrib::garbage_collect() as well.

◆ getAttrib() [1/2]

const RenderAttrib getAttrib ( TypeHandle  type)

Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found, or NULL if it is not.

◆ getAttrib() [2/2]

const RenderAttrib getAttrib ( int  slot)

Returns the RenderAttrib with the indicated slot index, or NULL if there is no such RenderAttrib in the state.

◆ getAttribDef()

const RenderAttrib getAttribDef ( int  slot)

Returns the RenderAttrib with the indicated slot index, or the default attrib for that slot if there is no such RenderAttrib in the state.

◆ getBinIndex()

int getBinIndex ( )

Returns the bin index indicated by the CullBinAttrib, if any, associated by this state (or the default bin index if there is no CullBinAttrib).

This function is provided as an optimization for determining this at render time.

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getCompositionCache()

object getCompositionCache ( )

◆ getCompositionCacheNumEntries()

int getCompositionCacheNumEntries ( )

Returns the number of entries in the composition cache for this RenderState.

This is the number of other RenderStates whose composition with this one has been cached. This number is not useful for any practical reason other than performance analysis.

◆ getCompositionCacheResult()

const RenderState getCompositionCacheResult ( int  n)

Returns the result RenderState of the nth element in the composition cache.

Returns NULL if there doesn't happen to be an entry in the nth element.

In general, a->compose(a->get_composition_cache_source(n)) == a->get_composition_cache_result(n).

This has no practical value other than for examining the cache for performance analysis.

◆ getCompositionCacheSize()

int getCompositionCacheSize ( )

Returns the number of slots in the composition cache for this RenderState.

You may use this as an upper bound when walking through all of the composition cache results via get_composition_cache_source() or result().

This has no practical value other than for examining the cache for performance analysis.

◆ getCompositionCacheSource()

const RenderState getCompositionCacheSource ( int  n)

Returns the source RenderState of the nth element in the composition cache.

Returns NULL if there doesn't happen to be an entry in the nth element. See get_composition_cache_result().

This has no practical value other than for examining the cache for performance analysis.

◆ getDrawOrder()

int getDrawOrder ( )

Returns the draw order indicated by the CullBinAttrib, if any, associated by this state (or 0 if there is no CullBinAttrib).

See get_bin_index().

◆ getGeomRendering()

int getGeomRendering ( int  geom_rendering)

Returns the union of the Geom::GeomRendering bits that will be required once this RenderState is applied to a geom which includes the indicated geom_rendering bits.

◆ getHash()

int getHash ( )

Returns a suitable hash value for phash_map.

◆ getInvertCompositionCache()

object getInvertCompositionCache ( )

◆ getInvertCompositionCacheNumEntries()

int getInvertCompositionCacheNumEntries ( )

Returns the number of entries in the invert_composition cache for this RenderState.

This is similar to the composition cache, but it records cache entries for the invert_compose() operation. See get_composition_cache_num_entries().

◆ getInvertCompositionCacheResult()

const RenderState getInvertCompositionCacheResult ( int  n)

Returns the result RenderState of the nth element in the invert composition cache.

Returns NULL if there doesn't happen to be an entry in the nth element.

In general, a->invert_compose(a->get_invert_composition_cache_source(n)) == a->get_invert_composition_cache_result(n).

This has no practical value other than for examining the cache for performance analysis.

◆ getInvertCompositionCacheSize()

int getInvertCompositionCacheSize ( )

Returns the number of slots in the composition cache for this RenderState.

You may use this as an upper bound when walking through all of the composition cache results via get_invert_composition_cache_source() or result().

This has no practical value other than for examining the cache for performance analysis.

◆ getInvertCompositionCacheSource()

const RenderState getInvertCompositionCacheSource ( int  n)

Returns the source RenderState of the nth element in the invert composition cache.

Returns NULL if there doesn't happen to be an entry in the nth element. See get_invert_composition_cache_result().

This has no practical value other than for examining the cache for performance analysis.

◆ getMaxPriority()

static int getMaxPriority ( )
static

Returns the maximum priority number (sometimes called override) that may be set on any node.

This may or may not be enforced, but the scene graph code assumes that no priority numbers will be larger than this, and some effects may not work properly if you use a larger number.

◆ getNumStates()

static int getNumStates ( )
static

Returns the total number of unique RenderState objects allocated in the world.

This will go up and down during normal operations.

◆ getNumUnusedStates()

static int getNumUnusedStates ( )
static

Returns the total number of RenderState objects that have been allocated but have no references outside of the internal RenderState cache.

A nonzero return value is not necessarily indicative of leaked references; it is normal for two RenderState objects, both of which have references held outside the cache, to have to result of their composition stored within the cache. This result will be retained within the cache until one of the base RenderStates is released.

Use list_cycles() to get an idea of the number of actual "leaked" RenderState objects.

◆ getOverride() [1/2]

int getOverride ( TypeHandle  type)

Looks for a RenderAttrib of the indicated type in the state, and returns its override value if it is found, or 0 if it is not.

◆ getOverride() [2/2]

int getOverride ( int  slot)

Looks for a RenderAttrib of the indicated type in the state, and returns its override value if it is found, or 0 if it is not.

◆ getStates()

static object getStates ( )
static

◆ getUnique()

const RenderState getUnique ( )

Returns the pointer to the unique RenderState in the cache that is equivalent to this one.

This may be the same pointer as this object, or it may be a different pointer; but it will be an equivalent object, and it will be a shared pointer. This may be called from time to time to improve cache benefits.

◆ hasAttrib() [1/2]

bool hasAttrib ( TypeHandle  type)

Returns true if an attrib of the indicated type is present, false otherwise.

◆ hasAttrib() [2/2]

bool hasAttrib ( int  slot)

Returns true if an attrib of the indicated type is present, false otherwise.

◆ hasCullCallback()

bool hasCullCallback ( )

Returns true if any of the RenderAttribs in this state request a cull_callback(), false if none of them do.

◆ invertCompose()

const RenderState invertCompose ( const RenderState  other)

Returns a new RenderState object that represents the composition of this state's inverse with the other state.

This is similar to compose(), but is particularly useful for computing the relative state of a node as viewed from some other node.

◆ isEmpty()

bool isEmpty ( )

Returns true if the state is empty, false otherwise.

◆ listCycles()

static listCycles ( Ostream  out)
static

Detects all of the reference-count cycles in the cache and reports them to standard output.

These cycles may be inadvertently created when state compositions cycle back to a starting point. Nowadays, these cycles should be automatically detected and broken, so this method should never list any cycles unless there is a bug in that detection logic.

The cycles listed here are not leaks in the strictest sense of the word, since they can be reclaimed by a call to clear_cache(); but they will not be reclaimed automatically.

◆ listStates()

static listStates ( Ostream  out)
static

Lists all of the RenderStates in the cache to the output stream, one per line.

This can be quite a lot of output if the cache is large, so be prepared.

◆ make() [1/5]

static const RenderState make ( const RenderAttrib  attrib1,
const RenderAttrib  attrib2,
const RenderAttrib  attrib3,
const RenderAttrib  attrib4,
const RenderAttrib  attrib5,
int  override 
)
static

Returns a RenderState with five attributes set.

◆ make() [2/5]

static const RenderState make ( const RenderAttrib  attrib1,
const RenderAttrib  attrib2,
const RenderAttrib  attrib3,
const RenderAttrib  attrib4,
int  override 
)
static

Returns a RenderState with four attributes set.

◆ make() [3/5]

static const RenderState make ( const RenderAttrib  attrib1,
const RenderAttrib  attrib2,
const RenderAttrib  attrib3,
int  override 
)
static

Returns a RenderState with three attributes set.

◆ make() [4/5]

static const RenderState make ( const RenderAttrib  attrib1,
const RenderAttrib  attrib2,
int  override 
)
static

Returns a RenderState with two attributes set.

◆ make() [5/5]

static const RenderState make ( const RenderAttrib  attrib,
int  override 
)
static

Returns a RenderState with one attribute set.

◆ makeEmpty()

static const RenderState makeEmpty ( )
static

Returns a RenderState with no attributes set.

◆ nodeRef()

nodeRef ( )

Overrides this method to update PStats appropriately.

◆ nodeUnref()

bool nodeUnref ( )

Overrides this method to update PStats appropriately.

◆ output()

output ( Ostream  out)

◆ removeAttrib() [1/2]

const RenderState removeAttrib ( TypeHandle  type)

Returns a new RenderState object that represents the same as the source state, with the indicated RenderAttrib removed.

◆ removeAttrib() [2/2]

const RenderState removeAttrib ( int  slot)

Returns a new RenderState object that represents the same as the source state, with the indicated RenderAttrib removed.

◆ setAttrib() [1/2]

const RenderState setAttrib ( const RenderAttrib  attrib)

Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added.

If there is already a RenderAttrib with the same type, it is replaced unconditionally. The override is not changed.

◆ setAttrib() [2/2]

const RenderState setAttrib ( const RenderAttrib  attrib,
int  override 
)

Returns a new RenderState object that represents the same as the source state, with the new RenderAttrib added.

If there is already a RenderAttrib with the same type, it is replaced unconditionally. The override is also replaced unconditionally.

◆ validateStates()

static bool validateStates ( )
static

Ensures that the cache is still stored in sorted order, and that none of the cache elements have been inadvertently deleted.

Returns true if so, false if there is a problem (which implies someone has modified one of the supposedly-const RenderState objects).

◆ write()

write ( Ostream  out,
int  indent_level 
)

Member Data Documentation

◆ attribs

const RenderAttrib attribs[]