diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-08-10 18:48:27 +0300 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-08-19 18:49:36 -0400 |
commit | d400fe0c91b66e066f50dbf3615db68af8895a10 (patch) | |
tree | 9959a4de05e6741ba862ecec51cb3533d8f323a9 /src | |
parent | c53a9fd00d4c0584eaf6c20157f1599bda21acd8 (diff) | |
download | qtlocation-mapboxgl-d400fe0c91b66e066f50dbf3615db68af8895a10.tar.gz |
use glClear to draw solid background fills
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 34 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.hpp | 1 |
2 files changed, 19 insertions, 16 deletions
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 8011dfd05f..4a9b121759 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -152,7 +152,7 @@ void Painter::clear() { config.stencilMask = 0xFF; config.depthTest = false; config.depthMask = GL_TRUE; - config.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f }; + config.clearColor = { background[0], background[1], background[2], background[3] }; MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); } @@ -314,7 +314,21 @@ std::vector<RenderItem> Painter::determineRenderOrder(const Style& style) { if (layer.bucket->visibility == VisibilityType::None) continue; if (layer.type == StyleLayerType::Background) { // This layer defines a background color/image. - order.emplace_back(layer); + if (layer.properties.is<BackgroundProperties>()) { + auto &props = layer.properties.get<BackgroundProperties>(); + if (props.image.from.empty()) { + // This is a solid background. We can use glClear(). + background = props.color; + background[0] *= props.opacity; + background[1] *= props.opacity; + background[2] *= props.opacity; + background[3] *= props.opacity; + } else { + // This is a textured background. We need to render it with a quad. + background = {{ 0, 0, 0, 0 }}; + order.emplace_back(layer); + } + } continue; } @@ -387,6 +401,8 @@ RenderPass Painter::determineRenderPasses(const StyleLayer& layer) { } void Painter::renderBackground(const StyleLayer &layer_desc) { + // Note: This function is only called for textured background. Otherwise, the background color + // is created with glClear. const BackgroundProperties& properties = layer_desc.getProperties<BackgroundProperties>(); if (!properties.image.to.empty()) { @@ -444,20 +460,6 @@ void Painter::renderBackground(const StyleLayer &layer_desc) { backgroundBuffer.bind(); patternShader->bind(0); spriteAtlas->bind(true); - } else { - Color color = properties.color; - color[0] *= properties.opacity; - color[1] *= properties.opacity; - color[2] *= properties.opacity; - color[3] *= properties.opacity; - - if ((color[3] >= 1.0f) != (pass == RenderPass::Opaque)) - return; - - useProgram(plainShader->program); - plainShader->u_matrix = identityMatrix; - plainShader->u_color = color; - backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0)); } config.stencilTest = false; diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 869aaa49cf..e5aeb3bf5a 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -207,6 +207,7 @@ private: float strata = 0; RenderPass pass = RenderPass::Opaque; const float strata_epsilon = 1.0f / (1 << 16); + Color background = {{ 0, 0, 0, 0 }}; public: FrameHistory frameHistory; |