# RenderState

from pandac.PandaModules import RenderState

Class : RenderState
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.

## Inheritance:

RenderState: NodeCachedReferenceCount
NodeCachedReferenceCount: CachedTypedWritableReferenceCount
CachedTypedWritableReferenceCount: TypedWritableReferenceCount
TypedWritableReferenceCount: TypedWritable ReferenceCount
TypedWritable: TypedObject
TypedObject: MemoryBase
MemoryBase:
ReferenceCount: MemoryBase

## Methods of RenderState:

addAttrib
adjustAllPriorities
cacheRef
cacheUnref
clearCache
clearMungerCache
compareSort
compose
cullCallback
getAttrib
getAttribDef
getBinIndex
getClassType
getCompositionCache
getCompositionCacheNumEntries
getCompositionCacheResult
getCompositionCacheSize
getCompositionCacheSource
getDrawOrder
getGeomRendering
getHash
getInvertCompositionCache
getInvertCompositionCacheNumEntries
getInvertCompositionCacheResult
getInvertCompositionCacheSize
getInvertCompositionCacheSource
getMaxPriority
getNumStates
getNumUnusedStates
getOverride
getStates
getUnique
hasAttrib
hasCullCallback
invertCompose
isEmpty
listCycles
listStates
make
makeEmpty
makeFullDefault
nodeRef
nodeUnref
operator <
output
removeAttrib
setAttrib
unref
validateStates
write

## Methods of NodeCachedReferenceCount:

getClassType
getNodeRefCount
getReferencedBits
nodeRef
nodeUnref
testRefCountIntegrity

## Methods of CachedTypedWritableReferenceCount:

cacheRef
cacheUnref
getCacheRefCount
getClassType
testRefCountIntegrity

## Methods of TypedWritableReferenceCount:

getClassType

## Methods of TypedWritable:

getClassType

## Methods of TypedObject:

getClassType
getType
getTypeIndex
isExactType
isOfType

## Methods of ReferenceCount:

getClassType
getRefCount
ref
testRefCountIntegrity
testRefCountNonzero
unref

## Constants in NodeCachedReferenceCount:

RNode | (Referenced)
RCache | (Referenced)

addAttrib ConstPointerTo< RenderState > RenderState::add_attrib(RenderAttrib const *attrib, int override = (0)) const; Description: 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 ConstPointerTo< RenderState > RenderState::adjust_all_priorities(int adjustment) const; Description: 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 void RenderState::cache_ref(void) const; Description: Overrides this method to update PStats appropriately.

cacheUnref bool RenderState::cache_unref(void) const; Description: Overrides this method to update PStats appropriately.

clearCache static int RenderState::clear_cache(void); Description: 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 void RenderState::clear_munger_cache(void); Description: Completely empties the cache of state + gsg -> munger, for all states and all gsg's. Normally there is no need to empty this cache.

compareSort int RenderState::compare_sort(RenderState const &other) const; Description: 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 operator <.

compose ConstPointerTo< RenderState > RenderState::compose(RenderState const *other) const; Description: 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 RenderState::cull_callback(CullTraverser *trav, CullTraverserData const &data) const; Description: 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.

getAttrib RenderAttrib const *RenderState::get_attrib(TypeHandle type) const; Description: Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found, or NULL if it is not. Description: Returns the RenderAttrib with the indicated slot index, or NULL if there is no such RenderAttrib in the state.

getAttribDef RenderAttrib const *RenderState::get_attrib_def(int slot) const; Description: 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 RenderState::get_bin_index(void) const; These methods are intended for use by low-level code, but they're also handy enough to expose to high-level users. Description: 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 RenderState::get_class_type(void); Undocumented function.

getCompositionCache PyObject *RenderState::get_composition_cache(void) const; Description: Returns a list of 2-tuples that represents the composition cache. For each tuple in the list, the first element is the source render, and the second is the result render. If both are None, there is no entry in the cache at that slot. In general, a->compose(source) == result. This has no practical value other than for examining the cache for performance analysis.

