forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyShaderGenerator.cpp
More file actions
307 lines (278 loc) · 7.78 KB
/
PyShaderGenerator.cpp
File metadata and controls
307 lines (278 loc) · 7.78 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#include <PyMaterialX/PyMaterialX.h>
#include <MaterialXGenShader/Shader.h>
#include <MaterialXGenShader/ShaderGenerator.h>
#include <MaterialXGenShader/GenContext.h>
#include <string>
namespace py = pybind11;
namespace mx = MaterialX;
class PyShaderGenerator : public mx::ShaderGenerator
{
public:
explicit PyShaderGenerator(mx::SyntaxPtr syntax) :
mx::ShaderGenerator(syntax)
{
}
const std::string& getTarget() const override
{
PYBIND11_OVERLOAD_PURE(
const std::string&,
mx::ShaderGenerator,
getTarget
);
}
mx::ShaderPtr generate(const std::string& name, mx::ElementPtr element, mx::GenContext& context) const override
{
PYBIND11_OVERLOAD_PURE(
mx::ShaderPtr,
mx::ShaderGenerator,
generate,
name,
element,
context
);
}
void emitScopeBegin(mx::ShaderStage& stage, mx::Syntax::Punctuation punc) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitScopeBegin,
stage,
punc
);
}
void emitScopeEnd(mx::ShaderStage& stage, bool semicolon, bool newline) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitScopeEnd,
stage,
semicolon,
newline
);
}
void emitLineBegin(mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitLineBegin,
stage
);
}
void emitLineEnd(mx::ShaderStage& stage, bool semicolon) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitLineEnd,
stage,
semicolon
);
}
void emitLineBreak(mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitLineBreak,
stage
);
}
void emitString(const std::string& str, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitString,
str,
stage
);
}
void emitLine(const std::string& str, mx::ShaderStage& stage, bool semicolon) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitLine,
str,
stage,
semicolon
);
}
void emitComment(const std::string& str, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitComment,
str,
stage
);
}
void emitBlock(const std::string& str, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitBlock,
str,
context,
stage
);
}
void emitInclude(const std::string& file, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitInclude,
file,
context,
stage
);
}
void emitFunctionDefinition(const mx::ShaderNode& node, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitFunctionDefinition,
node,
context,
stage
);
}
void emitFunctionCall(const mx::ShaderNode& node, mx::GenContext& context, mx::ShaderStage& stage, bool checkScope) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitFunctionCall,
node,
context,
stage,
checkScope
);
}
void emitFunctionDefinitions(const mx::ShaderGraph& graph, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitFunctionDefinitions,
graph,
context,
stage
);
}
void emitFunctionCalls(const mx::ShaderGraph& graph, mx::GenContext& context, mx::ShaderStage& stage, uint32_t classification = 0u) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitFunctionCalls,
graph,
context,
stage,
classification
);
}
void emitTypeDefinitions(mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitTypeDefinitions,
context,
stage
);
}
void emitInput(const mx::ShaderInput* input, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitInput,
input,
context,
stage
);
}
void emitOutput(const mx::ShaderOutput* output, bool includeType, bool assignValue, mx::GenContext& context, mx::ShaderStage& stage) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitOutput,
output,
includeType,
assignValue,
context,
stage
);
}
void emitVariableDeclarations(const mx::VariableBlock& block, const std::string& qualifier, const std::string& separator, mx::GenContext& context, mx::ShaderStage& stage, bool assignValue) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitVariableDeclarations,
block,
qualifier,
separator,
context,
stage,
assignValue
);
}
void emitVariableDeclaration(const mx::ShaderPort* variable, const std::string& qualifier, mx::GenContext& context, mx::ShaderStage& stage, bool assignValue) const override
{
PYBIND11_OVERLOAD(
void,
mx::ShaderGenerator,
emitVariableDeclaration,
variable,
qualifier,
context,
stage,
assignValue
);
}
std::string getUpstreamResult(const mx::ShaderInput* input, mx::GenContext& context) const override
{
PYBIND11_OVERLOAD(
std::string,
mx::ShaderGenerator,
getUpstreamResult,
input,
context
);
}
protected:
mx::ShaderStagePtr createStage(const std::string& name, mx::Shader& shader) const override
{
PYBIND11_OVERLOAD(
mx::ShaderStagePtr,
mx::ShaderGenerator,
createStage,
name,
shader
);
}
};
void bindPyShaderGenerator(py::module& mod)
{
py::class_<mx::ShaderGenerator, PyShaderGenerator, mx::ShaderGeneratorPtr>(mod, "ShaderGenerator")
.def("getTarget", &mx::ShaderGenerator::getTarget)
.def("generate", &mx::ShaderGenerator::generate)
.def("setColorManagementSystem", &mx::ShaderGenerator::setColorManagementSystem)
.def("getColorManagementSystem", &mx::ShaderGenerator::getColorManagementSystem)
.def("setUnitSystem", &mx::ShaderGenerator::setUnitSystem)
.def("getUnitSystem", &mx::ShaderGenerator::getUnitSystem);
}