Mercator
ShaderFactory.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2005 Alistair Riddoch
4 
5 #ifndef MERCATOR_SHADER_FACTORY_H
6 #define MERCATOR_SHADER_FACTORY_H
7 
8 #include <Mercator/Shader.h>
9 
10 namespace Mercator {
11 
13 class ShaderKit {
14  protected:
15  explicit ShaderKit();
16  public:
17  virtual ~ShaderKit();
18 
22  virtual Shader * newShader(const Shader::Parameters &) const = 0;
23 };
24 
26 template <class T>
27 class ShaderFactory : public ShaderKit {
28  public:
29  ShaderFactory();
30  ~ShaderFactory();
31 
32  virtual Shader * newShader(const Shader::Parameters &) const;
33 };
34 
40  private:
42  typedef std::map<std::string, ShaderKit *> FactoryMap;
43 
45  FactoryMap m_factories;
46 
49 
51  ~ShaderFactories();
52  public:
53  static ShaderFactories & instance();
54  static void del();
55 
56  Shader * newShader(const std::string & type,
57  const Shader::Parameters &) const;
58 };
59 
60 } // namespace Mercator
61 
62 #endif // MERCATOR_SHADER_FACTORY_H
Definition: Area.cpp:20
std::map< std::string, ShaderKit * > FactoryMap
STL map of shader factory pointers.
Definition: ShaderFactory.h:42
Factory template used to create ordinary shader objects.
Definition: ShaderFactory.h:27
std::map< std::string, float > Parameters
STL map of parameter values for a shader constructor.
Definition: Shader.h:63
virtual Shader * newShader(const Shader::Parameters &) const =0
Create a new Shader instance.
Class which manages all the shader factories available.
Definition: ShaderFactory.h:39
Interface for shader factory objects.
Definition: ShaderFactory.h:13
Base class for Shader objects which create surface data for use when rendering terrain.
Definition: Shader.h:29
FactoryMap m_factories
Map of shader factory pointers keyed on type string.
Definition: ShaderFactory.h:45
static ShaderFactories * m_instance
Pointer to the singleton instance of ShaderFactories.
Definition: ShaderFactory.h:48