#include #include #include #include #include #include #include namespace mbgl { namespace gl { gfx::UniqueDrawable DrawableGLBuilder::createDrawable() const { return std::make_unique(drawableName.empty() ? name : drawableName); }; std::unique_ptr DrawableGLBuilder::createSegment(gfx::DrawMode mode, SegmentBase&& seg) { return std::make_unique(mode, std::move(seg), VertexArray{{nullptr, false}}); } void DrawableGLBuilder::init() { auto& drawableGL = static_cast(*currentDrawable); drawableGL.setColorAttrName(colorAttrName); drawableGL.setVertexAttrName(vertexAttrName); if (impl->rawVerticesCount) { auto raw = impl->rawVertices; drawableGL.setVertices(std::move(raw), impl->rawVerticesCount, impl->rawVerticesType); } else { const auto& verts = impl->vertices.vector(); constexpr auto vertSize = sizeof(std::remove_reference::type::value_type); std::vector raw(verts.size() * vertSize); std::memcpy(raw.data(), verts.data(), raw.size()); drawableGL.setVertices(std::move(raw), verts.size(), gfx::AttributeDataType::Short2); } auto& attrs = drawableGL.mutableVertexAttributes(); if (colorAttrMode != ColorAttrMode::None && !colorAttrName.empty()) { if (const auto& colorAttr = attrs.getOrAdd(colorAttrName)) { // We should have either a single color or one per vertex. Otherwise, // the color mode was probably changed after vertexes were added. if (impl->colors.size() > 1 && impl->colors.size() != impl->vertices.elements()) { impl->colors.clear(); } if (impl->colors.empty()) { colorAttr->set(0, gfx::Drawable::colorAttrRGBA(getColor())); } else { std::size_t index = 0; colorAttr->reserve(impl->colors.size()); for (const auto& color : impl->colors) { colorAttr->set(index++, gfx::Drawable::colorAttrRGBA(color)); } } } } drawableGL.setIndexData(std::move(impl->indexes), std::move(impl->segments)); impl->indexes.clear(); impl->segments.clear(); impl->vertices.clear(); impl->colors.clear(); } } // namespace gl } // namespace mbgl