Panda3D
materialPool.I
1 // Filename: materialPool.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: MaterialPool::get_material
18 // Access: Public, Static
19 // Description: Returns a Material pointer that represents the
20 // same material described by temp, except that it is a
21 // shared pointer.
22 //
23 // Each call to get_material() passing an equivalent
24 // Material pointer will return the same shared pointer.
25 //
26 // If you modify the shared pointer, it will
27 // automatically disassociate it from the pool.
28 //
29 // Also, the return value may be a different pointer
30 // than that passed in, or it may be the same pointer.
31 // In either case, the passed in pointer has now been
32 // sacrificed to the greater good and should not be used
33 // again (like any other PointerTo, it will be freed
34 // when the last reference count is removed).
35 ////////////////////////////////////////////////////////////////////
38  return get_global_ptr()->ns_get_material(temp);
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: MaterialPool::release_material
43 // Access: Published, Static
44 // Description: Removes the indicated material from the pool.
45 ////////////////////////////////////////////////////////////////////
46 INLINE void MaterialPool::
48  get_global_ptr()->ns_release_material(material);
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: MaterialPool::release_all_materials
53 // Access: Published, Static
54 // Description: Releases all materials in the pool and restores the
55 // pool to the empty state.
56 ////////////////////////////////////////////////////////////////////
57 INLINE void MaterialPool::
59  get_global_ptr()->ns_release_all_materials();
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: MaterialPool::garbage_collect
64 // Access: Public, Static
65 // Description: Releases only those materials in the pool that have a
66 // reference count of exactly 1; i.e. only those
67 // materials that are not being used outside of the pool.
68 // Returns the number of materials released.
69 ////////////////////////////////////////////////////////////////////
70 INLINE int MaterialPool::
72  return get_global_ptr()->ns_garbage_collect();
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: MaterialPool::list_contents
77 // Access: Public, Static
78 // Description: Lists the contents of the material pool to the
79 // indicated output stream.
80 ////////////////////////////////////////////////////////////////////
81 INLINE void MaterialPool::
82 list_contents(ostream &out) {
83  get_global_ptr()->ns_list_contents(out);
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: MaterialPool::Constructor
88 // Access: Private
89 // Description: The constructor is not intended to be called
90 // directly; there's only supposed to be one MaterialPool
91 // in the universe and it constructs itself.
92 ////////////////////////////////////////////////////////////////////
93 INLINE MaterialPool::
94 MaterialPool() {
95 }
static Material * get_material(Material *temp)
Returns a Material pointer that represents the same material described by temp, except that it is a s...
Definition: materialPool.I:37
static void list_contents(ostream &out)
Lists the contents of the material pool to the indicated output stream.
Definition: materialPool.I:82
static void release_all_materials()
Releases all materials in the pool and restores the pool to the empty state.
Definition: materialPool.I:58
static int garbage_collect()
Releases only those materials in the pool that have a reference count of exactly 1; i...
Definition: materialPool.I:71
static void release_material(Material *temp)
Removes the indicated material from the pool.
Definition: materialPool.I:47
Defines the way an object appears in the presence of lighting.
Definition: material.h:34