diff options
-rw-r--r-- | include/mbgl/renderer/painter.hpp | 15 | ||||
-rw-r--r-- | include/mbgl/style/style.hpp | 3 | ||||
-rw-r--r-- | src/map/map.cpp | 10 | ||||
-rw-r--r-- | src/renderer/painter.cpp | 16 | ||||
-rw-r--r-- | src/style/style.cpp | 11 |
5 files changed, 38 insertions, 17 deletions
diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index fcbafc52d5..e2d56b1514 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -86,6 +86,8 @@ public: void renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); void renderSymbol(SymbolBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); void renderRaster(RasterBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix); + void renderBackground(std::shared_ptr<StyleLayer> layer_desc); + std::array<float, 3> spinWeights(float spin_value); void preparePrerender(RasterBucket &bucket); @@ -142,6 +144,12 @@ public: return flipMatrix; }(); + const mat4 identityMatrix = []{ + mat4 identity; + matrix::identity(identity); + return identity; + }(); + private: Map& map; @@ -170,6 +178,13 @@ public: std::unique_ptr<DotShader> dotShader; std::unique_ptr<GaussianShader> gaussianShader; + StaticVertexBuffer backgroundBuffer = { + { -1, -1 }, { 1, -1 }, + { -1, 1 }, { 1, 1 } + }; + + VertexArrayObject backgroundArray; + // Set up the stencil quad we're using to generate the stencil mask. StaticVertexBuffer tileStencilBuffer = { // top left triangle diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index 6acb5d0cb8..c09de6ebba 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -20,7 +20,6 @@ namespace mbgl { class Sprite; class StyleLayer; class StyleLayerGroup; -struct BackgroundProperties; class Style { public: @@ -47,8 +46,6 @@ public: bool hasTransitions() const; - const BackgroundProperties &getBackgroundProperties() const; - const std::string &getSpriteURL() const; public: diff --git a/src/map/map.cpp b/src/map/map.cpp index 86f7f9812a..ed4cdd005c 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -625,7 +625,15 @@ void Map::renderLayers(std::shared_ptr<StyleLayerGroup> group) { void Map::renderLayer(std::shared_ptr<StyleLayer> layer_desc, RenderPass pass, const Tile::ID* id, const mat4* matrix) { if (layer_desc->type == StyleLayerType::Background) { - // This layer defines the background color. + // This layer defines a background color/image. + if (pass == RenderPass::Translucent) return; + + if (debug::renderTree) { + std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " (" + << layer_desc->type << ")" << std::endl; + } + + painter.renderBackground(layer_desc); } else { // This is a singular layer. if (!layer_desc->bucket) { diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 240aff6887..f29d60f8d3 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -143,8 +143,7 @@ void Painter::clear() { glStencilMask(0xFF); depthMask(true); - const BackgroundProperties &properties = map.getStyle()->getBackgroundProperties(); - glClearColor(properties.color[0], properties.color[1], properties.color[2], properties.color[3]); + glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -184,6 +183,19 @@ void Painter::renderTileLayer(const Tile& tile, std::shared_ptr<StyleLayer> laye } } +void Painter::renderBackground(std::shared_ptr<StyleLayer> layer_desc) { + const BackgroundProperties& properties = layer_desc->getProperties<BackgroundProperties>(); + + useProgram(plainShader->program); + plainShader->setMatrix(identityMatrix); + plainShader->setColor(properties.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<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor) { if (translation[0] == 0 && translation[1] == 0) { diff --git a/src/style/style.cpp b/src/style/style.cpp index ee930751ea..6f0a0e3b28 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -103,15 +103,4 @@ void Style::loadJSON(const uint8_t *const data) { updateClasses(); } -const BackgroundProperties &Style::getBackgroundProperties() const { - if (layers && layers->layers.size()) { - const auto first = layers->layers.front(); - if (first && first->type == StyleLayerType::Background) { - return first->getProperties<BackgroundProperties>(); - } - } - - return defaultStyleProperties<BackgroundProperties>(); -} - } |