Panda3D
 All Classes Functions Variables Enumerations
shaderPool.h
00001 // Filename: shaderPool.h
00002 // Created by:  aignacio (Mar06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SHADERPOOL_H
00016 #define SHADERPOOL_H
00017 
00018 #include "pandabase.h"
00019 #include "shader.h"
00020 #include "filename.h"
00021 #include "lightMutex.h"
00022 #include "pmap.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : ShaderPool
00026 // Description : This is the preferred interface for loading shaders for
00027 //               the TextNode system.  It is similar to ModelPool and
00028 //               TexturePool in that it unifies references to the same
00029 //               filename.
00030 ////////////////////////////////////////////////////////////////////
00031 class EXPCL_PANDA_PGRAPH ShaderPool {
00032 PUBLISHED:
00033   INLINE static bool has_shader(const Filename &filename);
00034   INLINE static bool verify_shader(const Filename &filename);
00035   BLOCKING INLINE static CPT(Shader) load_shader(const Filename &filename);
00036   INLINE static void add_shader(const Filename &filename, Shader *shader);
00037   INLINE static void release_shader(const Filename &filename);
00038   INLINE static void release_all_shaders();
00039 
00040   INLINE static int garbage_collect();
00041 
00042   INLINE static void list_contents(ostream &out);
00043   static void write(ostream &out);
00044 
00045 private:
00046   INLINE ShaderPool();
00047 
00048   bool ns_has_shader(const Filename &orig_filename);
00049   CPT(Shader) ns_load_shader(const Filename &orig_filename);
00050   void ns_add_shader(const Filename &orig_filename, Shader *shader);
00051   void ns_release_shader(const Filename &orig_filename);
00052   void ns_release_all_shaders();
00053   int ns_garbage_collect();
00054   void ns_list_contents(ostream &out) const;
00055 
00056   void resolve_filename(Filename &new_filename, const Filename &orig_filename);
00057 
00058   static ShaderPool *get_ptr();
00059   static ShaderPool *_global_ptr;
00060 
00061   LightMutex _lock;
00062   typedef pmap<Filename,  CPT(Shader) > Shaders;
00063   Shaders _shaders;
00064 };
00065 
00066 #include "shaderPool.I"
00067 
00068 #endif
 All Classes Functions Variables Enumerations