Panda3D
renderAttribRegistry.h
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.h
10  * @author drose
11  * @date 2008-11-13
12  */
13 
14 #ifndef RENDERATTRIBREGISTRY_H
15 #define RENDERATTRIBREGISTRY_H
16 
17 #include "pandabase.h"
18 #include "typeHandle.h"
19 #include "vector_int.h"
20 #include "pointerTo.h"
21 #include "bitMask.h"
22 
23 class RenderAttrib;
24 class DeletedBufferChain;
25 
26 /**
27  * This class is used to associate each RenderAttrib with a different slot
28  * index at runtime, so we can store a list of RenderAttribs in the
29  * RenderState object, and very quickly look them up by type.
30  */
31 class EXPCL_PANDA_PGRAPH RenderAttribRegistry {
32 private:
35 
36 public:
37  typedef CPT(RenderAttrib) MakeDefaultFunc();
38 
39  // This typedef defines the native bitmask type for indicating which slots
40  // are present in a RenderState. It must be wide enough to allow room for
41  // all of the possible RenderAttribs that might register themselves.
42  // Presently, 32 bits is wide enough, but only barely; when we exceed this
43  // limit, we will need to go to a 64-bit type instead. It will be
44  // interesting to see whether a BitMask64 or a DoubleBitMask<BitMask32> will
45  // be faster on a 32-bit machine.
46  typedef BitMask32 SlotMask;
47 
48  // Raise this number whenever we add a new attrib. This used to be
49  // determined at runtime, but it's better to have it as a constexpr.
50  static const int _max_slots = 32;
51 
52  int register_slot(TypeHandle type_handle, int sort,
53  RenderAttrib *default_attrib);
54 
55 PUBLISHED:
56  INLINE int get_slot(TypeHandle type_handle) const;
57  static constexpr int get_max_slots() { return _max_slots; }
58 
59  INLINE int get_num_slots() const;
60  INLINE TypeHandle get_slot_type(int slot) const;
61  INLINE int get_slot_sort(int slot) const;
62  void set_slot_sort(int slot, int sort);
63  INLINE const RenderAttrib *get_slot_default(int slot) const;
64 
65  INLINE int get_num_sorted_slots() const;
66  INLINE int get_sorted_slot(int n) const;
67 
68  INLINE static RenderAttribRegistry *get_global_ptr();
69 
70 public:
71  INLINE static RenderAttribRegistry *quick_get_global_ptr();
72 
73 private:
74  static void init_global_ptr();
75 
76 private:
77  class SortSlots {
78  public:
79  INLINE SortSlots(RenderAttribRegistry *reg);
80  INLINE bool operator () (int a, int b) const;
82  };
83 
84  class RegistryNode {
85  public:
86  INLINE RegistryNode(TypeHandle type, int sort,
87  const RenderAttrib *default_attrib);
88 
89  TypeHandle _type;
90  int _sort;
91  const RenderAttrib *_default_attrib;
92  };
94  Registry _registry;
95 
96  vector_int _slots_by_type;
97  vector_int _sorted_slots;
98 
99  static RenderAttribRegistry *_global_ptr;
100 };
101 
102 #include "renderAttribRegistry.I"
103 
104 #endif
renderAttribRegistry.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector< RegistryNode >
vector_int.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
RenderAttrib
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
BitMask< uint32_t, 32 >
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
bitMask.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DeletedBufferChain
This template class can be used to provide faster allocation/deallocation for many Panda objects.
Definition: deletedBufferChain.h:58
typeHandle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
RenderAttribRegistry
This class is used to associate each RenderAttrib with a different slot index at runtime,...
Definition: renderAttribRegistry.h:31