AbstractUniform.h
Go to the documentation of this file.
#pragma once
#include <string>
#include <set>
#include <vector>
#include <array>
#include <unordered_map>
#include <glm/fwd.hpp>
#include <globjects/base/Referenced.h>
#include <globjects/globjects_api.h>
#include <globjects/LocationIdentity.h>
namespace globjects
{
class TextureHandle;
class Program;
template<typename T> class Uniform;
class GLOBJECTS_API AbstractUniform : public Referenced
{
friend class Program;
public:
enum BindlessImplementation
{
SeparateShaderObjectsARB
, Legacy
};
static void hintBindlessImplementation(const BindlessImplementation impl);
public:
AbstractUniform(gl::GLint location);
AbstractUniform(const std::string & name);
const std::string & name() const;
gl::GLint location() const;
const LocationIdentity & identity() const;
template<typename T> Uniform<T> * as();
template<typename T> const Uniform<T> * as() const;
protected:
virtual ~AbstractUniform();
void registerProgram(Program * program);
void deregisterProgram(Program * program);
void changed();
void update(const Program * program, bool invalidateLocation) const;
virtual void updateAt(const Program * program, gl::GLint location) const = 0;
gl::GLint locationFor(const Program * program) const;
protected:
void setValue(const Program * program, gl::GLint location, const float & value) const;
void setValue(const Program * program, gl::GLint location, const int & value) const;
void setValue(const Program * program, gl::GLint location, const unsigned int & value) const;
void setValue(const Program * program, gl::GLint location, const bool & value) const;
void setValue(const Program * program, gl::GLint location, const glm::vec2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::vec3 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::vec4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::ivec2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::ivec3 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::ivec4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::uvec2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::uvec3 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::uvec4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat3 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat2x3 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat3x2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat2x4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat4x2 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat3x4 & value) const;
void setValue(const Program * program, gl::GLint location, const glm::mat4x3 & value) const;
void setValue(const Program * program, gl::GLint location, const gl::GLuint64 & value) const;
void setValue(const Program * program, gl::GLint location, const TextureHandle & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<float> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<int> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<unsigned int> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<bool> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::vec4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::ivec4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::uvec4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2x3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3x2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat2x4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4x2> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat3x4> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<glm::mat4x3> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<gl::GLuint64> & value) const;
void setValue(const Program * program, gl::GLint location, const std::vector<TextureHandle> & value) const;
template <typename T, std::size_t Count>
void setValue(const Program * program, gl::GLint location, const std::array<T, Count> & value) const;
protected:
LocationIdentity m_identity;
std::set<Program *> m_programs;
mutable std::unordered_map<const Program *, gl::GLint> m_locations;
};
} // namespace globjects
#include <globjects/AbstractUniform.inl>
Referenced.h
globjects::Program
Wraps an OpenGL program.
Definition: Program.h:78
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::TextureHandle
Definition: TextureHandle.h:18
globjects::AbstractUniform
Abstract base class for templated Uniforms.
Definition: AbstractUniform.h:34
globjects::AbstractUniform::m_locations
std::unordered_map< const Program *, gl::GLint > m_locations
Definition: AbstractUniform.h:157
globjects::Referenced
Superclass for all classes that use reference counting in globjects.
Definition: Referenced.h:22
globjects::AbstractUniform::BindlessImplementation
BindlessImplementation
Definition: AbstractUniform.h:39
globjects::AbstractUniform::m_programs
std::set< Program * > m_programs
Definition: AbstractUniform.h:156
LocationIdentity.h
globjects::LocationIdentity
Definition: LocationIdentity.h:16
globjects::Uniform
Wraps access to typed global GLSL variables.
Definition: AbstractUniform.h:25
globjects::AbstractUniform::m_identity
LocationIdentity m_identity
Definition: AbstractUniform.h:155