HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bindingMap.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_GLF_BINDING_MAP_H
8 #define PXR_IMAGING_GLF_BINDING_MAP_H
9 
10 /// \file glf/bindingMap.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/glf/api.h"
15 #include "pxr/base/tf/refBase.h"
17 #include "pxr/base/tf/token.h"
18 #include "pxr/base/tf/weakBase.h"
19 
20 #include "pxr/base/tf/hashmap.h"
21 
23 
24 
25 class GlfBindingMap : public TfRefBase, public TfWeakBase {
26 public:
28 
30  : _samplerBindingBaseIndex(0)
31  , _uniformBindingBaseIndex(0)
32  { }
33 
34  GLF_API
35  int GetSamplerUnit(std::string const &name);
36  GLF_API
37  int GetSamplerUnit(TfToken const & name);
38 
39  // If GetAttributeIndex is called with an unknown
40  // attribute token they return -1
41  GLF_API
42  int GetAttributeIndex(std::string const & name);
43  GLF_API
44  int GetAttributeIndex(TfToken const & name);
45 
46  GLF_API
47  int GetUniformBinding(std::string const & name);
48  GLF_API
49  int GetUniformBinding(TfToken const & name);
50 
51  GLF_API
52  bool HasUniformBinding(std::string const & name) const;
53  GLF_API
54  bool HasUniformBinding(TfToken const & name) const;
55 
56  int GetNumSamplerBindings() const {
57  return (int)_samplerBindings.size();
58  }
59 
61  _attribBindings.clear();
62  }
63 
64  /// \name Sampler and UBO Bindings
65  ///
66  /// Sampler units and uniform block bindings are reset and will be
67  /// assigned sequentially starting from the specified baseIndex.
68  /// This allows other subsystems to claim sampler units and uniform
69  /// block bindings before additional indices are assigned by this
70  /// binding map.
71  ///
72  /// @{
73 
74  void ResetSamplerBindings(int baseIndex) {
75  _samplerBindings.clear();
76  _samplerBindingBaseIndex = baseIndex;
77  }
78 
79  void ResetUniformBindings(int baseIndex) {
80  _uniformBindings.clear();
81  _uniformBindingBaseIndex = baseIndex;
82  }
83 
84  /// @}
85 
86  void AddAttribBinding(TfToken const &name, int location) {
87  _attribBindings[name] = location;
88  }
89 
91  return _attribBindings;
92  }
93 
94  GLF_API
96 
97  GLF_API
99 
100  GLF_API
102 
103  GLF_API
104  void Debug() const;
105 
106 private:
107  void _AddActiveAttributeBindings(GLuint program);
108  void _AddActiveUniformBindings(GLuint program);
109  void _AddActiveUniformBlockBindings(GLuint program);
110 
111  BindingMap _attribBindings;
112  BindingMap _samplerBindings;
113  BindingMap _uniformBindings;
114 
115  int _samplerBindingBaseIndex;
116  int _uniformBindingBaseIndex;
117 };
118 
119 
121 
122 #endif // PXR_IMAGING_GLF_BINDING_MAP_H
GLF_API void AssignUniformBindingsToProgram(GLuint program)
GLF_API int GetAttributeIndex(std::string const &name)
#define GLF_API
Definition: api.h:23
void AddAttribBinding(TfToken const &name, int location)
Definition: bindingMap.h:86
unsigned int GLuint
Definition: cl.hpp:167
GLF_API bool HasUniformBinding(std::string const &name) const
TfHashMap< TfToken, int, TfToken::HashFunctor > BindingMap
Definition: bindingMap.h:27
Definition: token.h:70
GLF_API void AddCustomBindings(GLuint program)
GLF_API int GetUniformBinding(std::string const &name)
GLint location
Definition: glcorearb.h:805
GLF_API int GetSamplerUnit(std::string const &name)
GLuint const GLchar * name
Definition: glcorearb.h:786
BindingMap const & GetAttributeBindings() const
Definition: bindingMap.h:90
GLF_API void AssignSamplerUnitsToProgram(GLuint program)
GLF_API void Debug() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
void ResetSamplerBindings(int baseIndex)
Definition: bindingMap.h:74
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
int GetNumSamplerBindings() const
Definition: bindingMap.h:56
GLbitfield GLuint program
Definition: glcorearb.h:1931
void ClearAttribBindings()
Definition: bindingMap.h:60
void ResetUniformBindings(int baseIndex)
Definition: bindingMap.h:79