forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shader.cpp
75 lines (59 loc) · 1.63 KB
/
Shader.cpp
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
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#include <MaterialXGenShader/Shader.h>
#include <MaterialXGenShader/ShaderGenerator.h>
#include <MaterialXGenShader/Syntax.h>
#include <MaterialXGenShader/Util.h>
#include <MaterialXCore/Document.h>
#include <MaterialXCore/Node.h>
#include <MaterialXCore/Value.h>
MATERIALX_NAMESPACE_BEGIN
//
// Shader methods
//
Shader::Shader(const string& name, ShaderGraphPtr graph) :
_name(name),
_graph(graph)
{
}
ShaderStage& Shader::getStage(size_t index)
{
return *_stages[index];
}
const ShaderStage& Shader::getStage(size_t index) const
{
return *_stages[index];
}
bool Shader::hasStage(const string& name)
{
auto it = _stagesMap.find(name);
return (it != _stagesMap.end());
}
ShaderStage& Shader::getStage(const string& name)
{
auto it = _stagesMap.find(name);
if (it == _stagesMap.end())
{
throw ExceptionShaderGenError("Stage '" + name + "' doesn't exist in shader '" + getName() + "'");
}
return *it->second;
}
const ShaderStage& Shader::getStage(const string& name) const
{
return const_cast<Shader*>(this)->getStage(name);
}
ShaderStagePtr Shader::createStage(const string& name, ConstSyntaxPtr syntax)
{
auto it = _stagesMap.find(name);
if (it != _stagesMap.end())
{
throw ExceptionShaderGenError("Stage '" + name + "' already exist in shader '" + getName() + "'");
}
ShaderStagePtr s = std::make_shared<ShaderStage>(name, syntax);
_stagesMap[name] = s;
_stages.push_back(s.get());
return s;
}
MATERIALX_NAMESPACE_END