#include #include #include #include #include #include namespace mbgl { namespace gl { UniformLocation uniformLocation(ProgramID id, const char* name) { return MBGL_CHECK_ERROR(glGetUniformLocation(id, name)); } template <> void bindUniform(UniformLocation location, const float& t) { MBGL_CHECK_ERROR(glUniform1f(location, t)); } template <> void bindUniform(UniformLocation location, const int32_t& t) { MBGL_CHECK_ERROR(glUniform1i(location, t)); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data())); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data())); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data())); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, util::convert(t).data())); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, util::convert(t).data())); } template <> void bindUniform>(UniformLocation location, const std::array& t) { MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, util::convert(t).data())); } template <> void bindUniform(UniformLocation location, const bool& t) { return bindUniform(location, int32_t(t)); } template <> void bindUniform(UniformLocation location, const uint8_t& t) { bindUniform(location, int32_t(t)); } template <> void bindUniform(UniformLocation location, const Color& t) { bindUniform(location, std::array {{ t.r, t.g, t.b, t.a }}); } template <> void bindUniform(UniformLocation location, const Size& t) { bindUniform(location, util::convert(std::array {{ t.width, t.height }})); } template <> void bindUniform>(UniformLocation location, const std::array& t) { bindUniform(location, util::convert(t)); } // Add more as needed. #ifndef NDEBUG ActiveUniforms activeUniforms(ProgramID id) { ActiveUniforms active; GLint count; GLint maxLength; MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count)); MBGL_CHECK_ERROR(glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength)); auto name = std::make_unique(maxLength); GLsizei length; GLint size; GLenum type; for (GLint index = 0; index < count; index++) { MBGL_CHECK_ERROR( glGetActiveUniform(id, index, maxLength, &length, &size, &type, name.get())); active.emplace( std::string{ name.get(), static_cast(length) }, ActiveUniform{ static_cast(size), static_cast(type) }); } return active; } template <> bool verifyUniform(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::Float); return true; } template <> bool verifyUniform>(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::FloatVec2); return true; } template <> bool verifyUniform>(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::FloatVec3); return true; } template <> bool verifyUniform>(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::FloatMat4); return true; } template <> bool verifyUniform(const ActiveUniform& uniform) { assert(uniform.size == 1 && (uniform.type == UniformDataType::Bool || uniform.type == UniformDataType::Int || uniform.type == UniformDataType::Float)); return true; } template <> bool verifyUniform(const ActiveUniform& uniform) { assert(uniform.size == 1 && (uniform.type == UniformDataType::Int || uniform.type == UniformDataType::Float || uniform.type == UniformDataType::Sampler2D)); return true; } template <> bool verifyUniform(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::FloatVec4); return true; } template <> bool verifyUniform(const ActiveUniform& uniform) { assert(uniform.size == 1 && uniform.type == UniformDataType::FloatVec2); return true; } template <> bool verifyUniform>(const ActiveUniform& uniform) { assert(uniform.size == 1 && (uniform.type == UniformDataType::IntVec2 || uniform.type == UniformDataType::FloatVec2)); return true; } // Add more as needed. #endif } // namespace gl } // namespace mbgl