Panda3D

renderAttribRegistry.I

00001 // Filename: renderAttribRegistry.I
00002 // Created by:  drose (13Nov08)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: RenderAttribRegistry::get_slot
00018 //       Access: Published
00019 //  Description: Returns the slot number assigned to the indicated
00020 //               TypeHandle, or 0 if no slot number has been assigned.
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE int RenderAttribRegistry::
00023 get_slot(TypeHandle type_handle) const {
00024   int type_index = type_handle.get_index();
00025   if (type_index >= (int)_slots_by_type.size()) {
00026     return 0;
00027   }
00028   return _slots_by_type[type_index];
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: RenderAttribRegistry::get_max_slots
00033 //       Access: Published
00034 //  Description: Returns the maximum number that any slot number is
00035 //               allowed to grow.  Actually, this number will be one
00036 //               higher than the highest possible slot number.  This
00037 //               puts an upper bound on the number of RenderAttrib
00038 //               slots that may be allocated, and allows other code to
00039 //               define an array of slots.
00040 //
00041 //               This number will not change during the lifetime of
00042 //               the application.
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE int RenderAttribRegistry::
00045 get_max_slots() const {
00046   return _max_slots;
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: RenderAttribRegistry::get_num_slots
00051 //       Access: Published
00052 //  Description: Returns the number of RenderAttrib slots that have
00053 //               been allocated.  This is one more than the highest
00054 //               slot number in use.
00055 ////////////////////////////////////////////////////////////////////
00056 INLINE int RenderAttribRegistry::
00057 get_num_slots() const {
00058   return _registry.size();
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: RenderAttribRegistry::get_slot_type
00063 //       Access: Published
00064 //  Description: Returns the TypeHandle associated with slot n.
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE TypeHandle RenderAttribRegistry::
00067 get_slot_type(int slot) const {
00068   nassertr(slot >= 0 && slot < (int)_registry.size(), TypeHandle::none());
00069   return _registry[slot]._type;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: RenderAttribRegistry::get_slot_sort
00074 //       Access: Published
00075 //  Description: Returns the sort number associated with slot n.
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE int RenderAttribRegistry::
00078 get_slot_sort(int slot) const {
00079   nassertr(slot >= 0 && slot < (int)_registry.size(), 0);
00080   return _registry[slot]._sort;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: RenderAttribRegistry::get_num_sorted_slots
00085 //       Access: Published
00086 //  Description: Returns the number of entries in the sorted_slots
00087 //               list.
00088 ////////////////////////////////////////////////////////////////////
00089 INLINE int RenderAttribRegistry::
00090 get_num_sorted_slots() const {
00091   return _sorted_slots.size();
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: RenderAttribRegistry::get_sorted_slot
00096 //       Access: Published
00097 //  Description: Returns the nth slot in sorted order.  By traversing
00098 //               this list, you will retrieve all the slot numbers in
00099 //               order according to their registered sort value.
00100 ////////////////////////////////////////////////////////////////////
00101 INLINE int RenderAttribRegistry::
00102 get_sorted_slot(int n) const {
00103   nassertr(n >= 0 && n < (int)_sorted_slots.size(), 0);
00104   return _sorted_slots[n];
00105 }
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 //     Function: RenderAttribRegistry::get_array_chain
00109 //       Access: Published
00110 //  Description: Returns the DeletedBufferChain object that may be
00111 //               used to allocated appropriately-sized arrays of
00112 //               RenderState::Attribute objects.
00113 ////////////////////////////////////////////////////////////////////
00114 INLINE DeletedBufferChain *RenderAttribRegistry::
00115 get_array_chain() const {
00116   return _array_chain;
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: RenderAttribRegistry::get_global_ptr
00121 //       Access: Published, Static
00122 //  Description:
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE RenderAttribRegistry *RenderAttribRegistry::
00125 get_global_ptr() {
00126   if (_global_ptr == (RenderAttribRegistry *)NULL) {
00127     init_global_ptr();
00128   }
00129   return _global_ptr;
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: RenderAttribRegistry::quick_get_global_ptr
00134 //       Access: Public, Static
00135 //  Description: Returns the global_ptr without first ensuring it has
00136 //               been initialized.  Only safe for code that knows it
00137 //               has already been initialized.
00138 ////////////////////////////////////////////////////////////////////
00139 INLINE RenderAttribRegistry *RenderAttribRegistry::
00140 quick_get_global_ptr() {
00141   return _global_ptr;
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: RenderAttribRegistry::SortSlots::Constructor
00146 //       Access: Public
00147 //  Description: This is an STL function object for sorting the
00148 //               _sorted_slots list into order by slot sort number.
00149 ////////////////////////////////////////////////////////////////////
00150 INLINE RenderAttribRegistry::SortSlots::
00151 SortSlots(RenderAttribRegistry *reg) : _reg(reg) {
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: RenderAttribRegistry::SortSlots::operator ()
00156 //       Access: Public
00157 //  Description: 
00158 ////////////////////////////////////////////////////////////////////
00159 INLINE bool RenderAttribRegistry::SortSlots::
00160 operator () (int a, int b) const {
00161   return _reg->get_slot_sort(a) < _reg->get_slot_sort(b);
00162 }
 All Classes Functions Variables Enumerations