File: ShaderFactory.cpp

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 (75 lines) | stat: -rw-r--r-- 1,872 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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

#include <Mercator/ShaderFactory_impl.h>

#include <Mercator/DepthShader.h>
#include <Mercator/FillShader.h>
#include <Mercator/GrassShader.h>
#include <Mercator/ThresholdShader.h>

#include <cassert>

namespace Mercator {

ShaderKit::ShaderKit()
{
}

ShaderKit::~ShaderKit()
{
}

ShaderFactories * ShaderFactories::m_instance = 0;

ShaderFactories::ShaderFactories()
{
    m_factories["grass"] = new ShaderFactory<GrassShader>;
    m_factories["depth"] = new ShaderFactory<DepthShader>;
    m_factories["fill"] = new ShaderFactory<FillShader>;
    m_factories["high"] = new ShaderFactory<HighShader>;
    m_factories["low"] = new ShaderFactory<LowShader>;
    m_factories["band"] = new ShaderFactory<BandShader>;
}

ShaderFactories::~ShaderFactories()
{
}

/// \brief Construct a singleton instance if required.
///
/// @returns a reference to the instance.
ShaderFactories & ShaderFactories::instance()
{
    if (m_instance == 0) {
        m_instance = new ShaderFactories();
    }
    return *m_instance;
}

/// \brief Delete the instance
void ShaderFactories::del()
{
    if (m_instance != 0) {
        delete m_instance;
    }
}

/// \brief Create a shader of the specified type.
///
/// @param type a string giving the type of shader.
/// @param params a map of the parameters for the shader
/// @returns a pointer to the new shader object
Shader * ShaderFactories::newShader(const std::string & type,
                                    const Shader::Parameters & params) const
{
    FactoryMap::const_iterator I = m_factories.find(type);
    if (I == m_factories.end()) {
        return 0;
    }
    assert(I->second != 0);
    return I->second->newShader(params);
}

} // namespace Mercator