Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Friends

RenderState Class Reference

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

#include "renderState.h"

Inheritance diagram for RenderState:
NodeCachedReferenceCount CachedTypedWritableReferenceCount TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase

List of all members.

Classes

class  Attribute
class  Composition
class  CompositionCycleDescEntry

Public Types

enum  Referenced { R_node = 0x001, R_cache = 0x002 }
typedef
RenderAttribRegistry::SlotMask 
SlotMask

Public Member Functions

virtual ~RenderState ()
 The destructor is responsible for removing the RenderState from the global set if it is there.
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer.
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer.
void cache_ref () const
 Overrides this method to update PStats appropriately.
bool cache_unref () const
 Overrides this method to update PStats appropriately.
int compare_sort (const RenderState &other) const
 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.
virtual int complete_pointers (TypedWritable **plist, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
 CPT (RenderState) invert_compose(const RenderState *other) const
 CPT (RenderState) compose(const RenderState *other) const
 CPT (RenderAttrib) _generated_shader
 CPT (RenderState) add_attrib(const RenderAttrib *attrib
 CPT (RenderState) set_attrib(const RenderAttrib *attrib) const
 CPT (RenderState) get_unique() const
 CPT (RenderState) set_attrib(const RenderAttrib *attrib
 CPT (RenderState) remove_attrib(TypeHandle type) const
 CPT (RenderState) remove_attrib(int slot) const
 CPT (RenderState) adjust_all_priorities(int adjustment) const
bool cull_callback (CullTraverser *trav, const CullTraverserData &data) const
 Calls cull_callback() on each attrib.
string encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string.
bool encode_to_bam_stream (string &data, BamWriter *writer=NULL) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string.
virtual void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.
virtual TypeHandle force_init_type ()
const RenderAttribget_attrib (TypeHandle type) const
 Looks for a RenderAttrib of the indicated type in the state, and returns it if it is found, or NULL if it is not.
const RenderAttribget_attrib (int slot) const
 Returns the RenderAttrib with the indicated slot index, or NULL if there is no such RenderAttrib in the state.
const RenderAttribget_attrib_def (int slot) const
 Returns the RenderAttrib with the indicated slot index, or the default attrib for that slot if there is no such RenderAttrib in the state.
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter.
int get_best_parent_from_Set (const std::set< int > &) const
int get_bin_index () const
 Returns the bin index indicated by the CullBinAttrib, if any, associated by this state (or the default bin index if there is no CullBinAttrib).
int get_cache_ref_count () const
 Returns the current reference count.
int get_composition_cache_num_entries () const
 Returns the number of entries in the composition cache for this RenderState.
const RenderStateget_composition_cache_result (int n) const
 Returns the result RenderState of the nth element in the composition cache.
int get_composition_cache_size () const
 Returns the number of slots in the composition cache for this RenderState.
const RenderStateget_composition_cache_source (int n) const
 Returns the source RenderState of the nth element in the composition cache.
int get_draw_order () const
 Returns the draw order indicated by the CullBinAttrib, if any, associated by this state (or 0 if there is no CullBinAttrib).
int get_geom_rendering (int geom_rendering) const
 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.
size_t get_hash () const
 Returns a suitable hash value for phash_map.
int get_invert_composition_cache_num_entries () const
 Returns the number of entries in the invert_composition cache for this RenderState.
const RenderStateget_invert_composition_cache_result (int n) const
 Returns the result RenderState of the nth element in the invert composition cache.
int get_invert_composition_cache_size () const
 Returns the number of slots in the composition cache for this RenderState.
const RenderStateget_invert_composition_cache_source (int n) const
 Returns the source RenderState of the nth element in the invert composition cache.
int get_node_ref_count () const
 Returns the current reference count.
int get_override (TypeHandle type) const
 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.
int get_override (int slot) const
 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.
int get_ref_count () const
 Returns the current reference count.
int get_referenced_bits () const
 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.
virtual TypeHandle get_type () const
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object.
bool has_attrib (TypeHandle type) const
 Returns true if an attrib of the indicated type is present, false otherwise.
bool has_attrib (int slot) const
 Returns true if an attrib of the indicated type is present, false otherwise.
bool has_cull_callback () const
 Returns true if any of the RenderAttribs in this state request a cull_callback(), false if none of them do.
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.
bool is_empty () const
 Returns true if the state is empty, false otherwise.
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams.
void node_ref () const
 Overrides this method to update PStats appropriately.
bool node_unref () const
 Overrides this method to update PStats appropriately.
void operator delete (void *ptr)
void operator delete (void *ptr)
void operator delete (void *ptr, void *)
void operator delete (void *ptr, void *)
void operator delete[] (void *ptr)
void operator delete[] (void *, void *)
void operator delete[] (void *, void *)
void operator delete[] (void *ptr)
void * operator new (size_t size)
void * operator new (size_t size, void *ptr)
void * operator new (size_t size, void *ptr)
void * operator new (size_t size)
void * operator new[] (size_t size)
void * operator new[] (size_t size, void *ptr)
void * operator new[] (size_t size)
void * operator new[] (size_t size, void *ptr)
bool operator< (const RenderState &other) const
 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.
void output (ostream &out) const
void ref () const
 Explicitly increments the reference count.
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed.
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus.
virtual bool unref () const
 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.
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates.
void weak_ref (WeakPointerToVoid *ptv)
 Adds the indicated PointerToVoid as a weak reference to this object.
void weak_unref (WeakPointerToVoid *ptv)
 Removes the indicated PointerToVoid as a weak reference to this object.
void write (ostream &out, int indent_level) const
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file.

Static Public Member Functions

static void bin_removed (int bin_index)
 Intended to be called by CullBinManager::remove_bin(), this informs all the RenderStates in the world to remove the indicated bin_index from their cache if it has been cached.
static TypedWritablechange_this (TypedWritable *old_ptr, BamReader *manager)
 Called immediately after complete_pointers(), this gives the object a chance to adjust its own pointer if desired.
static int clear_cache ()
 Empties the cache of composed RenderStates.
static void clear_munger_cache ()
 Completely empties the cache of state + gsg -> munger, for all states and all gsg's.
static CPT (RenderState) make_empty()
static CPT (RenderState) make(const RenderAttrib *attrib1
static CPT (RenderState) make_full_default()
static CPT (RenderState) make(const RenderAttrib *attrib1
static CPT (RenderState) make(const RenderAttrib *attrib
static CPT (RenderState) make(const RenderAttrib *attrib1
static CPT (RenderState) make(const RenderAttrib *const *attrib
static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, const string &data, BamReader *reader=NULL)
 Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string.
static void flush_level ()
 Flushes the PStatCollectors used during traversal.
static TypeHandle get_class_type ()
static int get_max_priority ()
 Returns the maximum priority number (sometimes called override) that may be set on any node.
static int get_num_states ()
 Returns the total number of unique RenderState objects allocated in the world.
static int get_num_unused_states ()
 Returns the total number of RenderState objects that have been allocated but have no references outside of the internal RenderState cache.
static void init_states ()
 Make sure the global _states map is allocated.
static void init_type ()
static void list_cycles (ostream &out)
 Detects all of the reference-count cycles in the cache and reports them to standard output.
static void list_states (ostream &out)
 Lists all of the RenderStates in the cache to the output stream, one per line.
static PT (TypedWritableReferenceCount) decode_from_bam_stream(const string &data
static void register_with_read_factory ()
 Tells the BamReader how to create objects of type RenderState.
static bool validate_states ()
 Ensures that the cache is still stored in sorted order, and that none of the cache elements have been inadvertently deleted.

Public Attributes

static const RenderAttribattrib2
static const RenderAttrib
const RenderAttrib
attrib3
static const RenderAttrib
const RenderAttrib const
RenderAttrib
attrib4
int override const
static int num_attribs
static int int override = 0)
static const RenderAttrib
const RenderAttrib const
RenderAttrib int 
override = 0)
static const RenderAttrib int override = 0)
int override = 0) const
static int override = 0)
static const RenderAttrib
const RenderAttrib int 
override = 0)
static BamReaderreader = NULL)

Static Public Attributes

static TypedWritable *const Null = (TypedWritable*)0L

Protected Member Functions

 RenderState ()
 Actually, this could be a private constructor, since no one inherits from RenderState, but gcc gives us a spurious warning if all constructors are private.
void cache_unref_only () const
 Decrements the cache reference count without affecting the normal reference count.
bool do_test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.
bool do_test_ref_count_nonzero () const
 Returns true if the reference count is nonzero, false otherwise.
void fillin (DatagramIterator &scan, BamReader *manager)
 This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new RenderState.
void node_unref_only () const
 Decrements the node reference count without affecting the normal reference count.

Static Protected Member Functions

static TypedWritablemake_from_bam (const FactoryParams &params)
 This function is called by the BamReader's factory when a new object of type RenderState is encountered in the Bam file.

Friends

class GraphicsStateGuardian
class RenderAttribRegistry

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.

Definition at line 53 of file renderState.h.


Constructor & Destructor Documentation

RenderState::RenderState ( ) [protected]

Actually, this could be a private constructor, since no one inherits from RenderState, but gcc gives us a spurious warning if all constructors are private.

Definition at line 66 of file renderState.cxx.

References DeletedBufferChain::allocate(), RenderAttribRegistry::get_array_chain(), and RenderAttribRegistry::get_max_slots().

Referenced by make_from_bam().

RenderState::~RenderState ( ) [virtual]

Member Function Documentation

ReferenceCount * TypedWritableReferenceCount::as_reference_count ( ) [virtual, inherited]

Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type.

Reimplemented from TypedWritable.

Definition at line 26 of file typedWritableReferenceCount.cxx.

TypedObject * TypedObject::as_typed_object ( ) [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 99 of file typedObject.I.

const TypedObject * TypedObject::as_typed_object ( ) const [inline, inherited]

Returns the object, upcast (if necessary) to a TypedObject pointer.

Definition at line 110 of file typedObject.I.

void RenderState::bin_removed ( int  bin_index) [static]

Intended to be called by CullBinManager::remove_bin(), this informs all the RenderStates in the world to remove the indicated bin_index from their cache if it has been cached.

Definition at line 1370 of file renderState.cxx.

Referenced by CullBinManager::remove_bin().

void RenderState::cache_ref ( ) const [inline]

Overrides this method to update PStats appropriately.

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 167 of file renderState.I.

References NodeCachedReferenceCount::get_referenced_bits().

bool RenderState::cache_unref ( ) const [inline]

Overrides this method to update PStats appropriately.

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 183 of file renderState.I.

References NodeCachedReferenceCount::get_referenced_bits().

Referenced by clear_cache().

void CachedTypedWritableReferenceCount::cache_unref_only ( ) const [inline, protected, inherited]

Decrements the cache reference count without affecting the normal reference count.

Intended to be called by derived classes only, presumably to reimplement cache_unref().

Definition at line 204 of file cachedTypedWritableReferenceCount.I.

References CachedTypedWritableReferenceCount::test_ref_count_integrity().

TypedWritable * RenderState::change_this ( TypedWritable old_ptr,
BamReader manager 
) [static]

Called immediately after complete_pointers(), this gives the object a chance to adjust its own pointer if desired.

Most objects don't change pointers after completion, but some need to.

Once this function has been called, the old pointer will no longer be accessed.

Definition at line 2192 of file renderState.cxx.

References BamReader::register_finalize().

Referenced by make_from_bam().

int RenderState::clear_cache ( ) [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.

Definition at line 1078 of file renderState.cxx.

References CacheStats::add_total_size(), cache_unref(), SimpleHashMap< Key, Value, Compare >::clear(), SimpleHashMap< Key, Value, Compare >::get_data(), SimpleHashMap< Key, Value, Compare >::get_num_entries(), ReferenceCount::get_ref_count(), SimpleHashMap< Key, Value, Compare >::get_size(), and SimpleHashMap< Key, Value, Compare >::has_element().

void RenderState::clear_munger_cache ( ) [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.

Definition at line 1151 of file renderState.cxx.

int RenderState::compare_sort ( const RenderState other) const

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

Definition at line 197 of file renderState.cxx.

References BitMask< WType, nbits >::get_bit(), RenderAttribRegistry::get_num_sorted_slots(), RenderAttribRegistry::get_sorted_slot(), and RenderAttribRegistry::quick_get_global_ptr().

int RenderState::complete_pointers ( TypedWritable **  p_list,
BamReader manager 
) [virtual]

Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().

Returns the number of pointers processed.

Reimplemented from TypedWritable.

Definition at line 2154 of file renderState.cxx.

References RenderAttribRegistry::quick_get_global_ptr(), and BitMask< WType, nbits >::set_bit().

bool RenderState::cull_callback ( CullTraverser trav,
const CullTraverserData data 
) const

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.

Definition at line 252 of file renderState.cxx.

References BitMask< WType, nbits >::clear_bit(), and BitMask< WType, nbits >::get_lowest_on_bit().

bool TypedWritable::decode_raw_from_bam_stream ( TypedWritable *&  ptr,
ReferenceCount *&  ref_ptr,
const string &  data,
BamReader reader = NULL 
) [static, inherited]

Reads the string created by a previous call to encode_to_bam_stream(), and extracts the single object on that string.

Returns true on success, false on on error.

This variant sets the TypedWritable and ReferenceCount pointers separately; both are pointers to the same object. The reference count is not incremented; it is the caller's responsibility to manage the reference count.

Note that this method cannot be used to retrieve objects that do not inherit from ReferenceCount, because these objects cannot persist beyond the lifetime of the BamReader that reads them. To retrieve these objects from a bam stream, you must construct a BamReader directly.

If you happen to know that the particular object in question inherits from TypedWritableReferenceCount or PandaNode, consider calling the variant of decode_from_bam_stream() defined for those methods, which presents a simpler interface.

Definition at line 353 of file typedWritable.cxx.

References BamReader::init(), DatagramInputFile::open(), DatagramInputFile::read_header(), BamReader::read_object(), ReferenceCount::ref(), BamReader::resolve(), BamReader::set_source(), and ReferenceCount::unref().

bool NodeCachedReferenceCount::do_test_ref_count_integrity ( ) const [protected, inherited]

Does some easy checks to make sure that the reference count isn't completely bogus.

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 26 of file nodeCachedReferenceCount.cxx.

Referenced by NodeCachedReferenceCount::test_ref_count_integrity().

bool ReferenceCount::do_test_ref_count_nonzero ( ) const [protected, inherited]

Returns true if the reference count is nonzero, false otherwise.

Definition at line 56 of file referenceCount.cxx.

References ReferenceCount::do_test_ref_count_integrity().

Referenced by ReferenceCount::test_ref_count_nonzero().

string TypedWritable::encode_to_bam_stream ( ) const [inline, inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a string string.

Returns empty string on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 86 of file typedWritable.I.

bool TypedWritable::encode_to_bam_stream ( string &  data,
BamWriter writer = NULL 
) const [inherited]

Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string.

Returns true on success, false on failure.

This is a convenience method particularly useful for cases when you are only serializing a single object. If you have many objects to process, it is more efficient to use the same BamWriter to serialize all of them together.

Definition at line 283 of file typedWritable.cxx.

References BamWriter::init(), DatagramOutputFile::open(), BamWriter::set_target(), DatagramOutputFile::write_header(), and BamWriter::write_object().

void RenderState::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]

This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new RenderState.

Reimplemented from TypedWritable.

Definition at line 2261 of file renderState.cxx.

References DatagramIterator::get_int32(), DatagramIterator::get_uint16(), and BamReader::read_pointer().

Referenced by make_from_bam().

void RenderState::finalize ( BamReader manager) [virtual]

Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

Reimplemented from TypedWritable.

Definition at line 2220 of file renderState.cxx.

References ReferenceCount::get_ref_count(), and unref().

void RenderState::flush_level ( ) [inline, static]

Flushes the PStatCollectors used during traversal.

Definition at line 565 of file renderState.I.

Referenced by GraphicsEngine::render_frame().

const RenderAttrib * RenderState::get_attrib ( TypeHandle  type) const [inline]

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

Definition at line 87 of file renderState.I.

References RenderAttribRegistry::get_slot().

Referenced by CullResult::add_object(), CullTraverserData::apply_transform_and_state(), NodePath::clear_normal_map(), get_geom_rendering(), has_attrib(), StandardMunger::StandardMunger(), and CullTraverser::traverse().

const RenderAttrib * RenderState::get_attrib ( int  slot) const [inline]

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

Definition at line 101 of file renderState.I.

const RenderAttrib * RenderState::get_attrib_def ( int  slot) const [inline]

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

Definition at line 113 of file renderState.I.

Referenced by ShaderGenerator::analyze_renderstate().

UpdateSeq TypedWritable::get_bam_modified ( ) const [inline, inherited]

Returns the current bam_modified counter.

This counter is normally incremented automatically whenever the object is modified.

Definition at line 66 of file typedWritable.I.

Referenced by BamWriter::consider_update(), and BamWriter::write_pointer().

int RenderState::get_bin_index ( ) const [inline]

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.

Definition at line 407 of file renderState.I.

int CachedTypedWritableReferenceCount::get_cache_ref_count ( ) const [inline, inherited]
int RenderState::get_composition_cache_num_entries ( ) const [inline]

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.

Definition at line 237 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_num_entries().

const RenderState * RenderState::get_composition_cache_result ( int  n) const [inline]

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.

Definition at line 310 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_data(), and SimpleHashMap< Key, Value, Compare >::has_element().

int RenderState::get_composition_cache_size ( ) const [inline]

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.

Definition at line 270 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_size().

const RenderState * RenderState::get_composition_cache_source ( int  n) const [inline]

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.

Definition at line 287 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_key(), and SimpleHashMap< Key, Value, Compare >::has_element().

int RenderState::get_draw_order ( ) const [inline]

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

Definition at line 388 of file renderState.I.

int RenderState::get_geom_rendering ( int  geom_rendering) const

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.

Definition at line 1343 of file renderState.cxx.

References get_attrib(), TexMatrixAttrib::get_geom_rendering(), TexGenAttrib::get_geom_rendering(), and RenderModeAttrib::get_geom_rendering().

size_t RenderState::get_hash ( ) const
int RenderState::get_invert_composition_cache_num_entries ( ) const [inline]

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

Definition at line 252 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_num_entries().

const RenderState * RenderState::get_invert_composition_cache_result ( int  n) const [inline]

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.

Definition at line 372 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_data(), and SimpleHashMap< Key, Value, Compare >::has_element().

int RenderState::get_invert_composition_cache_size ( ) const [inline]

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.

Definition at line 331 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_size().

const RenderState * RenderState::get_invert_composition_cache_source ( int  n) const [inline]

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.

Definition at line 348 of file renderState.I.

References SimpleHashMap< Key, Value, Compare >::get_key(), and SimpleHashMap< Key, Value, Compare >::has_element().

int RenderState::get_max_priority ( ) [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.

Definition at line 944 of file renderState.cxx.

int NodeCachedReferenceCount::get_node_ref_count ( ) const [inline, inherited]

Returns the current reference count.

Definition at line 133 of file nodeCachedReferenceCount.I.

References NodeCachedReferenceCount::test_ref_count_integrity().

Referenced by NodeCachedReferenceCount::get_referenced_bits().

int RenderState::get_num_states ( ) [static]

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

This will go up and down during normal operations.

Definition at line 956 of file renderState.cxx.

Referenced by GraphicsEngine::render_frame().

int RenderState::get_num_unused_states ( ) [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.

Definition at line 983 of file renderState.cxx.

References CachedTypedWritableReferenceCount::get_cache_ref_count(), SimpleHashMap< Key, Value, Compare >::get_data(), ReferenceCount::get_ref_count(), SimpleHashMap< Key, Value, Compare >::get_size(), and SimpleHashMap< Key, Value, Compare >::has_element().

Referenced by GraphicsEngine::render_frame().

int RenderState::get_override ( TypeHandle  type) const [inline]

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.

Definition at line 128 of file renderState.I.

References RenderAttribRegistry::get_slot().

Referenced by NodePath::clear_clip_plane(), NodePath::clear_light(), NodePath::clear_texture(), NodePath::set_texture(), and NodePath::set_texture_off().

int RenderState::get_override ( int  slot) const [inline]

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.

Definition at line 142 of file renderState.I.

int ReferenceCount::get_ref_count ( ) const [inline, inherited]
int NodeCachedReferenceCount::get_referenced_bits ( ) const [inline, inherited]

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.

Definition at line 204 of file nodeCachedReferenceCount.I.

References CachedTypedWritableReferenceCount::get_cache_ref_count(), and NodeCachedReferenceCount::get_node_ref_count().

Referenced by TransformState::cache_ref(), cache_ref(), TransformState::cache_unref(), cache_unref(), TransformState::node_ref(), node_ref(), TransformState::node_unref(), and node_unref().

int TypedObject::get_type_index ( ) const [inline, inherited]

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

Definition at line 52 of file typedObject.I.

References TypeHandle::get_index().

WeakReferenceList * ReferenceCount::get_weak_list ( ) const [inline, inherited]

Returns the WeakReferenceList associated with this ReferenceCount object.

If there has never been a WeakReferenceList associated with this object, creates one now.

Definition at line 307 of file referenceCount.I.

Referenced by ReferenceCount::weak_ref().

bool RenderState::has_attrib ( TypeHandle  type) const [inline]

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

Definition at line 64 of file renderState.I.

References get_attrib().

bool RenderState::has_attrib ( int  slot) const [inline]

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

Definition at line 75 of file renderState.I.

References get_attrib().

bool RenderState::has_cull_callback ( ) const [inline]

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

Definition at line 34 of file renderState.I.

bool ReferenceCount::has_weak_list ( ) const [inline, inherited]

Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.

In general, this will be true if there was ever a WeakPointerTo created for this object (even if there is not any for it now).

Definition at line 294 of file referenceCount.I.

Referenced by ReferenceCount::weak_unref().

void RenderState::init_states ( ) [static]

Make sure the global _states map is allocated.

This only has to be done once. We could make this map static, but then we run into problems if anyone creates a RenderState object at static init time; it also seems to cause problems when the Panda shared library is unloaded at application exit time.

Definition at line 2092 of file renderState.cxx.

References Thread::get_current_thread(), Thread::get_main_thread(), and CacheStats::init().

bool RenderState::is_empty ( ) const [inline]

Returns true if the state is empty, false otherwise.

Definition at line 22 of file renderState.I.

References BitMask< WType, nbits >::is_zero().

Referenced by PandaNode::set_state().

bool TypedObject::is_exact_type ( TypeHandle  handle) const [inline, inherited]
bool TypedObject::is_of_type ( TypeHandle  handle) const [inline, inherited]

Returns true if the current object is or derives from the indicated type.

Definition at line 63 of file typedObject.I.

References TypeHandle::is_derived_from().

Referenced by EggSliderData::add_back_pointer(), EggJointData::add_back_pointer(), CIntervalManager::add_c_interval(), XFileNode::add_child(), CollisionTraverser::add_collider(), CollisionHandlerPhysical::add_collider(), EggXfmSAnim::add_data(), CharacterJointBundle::add_node(), NonlinearImager::add_screen(), EggGroupNode::apply_first_attribute(), EggGroupNode::apply_last_attribute(), DeferredNodeProperty::apply_to_node(), RecorderController::begin_playback(), NodePath::clear_clip_plane(), EggGroupNode::clear_connected_shading(), NodePath::clear_light(), EggBase::convert_paths(), NodePath::decode_from_bam_stream(), VrpnClient::disconnect_device(), PhysicsManager::do_physics(), GraphicsStateGuardian::fetch_specified_part(), EggRenderState::fill_state(), AnimBundleNode::find_anim_bundle(), EggGroupNode::find_coordsys_entry(), XFile::find_data_object(), Character::find_joint(), EggGroupNode::find_materials(), Character::find_slider(), XFile::find_template(), EggGroupNode::find_textures(), EggMaterialCollection::find_used_materials(), EggTextureCollection::find_used_textures(), EggGroupNode::force_filenames(), EggJointData::force_initial_rest_frame(), WindowFramework::get_aspect_2d(), EggPoolUniquifier::get_category(), EggGroupUniquifier::get_category(), EggGroupNode::get_connected_shading(), PandaFramework::get_mouse(), FactoryParams::get_param_of_type(), EggGroupNode::has_absolute_pathnames(), NodePath::has_clip_plane(), NodePath::has_clip_plane_off(), NodePath::has_light(), PandaFramework::hide_collision_solids(), x11GraphicsWindow::open_window(), eglGraphicsWindow::open_window(), EggNode::parse_egg(), CharacterMaker::part_to_node(), EggGroupNode::post_apply_flat_attribute(), EggBinner::prepare_node(), PortalClipper::prepare_portal(), NodePath::project_texture(), EggMatrixTablePointer::quantize_channels(), ParametricCurveCollection::r_add_curves(), SceneGraphReducer::r_collect_vertex_data(), EggGroupNode::r_load_externals(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::remove_invalid_primitives(), EggGroupNode::remove_unused_vertices(), EggLoader::reparent_decals(), EggMaterialCollection::replace_materials(), EggTextureCollection::replace_textures(), EggGroupNode::resolve_filenames(), EggGroupNode::reverse_vertex_ordering(), NodePath::set_clip_plane(), NodePath::set_clip_plane_off(), NodePath::set_light(), ProjectionScreen::set_projector(), NonlinearImager::set_source_camera(), EggXfmSAnim::set_value(), NonlinearImager::set_viewer_camera(), PandaFramework::show_collision_solids(), BamCache::store(), XFileToEggConverter::strip_nodes(), EggGroupNode::strip_normals(), DataGraphTraverser::traverse(), DataGraphTraverser::traverse_below(), EggGroupNode::triangulate_polygons(), EggGroupNode::unify_attributes(), EggNameUniquifier::uniquify(), NodeCullCallbackData::upcall(), PhysicsCollisionHandler::validate_target(), EggXfmSAnim::write(), EggGroup::write(), EggToDXFLayer::write_3d_face(), and EggToDXFLayer::write_entities().

void RenderState::list_cycles ( 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.

Definition at line 1186 of file renderState.cxx.

References ReferenceCount::get_ref_count().

void RenderState::list_states ( 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.

Definition at line 1265 of file renderState.cxx.

void ReferenceCount::local_object ( ) [inline, inherited]

This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.

This allows the object to be passed to functions that will increment and decrement the object's reference count temporarily, and it will prevent the object from being deleted (inappropriately), when the reference count returns to zero. It actually achieves this by setting a large positive value in the reference count field.

Definition at line 276 of file referenceCount.I.

Referenced by PGTop::cull_callback(), BoundingSphere::extend_by_hexahedron(), AsyncTaskManager::find_task(), AsyncTaskManager::find_tasks(), and AsyncTaskManager::find_tasks_matching().

TypedWritable * RenderState::make_from_bam ( const FactoryParams params) [static, protected]

This function is called by the BamReader's factory when a new object of type RenderState is encountered in the Bam file.

It should create the RenderState and extract its information from the file.

Definition at line 2241 of file renderState.cxx.

References change_this(), fillin(), BamReader::register_change_this(), and RenderState().

Referenced by register_with_read_factory().

void TypedWritable::mark_bam_modified ( ) [inline, inherited]
void RenderState::node_ref ( ) const [inline]

Overrides this method to update PStats appropriately.

Reimplemented from NodeCachedReferenceCount.

Definition at line 200 of file renderState.I.

References NodeCachedReferenceCount::get_referenced_bits().

bool RenderState::node_unref ( ) const [inline]

Overrides this method to update PStats appropriately.

Reimplemented from NodeCachedReferenceCount.

Definition at line 216 of file renderState.I.

References NodeCachedReferenceCount::get_referenced_bits().

void NodeCachedReferenceCount::node_unref_only ( ) const [inline, protected, inherited]

Decrements the node reference count without affecting the normal reference count.

Intended to be called by derived classes only, presumably to reimplement node_unref().

Definition at line 225 of file nodeCachedReferenceCount.I.

References NodeCachedReferenceCount::test_ref_count_integrity().

Referenced by NodeCachedReferenceCount::node_unref().

bool RenderState::operator< ( const RenderState other) const

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.

Definition at line 171 of file renderState.cxx.

References BitMask< WType, nbits >::clear_bit(), and BitMask< WType, nbits >::get_lowest_on_bit().

void ReferenceCount::ref ( ) const [inline, inherited]

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.

Definition at line 179 of file referenceCount.I.

References ReferenceCount::test_ref_count_integrity().

Referenced by CachedTypedWritableReferenceCount::cache_ref(), TypedWritable::decode_raw_from_bam_stream(), NodeCachedReferenceCount::node_ref(), NodeReferenceCount::node_ref(), BamCacheRecord::set_data(), CullableObject::set_draw_callback(), and ModelRoot::set_reference().

void RenderState::register_with_read_factory ( ) [static]

Tells the BamReader how to create objects of type RenderState.

Definition at line 2113 of file renderState.cxx.

References BamReader::get_factory(), make_from_bam(), and Factory< Type >::register_factory().

bool TypedWritable::require_fully_complete ( ) const [virtual, inherited]

Some objects require all of their nested pointers to have been completed before the objects themselves can be completed.

If this is the case, override this method to return true, and be careful with circular references (which would make the object unreadable from a bam file).

Reimplemented in GeomVertexData, ClipPlaneAttrib, and RenderEffects.

Definition at line 118 of file typedWritable.cxx.

bool NodeCachedReferenceCount::test_ref_count_integrity ( ) const [inline, inherited]

Does some easy checks to make sure that the reference count isn't completely bogus.

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 184 of file nodeCachedReferenceCount.I.

References NodeCachedReferenceCount::do_test_ref_count_integrity().

Referenced by NodeCachedReferenceCount::get_node_ref_count(), NodeCachedReferenceCount::node_ref(), and NodeCachedReferenceCount::node_unref_only().

bool ReferenceCount::test_ref_count_nonzero ( ) const [inline, inherited]

Does some easy checks to make sure that the reference count isn't zero, or completely bogus.

Returns true if ok, false otherwise.

Definition at line 252 of file referenceCount.I.

References ReferenceCount::do_test_ref_count_nonzero().

Referenced by CopyOnWritePointer::test_ref_count_nonzero().

bool RenderState::unref ( ) const [virtual]

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.

Reimplemented from ReferenceCount.

Definition at line 708 of file renderState.cxx.

References CachedTypedWritableReferenceCount::get_cache_ref_count(), ReferenceCount::get_ref_count(), and ReferenceCount::unref().

Referenced by finalize().

void TypedWritable::update_bam_nested ( BamWriter manager) [virtual, inherited]

Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates.

Reimplemented in CFDoCullCommand, and PandaNode.

Definition at line 77 of file typedWritable.cxx.

bool RenderState::validate_states ( ) [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).

Definition at line 1291 of file renderState.cxx.

void ReferenceCount::weak_ref ( WeakPointerToVoid ptv) [inline, inherited]

Adds the indicated PointerToVoid as a weak reference to this object.

Definition at line 321 of file referenceCount.I.

References WeakReferenceList::add_reference(), and ReferenceCount::get_weak_list().

void ReferenceCount::weak_unref ( WeakPointerToVoid ptv) [inline, inherited]

Removes the indicated PointerToVoid as a weak reference to this object.

It must have previously been added via a call to weak_ref().

Definition at line 334 of file referenceCount.I.

References WeakReferenceList::clear_reference(), and ReferenceCount::has_weak_list().

void RenderState::write_datagram ( BamWriter manager,
Datagram dg 
) [virtual]

Writes the contents of this object to the datagram for shipping out to a Bam file.

Reimplemented from TypedWritable.

Definition at line 2124 of file renderState.cxx.

References Datagram::add_int32(), Datagram::add_uint16(), BitMask< WType, nbits >::clear_bit(), BitMask< WType, nbits >::get_lowest_on_bit(), BitMask< WType, nbits >::get_num_on_bits(), and BamWriter::write_pointer().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations