Panda3D
renderAttribRegistry.I
1 // Filename: renderAttribRegistry.I
2 // Created by: drose (13Nov08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: RenderAttribRegistry::get_slot
18 // Access: Published
19 // Description: Returns the slot number assigned to the indicated
20 // TypeHandle, or 0 if no slot number has been assigned.
21 ////////////////////////////////////////////////////////////////////
22 INLINE int RenderAttribRegistry::
23 get_slot(TypeHandle type_handle) const {
24  int type_index = type_handle.get_index();
25  if (type_index >= (int)_slots_by_type.size()) {
26  return 0;
27  }
28  return _slots_by_type[type_index];
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: RenderAttribRegistry::get_max_slots
33 // Access: Published
34 // Description: Returns the maximum number that any slot number is
35 // allowed to grow. Actually, this number will be one
36 // higher than the highest possible slot number. This
37 // puts an upper bound on the number of RenderAttrib
38 // slots that may be allocated, and allows other code to
39 // define an array of slots.
40 //
41 // This number will not change during the lifetime of
42 // the application.
43 ////////////////////////////////////////////////////////////////////
44 INLINE int RenderAttribRegistry::
45 get_max_slots() const {
46  return _max_slots;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: RenderAttribRegistry::get_num_slots
51 // Access: Published
52 // Description: Returns the number of RenderAttrib slots that have
53 // been allocated. This is one more than the highest
54 // slot number in use.
55 ////////////////////////////////////////////////////////////////////
56 INLINE int RenderAttribRegistry::
57 get_num_slots() const {
58  return _registry.size();
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: RenderAttribRegistry::get_slot_type
63 // Access: Published
64 // Description: Returns the TypeHandle associated with slot n.
65 ////////////////////////////////////////////////////////////////////
67 get_slot_type(int slot) const {
68  nassertr(slot >= 0 && slot < (int)_registry.size(), TypeHandle::none());
69  return _registry[slot]._type;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: RenderAttribRegistry::get_slot_sort
74 // Access: Published
75 // Description: Returns the sort number associated with slot n.
76 ////////////////////////////////////////////////////////////////////
77 INLINE int RenderAttribRegistry::
78 get_slot_sort(int slot) const {
79  nassertr(slot >= 0 && slot < (int)_registry.size(), 0);
80  return _registry[slot]._sort;
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: RenderAttribRegistry::get_num_sorted_slots
85 // Access: Published
86 // Description: Returns the number of entries in the sorted_slots
87 // list.
88 ////////////////////////////////////////////////////////////////////
89 INLINE int RenderAttribRegistry::
91  return _sorted_slots.size();
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: RenderAttribRegistry::get_sorted_slot
96 // Access: Published
97 // Description: Returns the nth slot in sorted order. By traversing
98 // this list, you will retrieve all the slot numbers in
99 // order according to their registered sort value.
100 ////////////////////////////////////////////////////////////////////
101 INLINE int RenderAttribRegistry::
102 get_sorted_slot(int n) const {
103  nassertr(n >= 0 && n < (int)_sorted_slots.size(), 0);
104  return _sorted_slots[n];
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: RenderAttribRegistry::get_array_chain
109 // Access: Published
110 // Description: Returns the DeletedBufferChain object that may be
111 // used to allocated appropriately-sized arrays of
112 // RenderState::Attribute objects.
113 ////////////////////////////////////////////////////////////////////
116  return _array_chain;
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: RenderAttribRegistry::get_global_ptr
121 // Access: Published, Static
122 // Description:
123 ////////////////////////////////////////////////////////////////////
124 INLINE RenderAttribRegistry *RenderAttribRegistry::
125 get_global_ptr() {
126  if (_global_ptr == (RenderAttribRegistry *)NULL) {
127  init_global_ptr();
128  }
129  return _global_ptr;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: RenderAttribRegistry::quick_get_global_ptr
134 // Access: Public, Static
135 // Description: Returns the global_ptr without first ensuring it has
136 // been initialized. Only safe for code that knows it
137 // has already been initialized.
138 ////////////////////////////////////////////////////////////////////
141  return _global_ptr;
142 }
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: RenderAttribRegistry::SortSlots::Constructor
146 // Access: Public
147 // Description: This is an STL function object for sorting the
148 // _sorted_slots list into order by slot sort number.
149 ////////////////////////////////////////////////////////////////////
150 INLINE RenderAttribRegistry::SortSlots::
151 SortSlots(RenderAttribRegistry *reg) : _reg(reg) {
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: RenderAttribRegistry::SortSlots::operator ()
156 // Access: Public
157 // Description:
158 ////////////////////////////////////////////////////////////////////
159 INLINE bool RenderAttribRegistry::SortSlots::
160 operator () (int a, int b) const {
161  return _reg->get_slot_sort(a) < _reg->get_slot_sort(b);
162 }
TypeHandle get_slot_type(int slot) const
Returns the TypeHandle associated with slot n.
static TypeHandle none()
Returns a special zero-valued TypeHandle that is used to indicate no type.
Definition: typeHandle.I:274
int get_index() const
Returns the integer index associated with this TypeHandle.
Definition: typeHandle.I:253
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, so we can store a list of RenderAttribs in the RenderState object, and very quickly look them up by type.
int get_sorted_slot(int n) const
Returns the nth slot in sorted order.
int get_num_sorted_slots() const
Returns the number of entries in the sorted_slots list.
DeletedBufferChain * get_array_chain() const
Returns the DeletedBufferChain object that may be used to allocated appropriately-sized arrays of Ren...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This template class can be used to provide faster allocation/deallocation for many Panda objects...
static RenderAttribRegistry * quick_get_global_ptr()
Returns the global_ptr without first ensuring it has been initialized.
int get_max_slots() const
Returns the maximum number that any slot number is allowed to grow.