Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
abort rendering early if the style is disabled
Browse files Browse the repository at this point in the history
refs #184
  • Loading branch information
kkaefer committed May 13, 2014
1 parent 72c0410 commit b096373
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/llmr/style/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct TextClass {
FunctionProperty size = 12.0f;
FunctionProperty rotate = 0.0f;
FunctionProperty alwaysVisible = false;
FunctionProperty opacity = 1;
};

struct TextProperties {
Expand All @@ -138,6 +139,7 @@ struct TextProperties {
float size = 12.0f;
float rotate = 0.0f;
bool alwaysVisible = false;
float opacity = 1.0;
};

struct BackgroundClass {
Expand Down
22 changes: 22 additions & 0 deletions src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,16 @@ void Map::renderLayers(const std::vector<LayerDescription>& layers, RenderPass p
}
}

template <typename Styles>
bool is_invisible(const Styles &styles, const LayerDescription &layer_desc) {
auto it = styles.find(layer_desc.name);
if (it == styles.end()) return true;
const auto &properties = it->second;
if (!properties.enabled) return true;
if (properties.opacity <= 0) return true;
return false;
}

void Map::renderLayer(const LayerDescription& layer_desc, RenderPass pass) {
if (layer_desc.child_layer.size()) {
gl::group group(std::string("group: ") + layer_desc.name);
Expand All @@ -501,13 +511,25 @@ void Map::renderLayer(const LayerDescription& layer_desc, RenderPass pass) {
// Abort early if we can already deduce from the bucket type that
// we're not going to render anything anyway during this pass.
switch (bucket_desc.type) {
case BucketType::Fill:
if (is_invisible(style.computed.fills, layer_desc)) return;
break;
case BucketType::Line:
if (pass == Opaque) return;
if (is_invisible(style.computed.lines, layer_desc)) return;
break;
case BucketType::Point:
if (pass == Opaque) return;
if (is_invisible(style.computed.points, layer_desc)) return;
break;
case BucketType::Text:
if (pass == Opaque) return;
if (is_invisible(style.computed.texts, layer_desc)) return;
break;
case BucketType::Raster:
if (pass == Translucent) return;
if (is_invisible(style.computed.lines, layer_desc)) return;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void Style::cascade(float z) {
text.haloRadius = layer.haloRadius.evaluate<float>(z);
text.rotate = layer.rotate.evaluate<float>(z);
text.alwaysVisible = layer.alwaysVisible.evaluate<bool>(z);
text.opacity = layer.opacity.evaluate<float>(z);
}

// Cascade raster classes
Expand Down

0 comments on commit b096373

Please sign in to comment.