Panda3D
materialPool.h
1 // Filename: materialPool.h
2 // Created by: drose (30Apr01)
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 MATERIALPOOL_H
16 #define MATERIALPOOL_H
17 
18 #include "pandabase.h"
19 #include "material.h"
20 #include "pointerTo.h"
21 #include "lightMutex.h"
22 #include "pset.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : MaterialPool
26 // Description : The MaterialPool (there is only one in the universe)
27 // serves to unify different pointers to the same
28 // Material, so we do not (a) waste memory with many
29 // different Material objects that are all equivalent,
30 // and (b) waste time switching the graphics engine
31 // between different Material states that are really the
32 // same thing.
33 //
34 // The idea is to create a temporary Material
35 // representing the lighting state you want to apply,
36 // then call get_material(), passing in your temporary
37 // Material. The return value will either be a new
38 // Material object, or it may be the the same object you
39 // supplied; in either case, it will have the same
40 // value.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDA_GOBJ MaterialPool {
43 PUBLISHED:
44  INLINE static Material *get_material(Material *temp);
45  INLINE static void release_material(Material *temp);
46  INLINE static void release_all_materials();
47 
48  INLINE static int garbage_collect();
49  INLINE static void list_contents(ostream &out);
50 
51  static void write(ostream &out);
52 
53 private:
54  INLINE MaterialPool();
55 
56  Material *ns_get_material(Material *temp);
57  void ns_release_material(Material *temp);
58  void ns_release_all_materials();
59 
60  int ns_garbage_collect();
61  void ns_list_contents(ostream &out) const;
62 
63  static MaterialPool *get_global_ptr();
64 
65  static MaterialPool *_global_ptr;
66 
67  LightMutex _lock;
68 
69  // We store a map of CPT(Material) to PT(Material). These are two
70  // equivalent structures, but different pointers. The first pointer
71  // never leaves this class. If the second pointer changes value,
72  // we'll notice it and return a new one.
74  Materials _materials;
75 };
76 
77 #include "materialPool.I"
78 
79 #endif
80 
81 
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
The MaterialPool (there is only one in the universe) serves to unify different pointers to the same M...
Definition: materialPool.h:42
Defines the way an object appears in the presence of lighting.
Definition: material.h:34
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45