MaterialX 1.39.5
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
14#include <MaterialXGenHw/HwResourceBindingContext.h>
15#include <MaterialXGenHw/HwShaderGenerator.h>
16
17MATERIALX_NAMESPACE_BEGIN
18
19using GlslShaderGeneratorPtr = shared_ptr<class GlslShaderGenerator>;
20
23class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
24{
25 public:
27 GlslShaderGenerator(TypeSystemPtr typeSystem);
28
34 static ShaderGeneratorPtr create(TypeSystemPtr typeSystem = nullptr)
35 {
36 return std::make_shared<GlslShaderGenerator>(typeSystem ? typeSystem : TypeSystem::create());
37 }
38
41 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
42
44 const string& getTarget() const override { return TARGET; }
45
47 virtual const string& getVersion() const { return VERSION; }
48
50 void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
51 bool assignValue = true) const override;
52
54 string getVertexDataPrefix(const VariableBlock& vertexData) const override;
55
56 public:
58 static const string TARGET;
59
61 static const string VERSION;
62
63 protected:
64 virtual void emitVertexStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
65 virtual void emitPixelStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
66
67 virtual void emitDirectives(GenContext& context, ShaderStage& stage) const;
68 virtual void emitConstants(GenContext& context, ShaderStage& stage) const;
69 virtual void emitUniforms(GenContext& context, ShaderStage& stage) const;
70 virtual void emitLightData(GenContext& context, ShaderStage& stage) const;
71 virtual void emitInputs(GenContext& context, ShaderStage& stage) const;
72 virtual void emitOutputs(GenContext& context, ShaderStage& stage) const;
73
74 virtual HwResourceBindingContextPtr getResourceBindingContext(GenContext& context) const;
75
77 virtual void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
78
80 virtual void emitTransmissionRender(GenContext& context, ShaderStage& stage) const;
81
83 virtual void emitLightFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
84
86 vector<ShaderNodePtr> _lightSamplingNodes;
87};
88
89MATERIALX_NAMESPACE_END
90
91#endif
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
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 GlslShaderGenerator.h:44
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:47
static ShaderGeneratorPtr create(TypeSystemPtr typeSystem=nullptr)
Creator function.
Definition GlslShaderGenerator.h:34
vector< ShaderNodePtr > _lightSamplingNodes
Nodes used internally for light sampling.
Definition GlslShaderGenerator.h:86
GlslShaderGenerator(TypeSystemPtr typeSystem)
Constructor.
static const string TARGET
Unique identifier for this generator target.
Definition GlslShaderGenerator.h:58
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...
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:61
Class representing a graph (DAG) for shader generation.
Definition ShaderGraph.h:45
An input or output port on a ShaderNode.
Definition ShaderNode.h:124
A shader stage, containing the state and resulting source code for the stage.
Definition ShaderStage.h:145
static TypeSystemPtr create()
Create a new type system.
A block of variables in a shader stage.
Definition ShaderStage.h:67