MaterialX 1.39.3
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 GlslShaderGenerator(TypeSystemPtr typeSystem);
27
33 static ShaderGeneratorPtr create(TypeSystemPtr typeSystem = nullptr)
34 {
35 return std::make_shared<GlslShaderGenerator>(typeSystem ? typeSystem : TypeSystem::create());
36 }
37
40 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
41
43 const string& getTarget() const override { return TARGET; }
44
46 virtual const string& getVersion() const { return VERSION; }
47
49 void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
50 bool assignValue = true) const override;
51
54 ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;
55
57 string getVertexDataPrefix(const VariableBlock& vertexData) const override;
58
59 public:
61 static const string TARGET;
62
64 static const string VERSION;
65
66 protected:
67 virtual void emitVertexStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
68 virtual void emitPixelStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
69
70 virtual void emitDirectives(GenContext& context, ShaderStage& stage) const;
71 virtual void emitConstants(GenContext& context, ShaderStage& stage) const;
72 virtual void emitUniforms(GenContext& context, ShaderStage& stage) const;
73 virtual void emitLightData(GenContext& context, ShaderStage& stage) const;
74 virtual void emitInputs(GenContext& context, ShaderStage& stage) const;
75 virtual void emitOutputs(GenContext& context, ShaderStage& stage) const;
76
77 virtual HwResourceBindingContextPtr getResourceBindingContext(GenContext& context) const;
78
82 virtual bool requiresLighting(const ShaderGraph& graph) const;
83
85 virtual void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
86
88 virtual void emitTransmissionRender(GenContext& context, ShaderStage& stage) const;
89
91 virtual void emitLightFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
92
93 static void toVec4(TypeDesc type, string& variable);
94 [[deprecated]] static void toVec4(const TypeDesc* type, string& variable) { toVec4(*type, variable); }
95
97 vector<ShaderNodePtr> _lightSamplingNodes;
98};
99
101class MX_GENGLSL_API GlslImplementation : public HwImplementation
102{
103 public:
104 const string& getTarget() const override;
105
106 protected:
107 GlslImplementation() { }
108};
109
110MATERIALX_NAMESPACE_END
111
112#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:244
Macros for declaring imported and exported symbols.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition Library.h:33
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition Library.h:39
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition Library.h:37
A context class for shader generation.
Definition GenContext.h:30
const string & getTarget() const override
Return an identifier for the target used by this implementation.
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition GlslShaderGenerator.h:43
virtual void emitLightFunctionDefinitions(const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
Emit function definitions for lighting code.
virtual const string & getVersion() const
Return the version string for the GLSL version this generator is for.
Definition GlslShaderGenerator.h:46
static ShaderGeneratorPtr create(TypeSystemPtr typeSystem=nullptr)
Creator function.
Definition GlslShaderGenerator.h:33
vector< ShaderNodePtr > _lightSamplingNodes
Nodes used internally for light sampling.
Definition GlslShaderGenerator.h:97
GlslShaderGenerator(TypeSystemPtr typeSystem)
Constructor.
static const string TARGET
Unique identifier for this generator target.
Definition GlslShaderGenerator.h:61
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 bool requiresLighting(const ShaderGraph &graph) const
Logic to indicate whether code to support direct lighting should be emitted.
void emitVariableDeclaration(const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const override
Emit a shader variable.
virtual void emitSpecularEnvironment(GenContext &context, ShaderStage &stage) const
Emit specular environment lookup code.
string getVertexDataPrefix(const VariableBlock &vertexData) const override
Determine the prefix of vertex data variables.
virtual void emitTransmissionRender(GenContext &context, ShaderStage &stage) const
Emit transmission rendering code.
static const string VERSION
Version string for the generator target.
Definition GlslShaderGenerator.h:64
ShaderNodeImplPtr getImplementation(const NodeDef &nodedef, GenContext &context) const override
Return a registered shader node implementation given an implementation element.
A node definition element within a Document.
Definition Definition.h:82
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:40
static TypeSystemPtr create()
Create a new type system.
A block of variables in a shader stage.
Definition ShaderStage.h:61