forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OslShaderGenerator.h
73 lines (52 loc) · 2.33 KB
/
OslShaderGenerator.h
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
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#ifndef MATERIALX_OSLSHADERGENERATOR_H
#define MATERIALX_OSLSHADERGENERATOR_H
/// @file
/// OSL shading language generator
#include <MaterialXGenShader/ShaderGenerator.h>
namespace MaterialX
{
using OslShaderGeneratorPtr = shared_ptr<class OslShaderGenerator>;
/// @class OslShaderGenerator
/// Base class for OSL (Open Shading Language) shader generators.
/// A generator for a specific OSL target should be derived from this class.
class OslShaderGenerator : public ShaderGenerator
{
public:
OslShaderGenerator();
static ShaderGeneratorPtr create() { return std::make_shared<OslShaderGenerator>(); }
/// Return a unique identifier for the language used by this generator
const string& getLanguage() const override { return LANGUAGE; }
/// Return a unique identifier for the target this generator is for
const string& getTarget() const override { return TARGET; }
/// Generate a shader starting from the given element, translating
/// the element and all dependencies upstream into shader code.
ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
/// Add all function calls for a graph.
void emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const override;
/// Unique identifier for the osl language
static const string LANGUAGE;
/// Unique identifier for this generator target
static const string TARGET;
protected:
/// Create and initialize a new OSL shader for shader generation.
virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
/// Emit include headers needed by the generated shader code.
virtual void emitIncludes(ShaderStage& stage, GenContext& context) const;
/// Emit a block of shader inputs.
virtual void emitShaderInputs(const VariableBlock& inputs, ShaderStage& stage) const;
/// Emit a block of shader outputs.
virtual void emitShaderOutputs(const VariableBlock& inputs, ShaderStage& stage) const;
};
namespace OSL
{
/// Identifiers for OSL variable blocks
extern const string UNIFORMS;
extern const string INPUTS;
extern const string OUTPUTS;
}
} // namespace MaterialX
#endif