getCompositionCacheNumEntries int RenderState::get_composition_cache_num_entries(void) const; Description: 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 RenderState const *RenderState::get_composition_cache_result(int n) const; Description: 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 RenderState::get_composition_cache_size(void) const; Description: 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 RenderState const *RenderState::get_composition_cache_source(int n) const; Description: 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 RenderState::get_draw_order(void) const; These methods are intended for use by low-level code, but they're also handy enough to expose to high-level users. Description: 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 RenderState::get_geom_rendering(int geom_rendering) const; Description: 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 unsigned int RenderState::get_hash(void) const; Description: Returns a suitable hash value for phash_map.

getInvertCompositionCache PyObject *RenderState::get_invert_composition_cache(void) const; Description: Returns a list of 2-tuples that represents the invert_composition cache. For each tuple in the list, the first element is the source render, and the second is the result render. If both are None, there is no entry in the cache at that slot. In general, a->invert_compose(source) == result. This has no practical value other than for examining the cache for performance analysis.

getInvertCompositionCacheNumEntries int RenderState::get_invert_composition_cache_num_entries(void) const; Description: 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 RenderState const *RenderState::get_invert_composition_cache_result(int n) const; Description: 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 RenderState::get_invert_composition_cache_size(void) const; Description: 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 RenderState const *RenderState::get_invert_composition_cache_source(int n) const; Description: 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 RenderState::get_max_priority(void); Description: 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 RenderState::get_num_states(void); Description: Returns the total number of unique RenderState objects allocated in the world. This will go up and down during normal operations.

getNumUnusedStates static int RenderState::get_num_unused_states(void); Description: 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 int RenderState::get_override(TypeHandle type) const; Description: 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 PyObject *RenderState::get_states(void); Description: Returns a list of all of the RenderState objects in the state cache. The order of elements in this cache is arbitrary.

getUnique ConstPointerTo< RenderState > RenderState::get_unique(void) const; Description: 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 bool RenderState::has_attrib(TypeHandle type) const; Description: Returns true if an attrib of the indicated type is present, false otherwise.

hasCullCallback bool RenderState::has_cull_callback(void) const; Description: Returns true if any of the RenderAttribs in this state request a cull_callback(), false if none of them do.

invertCompose ConstPointerTo< RenderState > RenderState::invert_compose(RenderState const *other) const; Description: 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 RenderState::is_empty(void) const; Description: Returns true if the state is empty, false otherwise.

listCycles static void RenderState::list_cycles(ostream &out); Description: 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 void RenderState::list_states(ostream &out); Description: 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 static ConstPointerTo< RenderState > RenderState::make(RenderAttrib const *attrib, int override = (0)); Description: Returns a RenderState with one attribute set. Description: Returns a RenderState with two attributes set. Description: Returns a RenderState with three attributes set. Description: Returns a RenderState with four attributes set. Description: Returns a RenderState with n attributes set.

makeEmpty static ConstPointerTo< RenderState > RenderState::make_empty(void); Description: Returns a RenderState with no attributes set.

makeFullDefault static ConstPointerTo< RenderState > RenderState::make_full_default(void); Description: Returns a RenderState with all possible attributes set to their default value.

nodeRef void RenderState::node_ref(void) const; Description: Overrides this method to update PStats appropriately.

nodeUnref bool RenderState::node_unref(void) const; Description: Overrides this method to update PStats appropriately.

operator < bool RenderState::operator <(RenderState const &other) const; Description: 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.

output void RenderState::output(ostream &out) const; HAVE_PYTHON Description:

removeAttrib ConstPointerTo< RenderState > RenderState::remove_attrib(TypeHandle type) const; Description: Returns a new RenderState object that represents the same as the source state, with the indicated RenderAttrib removed.

setAttrib ConstPointerTo< RenderState > RenderState::set_attrib(RenderAttrib const *attrib) const; Description: 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. Description: 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.

