15 #include "renderAttribRegistry.h" 16 #include "renderAttrib.h" 17 #include "renderState.h" 18 #include "deletedChain.h" 27 RenderAttribRegistry::
28 RenderAttribRegistry() {
31 PRC_DESC(
"This specifies the maximum number of different RenderAttrib " 32 "types that may be defined at runtime. Normally you should " 33 "never need to change this, but if the default value is too " 34 "low for the number of attribs that Panda actually defines, " 35 "you may need to raise this number."));
38 _max_slots = max((
int)max_attribs, 1);
41 <<
"Value for max-attribs too large: cannot exceed " 43 <<
" in this build. To raise this limit, change the typedef " 44 <<
"for SlotMask in renderAttribRegistry.h and recompile.\n";
52 _array_chain = memory_hook->
get_deleted_chain(_max_slots *
sizeof(RenderState::Attribute));
58 node._make_default_func = NULL;
59 _registry.push_back(node);
67 RenderAttribRegistry::
68 ~RenderAttribRegistry() {
100 RenderAttribRegistry::MakeDefaultFunc *make_default_func) {
101 int type_index = type_handle.
get_index();
102 while (type_index >= (
int)_slots_by_type.size()) {
103 _slots_by_type.push_back(0);
106 if (_slots_by_type[type_index] != 0) {
108 return _slots_by_type[type_index];
111 int slot = (int)_registry.size();
112 if (slot >= _max_slots) {
114 <<
"Too many registered RenderAttribs; not registering " 115 << type_handle <<
"\n";
120 _slots_by_type[type_index] = slot;
123 node._type = type_handle;
125 node._make_default_func = make_default_func;
126 _registry.push_back(node);
128 _sorted_slots.push_back(slot);
129 ::sort(_sorted_slots.begin(), _sorted_slots.end(), SortSlots(
this));
141 nassertv(slot >= 0 && slot < (
int)_registry.size());
142 _registry[slot]._sort = sort;
145 _sorted_slots.clear();
146 _sorted_slots.reserve(_registry.size() - 1);
147 for (
int i = 1; i < (int)_registry.size(); ++i) {
148 _sorted_slots.push_back(i);
150 ::sort(_sorted_slots.begin(), _sorted_slots.end(), SortSlots(
this));
162 get_slot_default(
int slot)
const {
163 nassertr(slot >= 0 && slot < (
int)_registry.size(), 0);
164 return (*_registry[slot]._make_default_func)();
172 void RenderAttribRegistry::
DeletedBufferChain * get_deleted_chain(size_t buffer_size)
Returns a pointer to a global DeletedBufferChain object suitable for allocating arrays of the indicat...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
static CONSTEXPR int get_max_num_bits()
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits t...
int get_index() const
Returns the integer index associated with this TypeHandle.
int register_slot(TypeHandle type_handle, int sort, MakeDefaultFunc *make_default_func)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
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.
This is a convenience class to specialize ConfigVariable as an integer type.
TypeHandle is the identifier used to differentiate C++ class types.
void set_slot_sort(int slot, int sort)
Changes the sort number associated with slot n.