Loading...
Searching...
No Matches
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
11
12#include "pxr/pxr.h"
13#include "pxr/imaging/glf/api.h"
14#include "pxr/imaging/garch/glApi.h"
15#include "pxr/base/tf/refBase.h"
17#include "pxr/base/tf/token.h"
19
20#include "pxr/base/tf/hashmap.h"
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24
25class GlfBindingMap : public TfRefBase, public TfWeakBase {
26public:
27 typedef TfHashMap<TfToken, int, TfToken::HashFunctor> BindingMap;
28
29 GlfBindingMap()
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
60 void ClearAttribBindings() {
61 _attribBindings.clear();
62 }
63
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
85
86 void AddAttribBinding(TfToken const &name, int location) {
87 _attribBindings[name] = location;
88 }
89
90 BindingMap const &GetAttributeBindings() const {
91 return _attribBindings;
92 }
93
94 GLF_API
95 void AssignSamplerUnitsToProgram(GLuint program);
96
97 GLF_API
98 void AssignUniformBindingsToProgram(GLuint program);
99
100 GLF_API
101 void AddCustomBindings(GLuint program);
102
103 GLF_API
104 void Debug() const;
105
106private:
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
120PXR_NAMESPACE_CLOSE_SCOPE
121
122#endif // PXR_IMAGING_GLF_BINDING_MAP_H
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Definitions of basic string utilities in tf.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...