Merge branch 'master' into fuzz-pipe
Conflicts: test/test.gyp
This commit is contained in:
@@ -228,7 +228,7 @@ void SpriteAtlas::update(const Sprite &sprite) {
|
||||
if (!sprite.isLoaded()) return;
|
||||
|
||||
SpriteAtlas &atlas = *this;
|
||||
std::erase_if(uninitialized, [&sprite, &atlas](const std::string &name) {
|
||||
util::erase_if(uninitialized, [&sprite, &atlas](const std::string &name) {
|
||||
Rect<dimension> dst = atlas.getImage(name, sprite);
|
||||
const SpritePosition &src = sprite.getSpritePosition(name);
|
||||
if (!src) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <llmr/util/string.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
#include <llmr/util/uv.hpp>
|
||||
#include <llmr/util/std.hpp>
|
||||
#include <llmr/style/style_layer_group.hpp>
|
||||
#include <llmr/style/style_bucket.hpp>
|
||||
#include <llmr/geometry/sprite_atlas.hpp>
|
||||
@@ -410,11 +411,32 @@ void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) {
|
||||
}
|
||||
|
||||
void Map::updateSources() {
|
||||
activeSources.clear();
|
||||
// First, disable all existing sources.
|
||||
for (const std::shared_ptr<StyleSource> &source : activeSources) {
|
||||
source->enabled = false;
|
||||
}
|
||||
|
||||
// Then, reenable all of those that we actually use when drawing this layer.
|
||||
updateSources(style->layers);
|
||||
|
||||
// Then, construct or destroy the actual source object, depending on enabled state.
|
||||
for (const std::shared_ptr<StyleSource> &source : activeSources) {
|
||||
if (source->enabled) {
|
||||
if (!source->source) {
|
||||
source->source = std::make_shared<Source>(*source, getAccessToken());
|
||||
}
|
||||
} else {
|
||||
source->source.reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, remove all sources that are disabled.
|
||||
util::erase_if(activeSources, [](std::shared_ptr<StyleSource> source){
|
||||
return !source->enabled;
|
||||
});
|
||||
}
|
||||
|
||||
const std::set<std::shared_ptr<Source>> Map::getActiveSources() const {
|
||||
const std::set<std::shared_ptr<StyleSource>> Map::getActiveSources() const {
|
||||
return activeSources;
|
||||
}
|
||||
|
||||
@@ -426,8 +448,7 @@ void Map::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
|
||||
if (!layer) continue;
|
||||
if (layer->bucket) {
|
||||
if (layer->bucket->style_source) {
|
||||
auto ret = activeSources.emplace(std::make_shared<Source>(*layer->bucket->style_source, this->getAccessToken()));
|
||||
layer->bucket->source = *ret.first;
|
||||
(*activeSources.emplace(layer->bucket->style_source).first)->enabled = true;
|
||||
}
|
||||
} else if (layer->layers) {
|
||||
updateSources(layer->layers);
|
||||
@@ -436,23 +457,23 @@ void Map::updateSources(const std::shared_ptr<StyleLayerGroup> &group) {
|
||||
}
|
||||
|
||||
void Map::updateTiles() {
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->update(*this);
|
||||
for (const std::shared_ptr<StyleSource> &source : getActiveSources()) {
|
||||
source->source->update(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::updateRenderState() {
|
||||
std::forward_list<Tile::ID> ids;
|
||||
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
ids.splice_after(ids.before_begin(), source->getIDs());
|
||||
source->updateMatrices(painter.projMatrix, state);
|
||||
for (const std::shared_ptr<StyleSource> &source : getActiveSources()) {
|
||||
ids.splice_after(ids.before_begin(), source->source->getIDs());
|
||||
source->source->updateMatrices(painter.projMatrix, state);
|
||||
}
|
||||
|
||||
const std::map<Tile::ID, ClipID> clipIDs = computeClipIDs(ids);
|
||||
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->updateClipIDs(clipIDs);
|
||||
for (const std::shared_ptr<StyleSource> &source : getActiveSources()) {
|
||||
source->source->updateClipIDs(clipIDs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,8 +552,8 @@ void Map::render() {
|
||||
// This guarantees that we have at least one function per tile called.
|
||||
// When only rendering layers via the stylesheet, it's possible that we don't
|
||||
// ever visit a tile during rendering.
|
||||
for (const std::shared_ptr<Source> &source : getActiveSources()) {
|
||||
source->finishRender(painter);
|
||||
for (const std::shared_ptr<StyleSource> &source : getActiveSources()) {
|
||||
source->source->finishRender(painter);
|
||||
}
|
||||
|
||||
painter.renderMatte();
|
||||
@@ -629,6 +650,8 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
|
||||
return;
|
||||
}
|
||||
|
||||
StyleSource &style_source = *layer_desc->bucket->style_source;
|
||||
|
||||
// Abort early if we can already deduce from the bucket type that
|
||||
// we're not going to render anything anyway during this pass.
|
||||
switch (layer_desc->type) {
|
||||
@@ -660,6 +683,8 @@ void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass) {
|
||||
<< layer_desc->type << ")" << std::endl;
|
||||
}
|
||||
|
||||
layer_desc->bucket->source->render(painter, layer_desc);
|
||||
if (style_source.source) {
|
||||
style_source.source->render(painter, layer_desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ bool Source::updateTiles(Map &map) {
|
||||
// Remove tiles that we definitely don't need, i.e. tiles that are not on
|
||||
// the required list.
|
||||
std::set<Tile::ID> retain_data;
|
||||
std::erase_if(tiles, [&retain, &retain_data, &changed](std::pair<const Tile::ID, std::unique_ptr<Tile>> &pair) {
|
||||
util::erase_if(tiles, [&retain, &retain_data, &changed](std::pair<const Tile::ID, std::unique_ptr<Tile>> &pair) {
|
||||
Tile &tile = *pair.second;
|
||||
bool obsolete = std::find(retain.begin(), retain.end(), tile.id) == retain.end();
|
||||
if (obsolete) {
|
||||
@@ -296,7 +296,7 @@ bool Source::updateTiles(Map &map) {
|
||||
});
|
||||
|
||||
// Remove all the expired pointers from the set.
|
||||
std::erase_if(tile_data, [&retain_data](std::pair<const Tile::ID, std::weak_ptr<TileData>> &pair) {
|
||||
util::erase_if(tile_data, [&retain_data](std::pair<const Tile::ID, std::weak_ptr<TileData>> &pair) {
|
||||
const std::shared_ptr<TileData> tile = pair.second.lock();
|
||||
if (!tile) {
|
||||
return true;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#include <llmr/platform/event.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
EventSeverity parseEventSeverity(const char *name) {
|
||||
if (strcmp(name, "DEBUG") == 0) return EventSeverity::Debug;
|
||||
if (strcmp(name, "INFO") == 0) return EventSeverity::Info;
|
||||
if (strcmp(name, "TEST") == 0) return EventSeverity::Test;
|
||||
if (strcmp(name, "WARNING") == 0) return EventSeverity::Warning;
|
||||
if (strcmp(name, "ERROR") == 0) return EventSeverity::Error;
|
||||
return EventSeverity(-1);
|
||||
}
|
||||
|
||||
const char *stringifyEventSeverity(EventSeverity eventSeverity) {
|
||||
switch (eventSeverity) {
|
||||
case EventSeverity::Debug: return "DEBUG";
|
||||
case EventSeverity::Info: return "INFO";
|
||||
case EventSeverity::Test: return "TEST";
|
||||
case EventSeverity::Warning: return "WARNING";
|
||||
case EventSeverity::Error: return "ERROR";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
::std::ostream& operator<<(::std::ostream& os, EventSeverity eventSeverity) {
|
||||
return os << stringifyEventSeverity(eventSeverity);
|
||||
}
|
||||
|
||||
Event parseEvent(const char *name) {
|
||||
if (strcmp(name, "General") == 0) return Event::General;
|
||||
if (strcmp(name, "Setup") == 0) return Event::Setup;
|
||||
if (strcmp(name, "Shader") == 0) return Event::Shader;
|
||||
if (strcmp(name, "ParseStyle") == 0) return Event::ParseStyle;
|
||||
if (strcmp(name, "ParseTile") == 0) return Event::ParseTile;
|
||||
if (strcmp(name, "Render") == 0) return Event::Render;
|
||||
if (strcmp(name, "HttpRequest") == 0) return Event::HttpRequest;
|
||||
return Event(-1);
|
||||
}
|
||||
|
||||
const char *stringifyEvent(Event event) {
|
||||
switch (event) {
|
||||
case Event::General: return "General";
|
||||
case Event::Setup: return "Setup";
|
||||
case Event::Shader: return "Shader";
|
||||
case Event::ParseStyle: return "ParseStyle";
|
||||
case Event::ParseTile: return "ParseTile";
|
||||
case Event::Render: return "Render";
|
||||
case Event::HttpRequest: return "HttpRequest";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
::std::ostream& operator<<(::std::ostream& os, Event event) {
|
||||
return os << stringifyEvent(event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
void Painter::drawClippingMasks(const std::set<std::shared_ptr<Source>> &sources) {
|
||||
void Painter::drawClippingMasks(const std::set<std::shared_ptr<StyleSource>> &sources) {
|
||||
gl::group group("clipping masks");
|
||||
|
||||
useProgram(plainShader->program);
|
||||
@@ -18,8 +18,8 @@ void Painter::drawClippingMasks(const std::set<std::shared_ptr<Source>> &sources
|
||||
|
||||
coveringPlainArray.bind(*plainShader, tileStencilBuffer, BUFFER_OFFSET(0));
|
||||
|
||||
for (const std::shared_ptr<Source> &source : sources) {
|
||||
source->drawClippingMasks(*this);
|
||||
for (const std::shared_ptr<StyleSource> &source : sources) {
|
||||
source->source->drawClippingMasks(*this);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <llmr/renderer/text_bucket.hpp>
|
||||
#include <llmr/style/style_layer.hpp>
|
||||
#include <llmr/map/map.hpp>
|
||||
#include <llmr/util/math.hpp>
|
||||
#include <cmath>
|
||||
|
||||
using namespace llmr;
|
||||
@@ -88,12 +89,37 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
textShader->setMaxFadeZoom(std::floor(highZ * 10));
|
||||
textShader->setFadeZoom((map.getState().getNormalizedZoom() + bump) * 10);
|
||||
|
||||
// This defines the gamma around the SDF cutoff value.
|
||||
const float sdfGamma = 0.75f / 10.0f;
|
||||
|
||||
// Our signed distance fields are scaled so that 1 pixel is scaled to 32 pixels.
|
||||
// Our cutoff between positive and negative values is hard coded to 64 (== 2 pixels).
|
||||
// This means that our 6/8 of the value range lies outside the glyph outline.
|
||||
const float sdfOffset = (256.0f - 64.0f) / 32.0f;
|
||||
|
||||
// Currently, all of our fonts are rendered with a font size of 24px.
|
||||
const float sdfFontSize = 24.0f;
|
||||
|
||||
// The default gamma value has to be adjust for the current pixelratio so that we're not drawing
|
||||
// blurry font on retina screens.
|
||||
const float gamma = sdfGamma * sdfFontSize / fontSize / map.getState().getPixelRatio();
|
||||
|
||||
// We're drawing in the translucent pass which is bottom-to-top, so we need
|
||||
// to draw the halo first.
|
||||
if (properties.halo_color[3] > 0.0f) {
|
||||
// TODO: Get rid of the 2.4 magic value. It is currently 24 / 10, with 24 being the font size
|
||||
// of the SDF glyphs.
|
||||
textShader->setGamma(properties.halo_blur * 2.4f / fontSize / map.getState().getPixelRatio());
|
||||
const float haloWidth = util::clamp((sdfOffset - properties.halo_width / (fontSize / sdfFontSize)) / 8.0f, 0.0f, 1.0f);
|
||||
|
||||
if (properties.halo_blur != 0.0f) {
|
||||
// We are converting the halo_blur value to current screen pixels.
|
||||
// Then we're dividing it by two because the gamma value is added/subtracted into both
|
||||
// directions in the shader, but the halo_blur describes the entire width of the blur.
|
||||
// Note that this does *not* have to be adjusted for retina screens, because we want the
|
||||
// same blur width when we explicitly specify one.
|
||||
textShader->setGamma((properties.halo_blur / (fontSize / sdfFontSize)) / 8.0f / 2.0f);
|
||||
} else {
|
||||
textShader->setGamma(sdfGamma);
|
||||
}
|
||||
|
||||
if (properties.opacity < 1.0f) {
|
||||
Color color = properties.halo_color;
|
||||
color[0] *= properties.opacity;
|
||||
@@ -104,16 +130,14 @@ void Painter::renderText(TextBucket& bucket, std::shared_ptr<StyleLayer> layer_d
|
||||
} else {
|
||||
textShader->setColor(properties.halo_color);
|
||||
}
|
||||
textShader->setBuffer(properties.halo_width);
|
||||
textShader->setBuffer(haloWidth);
|
||||
glDepthRange(strata, 1.0f);
|
||||
bucket.drawGlyphs(*textShader);
|
||||
}
|
||||
|
||||
if (properties.color[3] > 0.0f) {
|
||||
// Then, we draw the text over the halo
|
||||
// TODO: Get rid of the 2.4 magic value. It is currently 24 / 10, with 24 being the font size
|
||||
// of the SDF glyphs.
|
||||
textShader->setGamma(2.4f / fontSize / map.getState().getPixelRatio());
|
||||
textShader->setGamma(gamma);
|
||||
if (properties.opacity < 1.0f) {
|
||||
Color color = properties.color;
|
||||
color[0] *= properties.opacity;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <llmr/platform/log.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
|
||||
@@ -560,7 +560,7 @@ void StyleParser::parseLayer(std::pair<JSVal, std::shared_ptr<StyleLayer>> &pair
|
||||
if (!type.IsString()) {
|
||||
Log::Warning(Event::ParseStyle, "layer type of '%s' must be a string", layer->id.c_str());
|
||||
} else {
|
||||
layer->type = parseStyleLayerType({ type.GetString(), type.GetStringLength() });
|
||||
layer->type = StyleLayerTypeClass(std::string { type.GetString(), type.GetStringLength() });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include <llmr/style/types.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace llmr {
|
||||
|
||||
StyleLayerType parseStyleLayerType(const std::string &type) {
|
||||
if (type == "fill") return StyleLayerType::Fill;
|
||||
if (type == "line") return StyleLayerType::Line;
|
||||
if (type == "icon") return StyleLayerType::Icon;
|
||||
if (type == "text") return StyleLayerType::Text;
|
||||
if (type == "raster") return StyleLayerType::Raster;
|
||||
if (type == "composite") return StyleLayerType::Composite;
|
||||
if (type == "background") return StyleLayerType::Background;
|
||||
return StyleLayerType::Unknown;
|
||||
}
|
||||
|
||||
const char *stringifyStyleLayerType(StyleLayerType type) {
|
||||
switch (type) {
|
||||
case StyleLayerType::Fill: return "fill";
|
||||
case StyleLayerType::Line: return "line";
|
||||
case StyleLayerType::Icon: return "icon";
|
||||
case StyleLayerType::Text: return "text";
|
||||
case StyleLayerType::Raster: return "raster";
|
||||
case StyleLayerType::Composite: return "composite";
|
||||
case StyleLayerType::Background: return "background";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, StyleLayerType type) {
|
||||
return os << stringifyStyleLayerType(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user