| globjects 1.0.0.000000000000 Strict OpenGL objects wrapper.

AbstractUniform.h
Go to the documentation of this file.
1
2 #pragma once
3
4 #include <string>
5 #include <set>
6 #include <vector>
7 #include <array>
8 #include <unordered_map>
9
10 #include <glm/fwd.hpp>
11
12 #include <globjects/base/Referenced.h>
13
14 #include <globjects/globjects_api.h>
15
16 #include <globjects/LocationIdentity.h>
17
18
19 namespace globjects
20 {
21
22
23 class TextureHandle;
24 class Program;
25 template<typename T> class Uniform;
26
34 class GLOBJECTS_API AbstractUniform : public Referenced
35 {
36 friend class Program;
37
38 public:
39 enum BindlessImplementation
40 {
41 SeparateShaderObjectsARB
42 , Legacy
43 };
44
45 static void hintBindlessImplementation(const BindlessImplementation impl);
46
47 public:
48 AbstractUniform(gl::GLint location);
49 AbstractUniform(const std::string & name);
50
51 const std::string & name() const;
52 gl::GLint location() const;
53
54 const LocationIdentity & identity() const;
55
64 template<typename T> Uniform<T> * as();
65 template<typename T> const Uniform<T> * as() const;
66
67 protected:
68 virtual ~AbstractUniform();
69
70 void registerProgram(Program * program);
71 void deregisterProgram(Program * program);
72
76 void changed();
77
80 void update(const Program * program, bool invalidateLocation) const;
81
84 virtual void updateAt(const Program * program, gl::GLint location) const = 0;
85
86 gl::GLint locationFor(const Program * program) const;
87
88 protected:
89 void setValue(const Program * program, gl::GLint location, const float & value) const;
90 void setValue(const Program * program, gl::GLint location, const int & value) const;
91 void setValue(const Program * program, gl::GLint location, const unsigned int & value) const;
92 void setValue(const Program * program, gl::GLint location, const bool & value) const;
93
94 void setValue(const Program * program, gl::GLint location, const glm::vec2 & value) const;
95 void setValue(const Program * program, gl::GLint location, const glm::vec3 & value) const;
96 void setValue(const Program * program, gl::GLint location, const glm::vec4 & value) const;
97
98 void setValue(const Program * program, gl::GLint location, const glm::ivec2 & value) const;
99 void setValue(const Program * program, gl::GLint location, const glm::ivec3 & value) const;
100 void setValue(const Program * program, gl::GLint location, const glm::ivec4 & value) const;
101
102 void setValue(const Program * program, gl::GLint location, const glm::uvec2 & value) const;
103 void setValue(const Program * program, gl::GLint location, const glm::uvec3 & value) const;
104 void setValue(const Program * program, gl::GLint location, const glm::uvec4 & value) const;
105
106 void setValue(const Program * program, gl::GLint location, const glm::mat2 & value) const;
107 void setValue(const Program * program, gl::GLint location, const glm::mat3 & value) const;
108 void setValue(const Program * program, gl::GLint location, const glm::mat4 & value) const;
109
110 void setValue(const Program * program, gl::GLint location, const glm::mat2x3 & value) const;
111 void setValue(const Program * program, gl::GLint location, const glm::mat3x2 & value) const;
112 void setValue(const Program * program, gl::GLint location, const glm::mat2x4 & value) const;
113 void setValue(const Program * program, gl::GLint location, const glm::mat4x2 & value) const;
114 void setValue(const Program * program, gl::GLint location, const glm::mat3x4 & value) const;
115 void setValue(const Program * program, gl::GLint location, const glm::mat4x3 & value) const;
116
117 void setValue(const Program * program, gl::GLint location, const gl::GLuint64 & value) const;
118 void setValue(const Program * program, gl::GLint location, const TextureHandle & value) const;
119
120 void setValue(const Program * program, gl::GLint location, const std::vector<float> & value) const;
121 void setValue(const Program * program, gl::GLint location, const std::vector<int> & value) const;
122 void setValue(const Program * program, gl::GLint location, const std::vector<unsigned int> & value) const;
123 void setValue(const Program * program, gl::GLint location, const std::vector<bool> & value) const;
124
125 void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec2> & value) const;
126 void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec3> & value) const;
127 void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec4> & value) const;
128
129 void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec2> & value) const;
130 void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec3> & value) const;
131 void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec4> & value) const;
132
133 void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec2> & value) const;
134 void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec3> & value) const;
135 void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec4> & value) const;
136
137 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2> & value) const;
138 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3> & value) const;
139 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4> & value) const;
140
141 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2x3> & value) const;
142 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3x2> & value) const;
143 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2x4> & value) const;
144 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4x2> & value) const;
145 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3x4> & value) const;
146 void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4x3> & value) const;
147
148 void setValue(const Program * program, gl::GLint location, const std::vector<gl::GLuint64> & value) const;
149 void setValue(const Program * program, gl::GLint location, const std::vector<TextureHandle> & value) const;
150
151 template <typename T, std::size_t Count>
152 void setValue(const Program * program, gl::GLint location, const std::array<T, Count> & value) const;
153
154 protected:
155 LocationIdentity m_identity;
156 std::set<Program *> m_programs;
157 mutable std::unordered_map<const Program *, gl::GLint> m_locations;
158 };
159
160
161 } // namespace globjects
162
163
164 #include <globjects/AbstractUniform.inl>
globjects::AbstractUniform::m_programs
std::set< Program * > m_programs
Definition: AbstractUniform.h:156
Referenced.h
globjects::Uniform
Wraps access to typed global GLSL variables.
Definition: AbstractUniform.h:25
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Program
Wraps an OpenGL program.
Definition: Program.h:78
globjects::TextureHandle
Definition: TextureHandle.h:18
globjects::AbstractUniform::m_locations
std::unordered_map< const Program *, gl::GLint > m_locations
Definition: AbstractUniform.h:157
globjects::AbstractUniform::BindlessImplementation
BindlessImplementation
Definition: AbstractUniform.h:39
globjects::AbstractUniform
Abstract base class for templated Uniforms.
Definition: AbstractUniform.h:34
globjects::AbstractUniform::m_identity
LocationIdentity m_identity
Definition: AbstractUniform.h:155
globjects::LocationIdentity
Definition: LocationIdentity.h:16
globjects::Referenced
Superclass for all classes that use reference counting in globjects.
Definition: Referenced.h:22
LocationIdentity.h