File: ShaderFactory.h

package info (click to toggle)
mercator 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,008 kB
  • sloc: sh: 10,433; cpp: 4,482; makefile: 115
file content (62 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// This file may be redistributed and modified only under the terms of
// the GNU General Public License (See COPYING for details).
// Copyright (C) 2005 Alistair Riddoch

#ifndef MERCATOR_SHADER_FACTORY_H
#define MERCATOR_SHADER_FACTORY_H

#include <Mercator/Shader.h>

namespace Mercator {

/// \brief Interface for shader factory objects.
class ShaderKit {
  protected:
    explicit ShaderKit();
  public:
    virtual ~ShaderKit();

    /// \brief Create a new Shader instance
    ///
    /// @return a pointer to the new Shader.
    virtual Shader * newShader(const Shader::Parameters &) const = 0;
};

/// \brief Factory template used to create ordinary shader objects.
template <class T>
class ShaderFactory : public ShaderKit {
  public:
    ShaderFactory();
    ~ShaderFactory();

    virtual Shader * newShader(const Shader::Parameters &) const;
};

/// \brief Class which manages all the shader factories available.
///
/// Requests for new shaders of a given type are passed here, and
/// shader objects are returned.
class ShaderFactories {
  private:
    /// \brief STL map of shader factory pointers.
    typedef std::map<std::string, ShaderKit *> FactoryMap;

    /// \brief Map of shader factory pointers keyed on type string.
    FactoryMap m_factories;

    /// \brief Pointer to the singleton instance of ShaderFactories.
    static ShaderFactories * m_instance;

    ShaderFactories();
    ~ShaderFactories();
  public:
    static ShaderFactories & instance();
    static void del();

    Shader * newShader(const std::string & type,
                       const Shader::Parameters &) const;
};

} // namespace Mercator

#endif // MERCATOR_SHADER_FACTORY_H