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