unref bool RenderState::unref(void) const; Description: This method overrides ReferenceCount::unref() to check whether the remaining reference count is entirely in the cache, and if so, it checks for and breaks a cycle in the cache involving this object. This is designed to prevent leaks from cyclical references within the cache. Note that this is not a virtual method, and cannot be because ReferenceCount itself declares no virtual methods (it avoids the overhead of a virtual function pointer). But this doesn't matter, because PT(TransformState) is a template class, and will call the appropriate method even though it is non-virtual.

validateStates static bool RenderState::validate_states(void); Description: 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 void RenderState::write(ostream &out, int indent_level) const; Description:

getClassType static TypeHandle NodeCachedReferenceCount::get_class_type(void); Undocumented function.

getNodeRefCount int NodeCachedReferenceCount::get_node_ref_count(void) const; Description: Returns the current reference count.

getReferencedBits int NodeCachedReferenceCount::get_referenced_bits(void) const; Description: 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. If R_node is included, at least one node is holding a pointer; if R_cache is included, at least one cache element is.

nodeRef void NodeCachedReferenceCount::node_ref(void) const; Description: Explicitly increments the reference count. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

nodeUnref bool NodeCachedReferenceCount::node_unref(void) const; Description: Explicitly decrements the node reference count and the normal reference count simultaneously. The return value is true if the new reference count is nonzero, false if it is zero.

testRefCountIntegrity bool NodeCachedReferenceCount::test_ref_count_integrity(void) const; Description: Does some easy checks to make sure that the reference count isn't completely bogus.

cacheRef void CachedTypedWritableReferenceCount::cache_ref(void) const; Description: Explicitly increments the cache reference count and the normal reference count simultaneously.

cacheUnref bool CachedTypedWritableReferenceCount::cache_unref(void) const; Description: Explicitly decrements the cache reference count and the normal reference count simultaneously. The return value is true if the new reference count is nonzero, false if it is zero.

getCacheRefCount int CachedTypedWritableReferenceCount::get_cache_ref_count(void) const; Description: Returns the current reference count.

getClassType static TypeHandle CachedTypedWritableReferenceCount::get_class_type(void); Undocumented function.

testRefCountIntegrity bool CachedTypedWritableReferenceCount::test_ref_count_integrity(void) const; Description: Does some easy checks to make sure that the reference count isn't completely bogus.

getClassType static TypeHandle TypedWritableReferenceCount::get_class_type(void); Undocumented function.

getClassType static TypeHandle TypedWritable::get_class_type(void); Undocumented function.

getClassType static TypeHandle TypedObject::get_class_type(void); Undocumented function.

getType virtual TypeHandle TypedObject::get_type(void) const = 0; Derived classes should override this function to return get_class_type().

getTypeIndex int TypedObject::get_type_index(void) const; Description: Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. This is equivalent to get_type().get_index().

isExactType bool TypedObject::is_exact_type(TypeHandle handle) const; Description: Returns true if the current object is the indicated type exactly.

isOfType bool TypedObject::is_of_type(TypeHandle handle) const; Description: Returns true if the current object is or derives from the indicated type.

getClassType static TypeHandle ReferenceCount::get_class_type(void); Undocumented function.

getRefCount int ReferenceCount::get_ref_count(void) const; Description: Returns the current reference count.

ref void ReferenceCount::ref(void) const; Description: Explicitly increments the reference count. User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

testRefCountIntegrity bool ReferenceCount::test_ref_count_integrity(void) const; Description: Does some easy checks to make sure that the reference count isn't completely bogus. Returns true if ok, false otherwise.

testRefCountNonzero bool ReferenceCount::test_ref_count_nonzero(void) const; Description: Does some easy checks to make sure that the reference count isn't zero, or completely bogus. Returns true if ok, false otherwise.

unref bool ReferenceCount::unref(void) const; Description: Explicitly decrements the reference count. Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete(). User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically. This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it. The return value is true if the new reference count is nonzero, false if it is zero.