#include #include #include #include namespace mbgl { namespace gl { DrawableGL::DrawableGL(std::string name_) : Drawable(std::move(name_)), impl(std::make_unique()) {} DrawableGL::~DrawableGL() { impl->vertexArray = {{nullptr, false}}; impl->indexBuffer = {0, nullptr}; impl->attributeBuffer.reset(); } void DrawableGL::draw(const PaintParameters& parameters) const { bindUniformBuffers(); impl->draw(parameters, lineWidth); unbindUniformBuffers(); } void DrawableGL::setLineIndexData(std::vector indexes) { impl->lineIndexes = std::move(indexes); } void DrawableGL::setTriangleIndexData(std::vector indexes) { impl->triangleIndexes = std::move(indexes); } std::vector& DrawableGL::getLineIndexData() const { return impl->lineIndexes; } std::vector& DrawableGL::getTriangleIndexData() const { return impl->triangleIndexes; } const gl::VertexArray& DrawableGL::getVertexArray() const { return impl->vertexArray; } const gfx::IndexBuffer& DrawableGL::getIndexBuffer() const { return impl->indexBuffer; } const gfx::UniqueVertexBufferResource& DrawableGL::getBuffer() const { return impl->attributeBuffer; } const gfx::VertexAttributeArray& DrawableGL::getVertexAttributes() const { return impl->vertexAttributes; } gfx::VertexAttributeArray& DrawableGL::mutableVertexAttributes() { return impl->vertexAttributes; } void DrawableGL::setVertexAttributes(const gfx::VertexAttributeArray& value) { impl->vertexAttributes = static_cast(value); } void DrawableGL::setVertexAttributes(gfx::VertexAttributeArray&& value) { impl->vertexAttributes = std::move(static_cast(value)); } void DrawableGL::setVertexArray(gl::VertexArray&& vertexArray_, gfx::UniqueVertexBufferResource&& attributeBuffer_, gfx::IndexBuffer&& indexBuffer_) { impl->vertexArray = std::move(vertexArray_); impl->attributeBuffer = std::move(attributeBuffer_); impl->indexBuffer = std::move(indexBuffer_); } const gfx::UniformBufferArray& DrawableGL::getUniformBuffers() const { return impl->uniformBuffers; } gfx::UniformBufferArray& DrawableGL::mutableUniformBuffers() { return impl->uniformBuffers; } void DrawableGL::resetColor(const Color& newColor) { if (const auto& colorAttr = impl->vertexAttributes.get("a_color")) { colorAttr->clear(); colorAttr->set(0, Drawable::colorAttrRGBA(newColor)); } } void DrawableGL::bindUniformBuffers() const { if (shader) { const auto& shaderGL = static_cast(*shader); for (const auto& element : shaderGL.getUniformBlocks().getMap()) { const auto& uniformBuffer = getUniformBuffers().get(element.first); if (!uniformBuffer) { continue; } element.second->bindBuffer(*uniformBuffer); } } } void DrawableGL::unbindUniformBuffers() const { if (shader) { const auto& shaderGL = static_cast(*shader); for (const auto& element : shaderGL.getUniformBlocks().getMap()) { element.second->unbindBuffer(); } } } } // namespace gl } // namespace mbgl