Panda3D
shaderPool.I
1 // Filename: shaderPool.I
2 // Created by: aignacio (Mar06)
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: ShaderPool::has_shader
18 // Access: Public, Static
19 // Description: Returns true if the shader has ever been loaded,
20 // false otherwise.
21 ////////////////////////////////////////////////////////////////////
22 INLINE bool ShaderPool::
23 has_shader(const Filename &filename) {
24  return get_ptr()->ns_has_shader(filename);
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: ShaderPool::verify_shader
29 // Access: Public, Static
30 // Description: Loads the given filename up into a shader, if it has
31 // not already been loaded, and returns true to indicate
32 // success, or false to indicate failure. If this
33 // returns true, it is guaranteed that a subsequent call
34 // to load_shader() with the same shader name will
35 // return a valid Shader pointer.
36 ////////////////////////////////////////////////////////////////////
37 INLINE bool ShaderPool::
38 verify_shader(const Filename &filename) {
39  return load_shader(filename) != (Shader *)NULL;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ShaderPool::load_shader
44 // Access: Public, Static
45 // Description: Loads the given filename up into a shader, if it has
46 // not already been loaded, and returns the new shader.
47 // If a shader with the same filename was previously
48 // loaded, returns that one instead. If the shader
49 // file cannot be found, returns NULL.
50 ////////////////////////////////////////////////////////////////////
51 INLINE CPT(Shader) ShaderPool::
52 load_shader(const Filename &filename) {
53  return get_ptr()->ns_load_shader(filename);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: ShaderPool::add_shader
58 // Access: Public, Static
59 // Description: Adds the indicated already-loaded shader to the
60 // pool. The shader will always replace any
61 // previously-loaded shader in the pool that had the
62 // same filename.
63 ////////////////////////////////////////////////////////////////////
64 INLINE void ShaderPool::
65 add_shader(const Filename &filename, Shader *shader) {
66  get_ptr()->ns_add_shader(filename, shader);
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: ShaderPool::release_shader
71 // Access: Public, Static
72 // Description: Removes the indicated shader from the pool,
73 // indicating it will never be loaded again; the shader
74 // may then be freed. If this function is never called,
75 // a reference count will be maintained on every shader
76 // every loaded, and shaders will never be freed.
77 ////////////////////////////////////////////////////////////////////
78 INLINE void ShaderPool::
79 release_shader(const Filename &filename) {
80  get_ptr()->ns_release_shader(filename);
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: ShaderPool::release_all_shaders
85 // Access: Public, Static
86 // Description: Releases all shaders in the pool and restores the
87 // pool to the empty state.
88 ////////////////////////////////////////////////////////////////////
89 INLINE void ShaderPool::
91  get_ptr()->ns_release_all_shaders();
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: ShaderPool::garbage_collect
96 // Access: Public, Static
97 // Description: Releases only those shaders in the pool that have a
98 // reference count of exactly 1; i.e. only those
99 // shaders that are not being used outside of the pool.
100 // Returns the number of shaders released.
101 ////////////////////////////////////////////////////////////////////
102 INLINE int ShaderPool::
104  return get_ptr()->ns_garbage_collect();
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: ShaderPool::list_contents
109 // Access: Public, Static
110 // Description: Lists the contents of the shader pool to the
111 // indicated output stream.
112 ////////////////////////////////////////////////////////////////////
113 INLINE void ShaderPool::
114 list_contents(ostream &out) {
115  get_ptr()->ns_list_contents(out);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: ShaderPool::Constructor
120 // Access: Private
121 // Description: The constructor is not intended to be called
122 // directly; there's only supposed to be one ShaderPool
123 // in the universe and it constructs itself.
124 ////////////////////////////////////////////////////////////////////
125 INLINE ShaderPool::
126 ShaderPool() {
127 }
static void add_shader(const Filename &filename, Shader *shader)
Adds the indicated already-loaded shader to the pool.
Definition: shaderPool.I:65
Definition: shader.h:50
static void release_all_shaders()
Releases all shaders in the pool and restores the pool to the empty state.
Definition: shaderPool.I:90
static int garbage_collect()
Releases only those shaders in the pool that have a reference count of exactly 1; i...
Definition: shaderPool.I:103
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
static bool verify_shader(const Filename &filename)
Loads the given filename up into a shader, if it has not already been loaded, and returns true to ind...
Definition: shaderPool.I:38
static void release_shader(const Filename &filename)
Removes the indicated shader from the pool, indicating it will never be loaded again; the shader may ...
Definition: shaderPool.I:79
static void list_contents(ostream &out)
Lists the contents of the shader pool to the indicated output stream.
Definition: shaderPool.I:114
static bool has_shader(const Filename &filename)
Returns true if the shader has ever been loaded, false otherwise.
Definition: shaderPool.I:23