HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlslResourceBindingContext.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_GLSLRESOURCEBINDING_H
7 #define MATERIALX_GLSLRESOURCEBINDING_H
8 
9 /// @file
10 /// GLSL resource binding context
11 
13 
15 
17 
18 /// Shared pointer to a GlslResourceBindingContext
19 using GlslResourceBindingContextPtr = shared_ptr<class GlslResourceBindingContext>;
20 
21 /// @class GlslResourceBindingContext
22 /// Class representing a resource binding for Glsl shader resources.
24 {
25  public:
26  GlslResourceBindingContext(size_t uniformBindingLocation, size_t samplerBindingLocation);
27 
29  size_t uniformBindingLocation = 0, size_t samplerBindingLocation = 0)
30  {
31  return std::make_shared<GlslResourceBindingContext>(
32  uniformBindingLocation, samplerBindingLocation);
33  }
34 
35  // Initialize the context before generation starts.
36  void initialize() override;
37 
38  // Emit directives for stage
39  void emitDirectives(GenContext& context, ShaderStage& stage) override;
40 
41  // Emit uniforms with binding information
42  void emitResourceBindings(GenContext& context, const VariableBlock& uniforms, ShaderStage& stage) override;
43 
44  // Emit structured uniforms with binding information and align members where possible
45  void emitStructuredResourceBindings(GenContext& context, const VariableBlock& uniforms,
46  ShaderStage& stage, const std::string& structInstanceName,
47  const std::string& arraySuffix) override;
48 
49  // Emit separate binding locations for sampler and uniform table
50  void enableSeparateBindingLocations(bool separateBindingLocation) { _separateBindingLocation = separateBindingLocation; };
51 
52  protected:
53  // List of required extensions
54  StringSet _requiredExtensions;
55 
56  // Binding location for uniform blocks
57  size_t _hwUniformBindLocation = 0;
58 
59  // Initial value of uniform binding location
60  size_t _hwInitUniformBindLocation = 0;
61 
62  // Binding location for sampler blocks
63  size_t _hwSamplerBindLocation = 0;
64 
65  // Initial value of sampler binding location
66  size_t _hwInitSamplerBindLocation = 0;
67 
68  // Separate binding locations flag
69  // Indicates whether to use a shared binding counter for samplers and uniforms or separate ones.
70  // By default a shader counter is used.
71  bool _separateBindingLocation = false;
72 };
73 
75 
76 #endif
void enableSeparateBindingLocations(bool separateBindingLocation)
virtual void initialize()=0
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual void emitDirectives(GenContext &context, ShaderStage &stage)=0
virtual void emitResourceBindings(GenContext &context, const VariableBlock &uniforms, ShaderStage &stage)=0
shared_ptr< class GlslResourceBindingContext > GlslResourceBindingContextPtr
Shared pointer to a GlslResourceBindingContext.
virtual void emitStructuredResourceBindings(GenContext &context, const VariableBlock &uniforms, ShaderStage &stage, const std::string &structInstanceName, const std::string &arraySuffix=EMPTY_STRING)=0
std::set< string > StringSet
A set of strings.
Definition: Library.h:61
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
static GlslResourceBindingContextPtr create(size_t uniformBindingLocation=0, size_t samplerBindingLocation=0)
#define MX_GENGLSL_API
Definition: Export.h:18