Loading...
Searching...
No Matches
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
28
29#include "pxr/pxr.h"
30#include "pxr/imaging/glf/api.h"
31#include "pxr/imaging/garch/glApi.h"
32#include "pxr/base/tf/refBase.h"
34#include "pxr/base/tf/token.h"
36
37#include "pxr/base/tf/hashmap.h"
38
39PXR_NAMESPACE_OPEN_SCOPE
40
41
42class GlfBindingMap : public TfRefBase, public TfWeakBase {
43public:
44 typedef TfHashMap<TfToken, int, TfToken::HashFunctor> BindingMap;
45
46 GlfBindingMap()
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
77 void ClearAttribBindings() {
78 _attribBindings.clear();
79 }
80
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
102
103 void AddAttribBinding(TfToken const &name, int location) {
104 _attribBindings[name] = location;
105 }
106
107 BindingMap const &GetAttributeBindings() const {
108 return _attribBindings;
109 }
110
111 GLF_API
112 void AssignSamplerUnitsToProgram(GLuint program);
113
114 GLF_API
115 void AssignUniformBindingsToProgram(GLuint program);
116
117 GLF_API
118 void AddCustomBindings(GLuint program);
119
120 GLF_API
121 void Debug() const;
122
123private:
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
137PXR_NAMESPACE_CLOSE_SCOPE
138
139#endif // PXR_IMAGING_GLF_BINDING_MAP_H
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:73
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
Definitions of basic string utilities in tf.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...