HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
9 /// @file
10 /// GLSL shader generator
11 
13 
16 
18 
19 using GlslShaderGeneratorPtr = shared_ptr<class GlslShaderGenerator>;
20 
21 /// Base class for GLSL (OpenGL Shading Language) code generation.
22 /// A generator for a specific GLSL target should be derived from this class.
24 {
25  public:
26  /// Constructor.
28 
29  /// Creator function.
30  /// If a TypeSystem is not provided it will be created internally.
31  /// Optionally pass in an externally created TypeSystem here,
32  /// if you want to keep type descriptions alive after the lifetime
33  /// of the shader generator.
34  static ShaderGeneratorPtr create(TypeSystemPtr typeSystem = nullptr)
35  {
36  return std::make_shared<GlslShaderGenerator>(typeSystem ? typeSystem : TypeSystem::create());
37  }
38 
39  /// Generate a shader starting from the given element, translating
40  /// the element and all dependencies upstream into shader code.
41  ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
42 
43  /// Return a unique identifier for the target this generator is for
44  const string& getTarget() const override { return TARGET; }
45 
46  /// Return the version string for the GLSL version this generator is for
47  virtual const string& getVersion() const { return VERSION; }
48 
49  /// Emit a shader variable.
50  void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
51  bool assignValue = true) const override;
52 
53  /// Determine the prefix of vertex data variables.
54  string getVertexDataPrefix(const VariableBlock& vertexData) const override;
55 
56  public:
57  /// Unique identifier for this generator target
58  static const string TARGET;
59 
60  /// Version string for the generator target
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 
76  /// Emit specular environment lookup code
77  virtual void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
78 
79  /// Emit transmission rendering code
80  virtual void emitTransmissionRender(GenContext& context, ShaderStage& stage) const;
81 
82  /// Emit function definitions for lighting code
83  virtual void emitLightFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
84 
85  /// Nodes used internally for light sampling.
86  vector<ShaderNodePtr> _lightSamplingNodes;
87 };
88 
90 
91 #endif
vector< ShaderNodePtr > _lightSamplingNodes
Nodes used internally for light sampling.
shared_ptr< class HwResourceBindingContext > HwResourceBindingContextPtr
Shared pointer to a HwResourceBindingContext.
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
virtual void emitVariableDeclaration(const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const
shared_ptr< class GlslShaderGenerator > GlslShaderGeneratorPtr
static const string TARGET
Unique identifier for this generator target.
static TypeSystemPtr create()
Create a new type system.
static ShaderGeneratorPtr create(TypeSystemPtr typeSystem=nullptr)
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
shared_ptr< class TypeSystem > TypeSystemPtr
Definition: TypeDesc.h:219
static const string VERSION
Version string for the generator target.
virtual const string & getVersion() const
Return the version string for the GLSL version this generator is for.
virtual string getVertexDataPrefix(const VariableBlock &vertexData) const =0
Determine the prefix of vertex data variables.
GLuint const GLchar * name
Definition: glcorearb.h:786
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:33
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition: Library.h:37
virtual ShaderPtr generate(const string &, ElementPtr, GenContext &) const
#define MX_GENGLSL_API
Definition: Export.h:18