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 GLF_BINDING_MAP_H
25 #define GLF_BINDING_MAP_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
31 #include "pxr/imaging/garch/gl.h"
32 #include "pxr/base/tf/refBase.h"
33 #include "pxr/base/tf/stringUtils.h"
34 #include "pxr/base/tf/token.h"
35 #include "pxr/base/tf/weakBase.h"
36 
37 #include "pxr/base/tf/hashmap.h"
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
42 class GlfBindingMap : public TfRefBase, public TfWeakBase {
43 public:
44  typedef TfHashMap<TfToken, int, TfToken::HashFunctor> BindingMap;
45 
46  GLF_API
47  int GetSamplerUnit(std::string const &name);
48  GLF_API
49  int GetSamplerUnit(TfToken const & name);
50 
51  // If GetAttributeIndex is called with an unknown
52  // attribute token they return -1
53  GLF_API
54  int GetAttributeIndex(std::string const & name);
55  GLF_API
56  int GetAttributeIndex(TfToken const & name);
57 
58  GLF_API
59  int GetUniformBinding(std::string const & name);
60  GLF_API
61  int GetUniformBinding(TfToken const & name);
62 
63  GLF_API
64  bool HasUniformBinding(std::string const & name) const;
65  GLF_API
66  bool HasUniformBinding(TfToken const & name) const;
67 
68  int GetNumSamplerBindings() const {
69  return (int)_samplerBindings.size();
70  }
71 
72  void ClearAttribBindings() {
73  _attribBindings.clear();
74  }
75 
76  void AddAttribBinding(TfToken const &name, int location) {
77  _attribBindings[name] = location;
78  }
79 
80  BindingMap const &GetAttributeBindings() const {
81  return _attribBindings;
82  }
83 
84  GLF_API
85  void AssignSamplerUnitsToProgram(GLuint program);
86 
87  GLF_API
88  void AssignUniformBindingsToProgram(GLuint program);
89 
90  GLF_API
91  void AddCustomBindings(GLuint program);
92 
93  GLF_API
94  void Debug() const;
95 
96 private:
97  void _AddActiveAttributeBindings(GLuint program);
98  void _AddActiveUniformBindings(GLuint program);
99  void _AddActiveUniformBlockBindings(GLuint program);
100 
101  BindingMap _attribBindings;
102  BindingMap _samplerBindings;
103  BindingMap _uniformBindings;
104 };
105 
106 
107 PXR_NAMESPACE_CLOSE_SCOPE
108 
109 #endif // GLF_BINDING_MAP_H
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:72
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:142