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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_GLF_BINDING_MAP_H
25 #define PXR_IMAGING_GLF_BINDING_MAP_H
26 
27 /// \file glf/bindingMap.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
32 #include "pxr/base/tf/refBase.h"
34 #include "pxr/base/tf/token.h"
35 #include "pxr/base/tf/weakBase.h"
36 
37 #include "pxr/base/tf/hashmap.h"
38 
40 
41 
42 class GlfBindingMap : public TfRefBase, public TfWeakBase {
43 public:
45 
47  : _samplerBindingBaseIndex(0)
48  , _uniformBindingBaseIndex(0)
49  { }
50 
51  GLF_API
52  int GetSamplerUnit(std::string const &name);
53  GLF_API
54  int GetSamplerUnit(TfToken const & name);
55 
56  // If GetAttributeIndex is called with an unknown
57  // attribute token they return -1
58  GLF_API
59  int GetAttributeIndex(std::string const & name);
60  GLF_API
61  int GetAttributeIndex(TfToken const & name);
62 
63  GLF_API
64  int GetUniformBinding(std::string const & name);
65  GLF_API
66  int GetUniformBinding(TfToken const & name);
67 
68  GLF_API
69  bool HasUniformBinding(std::string const & name) const;
70  GLF_API
71  bool HasUniformBinding(TfToken const & name) const;
72 
73  int GetNumSamplerBindings() const {
74  return (int)_samplerBindings.size();
75  }
76 
78  _attribBindings.clear();
79  }
80 
81  /// \name Sampler and UBO Bindings
82  ///
83  /// Sampler units and uniform block bindings are reset and will be
84  /// assigned sequentially starting from the specified baseIndex.
85  /// This allows other subsystems to claim sampler units and uniform
86  /// block bindings before additional indices are assigned by this
87  /// binding map.
88  ///
89  /// @{
90 
91  void ResetSamplerBindings(int baseIndex) {
92  _samplerBindings.clear();
93  _samplerBindingBaseIndex = baseIndex;
94  }
95 
96  void ResetUniformBindings(int baseIndex) {
97  _uniformBindings.clear();
98  _uniformBindingBaseIndex = baseIndex;
99  }
100 
101  /// @}
102 
103  void AddAttribBinding(TfToken const &name, int location) {
104  _attribBindings[name] = location;
105  }
106 
108  return _attribBindings;
109  }
110 
111  GLF_API
113 
114  GLF_API
116 
117  GLF_API
119 
120  GLF_API
121  void Debug() const;
122 
123 private:
124  void _AddActiveAttributeBindings(GLuint program);
125  void _AddActiveUniformBindings(GLuint program);
126  void _AddActiveUniformBlockBindings(GLuint program);
127 
128  BindingMap _attribBindings;
129  BindingMap _samplerBindings;
130  BindingMap _uniformBindings;
131 
132  int _samplerBindingBaseIndex;
133  int _uniformBindingBaseIndex;
134 };
135 
136 
138 
139 #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:40
void AddAttribBinding(TfToken const &name, int location)
Definition: bindingMap.h:103
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:44
Definition: token.h:87
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:107
GLF_API void AssignSamplerUnitsToProgram(GLuint program)
GLF_API void Debug() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
void ResetSamplerBindings(int baseIndex)
Definition: bindingMap.h:91
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
int GetNumSamplerBindings() const
Definition: bindingMap.h:73
GLbitfield GLuint program
Definition: glcorearb.h:1931
void ClearAttribBindings()
Definition: bindingMap.h:77
void ResetUniformBindings(int baseIndex)
Definition: bindingMap.h:96