MaterialX 1.39.1
Loading...
Searching...
No Matches
OslShaderGenerator.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_OSLSHADERGENERATOR_H
7#define MATERIALX_OSLSHADERGENERATOR_H
8
11
13
15
16MATERIALX_NAMESPACE_BEGIN
17
18using OslShaderGeneratorPtr = shared_ptr<class OslShaderGenerator>;
19
23class MX_GENOSL_API OslShaderGenerator : public ShaderGenerator
24{
25 public:
27
28 static ShaderGeneratorPtr create() { return std::make_shared<OslShaderGenerator>(); }
29
31 const string& getTarget() const override { return TARGET; }
32
35 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
36
39 void emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage, uint32_t classification = 0u) const override;
40
42 void emitFunctionBodyBegin(const ShaderNode& node, GenContext& context, ShaderStage& stage, Syntax::Punctuation punc = Syntax::CURLY_BRACKETS) const override;
43
45 static const string TARGET;
46
48 void registerShaderMetadata(const DocumentPtr& doc, GenContext& context) const override;
49
50 protected:
52 virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
53
55 virtual void emitLibraryIncludes(ShaderStage& stage, GenContext& context) const;
56
58 virtual void emitShaderInputs(const VariableBlock& inputs, ShaderStage& stage) const;
59
61 virtual void emitShaderOutputs(const VariableBlock& inputs, ShaderStage& stage) const;
62
64 virtual void emitMetadata(const ShaderPort* port, ShaderStage& stage) const;
65};
66
67namespace OSL
68{
69
71extern MX_GENOSL_API const string UNIFORMS;
72extern MX_GENOSL_API const string INPUTS;
73extern MX_GENOSL_API const string OUTPUTS;
74
75} // namespace OSL
76
77MATERIALX_NAMESPACE_END
78
79#endif
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Macros for declaring imported and exported symbols.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition: Library.h:38
Base shader generator class.
A context class for shader generation.
Definition: GenContext.h:31
Base class for OSL (Open Shading Language) shader generators.
Definition: OslShaderGenerator.h:24
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition: OslShaderGenerator.h:31
void registerShaderMetadata(const DocumentPtr &doc, GenContext &context) const override
Register metadata that should be exported to the generated shaders.
void emitFunctionBodyBegin(const ShaderNode &node, GenContext &context, ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const override
Emit code for starting a new function body.
virtual void emitShaderOutputs(const VariableBlock &inputs, ShaderStage &stage) const
Emit a block of shader outputs.
static const string TARGET
Unique identifier for this generator target.
Definition: OslShaderGenerator.h:45
ShaderPtr generate(const string &name, ElementPtr element, GenContext &context) const override
Generate a shader starting from the given element, translating the element and all dependencies upstr...
virtual ShaderPtr createShader(const string &name, ElementPtr element, GenContext &context) const
Create and initialize a new OSL shader for shader generation.
virtual void emitLibraryIncludes(ShaderStage &stage, GenContext &context) const
Emit include headers needed by the generated shader code.
virtual void emitShaderInputs(const VariableBlock &inputs, ShaderStage &stage) const
Emit a block of shader inputs.
void emitFunctionCalls(const ShaderGraph &graph, GenContext &context, ShaderStage &stage, uint32_t classification=0u) const override
Add all function calls for a graph.
virtual void emitMetadata(const ShaderPort *port, ShaderStage &stage) const
Emit metadata for a shader parameter.
Base class for shader generators All third-party shader generators should derive from this class.
Definition: ShaderGenerator.h:31
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:44
Class representing a node in the shader generation DAG.
Definition: ShaderNode.h:320
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:139
Punctuation
Punctuation types.
Definition: Syntax.h:45
A block of variables in a shader stage.
Definition: ShaderStage.h:61