Files
MapLibreParticleLab/include/mbgl/shader/uniform.hpp
2014-09-04 16:22:25 -07:00

54 lines
941 B
C++

#ifndef MBGL_SHADER_UNIFORM
#define MBGL_SHADER_UNIFORM
#include <mbgl/shader/shader.hpp>
#include <mbgl/platform/gl.hpp>
namespace mbgl {
template <typename T>
class Uniform {
public:
Uniform(const GLchar* name, const Shader& shader)
: location(glGetUniformLocation(shader.program, name)) {}
void operator=(const T& t) {
if (current != t) {
current = t;
bind(t);
}
}
private:
void bind(const T&);
T current;
GLint location;
};
template <size_t C, size_t R = C>
class UniformMatrix {
public:
typedef std::array<float, C*R> T;
UniformMatrix(const GLchar* name, const Shader& shader)
: location(glGetUniformLocation(shader.program, name)) {}
void operator=(const T& t) {
if (current != t) {
current = t;
bind(t);
}
}
private:
void bind(const T&);
T current;
GLint location;
};
}
#endif