From 008f584b9e7609563c1c5014f5c0620bb389f3f3 Mon Sep 17 00:00:00 2001 From: Stefan Karschti Date: Fri, 9 Jun 2023 17:48:07 +0300 Subject: [PATCH] Convert Line Atlas to Texture2D & std::variant (#1226) Co-authored-by: Bart Louwers Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Sylvester Co-authored-by: Alex Cristici --- src/mbgl/geometry/line_atlas.cpp | 18 +++++++++++++----- src/mbgl/geometry/line_atlas.hpp | 9 +++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index 02c2b311c..8a0b1f605 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -206,15 +207,19 @@ DashPatternTexture::DashPatternTexture(const std::vector& from_, } void DashPatternTexture::upload(gfx::UploadPass& uploadPass) { - if (texture.is()) { - texture = uploadPass.createTexture(texture.get()); + if (std::holds_alternative(texture)) { + auto tempTexture = uploadPass.getContext().createTexture2D(); + tempTexture->upload(std::get(texture)); + tempTexture->setSamplerConfiguration( + {gfx::TextureFilterType::Linear, gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp}); + texture = std::move(tempTexture); } } gfx::TextureBinding DashPatternTexture::textureBinding() const { // The texture needs to have been uploaded already. - assert(texture.is()); - return {texture.get().getResource(), + assert(std::holds_alternative(texture)); + return {std::get(texture)->getResource(), gfx::TextureFilterType::Linear, gfx::TextureMipMapType::No, gfx::TextureWrapType::Repeat, @@ -222,7 +227,10 @@ gfx::TextureBinding DashPatternTexture::textureBinding() const { } Size DashPatternTexture::getSize() const { - return texture.match([](const auto& obj) { return obj.size; }); + if (std::holds_alternative(texture)) { + return std::get(texture).size; + } + return std::get(texture)->getSize(); } LineAtlas::LineAtlas() = default; diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index c65a94662..298c14bfd 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -1,13 +1,14 @@ #pragma once #include +#include +#include #include -#include #include #include #include -#include +#include namespace mbgl { @@ -54,7 +55,7 @@ public: private: LinePatternPos from, to; - variant texture; + std::variant texture; }; class LineAtlas { @@ -75,7 +76,7 @@ public: private: std::map textures; - // Stores a list of hashes of texture objcts that need uploading. + // Stores a list of hashes of texture objects that need uploading. std::vector needsUpload; };