Panda3D

renderAttribRegistry.h

00001 // Filename: renderAttribRegistry.h
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 #ifndef RENDERATTRIBREGISTRY_H
00016 #define RENDERATTRIBREGISTRY_H
00017 
00018 #include "pandabase.h"
00019 #include "typeHandle.h"
00020 #include "vector_int.h"
00021 #include "pointerTo.h"
00022 #include "bitMask.h"
00023 
00024 class RenderAttrib;
00025 class DeletedBufferChain;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : RenderAttribRegistry
00029 // Description : This class is used to associate each RenderAttrib
00030 //               with a different slot index at runtime, so we can
00031 //               store a list of RenderAttribs in the RenderState
00032 //               object, and very quickly look them up by type.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_PGRAPH RenderAttribRegistry {
00035 private:
00036   RenderAttribRegistry();
00037   ~RenderAttribRegistry();
00038 
00039 public:
00040   typedef CPT(RenderAttrib) MakeDefaultFunc();
00041 
00042   // This typedef defines the native bitmask type for indicating which
00043   // slots are present in a RenderState.  It must be wide enough to
00044   // allow room for all of the possible RenderAttribs that might
00045   // register themselves.  Presently, 32 bits is wide enough, but only
00046   // barely; when we exceed this limit, we will need to go to a 64-bit
00047   // type instead.  It will be interesting to see whether a BitMask64
00048   // or a DoubleBitMask<BitMask32> will be faster on a 32-bit machine.
00049   typedef BitMask32 SlotMask;
00050 
00051   int register_slot(TypeHandle type_handle, int sort,
00052                     MakeDefaultFunc *make_default_func);
00053 
00054 PUBLISHED:
00055   INLINE int get_slot(TypeHandle type_handle) const;
00056   INLINE int get_max_slots() const;
00057 
00058   INLINE int get_num_slots() const;
00059   INLINE TypeHandle get_slot_type(int slot) const;
00060   INLINE int get_slot_sort(int slot) const;
00061   void set_slot_sort(int slot, int sort);
00062   CPT(RenderAttrib) get_slot_default(int slot) const;
00063 
00064   INLINE int get_num_sorted_slots() const;
00065   INLINE int get_sorted_slot(int n) const;
00066 
00067   INLINE DeletedBufferChain *get_array_chain() const;
00068 
00069   INLINE static RenderAttribRegistry *get_global_ptr();
00070 
00071 public:
00072   INLINE static RenderAttribRegistry *quick_get_global_ptr();
00073 
00074 private:
00075   static void init_global_ptr();
00076 
00077 private:
00078   int _max_slots;
00079 
00080   class SortSlots {
00081   public:
00082     INLINE SortSlots(RenderAttribRegistry *reg);
00083     INLINE bool operator () (int a, int b) const;
00084     RenderAttribRegistry *_reg;
00085   };
00086 
00087   class RegistryNode {
00088   public:
00089     TypeHandle _type;
00090     int _sort;
00091     MakeDefaultFunc *_make_default_func;
00092   };
00093   typedef pvector<RegistryNode> Registry;
00094   Registry _registry;
00095 
00096   vector_int _slots_by_type;
00097   vector_int _sorted_slots;
00098 
00099   DeletedBufferChain *_array_chain;
00100 
00101   static RenderAttribRegistry *_global_ptr;
00102 };
00103 
00104 #include "renderAttribRegistry.I"
00105 
00106 #endif
00107 
 All Classes Functions Variables Enumerations