24 RenderAttribRegistry::
25 RenderAttribRegistry() {
26 _registry.reserve(_max_slots);
27 _sorted_slots.reserve(_max_slots);
31 _registry.push_back(RegistryNode(TypeHandle::none(), 0,
nullptr));
37 RenderAttribRegistry::
38 ~RenderAttribRegistry() {
64 nassertr(default_attrib->get_type() == type_handle, 0);
67 while (type_index >= (
int)_slots_by_type.size()) {
68 _slots_by_type.push_back(0);
71 if (_slots_by_type[type_index] != 0) {
73 return _slots_by_type[type_index];
76 int slot = (int)_registry.size();
77 if (slot >= _max_slots) {
79 <<
"Too many registered RenderAttribs; not registering " 80 << type_handle <<
"\n";
81 nassert_raise(
"out of RenderAttrib slots");
89 if (default_attrib !=
nullptr) {
90 default_attrib->calc_hash();
92 if (default_attrib->_saved_entry == -1) {
94 nassertr(RenderAttrib::_attribs->find(default_attrib) == -1, 0);
95 default_attrib->_saved_entry =
96 RenderAttrib::_attribs->
store(default_attrib,
nullptr);
103 _slots_by_type[type_index] = slot;
105 _registry.push_back(RegistryNode(type_handle, sort, default_attrib));
107 _sorted_slots.push_back(slot);
108 std::sort(_sorted_slots.begin(), _sorted_slots.end(), SortSlots(
this));
118 nassertv(slot >= 0 && slot < (
int)_registry.size());
119 _registry[slot]._sort = sort;
122 _sorted_slots.clear();
123 for (
int i = 1; i < (int)_registry.size(); ++i) {
124 _sorted_slots.push_back(i);
126 std::sort(_sorted_slots.begin(), _sorted_slots.end(), SortSlots(
this));
132 void RenderAttribRegistry::
This is the base class for a number of render attributes (other than transform) that may be set on sc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int store(const Key &key, const Value &data)
Records the indicated key/data pair in the map.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
This class is used to associate each RenderAttrib with a different slot index at runtime,...
get_index
Returns the integer index associated with this TypeHandle.
void local_object()
This function should be called, once, immediately after creating a new instance of some ReferenceCoun...
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_slot_sort(int slot, int sort)
Changes the sort number associated with slot n.