Panda3D
 All Classes Functions Variables Enumerations
renderAttribRegistry.h
1 // Filename: renderAttribRegistry.h
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 #ifndef RENDERATTRIBREGISTRY_H
16 #define RENDERATTRIBREGISTRY_H
17 
18 #include "pandabase.h"
19 #include "typeHandle.h"
20 #include "vector_int.h"
21 #include "pointerTo.h"
22 #include "bitMask.h"
23 
24 class RenderAttrib;
25 class DeletedBufferChain;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : RenderAttribRegistry
29 // Description : This class is used to associate each RenderAttrib
30 // with a different slot index at runtime, so we can
31 // store a list of RenderAttribs in the RenderState
32 // object, and very quickly look them up by type.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PGRAPH RenderAttribRegistry {
35 private:
38 
39 public:
40  typedef CPT(RenderAttrib) MakeDefaultFunc();
41 
42  // This typedef defines the native bitmask type for indicating which
43  // slots are present in a RenderState. It must be wide enough to
44  // allow room for all of the possible RenderAttribs that might
45  // register themselves. Presently, 32 bits is wide enough, but only
46  // barely; when we exceed this limit, we will need to go to a 64-bit
47  // type instead. It will be interesting to see whether a BitMask64
48  // or a DoubleBitMask<BitMask32> will be faster on a 32-bit machine.
49  typedef BitMask32 SlotMask;
50 
51  int register_slot(TypeHandle type_handle, int sort,
52  MakeDefaultFunc *make_default_func);
53 
54 PUBLISHED:
55  INLINE int get_slot(TypeHandle type_handle) const;
56  INLINE int get_max_slots() const;
57 
58  INLINE int get_num_slots() const;
59  INLINE TypeHandle get_slot_type(int slot) const;
60  INLINE int get_slot_sort(int slot) const;
61  void set_slot_sort(int slot, int sort);
62  CPT(RenderAttrib) get_slot_default(int slot) const;
63 
64  INLINE int get_num_sorted_slots() const;
65  INLINE int get_sorted_slot(int n) const;
66 
67  INLINE DeletedBufferChain *get_array_chain() const;
68 
69  INLINE static RenderAttribRegistry *get_global_ptr();
70 
71 public:
72  INLINE static RenderAttribRegistry *quick_get_global_ptr();
73 
74 private:
75  static void init_global_ptr();
76 
77 private:
78  int _max_slots;
79 
80  class SortSlots {
81  public:
82  INLINE SortSlots(RenderAttribRegistry *reg);
83  INLINE bool operator () (int a, int b) const;
85  };
86 
87  class RegistryNode {
88  public:
89  TypeHandle _type;
90  int _sort;
91  MakeDefaultFunc *_make_default_func;
92  };
94  Registry _registry;
95 
96  vector_int _slots_by_type;
97  vector_int _sorted_slots;
98 
99  DeletedBufferChain *_array_chain;
100 
101  static RenderAttribRegistry *_global_ptr;
102 };
103 
104 #include "renderAttribRegistry.I"
105 
106 #endif
107 
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:60
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.
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...