Convert Line Atlas to Texture2D & std::variant (#1226)

Co-authored-by: Bart Louwers <bart@emeel.net>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
This commit is contained in:
Stefan Karschti
2023-06-09 17:48:07 +03:00
committed by Bart Louwers
parent b060abeb92
commit 008f584b9e
2 changed files with 18 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
#include <cmath>
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/gfx/upload_pass.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/math/log2.hpp>
#include <mbgl/math/minmax.hpp>
#include <mbgl/util/hash.hpp>
@@ -206,15 +207,19 @@ DashPatternTexture::DashPatternTexture(const std::vector<float>& from_,
}
void DashPatternTexture::upload(gfx::UploadPass& uploadPass) {
if (texture.is<AlphaImage>()) {
texture = uploadPass.createTexture(texture.get<AlphaImage>());
if (std::holds_alternative<AlphaImage>(texture)) {
auto tempTexture = uploadPass.getContext().createTexture2D();
tempTexture->upload(std::get<AlphaImage>(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<gfx::Texture>());
return {texture.get<gfx::Texture>().getResource(),
assert(std::holds_alternative<gfx::Texture2DPtr>(texture));
return {std::get<gfx::Texture2DPtr>(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<AlphaImage>(texture)) {
return std::get<AlphaImage>(texture).size;
}
return std::get<gfx::Texture2DPtr>(texture)->getSize();
}
LineAtlas::LineAtlas() = default;

View File

@@ -1,13 +1,14 @@
#pragma once
#include <mbgl/gfx/texture.hpp>
#include <mbgl/gfx/texture2d.hpp>
#include <mbgl/gfx/context.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/variant.hpp>
#include <map>
#include <memory>
#include <vector>
#include <optional>
#include <variant>
namespace mbgl {
@@ -54,7 +55,7 @@ public:
private:
LinePatternPos from, to;
variant<AlphaImage, gfx::Texture> texture;
std::variant<AlphaImage, gfx::Texture2DPtr> texture;
};
class LineAtlas {
@@ -75,7 +76,7 @@ public:
private:
std::map<size_t, DashPatternTexture> 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<size_t> needsUpload;
};