Panda3D
cullBinManager.h
1 // Filename: cullBinManager.h
2 // Created by: drose (27Feb02)
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 CULLBINMANAGER_H
16 #define CULLBINMANAGER_H
17 
18 #include "pandabase.h"
19 #include "cullBin.h"
20 #include "cullBinEnums.h"
21 #include "pointerTo.h"
22 #include "pvector.h"
23 #include "epvector.h"
24 #include "pmap.h"
25 #include "vector_int.h"
26 #include "pStatCollector.h"
27 
28 class CullResult;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : CullBinManager
33 // Description : This is a global object that maintains the collection
34 // of named CullBins in the world.
35 ////////////////////////////////////////////////////////////////////
36 class EXPCL_PANDA_PGRAPH CullBinManager : public CullBinEnums {
37 protected:
39  ~CullBinManager();
40 
41 PUBLISHED:
42  typedef CullBin::BinType BinType;
43 
44  int add_bin(const string &name, BinType type, int sort);
45  void remove_bin(int bin_index);
46 
47  INLINE int get_num_bins() const;
48  INLINE int get_bin(int n) const;
49  MAKE_SEQ(get_bins, get_num_bins, get_bin);
50  int find_bin(const string &name) const;
51 
52  INLINE string get_bin_name(int bin_index) const;
53 
54  INLINE BinType get_bin_type(int bin_index) const;
55  INLINE BinType get_bin_type(const string &name) const;
56  INLINE void set_bin_type(int bin_index, BinType type);
57  INLINE void set_bin_type(const string &name, BinType type);
58 
59  INLINE int get_bin_sort(int bin_index) const;
60  INLINE int get_bin_sort(const string &name) const;
61  INLINE void set_bin_sort(int bin_index, int sort);
62  INLINE void set_bin_sort(const string &name, int sort);
63 
64  INLINE bool get_bin_active(int bin_index) const;
65  INLINE bool get_bin_active(const string &name) const;
66  INLINE void set_bin_active(int bin_index, bool active);
67  INLINE void set_bin_active(const string &name, bool active);
68 
69 #ifndef NDEBUG
70  INLINE bool get_bin_flash_active(int bin_index) const;
71  INLINE const LColor &get_bin_flash_color(int bin_index) const;
72  INLINE void set_bin_flash_active(int bin_index, bool active);
73  INLINE void set_bin_flash_color(int bin_index, const LColor &color);
74 #endif
75 
76  void write(ostream &out) const;
77 
78  INLINE static CullBinManager *get_global_ptr();
79 
80 public:
81  // This interface is only intended to be used by CullResult.
82  PT(CullBin) make_new_bin(int bin_index, GraphicsStateGuardianBase *gsg,
83  const PStatCollector &draw_region_pcollector);
84 
85  // This defines the factory interface for defining constructors to
86  // bin types (the implementations are in the cull directory, not
87  // here in pgraph, so we can't call the constructors directly).
88  typedef CullBin *BinConstructor(const string &name,
90  const PStatCollector &draw_region_pcollector);
91 
92  void register_bin_type(BinType type, BinConstructor *constructor);
93 
94 private:
95  void do_sort_bins();
96  void setup_initial_bins();
97  static BinType parse_bin_type(const string &bin_type);
98 
99  class EXPCL_PANDA_PGRAPH BinDefinition {
100  public:
101 #ifndef NDEBUG
102  LColor _flash_color;
103  bool _flash_active;
104 #endif
105  bool _in_use;
106  string _name;
107  BinType _type;
108  int _sort;
109  bool _active;
110  };
111  typedef epvector<BinDefinition> BinDefinitions;
112  BinDefinitions _bin_definitions;
113 
114  class SortBins {
115  public:
116  INLINE SortBins(CullBinManager *manager);
117  INLINE bool operator () (int a, int b) const;
118  CullBinManager *_manager;
119  };
120 
122  BinsByName _bins_by_name;
123 
124  typedef vector_int SortedBins;
125  SortedBins _sorted_bins;
126  bool _bins_are_sorted;
127  bool _unused_bin_index;
128 
130  BinConstructors _bin_constructors;
131 
132  static CullBinManager *_global_ptr;
133  friend class SortBins;
134 };
135 
136 EXPCL_PANDA_PGRAPH ostream &
137 operator << (ostream &out, CullBinManager::BinType bin_type);
138 
139 #include "cullBinManager.I"
140 
141 #endif
A collection of Geoms and their associated state, for a particular scene.
Definition: cullBin.h:44
Provides scoping for the enumerated type shared by CullBin and CullBinManager.
Definition: cullBinEnums.h:25
A lightweight class that represents a single element that may be timed and/or counted via stats...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This stores the result of a BinCullHandler traversal: an ordered collection of CullBins, each of which holds a number of Geoms and RenderStates to be rendered in some defined order.
Definition: cullResult.h:47
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is a global object that maintains the collection of named CullBins in the world.