15 #include "shaderPool.h"
16 #include "config_util.h"
17 #include "config_express.h"
18 #include "virtualFileSystem.h"
21 #include "string_utils.h"
33 get_ptr()->ns_list_contents(out);
42 ns_has_shader(
const Filename &orig_filename) {
44 resolve_filename(filename, orig_filename);
47 Shaders::const_iterator ti;
48 ti = _shaders.find(filename);
49 if (ti != _shaders.end()) {
63 ns_load_shader(const
Filename &orig_filename) {
65 resolve_filename(filename, orig_filename);
70 Shaders::const_iterator ti;
71 ti = _shaders.find(filename);
72 if (ti != _shaders.end()) {
80 <<
"Loading shader " << filename <<
"\n";
82 Shader::ShaderLanguage lang = Shader::SL_none;
89 if (ext ==
"cg" || ext ==
"sha") {
93 }
else if (ext ==
"glsl" || ext ==
"vert" || ext ==
"frag" ||
94 ext ==
"geom" || ext ==
"tesc" || ext ==
"tese" ||
96 lang = Shader::SL_GLSL;
100 if (shader == (
Shader *)NULL) {
110 Shaders::const_iterator ti;
111 ti = _shaders.find(filename);
112 if (ti != _shaders.end()) {
117 _shaders[filename] = shader;
131 resolve_filename(filename, orig_filename);
135 _shaders[filename] = shader;
144 ns_release_shader(
const Filename &filename) {
147 Shaders::iterator ti;
148 ti = _shaders.find(filename);
149 if (ti != _shaders.end()) {
160 ns_release_all_shaders() {
172 ns_garbage_collect() {
175 int num_released = 0;
178 Shaders::iterator ti;
179 for (ti = _shaders.begin(); ti != _shaders.end(); ++ti) {
180 CPT(
Shader) shader = (*ti).second;
181 if (shader->get_ref_count() == 1) {
190 new_set.insert(new_set.end(), *ti);
194 _shaders.swap(new_set);
204 ns_list_contents(ostream &out)
const {
207 out << _shaders.size() <<
" shaders:\n";
208 Shaders::const_iterator ti;
209 for (ti = _shaders.begin(); ti != _shaders.end(); ++ti) {
210 CPT(
Shader) shader = (*ti).second;
211 out << " " << (*ti).first
212 << " (count = " << shader->get_ref_count() << ")\n";
225 new_filename = orig_filename;
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
This is the preferred interface for loading shaders for the TextNode system.
The name of a file, such as a texture file or an Egg file.
Similar to MutexHolder, but for a light mutex.
static void write(ostream &out)
Lists the contents of the shader pool to the indicated output stream.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const string &default_extension=string()) const
Searches the given search path for the filename.
string get_extension() const
Returns the file extension.