#pragma once #include #include #include namespace mbgl { template class Uniform { public: Uniform(const GLchar* name, const Shader& shader) : current() { location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); } void operator=(const T& t) { if (current != t) { current = t; bind(t); } } private: void bind(const T&); T current; GLint location; }; template class UniformMatrix { public: typedef std::array T; UniformMatrix(const GLchar* name, const Shader& shader) : current() { location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.getID(), name)); } void operator=(const std::array& t) { bool dirty = false; for (unsigned int i = 0; i < C*R; i++) { if (current[i] != t[i]) { current[i] = t[i]; dirty = true; } } if (dirty) { bind(current); } } private: void bind(const T&); T current; GLint location; }; } // namespace mbgl