Panda3D
Loading...
Searching...
No Matches
shaderPool.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 shaderPool.h
10 * @author aignacio
11 * @date 2006-03
12 */
13
14#ifndef SHADERPOOL_H
15#define SHADERPOOL_H
16
17#include "pandabase.h"
18#include "shader.h"
19#include "filename.h"
20#include "lightMutex.h"
21#include "pmap.h"
22
23/**
24 * This is the preferred interface for loading shaders for the TextNode
25 * system. It is similar to ModelPool and TexturePool in that it unifies
26 * references to the same filename.
27 */
28class EXPCL_PANDA_PGRAPH ShaderPool {
29PUBLISHED:
30 INLINE static bool has_shader(const Filename &filename);
31 INLINE static bool verify_shader(const Filename &filename);
32 BLOCKING INLINE static CPT(Shader) load_shader(const Filename &filename);
33 INLINE static void add_shader(const Filename &filename, Shader *shader);
34 INLINE static void release_shader(const Filename &filename);
35 INLINE static void release_all_shaders();
36
37 INLINE static int garbage_collect();
38
39 INLINE static void list_contents(std::ostream &out);
40 static void write(std::ostream &out);
41
42private:
43 INLINE ShaderPool();
44
45 bool ns_has_shader(const Filename &orig_filename);
46 CPT(Shader) ns_load_shader(const Filename &orig_filename);
47 void ns_add_shader(const Filename &orig_filename, Shader *shader);
48 void ns_release_shader(const Filename &orig_filename);
49 void ns_release_all_shaders();
50 int ns_garbage_collect();
51 void ns_list_contents(std::ostream &out) const;
52
53 void resolve_filename(Filename &new_filename, const Filename &orig_filename);
54
55 static ShaderPool *get_ptr();
56 static ShaderPool *_global_ptr;
57
58 LightMutex _lock;
59 typedef pmap<Filename, CPT(Shader) > Shaders;
60 Shaders _shaders;
61};
62
63#include "shaderPool.I"
64
65#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
static void list_contents(std::ostream &out)
Lists the contents of the shader pool to the indicated output stream.
Definition shaderPool.I:87
static void write(std::ostream &out)
Lists the contents of the shader pool to the indicated output stream.
static void add_shader(const Filename &filename, Shader *shader)
Adds the indicated already-loaded shader to the pool.
Definition shaderPool.I:50
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 int garbage_collect()
Releases only those shaders in the pool that have a reference count of exactly 1; i....
Definition shaderPool.I:79
static void release_all_shaders()
Releases all shaders in the pool and restores the pool to the empty state.
Definition shaderPool.I:69
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 bool has_shader(const Filename &filename)
Returns true if the shader has ever been loaded, false otherwise.
Definition shaderPool.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.