Panda3D
renderAttribRegistry.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file renderAttribRegistry.I
10  * @author drose
11  * @date 2008-11-13
12  */
13 
14 /**
15  * Returns the slot number assigned to the indicated TypeHandle, or 0 if no
16  * slot number has been assigned.
17  */
18 INLINE int RenderAttribRegistry::
19 get_slot(TypeHandle type_handle) const {
20  int type_index = type_handle.get_index();
21  if (type_index >= (int)_slots_by_type.size()) {
22  return 0;
23  }
24  return _slots_by_type[(size_t)type_index];
25 }
26 
27 /**
28  * Returns the number of RenderAttrib slots that have been allocated. This is
29  * one more than the highest slot number in use.
30  */
31 INLINE int RenderAttribRegistry::
32 get_num_slots() const {
33  return _registry.size();
34 }
35 
36 /**
37  * Returns the TypeHandle associated with slot n.
38  */
40 get_slot_type(int slot) const {
41  nassertr(slot >= 0 && slot < (int)_registry.size(), TypeHandle::none());
42  return _registry[slot]._type;
43 }
44 
45 /**
46  * Returns the sort number associated with slot n.
47  */
48 INLINE int RenderAttribRegistry::
49 get_slot_sort(int slot) const {
50  nassertr(slot >= 0 && slot < (int)_registry.size(), 0);
51  return _registry[slot]._sort;
52 }
53 
54 /**
55  * Returns the default RenderAttrib object associated with slot n. This is
56  * the attrib that should be applied in the absence of any other attrib of
57  * this type.
58  */
60 get_slot_default(int slot) const {
61  nassertr(slot >= 0 && slot < (int)_registry.size(), 0);
62  return _registry[slot]._default_attrib;
63 }
64 
65 /**
66  * Returns the number of entries in the sorted_slots list.
67  */
68 INLINE int RenderAttribRegistry::
70  return _sorted_slots.size();
71 }
72 
73 /**
74  * Returns the nth slot in sorted order. By traversing this list, you will
75  * retrieve all the slot numbers in order according to their registered sort
76  * value.
77  */
78 INLINE int RenderAttribRegistry::
79 get_sorted_slot(int n) const {
80  nassertr(n >= 0 && n < (int)_sorted_slots.size(), 0);
81  return _sorted_slots[n];
82 }
83 
84 /**
85  *
86  */
87 INLINE RenderAttribRegistry *RenderAttribRegistry::
88 get_global_ptr() {
89  if (_global_ptr == nullptr) {
90  init_global_ptr();
91  }
92  return _global_ptr;
93 }
94 
95 /**
96  * Returns the global_ptr without first ensuring it has been initialized.
97  * Only safe for code that knows it has already been initialized.
98  */
101  return _global_ptr;
102 }
103 
104 /**
105  * This is an STL function object for sorting the _sorted_slots list into
106  * order by slot sort number.
107  */
108 INLINE RenderAttribRegistry::SortSlots::
109 SortSlots(RenderAttribRegistry *reg) : _reg(reg) {
110 }
111 
112 /**
113  *
114  */
115 INLINE bool RenderAttribRegistry::SortSlots::
116 operator () (int a, int b) const {
117  return _reg->get_slot_sort(a) < _reg->get_slot_sort(b);
118 }
119 
120 /**
121  *
122  */
123 INLINE RenderAttribRegistry::RegistryNode::
124 RegistryNode(TypeHandle type, int sort, const RenderAttrib *default_attrib) :
125  _type(type),
126  _sort(sort),
127  _default_attrib(default_attrib) {
128 }
TypeHandle get_slot_type(int slot) const
Returns the TypeHandle associated with slot n.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
int get_num_slots() const
Returns the number of RenderAttrib slots that have been allocated.
int get_slot_sort(int slot) const
Returns the sort number associated with slot n.
int get_slot(TypeHandle type_handle) const
Returns the slot number assigned to the indicated TypeHandle, or 0 if no slot number has been assigne...
This class is used to associate each RenderAttrib with a different slot index at runtime,...
int get_sorted_slot(int n) const
Returns the nth slot in sorted order.
get_index
Returns the integer index associated with this TypeHandle.
Definition: typeHandle.h:135
int get_num_sorted_slots() const
Returns the number of entries in the sorted_slots list.
const RenderAttrib * get_slot_default(int slot) const
Returns the default RenderAttrib object associated with slot n.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
static RenderAttribRegistry * quick_get_global_ptr()
Returns the global_ptr without first ensuring it has been initialized.