MaterialX 1.39.3
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 OslShaderGenerator(TypeSystemPtr typeSystem);
28
34 static ShaderGeneratorPtr create(TypeSystemPtr typeSystem = nullptr)
35 {
36 return std::make_shared<OslShaderGenerator>(typeSystem ? typeSystem : TypeSystem::create());
37 }
38
40 const string& getTarget() const override { return TARGET; }
41
44 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
45
48 void emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage, uint32_t classification = 0u) const override;
49
51 void emitFunctionBodyBegin(const ShaderNode& node, GenContext& context, ShaderStage& stage, Syntax::Punctuation punc = Syntax::CURLY_BRACKETS) const override;
52
54 static const string TARGET;
55
57 void registerShaderMetadata(const DocumentPtr& doc, GenContext& context) const override;
58
59 protected:
61 virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
62
64 virtual void emitLibraryIncludes(ShaderStage& stage, GenContext& context) const;
65
67 virtual void emitShaderInputs(const VariableBlock& inputs, ShaderStage& stage) const;
68
70 virtual void emitShaderOutputs(const VariableBlock& inputs, ShaderStage& stage) const;
71
73 virtual void emitMetadata(const ShaderPort* port, ShaderStage& stage) const;
74};
75
76namespace OSL
77{
78
80extern MX_GENOSL_API const string UNIFORMS;
81extern MX_GENOSL_API const string INPUTS;
82extern MX_GENOSL_API const string OUTPUTS;
83
84} // namespace OSL
85
86MATERIALX_NAMESPACE_END
87
88#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:33
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition Library.h:37
Base shader generator class.
A context class for shader generation.
Definition GenContext.h:30
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition OslShaderGenerator.h:40
static ShaderGeneratorPtr create(TypeSystemPtr typeSystem=nullptr)
Creator function.
Definition OslShaderGenerator.h:34
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:54
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.
OslShaderGenerator(TypeSystemPtr typeSystem)
Constructor.
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.
ShaderGenerator(TypeSystemPtr typeSystem, SyntaxPtr syntax)
Protected constructor.
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:48
static TypeSystemPtr create()
Create a new type system.
A block of variables in a shader stage.
Definition ShaderStage.h:61