diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2014-08-29 15:43:13 -0400 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2014-08-29 15:43:13 -0400 |
commit | a8021e84f876c52b5da7428a019cb062e5f80537 (patch) | |
tree | f9b4f8db311c040696c2545ca814df2af53b23e8 /src | |
parent | cffd68f9cabb69491ff8f2c43c680f6b345b25be (diff) | |
parent | eb1fbc542b8d8b90d17e9e76f98d7b021b449c7b (diff) | |
download | qtlocation-mapboxgl-a8021e84f876c52b5da7428a019cb062e5f80537.tar.gz |
Merge branch 'master' into libuv010
Diffstat (limited to 'src')
-rw-r--r-- | src/map/map.cpp | 11 | ||||
-rw-r--r-- | src/renderer/painter.cpp | 28 | ||||
-rw-r--r-- | src/renderer/painter_fill.cpp | 14 | ||||
-rw-r--r-- | src/renderer/painter_line.cpp | 2 | ||||
-rw-r--r-- | src/renderer/painter_symbol.cpp | 11 | ||||
-rw-r--r-- | src/style/property_fallback.cpp | 1 | ||||
-rw-r--r-- | src/style/style.cpp | 11 | ||||
-rw-r--r-- | src/style/style_layer.cpp | 1 | ||||
-rw-r--r-- | src/style/style_parser.cpp | 5 | ||||
-rw-r--r-- | src/text/glyph_store.cpp | 2 |
10 files changed, 53 insertions, 33 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp index b657ab6890..5c139f3646 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -559,6 +559,8 @@ void Map::render() { painter.drawClippingMasks(getActiveSources()); + painter.frameHistory.record(getAnimationTime(), getState().getNormalizedZoom()); + // Actually render the layers if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } renderLayers(style->layers); @@ -625,7 +627,14 @@ 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 (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..2a3d45c9ed 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); } @@ -180,18 +179,39 @@ void Painter::renderTileLayer(const Tile& tile, std::shared_ptr<StyleLayer> laye gl::group group(util::sprintf<32>("render %d/%d/%d\n", tile.id.z, tile.id.y, tile.id.z)); prepareTile(tile); tile.data->render(*this, layer_desc, matrix); - frameHistory.record(map.getAnimationTime(), map.getState().getNormalizedZoom()); } } +void Painter::renderBackground(std::shared_ptr<StyleLayer> layer_desc) { + const BackgroundProperties& properties = layer_desc->getProperties<BackgroundProperties>(); -const mat4 &Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor) { + 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)) { + 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); + } +} + +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) { return matrix; } else { // TODO: Get rid of the 8 (scaling from 4096 to tile size) const double factor = ((double)(1 << id.z)) / map.getState().getScale() * (4096.0 / util::tileSize); + mat4 vtxMatrix; if (anchor == TranslateAnchorType::Viewport) { const double sin_a = std::sin(-map.getState().getAngle()); const double cos_a = std::cos(-map.getState().getAngle()); diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index fe08d4c2fa..97ca1767f9 100644 --- a/src/renderer/painter_fill.cpp +++ b/src/renderer/painter_fill.cpp @@ -10,9 +10,13 @@ using namespace mbgl; +void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix) { + // Abort early. + if (!bucket.hasData()) return; + const FillProperties &properties = layer_desc->getProperties<FillProperties>(); + mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); -void Painter::renderFill(FillBucket& bucket, const FillProperties& properties, const Tile::ID& id, const mat4 &vtxMatrix) { Color fill_color = properties.fill_color; fill_color[0] *= properties.opacity; fill_color[1] *= properties.opacity; @@ -136,11 +140,3 @@ void Painter::renderFill(FillBucket& bucket, const FillProperties& properties, c bucket.drawVertices(*outlineShader); } } - -void Painter::renderFill(FillBucket& bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID& id, const mat4 &matrix) { - // Abort early. - if (!bucket.hasData()) return; - const FillProperties &properties = layer_desc->getProperties<FillProperties>(); - const mat4 &vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); - renderFill(bucket, properties, id, vtxMatrix); -} diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index 24358c51dd..ad0778fc0b 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -31,7 +31,7 @@ void Painter::renderLine(LineBucket& bucket, std::shared_ptr<StyleLayer> layer_d float dash_length = properties.dash_array[0]; float dash_gap = properties.dash_array[1]; - const mat4 &vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); + mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); depthRange(strata, 1.0f); diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp index c2d62bec7a..e412bc49d7 100644 --- a/src/renderer/painter_symbol.cpp +++ b/src/renderer/painter_symbol.cpp @@ -9,8 +9,7 @@ namespace mbgl { -void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> layer_desc, - const Tile::ID &/*id*/, const mat4 &matrix) { +void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id, const mat4 &matrix) { // Abort early. if (pass == RenderPass::Opaque) { return; @@ -21,6 +20,8 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay glDisable(GL_STENCIL_TEST); if (bucket.hasTextData()) { + mat4 vtxMatrix = translatedMatrix(matrix, properties.text.translate, id, properties.text.translate_anchor); + mat4 exMatrix; matrix::copy(exMatrix, projMatrix); if (bucket.properties.placement == PlacementType::Line) { @@ -32,7 +33,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f); useProgram(textShader->program); - textShader->setMatrix(matrix); + textShader->setMatrix(vtxMatrix); textShader->setExtrudeMatrix(exMatrix); GlyphAtlas &glyphAtlas = *map.getGlyphAtlas(); @@ -161,6 +162,8 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay } if (bucket.hasIconData()) { + mat4 vtxMatrix = translatedMatrix(matrix, properties.icon.translate, id, properties.icon.translate_anchor); + mat4 exMatrix; matrix::copy(exMatrix, projMatrix); @@ -179,7 +182,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, std::shared_ptr<StyleLayer> lay matrix::scale(exMatrix, exMatrix, fontScale, fontScale, 1.0f); useProgram(iconShader->program); - iconShader->setMatrix(matrix); + iconShader->setMatrix(vtxMatrix); iconShader->setExtrudeMatrix(exMatrix); SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); diff --git a/src/style/property_fallback.cpp b/src/style/property_fallback.cpp index 0f8335dd66..572c4b7a8a 100644 --- a/src/style/property_fallback.cpp +++ b/src/style/property_fallback.cpp @@ -52,6 +52,7 @@ const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = { { PropertyKey::RasterContrast, defaultStyleProperties<RasterProperties>().contrast }, { PropertyKey::RasterFade, defaultStyleProperties<RasterProperties>().fade }, + { PropertyKey::BackgroundOpacity, defaultStyleProperties<BackgroundProperties>().opacity }, { PropertyKey::BackgroundColor, defaultStyleProperties<BackgroundProperties>().color }, }; 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>(); -} - } diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 71916afe23..4f758fe723 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -233,6 +233,7 @@ template <> void StyleLayer::applyStyleProperties<BackgroundProperties>(const float z, const timestamp now) { properties.set<BackgroundProperties>(); BackgroundProperties &background = properties.get<BackgroundProperties>(); + 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 2fccf1f404..3d51a2ebeb 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -633,9 +633,10 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { parseOptionalProperty<PropertyTransition>("transition-raster-saturation", Key::RasterSaturation, klass, value); parseOptionalProperty<Function<float>>("raster-contrast", Key::RasterContrast, klass, value); parseOptionalProperty<PropertyTransition>("transition-raster-contrast", Key::RasterContrast, klass, value); - parseOptionalProperty<Function<float>>("raster-fade", Key::RasterFade, klass, value); - parseOptionalProperty<PropertyTransition>("transition-raster-fade", Key::RasterFade, klass, value); + parseOptionalProperty<Function<float>>("raster-fade-duration", Key::RasterFade, klass, value); + parseOptionalProperty<PropertyTransition>("transition-raster-fade-duration", Key::RasterFade, klass, value); + parseOptionalProperty<Function<float>>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty<Function<Color>>("background-color", Key::BackgroundColor, klass, value); } diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 65941e91f7..783710d929 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -131,7 +131,7 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m } } - maxLineLength = maxLineLength || shaping.back().x; + if (!maxLineLength) maxLineLength = shaping.back().x; justifyLine(shaping, metrics, lineStartIndex, uint32_t(shaping.size()) - 1, justify); align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line); |