MaterialX 1.38.9
Loading...
Searching...
No Matches
GlslShaderGenerator.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_GLSLSHADERGENERATOR_H
7#define MATERIALX_GLSLSHADERGENERATOR_H
8
11
13
15
16MATERIALX_NAMESPACE_BEGIN
17
18using GlslShaderGeneratorPtr = shared_ptr<class GlslShaderGenerator>;
19
22class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
23{
24 public:
26
27 static ShaderGeneratorPtr create() { return std::make_shared<GlslShaderGenerator>(); }
28
31 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
32
34 const string& getTarget() const override { return TARGET; }
35
37 virtual const string& getVersion() const { return VERSION; }
38
40 void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
41 bool assignValue = true) const override;
42
45 ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;
46
48 string getVertexDataPrefix(const VariableBlock& vertexData) const override;
49
50 public:
52 static const string TARGET;
53
55 static const string VERSION;
56
57 protected:
58 virtual void emitVertexStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
59 virtual void emitPixelStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
60
61 virtual void emitDirectives(GenContext& context, ShaderStage& stage) const;
62 virtual void emitConstants(GenContext& context, ShaderStage& stage) const;
63 virtual void emitUniforms(GenContext& context, ShaderStage& stage) const;
64 virtual void emitLightData(GenContext& context, ShaderStage& stage) const;
65 virtual void emitInputs(GenContext& context, ShaderStage& stage) const;
66 virtual void emitOutputs(GenContext& context, ShaderStage& stage) const;
67
68 virtual HwResourceBindingContextPtr getResourceBindingContext(GenContext& context) const;
69
73 virtual bool requiresLighting(const ShaderGraph& graph) const;
74
76 virtual void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
77
79 virtual void emitTransmissionRender(GenContext& context, ShaderStage& stage) const;
80
82 virtual void emitLightFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
83
84 static void toVec4(const TypeDesc* type, string& variable);
85
87 vector<ShaderNodePtr> _lightSamplingNodes;
88};
89
91class MX_GENGLSL_API GlslImplementation : public HwImplementation
92{
93 public:
94 const string& getTarget() const override;
95
96 protected:
98};
99
100MATERIALX_NAMESPACE_END
101
102#endif
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Hardware shader generator base class.
shared_ptr< class HwResourceBindingContext > HwResourceBindingContextPtr
Shared pointer to a HwResourceBindingContext.
Definition: HwShaderGenerator.h:236
Macros for declaring imported and exported symbols.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition: Library.h:38
A context class for shader generation.
Definition: GenContext.h:31
Base class for common GLSL node implementations.
Definition: GlslShaderGenerator.h:92
Base class for GLSL (OpenGL Shading Language) code generation.
Definition: GlslShaderGenerator.h:23
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition: GlslShaderGenerator.h:34
virtual const string & getVersion() const
Return the version string for the GLSL version this generator is for.
Definition: GlslShaderGenerator.h:37
vector< ShaderNodePtr > _lightSamplingNodes
Nodes used internally for light sampling.
Definition: GlslShaderGenerator.h:87
static const string TARGET
Unique identifier for this generator target.
Definition: GlslShaderGenerator.h:52
static const string VERSION
Version string for the generator target.
Definition: GlslShaderGenerator.h:55
Definition: HwShaderGenerator.h:346
Base class for shader generators targeting HW rendering.
Definition: HwShaderGenerator.h:288
virtual string getVertexDataPrefix(const VariableBlock &vertexData) const =0
Determine the prefix of vertex data variables.
A node definition element within a Document.
Definition: Definition.h:82
virtual ShaderNodeImplPtr getImplementation(const NodeDef &nodedef, GenContext &context) const
Return a registered shader node implementation for the given nodedef.
Definition: ShaderGenerator.cpp:284
virtual void emitVariableDeclaration(const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const
Emit definition of a single shader variable.
Definition: ShaderGenerator.cpp:166
virtual const string & getTarget() const
Return the name of the target this generator is for.
Definition: ShaderGenerator.h:37
virtual ShaderPtr generate(const string &, ElementPtr, GenContext &) const
Generate a shader starting from the given element, translating the element and all dependencies upstr...
Definition: ShaderGenerator.h:44
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:44
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
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:28
A block of variables in a shader stage.
Definition: ShaderStage.h:61