# 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:
ReferenceCount:

## Methods of RenderState:

addAttrib
adjustAllPriorities
cacheRef
cacheUnref
clearCache
compose
cullCallback
findAttrib
getAttrib
getBin
getBinIndex
getClassType
getClipPlane
getColor
getColorScale
getDrawOrder
getFog
getGeomRendering
getMaxPriority
getNumAttribs
getNumStates
getNumUnusedStates
getOverride
getRenderMode
getShader
getTexGen
getTexMatrix
getTexture
getTransparency
hasCullCallback
invertCompose
isEmpty
listCycles
listStates
make
makeEmpty
nodeRef
nodeUnref
operator <
output
removeAttrib
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:

getBestParentFromSet
getClassType
getType
getTypeIndex
isExactType
isOfType

## Methods of ReferenceCount:

getClassType
getRefCount
ref
testRefCountIntegrity
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.

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.

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.

findAttrib int RenderState::find_attrib(TypeHandle type) const; Description: Searches for an attribute with the indicated type in the state, and returns its index if it is found, or -1 if it is not.

getAttrib RenderAttrib const *RenderState::get_attrib(int n) const; Description: Returns the nth attribute in the state. 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.

getBin CullBinAttrib const *RenderState::get_bin(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a BinAttrib on this state. It returns a pointer to the BinAttrib, if there is one, or NULL if there is not.

getBinIndex int RenderState::get_bin_index(void) const; 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.

getClipPlane ClipPlaneAttrib const *RenderState::get_clip_plane(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a ClipPlaneAttrib on this state. It returns a pointer to the ClipPlaneAttrib, if there is one, or NULL if there is not.

getColor ColorAttrib const *RenderState::get_color(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a ColorAttrib on this state. It returns a pointer to the ColorAttrib, if there is one, or NULL if there is not.

getColorScale ColorScaleAttrib const *RenderState::get_color_scale(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a ColorScaleAttrib on this state. It returns a pointer to the ColorScaleAttrib, if there is one, or NULL if there is not.

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

getFog FogAttrib const *RenderState::get_fog(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: This function is provided as an optimization, to speed up the render-time checking for the existance of a FogAttrib on this state. It returns a pointer to the FogAttrib, if there is one, or NULL if there is not.

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.

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.

getNumAttribs int RenderState::get_num_attribs(void) const; Description: Returns the number of separate attributes indicated in the state.

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(int n) const; Description: Returns the override associated with the nth attribute in the state. 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.

getRenderMode RenderModeAttrib const *RenderState::get_render_mode(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a RenderModeAttrib on this state. It returns a pointer to the RenderModeAttrib, if there is one, or NULL if there is not.

getShader ShaderAttrib const *RenderState::get_shader(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a ShaderAttrib on this state. It returns a pointer to the ShaderAttrib, if there is one, or NULL if there is not.

getTexGen TexGenAttrib const *RenderState::get_tex_gen(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a TexGenAttrib on this state. It returns a pointer to the TexGenAttrib, if there is one, or NULL if there is not.

getTexMatrix TexMatrixAttrib const *RenderState::get_tex_matrix(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a TexMatrixAttrib on this state. It returns a pointer to the TexMatrixAttrib, if there is one, or NULL if there is not.

getTexture TextureAttrib const *RenderState::get_texture(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a TextureAttrib on this state. It returns a pointer to the TextureAttrib, if there is one, or NULL if there is not.

getTransparency TransparencyAttrib const *RenderState::get_transparency(void) const; Description: This function is provided as an optimization, to speed up the render-time checking for the existance of a TransparencyAttrib on this state. It returns a pointer to the TransparencyAttrib, if there is one, or NULL if there is not.

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; Filename: renderState.I Created by: drose (21Feb02) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . 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. Description: Returns a RenderState made from the specified slots.

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

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; 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.

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

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

cacheUnref bool CachedTypedWritableReferenceCount::cache_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.

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.

getBestParentFromSet int TypedObject::get_best_parent_from_Set(set< int > const &) const; Description: Returns true if the current object is the indicated type exactly.

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.

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.