Drawable PR 3 - Layers (#1501)
Co-authored-by: Tim Sylvester <tim@wetdogweather.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
26
BUILD.bazel
26
BUILD.bazel
@@ -1,6 +1,16 @@
|
||||
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS")
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
|
||||
load("//bazel:core.bzl",
|
||||
load(
|
||||
"//bazel:core.bzl",
|
||||
"MLN_CORE_HEADERS",
|
||||
"MLN_CORE_SOURCE",
|
||||
"MLN_DRAWABLES_SOURCE",
|
||||
"MLN_DRAWABLES_HEADERS",
|
||||
"MLN_GENERATED_SHADER_HEADERS",
|
||||
"MLN_GENERATED_STYLE_SOURCE",
|
||||
"MLN_OPENGL_HEADERS",
|
||||
"MLN_OPENGL_SOURCE",
|
||||
"MLN_PRIVATE_GENERATED_STYLE_HEADERS",
|
||||
"MLN_PUBLIC_GENERATED_STYLE_HEADERS",
|
||||
"MLN_PRIVATE_GENERATED_STYLE_HEADERS",
|
||||
"MLN_GENERATED_STYLE_SOURCE",
|
||||
@@ -83,17 +93,15 @@ cc_library(
|
||||
# the prefix from the path.
|
||||
cc_library(
|
||||
name = "mbgl-core",
|
||||
srcs = MLN_CORE_SOURCE
|
||||
+ PREFIXED["MLN_GENERATED_STYLE_SOURCE"]
|
||||
+ MLN_OPENGL_SOURCE
|
||||
+ select({
|
||||
srcs = MLN_CORE_SOURCE +
|
||||
MLN_GENERATED_STYLE_SOURCE +
|
||||
MLN_OPENGL_SOURCE + select({
|
||||
":drawable_renderer": MLN_DRAWABLES_SOURCE,
|
||||
":split_renderer": MLN_DRAWABLES_SOURCE,
|
||||
"//conditions:default": []
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
hdrs = MLN_CORE_HEADERS
|
||||
+ MLN_OPENGL_HEADERS
|
||||
+ select({
|
||||
hdrs = MLN_CORE_HEADERS +
|
||||
MLN_OPENGL_HEADERS + select({
|
||||
":drawable_renderer": MLN_DRAWABLES_HEADERS,
|
||||
":split_renderer": MLN_DRAWABLES_HEADERS,
|
||||
"//conditions:default": []
|
||||
|
||||
@@ -148,7 +148,6 @@ public:
|
||||
|
||||
/// Add a triangle
|
||||
void addTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
|
||||
|
||||
/// Add another triangle based on the previous two points
|
||||
void appendTriangle(int16_t x0, int16_t y0);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ void main() {
|
||||
// we want to vertically exaggerate the hillshading though, because otherwise
|
||||
// it is barely noticeable at low zooms. to do this, we multiply this by some
|
||||
// scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value
|
||||
// Here we use a=0.3 which works out to the expression below. see
|
||||
// Here we use a=0.3 which works out to the expression below. see
|
||||
// nickidlugash's awesome breakdown for more info
|
||||
// https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556
|
||||
float exaggeration = u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;
|
||||
|
||||
@@ -56,7 +56,7 @@ layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
|
||||
|
||||
highp float pad2;
|
||||
};
|
||||
|
||||
@@ -216,7 +216,7 @@ layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
|
||||
|
||||
highp float pad2;
|
||||
};
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
// we want to vertically exaggerate the hillshading though, because otherwise
|
||||
// it is barely noticeable at low zooms. to do this, we multiply this by some
|
||||
// scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value
|
||||
// Here we use a=0.3 which works out to the expression below. see
|
||||
// Here we use a=0.3 which works out to the expression below. see
|
||||
// nickidlugash's awesome breakdown for more info
|
||||
// https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556
|
||||
float exaggeration = u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;
|
||||
|
||||
@@ -32,7 +32,7 @@ layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
|
||||
|
||||
highp float pad2;
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ layout (std140) uniform LineSDFInterpolationUBO {
|
||||
lowp float u_offset_t;
|
||||
lowp float u_width_t;
|
||||
lowp float u_floorwidth_t;
|
||||
|
||||
|
||||
highp float pad2;
|
||||
};
|
||||
|
||||
|
||||
@@ -202,23 +202,15 @@ void RenderHeatmapLayer::render(PaintParameters& parameters) {
|
||||
#endif // MLN_LEGACY_RENDERER
|
||||
|
||||
void RenderHeatmapLayer::updateColorRamp() {
|
||||
auto colorValue = unevaluated.get<HeatmapColor>().getValue();
|
||||
if (colorValue.isUndefined()) {
|
||||
colorValue = HeatmapLayer::getDefaultHeatmapColor();
|
||||
}
|
||||
if (colorRamp) {
|
||||
auto colorValue = unevaluated.get<HeatmapColor>().getValue();
|
||||
if (colorValue.isUndefined()) {
|
||||
colorValue = HeatmapLayer::getDefaultHeatmapColor();
|
||||
}
|
||||
|
||||
const auto length = (*colorRamp).bytes();
|
||||
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
const auto color = colorValue.evaluate(static_cast<double>(i) / length);
|
||||
(*colorRamp).data[i + 0] = static_cast<uint8_t>(std::floor(color.r * 255.f));
|
||||
(*colorRamp).data[i + 1] = static_cast<uint8_t>(std::floor(color.g * 255.f));
|
||||
(*colorRamp).data[i + 2] = static_cast<uint8_t>(std::floor(color.b * 255.f));
|
||||
(*colorRamp).data[i + 3] = static_cast<uint8_t>(std::floor(color.a * 255.f));
|
||||
}
|
||||
|
||||
if (colorRampTexture) {
|
||||
colorRampTexture = std::nullopt;
|
||||
if (applyColorRamp(colorValue, *colorRamp)) {
|
||||
colorRampTexture = std::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -306,24 +306,12 @@ bool RenderLineLayer::queryIntersectsFeature(const GeometryCoordinates& queryGeo
|
||||
}
|
||||
|
||||
void RenderLineLayer::updateColorRamp() {
|
||||
auto colorValue = unevaluated.get<LineGradient>().getValue();
|
||||
if (colorValue.isUndefined()) {
|
||||
const style::ColorRampPropertyValue colorValue = unevaluated.get<LineGradient>().getValue();
|
||||
if (!colorRamp || !applyColorRamp(colorValue, *colorRamp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto length = colorRamp->bytes();
|
||||
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
const auto color = colorValue.evaluate(static_cast<double>(i) / length);
|
||||
colorRamp->data[i] = static_cast<uint8_t>(std::floor(color.r * 255.f));
|
||||
colorRamp->data[i + 1] = static_cast<uint8_t>(std::floor(color.g * 255.f));
|
||||
colorRamp->data[i + 2] = static_cast<uint8_t>(std::floor(color.b * 255.f));
|
||||
colorRamp->data[i + 3] = static_cast<uint8_t>(std::floor(color.a * 255.f));
|
||||
}
|
||||
|
||||
if (colorRampTexture) {
|
||||
colorRampTexture = std::nullopt;
|
||||
}
|
||||
colorRampTexture = std::nullopt;
|
||||
|
||||
#if MLN_DRAWABLE_RENDERER
|
||||
if (colorRampTexture2D) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <mbgl/renderer/render_layer.hpp>
|
||||
|
||||
#include <mbgl/gfx/context.hpp>
|
||||
#include <mbgl/renderer/paint_parameters.hpp>
|
||||
#include <mbgl/renderer/render_source.hpp>
|
||||
#include <mbgl/renderer/render_tile.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/style/color_ramp_property_value.hpp>
|
||||
#include <mbgl/style/layer.hpp>
|
||||
#include <mbgl/style/layer_properties.hpp>
|
||||
#include <mbgl/style/types.hpp>
|
||||
#include <mbgl/tile/tile.hpp>
|
||||
#include <mbgl/gfx/context.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#if MLN_DRAWABLE_RENDERER
|
||||
@@ -223,4 +224,21 @@ void RenderLayer::activateLayerGroup(const LayerGroupBasePtr& layerGroup_,
|
||||
}
|
||||
#endif
|
||||
|
||||
bool RenderLayer::applyColorRamp(const style::ColorRampPropertyValue& colorValue, PremultipliedImage& image) {
|
||||
if (colorValue.isUndefined()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto length = image.bytes();
|
||||
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
const auto color = colorValue.evaluate(static_cast<double>(i) / length);
|
||||
image.data[i + 0] = static_cast<uint8_t>(std::floor(color.r * 255.f));
|
||||
image.data[i + 1] = static_cast<uint8_t>(std::floor(color.g * 255.f));
|
||||
image.data[i + 2] = static_cast<uint8_t>(std::floor(color.b * 255.f));
|
||||
image.data[i + 3] = static_cast<uint8_t>(std::floor(color.a * 255.f));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -51,6 +51,10 @@ using UniformBufferPtr = std::shared_ptr<UniformBuffer>;
|
||||
#endif
|
||||
} // namespace gfx
|
||||
|
||||
namespace style {
|
||||
class ColorRampPropertyValue;
|
||||
} // namespace style
|
||||
|
||||
class LayerRenderData {
|
||||
public:
|
||||
std::shared_ptr<Bucket> bucket;
|
||||
@@ -212,13 +216,20 @@ protected:
|
||||
bool hasRenderTile(const OverscaledTileID&) const;
|
||||
|
||||
/// Get the bucket ID from which a given tile was built
|
||||
/// @details When a new style is loaded and contains a layer with the same ID, `layerChanged` will be called during
|
||||
/// style
|
||||
/// parsing, but the `Bucket` in a tile's `RenderData` will only be replaced when the asynchronous load for
|
||||
/// the tile is complete, at which point the drawable for the tile may need to be updated or replaced.
|
||||
util::SimpleIdentity getRenderTileBucketID(const OverscaledTileID&) const;
|
||||
|
||||
/// Set the bucket ID from which a given tile was built
|
||||
/// @return true if updated, false if missing or unchanged
|
||||
/// @return true if updated, false if the tile ID is not present in the set of tiles to be rendered or the ID is
|
||||
/// unchanged
|
||||
bool setRenderTileBucketID(const OverscaledTileID&, util::SimpleIdentity bucketID);
|
||||
#endif // MLN_DRAWABLE_RENDERER
|
||||
|
||||
static bool applyColorRamp(const style::ColorRampPropertyValue&, PremultipliedImage&);
|
||||
|
||||
protected:
|
||||
// Stores current set of tiles to be rendered for this layer.
|
||||
RenderTiles renderTiles;
|
||||
|
||||
Reference in New Issue
Block a user