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