Drawable Renderer (#1570), Fix color normalization problems, don't produce zero-alpha drawables

This commit is contained in:
Tim Sylvester
2023-05-16 09:59:12 -07:00
committed by Bart Louwers
parent 1fa3502048
commit 76658d8717
5 changed files with 17 additions and 16 deletions

View File

@@ -3,6 +3,7 @@
#include <mbgl/gfx/uniform_buffer.hpp>
#include <mbgl/gfx/vertex_attribute.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/identity.hpp>
#include <cstdint>
@@ -102,6 +103,15 @@ public:
// Reset a single color attribute for all vertexes
virtual void resetColor(const Color&) = 0;
/// Convert from the odd partially-normalized color component array produced by `Color::toArray` into normalized RGBA.
static gfx::VertexAttribute::float4 colorAttrRGBA(const Color& color) {
const auto components = color.toArray();
return {static_cast<float>(components[0] / 255.0),
static_cast<float>(components[1] / 255.0),
static_cast<float>(components[2] / 255.0),
static_cast<float>(components[3])};
}
protected:
std::string name;
util::SimpleIdentity uniqueID;

View File

@@ -2,7 +2,6 @@
#include <mbgl/gfx/drawable.hpp>
#include <mbgl/gl/vertex_attribute_gl.hpp>
#include <mbgl/util/color.hpp>
#include <memory>
@@ -48,14 +47,6 @@ public:
/// Reset a single color attribute for all vertexes
void resetColor(const Color&) override;
static gfx::VertexAttribute::float4 colorAttrValue(const Color& color) {
const auto components = color.toArray();
return {static_cast<float>(components[0] / 255.0),
static_cast<float>(components[1] / 255.0),
static_cast<float>(components[2] / 255.0),
static_cast<float>(components[3])};
}
protected:
class Impl;
const std::unique_ptr<Impl> impl;