#pragma once #include #include #include #include #include namespace mbgl { namespace gfx { class ShaderProgramBase : public gfx::Shader { protected: ShaderProgramBase() {} ShaderProgramBase(ShaderProgramBase&&) {} ~ShaderProgramBase() noexcept override = default; template bool set(gfx::VertexAttributeArray& attrs, const std::string& name, std::size_t i, T value) { const auto& item = attrs.get(name); if (item && i < item->getCount()) { item->set(i, value); return true; } return false; } public: const util::SimpleIdentity& getID() const { return shaderProgramID; } /// Get the available uniform blocks attached to this shader virtual const gfx::UniformBlockArray& getUniformBlocks() const = 0; /// Get the available vertex attributes and their default values virtual const gfx::VertexAttributeArray& getVertexAttributes() const = 0; template bool setAttribute(const std::string& name, std::size_t i, T value) { return set(mutableVertexAttributes(), name, i, value); } protected: virtual gfx::UniformBlockArray& mutableUniformBlocks() = 0; virtual gfx::VertexAttributeArray& mutableVertexAttributes() = 0; protected: util::SimpleIdentity shaderProgramID; }; } // namespace gfx } // namespace mbgl