Mercator
ShaderFactory.h
00001 // This file may be redistributed and modified only under the terms of
00002 // the GNU General Public License (See COPYING for details).
00003 // Copyright (C) 2005 Alistair Riddoch
00004 
00005 #ifndef MERCATOR_SHADER_FACTORY_H
00006 #define MERCATOR_SHADER_FACTORY_H
00007 
00008 #include <Mercator/Shader.h>
00009 
00010 namespace Mercator {
00011 
00013 class ShaderKit {
00014   protected:
00015     explicit ShaderKit();
00016   public:
00017     virtual ~ShaderKit();
00018 
00022     virtual Shader * newShader(const Shader::Parameters &) const = 0;
00023 };
00024 
00026 template <class T>
00027 class ShaderFactory : public ShaderKit {
00028   public:
00029     ShaderFactory();
00030     ~ShaderFactory();
00031 
00032     virtual Shader * newShader(const Shader::Parameters &) const;
00033 };
00034 
00039 class ShaderFactories {
00040   private:
00042     typedef std::map<std::string, ShaderKit *> FactoryMap;
00043 
00045     FactoryMap m_factories;
00046 
00048     static ShaderFactories * m_instance;
00049 
00050     ShaderFactories();
00051     ~ShaderFactories();
00052   public:
00053     static ShaderFactories & instance();
00054     static void del();
00055 
00056     Shader * newShader(const std::string & type,
00057                        const Shader::Parameters &) const;
00058 };
00059 
00060 } // namespace Mercator
00061 
00062 #endif // MERCATOR_SHADER_FACTORY_H