Panda3D
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
RenderAttribRegistry Class Reference

This class is used to associate each RenderAttrib with a different slot index at runtime, so we can store a list of RenderAttribs in the RenderState object, and very quickly look them up by type. More...

#include "renderAttribRegistry.h"

Public Types

typedef BitMask32 SlotMask
 

Public Member Functions

typedef CPT (RenderAttrib) MakeDefaultFunc()
 
int get_num_slots () const
 Returns the number of RenderAttrib slots that have been allocated.
 
int get_num_sorted_slots () const
 Returns the number of entries in the sorted_slots list.
 
int get_slot (TypeHandle type_handle) const
 Returns the slot number assigned to the indicated TypeHandle, or 0 if no slot number has been assigned.
 
const RenderAttribget_slot_default (int slot) const
 Returns the default RenderAttrib object associated with slot n.
 
int get_slot_sort (int slot) const
 Returns the sort number associated with slot n.
 
TypeHandle get_slot_type (int slot) const
 Returns the TypeHandle associated with slot n.
 
int get_sorted_slot (int n) const
 Returns the nth slot in sorted order.
 
int register_slot (TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
 Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot number in the range 0 < slot < get_max_slots().
 
void set_slot_sort (int slot, int sort)
 Changes the sort number associated with slot n.
 

Static Public Member Functions

static RenderAttribRegistryget_global_ptr ()
 
static constexpr int get_max_slots ()
 
static RenderAttribRegistryquick_get_global_ptr ()
 Returns the global_ptr without first ensuring it has been initialized.
 

Static Public Attributes

static const int _max_slots = 32
 

Detailed Description

This class is used to associate each RenderAttrib with a different slot index at runtime, so we can store a list of RenderAttribs in the RenderState object, and very quickly look them up by type.

Definition at line 31 of file renderAttribRegistry.h.

Member Typedef Documentation

◆ SlotMask

Definition at line 46 of file renderAttribRegistry.h.

Member Function Documentation

◆ get_global_ptr()

RenderAttribRegistry * RenderAttribRegistry::get_global_ptr ( )
inlinestatic

Definition at line 87 of file renderAttribRegistry.I.

◆ get_max_slots()

static constexpr int RenderAttribRegistry::get_max_slots ( )
inlinestaticconstexpr

Definition at line 57 of file renderAttribRegistry.h.

◆ get_num_slots()

int RenderAttribRegistry::get_num_slots ( ) const
inline

Returns the number of RenderAttrib slots that have been allocated.

This is one more than the highest slot number in use.

Definition at line 31 of file renderAttribRegistry.I.

◆ get_num_sorted_slots()

int RenderAttribRegistry::get_num_sorted_slots ( ) const
inline

Returns the number of entries in the sorted_slots list.

Definition at line 68 of file renderAttribRegistry.I.

Referenced by RenderState::compare_sort().

◆ get_slot()

int RenderAttribRegistry::get_slot ( TypeHandle type_handle) const
inline

Returns the slot number assigned to the indicated TypeHandle, or 0 if no slot number has been assigned.

Definition at line 18 of file renderAttribRegistry.I.

References TypeHandle::get_index.

◆ get_slot_default()

const RenderAttrib * RenderAttribRegistry::get_slot_default ( int slot) const
inline

Returns the default RenderAttrib object associated with slot n.

This is the attrib that should be applied in the absence of any other attrib of this type.

Definition at line 59 of file renderAttribRegistry.I.

Referenced by CPT().

◆ get_slot_sort()

int RenderAttribRegistry::get_slot_sort ( int slot) const
inline

Returns the sort number associated with slot n.

Definition at line 48 of file renderAttribRegistry.I.

◆ get_slot_type()

TypeHandle RenderAttribRegistry::get_slot_type ( int slot) const
inline

Returns the TypeHandle associated with slot n.

Definition at line 39 of file renderAttribRegistry.I.

◆ get_sorted_slot()

int RenderAttribRegistry::get_sorted_slot ( int n) const
inline

Returns the nth slot in sorted order.

By traversing this list, you will retrieve all the slot numbers in order according to their registered sort value.

Definition at line 78 of file renderAttribRegistry.I.

Referenced by RenderState::compare_sort().

◆ quick_get_global_ptr()

RenderAttribRegistry * RenderAttribRegistry::quick_get_global_ptr ( )
inlinestatic

Returns the global_ptr without first ensuring it has been initialized.

Only safe for code that knows it has already been initialized.

Definition at line 99 of file renderAttribRegistry.I.

Referenced by RenderState::compare_sort(), RenderState::complete_pointers(), and CPT().

◆ register_slot()

int RenderAttribRegistry::register_slot ( TypeHandle type_handle,
int sort,
RenderAttrib * default_attrib )

Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot number in the range 0 < slot < get_max_slots().

The sort value is an arbitrary integer. In general, the RenderAttribs will be sorted in order from lowest sort value to highest sort value, when they are traversed via the get_num_sorted_slots() get_sorted_slot() methods. This will be used to sort render states, so that heavier RenderAttribs are changed less frequently. In general, you should choose sort values such that the heavier RenderAttribs (that is, those which are more expensive to change) have lower sort values.

The default_attrib pointer should be a newly created instance of this attribute that represents the default state for this attribute.

register_slot() is intended to be called at application start for each different RenderAttrib type in the system, to assign a different integer slot number to each one.

Definition at line 60 of file renderAttribRegistry.cxx.

References TypeHandle::get_index, ReferenceCount::local_object(), and SimpleHashMap< Key, Value, Compare >::store().

Referenced by RenderAttrib::register_slot().

◆ set_slot_sort()

void RenderAttribRegistry::set_slot_sort ( int slot,
int sort )

Changes the sort number associated with slot n.

Definition at line 116 of file renderAttribRegistry.cxx.

Member Data Documentation

◆ _max_slots

const int RenderAttribRegistry::_max_slots = 32
static

Definition at line 50 of file renderAttribRegistry.h.


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