diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp index ec68ea991..28aa80060 100644 --- a/include/mbgl/style/property_key.hpp +++ b/include/mbgl/style/property_key.hpp @@ -60,6 +60,7 @@ enum class PropertyKey { RasterContrast, RasterFade, + BackgroundOpacity, BackgroundColor }; diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index bbe8812bc..891406ff8 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -92,6 +92,7 @@ struct RasterProperties { struct BackgroundProperties { inline BackgroundProperties() {} + float opacity = 1.0f; Color color = {{ 0, 0, 0, 1 }}; }; diff --git a/src/map/map.cpp b/src/map/map.cpp index ed4cdd005..39542d3f5 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -626,7 +626,6 @@ void Map::renderLayers(std::shared_ptr group) { void Map::renderLayer(std::shared_ptr layer_desc, RenderPass pass, const Tile::ID* id, const mat4* matrix) { if (layer_desc->type == StyleLayerType::Background) { // This layer defines a background color/image. - if (pass == RenderPass::Translucent) return; if (debug::renderTree) { std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " (" diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index f29d60f8d..cfc3e8e54 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -186,15 +186,23 @@ void Painter::renderTileLayer(const Tile& tile, std::shared_ptr laye void Painter::renderBackground(std::shared_ptr layer_desc) { const BackgroundProperties& properties = layer_desc->getProperties(); - useProgram(plainShader->program); - plainShader->setMatrix(identityMatrix); - plainShader->setColor(properties.color); - backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0)); + Color color = properties.color; + color[0] *= properties.opacity; + color[1] *= properties.opacity; + color[2] *= properties.opacity; + color[3] *= properties.opacity; - glDisable(GL_STENCIL_TEST); - depthRange(strata + strata_epsilon, 1.0f); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glEnable(GL_STENCIL_TEST); + if ((color[3] >= 1.0f) == (pass == RenderPass::Opaque)) { + useProgram(plainShader->program); + plainShader->setMatrix(identityMatrix); + plainShader->setColor(color); + backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0)); + + glDisable(GL_STENCIL_TEST); + depthRange(strata + strata_epsilon, 1.0f); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glEnable(GL_STENCIL_TEST); + } } const mat4 &Painter::translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor) { diff --git a/src/style/property_fallback.cpp b/src/style/property_fallback.cpp index 0f8335dd6..572c4b7a8 100644 --- a/src/style/property_fallback.cpp +++ b/src/style/property_fallback.cpp @@ -52,6 +52,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::RasterContrast, defaultStyleProperties().contrast }, { PropertyKey::RasterFade, defaultStyleProperties().fade }, + { PropertyKey::BackgroundOpacity, defaultStyleProperties().opacity }, { PropertyKey::BackgroundColor, defaultStyleProperties().color }, }; diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 71916afe2..4f758fe72 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -233,6 +233,7 @@ template <> void StyleLayer::applyStyleProperties(const float z, const timestamp now) { properties.set(); BackgroundProperties &background = properties.get(); + applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now); applyTransitionedStyleProperty(PropertyKey::BackgroundColor, background.color, z, now); } diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 88be68eb4..3d51a2ebe 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -636,6 +636,7 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { parseOptionalProperty>("raster-fade-duration", Key::RasterFade, klass, value); parseOptionalProperty("transition-raster-fade-duration", Key::RasterFade, klass, value); + parseOptionalProperty>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty>("background-color", Key::BackgroundColor, klass, value); }