From 071f92079082aa0676772946d8d40184dcc3d40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 27 Oct 2014 12:34:10 -0700 Subject: [PATCH 01/20] mark as standalone static libraries so they get placed into the correct directory on non-osx targets --- gyp/mbgl-ios.gypi | 1 + gyp/mbgl-linux.gypi | 1 + gyp/mbgl-osx.gypi | 1 + gyp/mbgl.gypi | 1 + 4 files changed, 4 insertions(+) diff --git a/gyp/mbgl-ios.gypi b/gyp/mbgl-ios.gypi index dbad60086..4398f04eb 100644 --- a/gyp/mbgl-ios.gypi +++ b/gyp/mbgl-ios.gypi @@ -28,6 +28,7 @@ { 'target_name': 'mbgl-ios', 'product_name': 'mbgl-ios', 'type': 'static_library', + 'standalone_static_library': 1, 'hard_dependency': 1, 'include_dirs': [ '../include', diff --git a/gyp/mbgl-linux.gypi b/gyp/mbgl-linux.gypi index 39a175556..6d8631e8d 100644 --- a/gyp/mbgl-linux.gypi +++ b/gyp/mbgl-linux.gypi @@ -3,6 +3,7 @@ { 'target_name': 'mbgl-linux', 'product_name': 'mbgl-linux', 'type': 'static_library', + 'standalone_static_library': 1, 'hard_dependency': 1, 'include_dirs': [ '../include' diff --git a/gyp/mbgl-osx.gypi b/gyp/mbgl-osx.gypi index ba117e5a5..80af5b97a 100644 --- a/gyp/mbgl-osx.gypi +++ b/gyp/mbgl-osx.gypi @@ -3,6 +3,7 @@ { 'target_name': 'mbgl-osx', 'product_name': 'mbgl-osx', 'type': 'static_library', + 'standalone_static_library': 1, 'hard_dependency': 1, 'include_dirs': [ '../include', diff --git a/gyp/mbgl.gypi b/gyp/mbgl.gypi index f268fd625..0d914f46f 100644 --- a/gyp/mbgl.gypi +++ b/gyp/mbgl.gypi @@ -3,6 +3,7 @@ { 'target_name': 'mbgl', 'product_name': 'mbgl', 'type': 'static_library', + 'standalone_static_library': 1, 'hard_dependency': 1, 'dependencies': [ 'shaders', From f716acb0621e1f4ae04dee4fd648666d469fb176 Mon Sep 17 00:00:00 2001 From: Young Hahn Date: Mon, 27 Oct 2014 15:43:54 -0400 Subject: [PATCH 02/20] standalone flag for mbgl-headless --- gyp/mbgl-headless.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/gyp/mbgl-headless.gypi b/gyp/mbgl-headless.gypi index 5ffc251d2..e71fb7efb 100644 --- a/gyp/mbgl-headless.gypi +++ b/gyp/mbgl-headless.gypi @@ -3,6 +3,7 @@ { 'target_name': 'mbgl-headless', 'product_name': 'mbgl-headless', 'type': 'static_library', + 'standalone_static_library': 1, 'include_dirs': [ '../include', ], From d13a10f8ff0706368a13ffb1ecdf659a3c369518 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 27 Oct 2014 16:04:42 -0400 Subject: [PATCH 03/20] add mbgl-config template --- utils/mbgl-config/mbgl-config.template.sh | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 utils/mbgl-config/mbgl-config.template.sh diff --git a/utils/mbgl-config/mbgl-config.template.sh b/utils/mbgl-config/mbgl-config.template.sh new file mode 100644 index 000000000..8ca8cde6b --- /dev/null +++ b/utils/mbgl-config/mbgl-config.template.sh @@ -0,0 +1,128 @@ + +## program below + +usage() +{ + cat <&2; } + +if test $# -eq 0; then + usage 1 +fi + +while test $# -gt 0; do + case "$1" in + esac + + case "$1" in + + --help) + usage 0 + ;; + + -h) + usage 0 + ;; + + -v) + echo ${CONFIG_MBGL_VERSION_STRING} + ;; + + --version) + echo ${CONFIG_MBGL_VERSION_STRING} + ;; + + --version-number) + echo ${CONFIG_MBGL_VERSION} + ;; + + --git-revision) + echo ${CONFIG_MBGL_GIT_REVISION} + ;; + + --git-describe) + echo ${CONFIG_MBGL_GIT_DESCRIBE} + ;; + + --defines) + echo ${CONFIG_MBGL_DEFINES} + ;; + + --prefix) + echo ${CONFIG_MBGL_PREFIX} + ;; + + --lib-name) + echo ${CONFIG_MBGL_LIBNAME} + ;; + + --libs) + echo -L${CONFIG_MBGL_LIBPATH} -l${CONFIG_MBGL_LIBNAME} + ;; + + --dep-libs) + echo ${CONFIG_MBGL_DEP_LIBS} + ;; + + --ldflags) + echo ${CONFIG_MBGL_LDFLAGS} + ;; + + --includes) + echo -I${CONFIG_MBGL_INCLUDES} + ;; + + --dep-includes) + echo ${CONFIG_MBGL_DEP_INCLUDES} + ;; + + --cxxflags) + echo ${CONFIG_MBGL_CXXFLAGS} + ;; + + --cflags) + echo -I${CONFIG_MBGL_INCLUDE} ${CONFIG_MBGL_DEP_INCLUDES} ${CONFIG_MBGL_DEFINES} ${CONFIG_MBGL_CXXFLAGS} + ;; + + --cxx) + echo ${CONFIG_MBGL_CXX} + ;; + + --all-flags) + echo -I${CONFIG_MBGL_INCLUDES} ${CONFIG_MBGL_DEP_INCLUDES} ${CONFIG_MBGL_DEFINES} ${CONFIG_MBGL_CXXFLAGS} -L${CONFIG_MBGL_LIBPATH} -l${CONFIG_MBGL_LIBNAME} ${CONFIG_MBGL_LDFLAGS} ${CONFIG_MBGL_DEP_LIBS} + ;; + + *) + # push to stderr any invalid options + echo "unknown option $1" 1>&2; + ;; + esac + shift +done + +exit 0 From e816d301bb2c25a4471c4614abc5fc6671b91f56 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Mon, 27 Oct 2014 17:02:20 -0400 Subject: [PATCH 04/20] refs #509: tickets good, inline TODO bad --- include/mbgl/map/transform.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index 5404f333c..4801ff109 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -91,7 +91,6 @@ private: TransformState final; // Limit the amount of zooming possible on the map. - // TODO: make these modifiable from outside. const double min_scale = std::pow(2, 0); const double max_scale = std::pow(2, 18); From 124cc01bf101b242792ef94b338635b8520b6721 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 27 Oct 2014 19:26:17 -0400 Subject: [PATCH 05/20] add dummy mbgl-config generator script --- gyp/install.gypi | 24 ++++++++++++++++++++++++ utils/mbgl-config/dummy.sh | 3 +++ 2 files changed, 27 insertions(+) create mode 100755 utils/mbgl-config/dummy.sh diff --git a/gyp/install.gypi b/gyp/install.gypi index 8b79a4518..b3b20cef5 100644 --- a/gyp/install.gypi +++ b/gyp/install.gypi @@ -10,12 +10,36 @@ 'mbgl-headless', 'mbgl-<(platform)', ], + 'defines': [ + 'PLATFORM=<(platform)', + ], + 'export_dependent_settings': [ + 'mbgl', + 'mbgl-headless', + 'mbgl-<(platform)', + ], 'copies': [ { 'files': [ '<(PRODUCT_DIR)/libmbgl.a' ], 'destination': '<(install_prefix)/lib' }, { 'files': [ '<(PRODUCT_DIR)/libmbgl-headless.a' ], 'destination': '<(install_prefix)/lib' }, { 'files': [ '<(PRODUCT_DIR)/libmbgl-<(platform).a' ], 'destination': '<(install_prefix)/lib' }, { 'files': [ '../include/mbgl' ], 'destination': '<(install_prefix)/include' } ], + 'actions': [ + { 'action_name': 'mbgl-config', + 'inputs': [ + '../utils/mbgl-config/mbgl-config.template.sh', + '../utils/mbgl-config/dummy.sh', + ], + 'outputs': [ + '<(install_prefix)/bin/mbgl-config', + ], + 'action': [ + './utils/mbgl-config/dummy.sh', + 'PREFIX=<(install_prefix)', + 'PLATFORM=<(platform)', + ] + } + ] }, ] }], diff --git a/utils/mbgl-config/dummy.sh b/utils/mbgl-config/dummy.sh new file mode 100755 index 000000000..04685b2c1 --- /dev/null +++ b/utils/mbgl-config/dummy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "mbgl-config DUMMY $PLATFORM $PREFIX"; From 652c616048745cf78df656536fefed18e595f6d9 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 28 Oct 2014 13:42:23 -0400 Subject: [PATCH 06/20] build simple, working mbgl-config script from gyp --- gyp/install.gypi | 17 ++--- utils/mbgl-config/build.sh | 17 +++++ utils/mbgl-config/dummy.sh | 3 - utils/mbgl-config/mbgl-config.template.sh | 87 +++-------------------- 4 files changed, 32 insertions(+), 92 deletions(-) create mode 100755 utils/mbgl-config/build.sh delete mode 100755 utils/mbgl-config/dummy.sh diff --git a/gyp/install.gypi b/gyp/install.gypi index b3b20cef5..0eadb94f5 100644 --- a/gyp/install.gypi +++ b/gyp/install.gypi @@ -10,14 +10,6 @@ 'mbgl-headless', 'mbgl-<(platform)', ], - 'defines': [ - 'PLATFORM=<(platform)', - ], - 'export_dependent_settings': [ - 'mbgl', - 'mbgl-headless', - 'mbgl-<(platform)', - ], 'copies': [ { 'files': [ '<(PRODUCT_DIR)/libmbgl.a' ], 'destination': '<(install_prefix)/lib' }, { 'files': [ '<(PRODUCT_DIR)/libmbgl-headless.a' ], 'destination': '<(install_prefix)/lib' }, @@ -28,15 +20,16 @@ { 'action_name': 'mbgl-config', 'inputs': [ '../utils/mbgl-config/mbgl-config.template.sh', - '../utils/mbgl-config/dummy.sh', + '../utils/mbgl-config/build.sh', ], 'outputs': [ '<(install_prefix)/bin/mbgl-config', ], 'action': [ - './utils/mbgl-config/dummy.sh', - 'PREFIX=<(install_prefix)', - 'PLATFORM=<(platform)', + './utils/mbgl-config/build.sh', + '<(install_prefix)', + '<(platform)', + 'mbgl', ] } ] diff --git a/utils/mbgl-config/build.sh b/utils/mbgl-config/build.sh new file mode 100755 index 000000000..4fd4a93cf --- /dev/null +++ b/utils/mbgl-config/build.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +PREFIX=$1 +PLATFORM=$2 + +VARIABLES="#!/bin/bash + +## variables + +CONFIG_MBGL_PREFIX=$PREFIX +CONFIG_MBGL_PLATFORM=$PLATFORM +" + +echo "$VARIABLES" | cat - utils/mbgl-config/mbgl-config.template.sh \ + > $PREFIX/bin/mbgl-config + +chmod 755 $PREFIX/bin/mbgl-config diff --git a/utils/mbgl-config/dummy.sh b/utils/mbgl-config/dummy.sh deleted file mode 100755 index 04685b2c1..000000000 --- a/utils/mbgl-config/dummy.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -echo "mbgl-config DUMMY $PLATFORM $PREFIX"; diff --git a/utils/mbgl-config/mbgl-config.template.sh b/utils/mbgl-config/mbgl-config.template.sh index 8ca8cde6b..87f4d50e1 100644 --- a/utils/mbgl-config/mbgl-config.template.sh +++ b/utils/mbgl-config/mbgl-config.template.sh @@ -1,29 +1,18 @@ - ## program below usage() { cat < Date: Tue, 28 Oct 2014 14:50:44 -0400 Subject: [PATCH 07/20] fix 'flip' logic to take into account rotation_alignment and keep_upright (#470) --- src/renderer/painter_symbol.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp index 415dead70..2992199b3 100644 --- a/src/renderer/painter_symbol.cpp +++ b/src/renderer/painter_symbol.cpp @@ -24,11 +24,8 @@ void Painter::renderSDF(SymbolBucket &bucket, mat4 exMatrix; matrix::copy(exMatrix, projMatrix); - - const float angleOffset = - bucketProperties.rotation_alignment == RotationAlignmentType::Map - ? map.getState().getAngle() - : 0; + bool aligned_with_map = (bucketProperties.rotation_alignment == RotationAlignmentType::Map); + const float angleOffset = aligned_with_map ? map.getState().getAngle() : 0; if (angleOffset) { matrix::rotate_z(exMatrix, exMatrix, angleOffset); @@ -50,8 +47,8 @@ void Painter::renderSDF(SymbolBucket &bucket, // adjust min/max zooms for variable font sies float zoomAdjust = std::log(fontSize / bucketProperties.max_size) / std::log(2); + sdfShader.u_flip = (aligned_with_map && bucketProperties.keep_upright) ? 1 : 0; sdfShader.u_angle = (int32_t)(angle + 256) % 256; - sdfShader.u_flip = (bucket.properties.placement == PlacementType::Line ? 1 : 0); sdfShader.u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level FadeProperties f = frameHistory.getFadeProperties(300_milliseconds); @@ -191,7 +188,10 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des float zoomAdjust = std::log(fontSize / bucket.properties.icon.max_size) / std::log(2); iconShader->u_angle = (int32_t)(angle + 256) % 256; - iconShader->u_flip = bucket.properties.placement == PlacementType::Line ? 1 : 0; + + bool flip = (bucket.properties.icon.rotation_alignment == RotationAlignmentType::Map) + && bucket.properties.icon.keep_upright; + iconShader->u_flip = flip ? 1 : 0; iconShader->u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level iconShader->u_fadedist = 0 * 10; From 14829db508035426ef8a38d1f8dc83a8ccf60b0f Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 28 Oct 2014 15:43:10 -0400 Subject: [PATCH 08/20] fix text/icon rendering order (#470) --- src/renderer/painter_symbol.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp index 2992199b3..8ca8624ad 100644 --- a/src/renderer/painter_symbol.cpp +++ b/src/renderer/painter_symbol.cpp @@ -119,21 +119,6 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des glDisable(GL_STENCIL_TEST); - if (bucket.hasTextData()) { - GlyphAtlas &glyphAtlas = *map.getGlyphAtlas(); - glyphAtlas.bind(); - - renderSDF(bucket, - id, - matrix, - bucket.properties.text, - properties.text, - 24.0f, - {{ float(glyphAtlas.width) / 4, float(glyphAtlas.height) / 4 }}, - *sdfGlyphShader, - &SymbolBucket::drawGlyphs); - } - if (bucket.hasIconData()) { bool sdf = bucket.sdfIcons; @@ -205,5 +190,19 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des } } + if (bucket.hasTextData()) { + GlyphAtlas &glyphAtlas = *map.getGlyphAtlas(); + glyphAtlas.bind(); + + renderSDF(bucket, + id, + matrix, + bucket.properties.text, + properties.text, + 24.0f, + {{ float(glyphAtlas.width) / 4, float(glyphAtlas.height) / 4 }}, + *sdfGlyphShader, + &SymbolBucket::drawGlyphs); + } glEnable(GL_STENCIL_TEST); } From 4f7bc80664c29d7f15598392946ff0ac73dd520c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 22 Oct 2014 14:25:10 -0700 Subject: [PATCH 09/20] Hold internal reference to Sprite in SpriteAtlas --- include/mbgl/geometry/sprite_atlas.hpp | 29 ++++++-------- src/geometry/sprite_atlas.cpp | 53 ++++++++++++-------------- src/map/map.cpp | 2 +- src/renderer/painter.cpp | 2 +- src/renderer/painter_fill.cpp | 2 +- src/renderer/symbol_bucket.cpp | 3 +- 6 files changed, 40 insertions(+), 51 deletions(-) diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 0946f0fc4..9fb42a30b 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -26,7 +27,6 @@ class SpriteAtlas : public util::noncopyable { public: typedef uint16_t dimension; -public: // Add way to construct this from another SpriteAtlas (e.g. with another pixelRatio) SpriteAtlas(dimension width, dimension height); ~SpriteAtlas(); @@ -34,22 +34,16 @@ public: // Changes the pixel ratio. bool resize(float newRatio); - // Update uninitialized (= outdated) sprites in this atlas from the given sprite. - void update(const Sprite &sprite); + // Changes the source sprite. + void setSprite(util::ptr sprite); // Returns the coordinates of an image that is sourced from the sprite image. // This getter attempts to read the image from the sprite if it is already loaded. // In that case, it copies it into the sprite atlas and returns the dimensions. // Otherwise, it returns a 0/0/0/0 rect. - Rect getImage(const std::string &name, const Sprite &sprite); + Rect getImage(const std::string& name); - // Returns the coordinates of an image that is sourced from the sprite image. - // This getter waits until the sprite image was loaded, copies it into the sprite - // image and returns the dimensions. - // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. - Rect waitForImage(const std::string &name, const Sprite &sprite); - - SpriteAtlasPosition getPosition(const std::string &name, const Sprite &sprite, bool repeating = false); + SpriteAtlasPosition getPosition(const std::string& name, bool repeating = false); // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out // of date. @@ -61,19 +55,18 @@ public: inline float getTextureHeight() const { return height * pixelRatio; } inline float getPixelRatio() const { return pixelRatio; } -private: - void allocate(); - Rect allocateImage(size_t width, size_t height); - void copy(const Rect &dst, const SpritePosition &src, const Sprite &sprite); - -public: const dimension width = 0; const dimension height = 0; private: - std::mutex mtx; + void allocate(); + Rect allocateImage(size_t width, size_t height); + void copy(const Rect& dst, const SpritePosition& src); + + std::recursive_mutex mtx; float pixelRatio = 1.0f; BinPack bin; + util::ptr sprite; std::map> images; std::set uninitialized; uint32_t *data = nullptr; diff --git a/src/geometry/sprite_atlas.cpp b/src/geometry/sprite_atlas.cpp index 22e6a29a0..527112291 100644 --- a/src/geometry/sprite_atlas.cpp +++ b/src/geometry/sprite_atlas.cpp @@ -24,7 +24,7 @@ SpriteAtlas::SpriteAtlas(dimension width_, dimension height_) bool SpriteAtlas::resize(const float newRatio) { if (pixelRatio == newRatio) return false; - std::lock_guard lock(mtx); + std::lock_guard lock(mtx); const float oldRatio = pixelRatio; pixelRatio = newRatio; @@ -104,15 +104,15 @@ Rect SpriteAtlas::allocateImage(size_t pixel_width, size return rect; } -Rect SpriteAtlas::getImage(const std::string &name, const Sprite &sprite) { - std::lock_guard lock(mtx); +Rect SpriteAtlas::getImage(const std::string& name) { + std::lock_guard lock(mtx); auto rect_it = images.find(name); if (rect_it != images.end()) { return rect_it->second; } - const SpritePosition &pos = sprite.getSpritePosition(name); + const SpritePosition &pos = sprite->getSpritePosition(name); if (!pos.width || !pos.height) { return Rect { 0, 0, 0, 0 }; } @@ -127,16 +127,17 @@ Rect SpriteAtlas::getImage(const std::string &name, cons images.emplace(name, rect); - copy(rect, pos, sprite); + copy(rect, pos); return rect; } -SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, const Sprite& sprite, bool repeating) { +SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, bool repeating) { + std::lock_guard lock(mtx); // `repeating` indicates that the image will be used in a repeating pattern // repeating pattern images are assumed to have a 1px padding that mirrors the opposite edge // positions for repeating images are adjusted to exclude the edge - Rect rect = getImage(name, sprite); + Rect rect = getImage(name); const int r = repeating ? 1 : 0; return SpriteAtlasPosition { {{ float(rect.w) / pixelRatio, float(rect.h) / pixelRatio }}, @@ -145,11 +146,6 @@ SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, const Spri }; } -Rect SpriteAtlas::waitForImage(const std::string &name, const Sprite &sprite) { - sprite.waitUntilLoaded(); - return getImage(name, sprite); -} - void SpriteAtlas::allocate() { if (!data) { dimension w = static_cast(width * pixelRatio); @@ -159,15 +155,15 @@ void SpriteAtlas::allocate() { } } -void SpriteAtlas::copy(const Rect &dst, const SpritePosition &src, const Sprite &sprite) { - if (!sprite.raster) return; - const uint32_t *src_img = reinterpret_cast(sprite.raster->getData()); +void SpriteAtlas::copy(const Rect& dst, const SpritePosition& src) { + if (!sprite->raster) return; + const uint32_t *src_img = reinterpret_cast(sprite->raster->getData()); allocate(); uint32_t *dst_img = reinterpret_cast(data); copy_bitmap( /* source buffer */ src_img, - /* source stride */ sprite.raster->getWidth(), + /* source stride */ sprite->raster->getWidth(), /* source x */ src.x, /* source y */ src.y, /* dest buffer */ dst_img, @@ -181,14 +177,16 @@ void SpriteAtlas::copy(const Rect &dst, const SpritePosition &src, co dirty = true; } +void SpriteAtlas::setSprite(util::ptr sprite_) { + std::lock_guard lock(mtx); -void SpriteAtlas::update(const Sprite &sprite) { - if (!sprite.isLoaded()) return; + sprite = sprite_; - SpriteAtlas &atlas = *this; - util::erase_if(uninitialized, [&sprite, &atlas](const std::string &name) { - Rect dst = atlas.getImage(name, sprite); - const SpritePosition &src = sprite.getSpritePosition(name); + if (!sprite->isLoaded()) return; + + util::erase_if(uninitialized, [this](const std::string &name) { + Rect dst = getImage(name); + const SpritePosition& src = sprite->getSpritePosition(name); if (!src) { if (debug::spriteWarnings) { fprintf(stderr, "[WARNING] sprite doesn't have image with name '%s'\n", name.c_str()); @@ -196,8 +194,8 @@ void SpriteAtlas::update(const Sprite &sprite) { return true; } - if (src.width == dst.w * atlas.pixelRatio && src.height == dst.h * atlas.pixelRatio && src.pixelRatio == atlas.pixelRatio) { - atlas.copy(dst, src, sprite); + if (src.width == dst.w * pixelRatio && src.height == dst.h * pixelRatio && src.pixelRatio == pixelRatio) { + copy(dst, src); return true; } else { if (debug::spriteWarnings) { @@ -228,7 +226,7 @@ void SpriteAtlas::bind(bool linear) { } if (dirty) { - std::lock_guard lock(mtx); + std::lock_guard lock(mtx); allocate(); if (first) { @@ -257,15 +255,12 @@ void SpriteAtlas::bind(bool linear) { ); } -#if defined(DEBUG) - // platform::show_color_debug_image("Sprite Atlas", reinterpret_cast(data), width, height, width * pixelRatio, height * pixelRatio); -#endif dirty = false; } }; SpriteAtlas::~SpriteAtlas() { - std::lock_guard lock(mtx); + std::lock_guard lock(mtx); glDeleteTextures(1, &texture); texture = 0; diff --git a/src/map/map.cpp b/src/map/map.cpp index 2f0dceb42..82108d000 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -646,7 +646,7 @@ void Map::prepare() { // Allow the sprite atlas to potentially pull new sprite images if needed. spriteAtlas->resize(state.getPixelRatio()); - spriteAtlas->update(*getSprite()); + spriteAtlas->setSprite(getSprite()); updateTiles(); } diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 38c2176ae..a5f4a5b00 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -218,7 +218,7 @@ void Painter::renderBackground(util::ptr layer_desc) { return; SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); - SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, *sprite, true); + SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, true); float zoomFraction = map.getState().getZoomFraction(); useProgram(patternShader->program); diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index 6c17ab037..0f7eadce6 100644 --- a/src/renderer/painter_fill.cpp +++ b/src/renderer/painter_fill.cpp @@ -61,7 +61,7 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c Sprite &sprite = *map.getSprite(); if (pass == RenderPass::Translucent && sprite) { SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); - const SpriteAtlasPosition pos = spriteAtlas.getPosition(properties.image, sprite, true); + const SpriteAtlasPosition pos = spriteAtlas.getPosition(properties.image, true); const float mix = std::fmod(float(map.getState().getZoom()), 1.0f); const float factor = 8.0 / std::pow(2, map.getState().getIntegerZoom() - id.z); diff --git a/src/renderer/symbol_bucket.cpp b/src/renderer/symbol_bucket.cpp index 7d5036eea..1fe91bffe 100644 --- a/src/renderer/symbol_bucket.cpp +++ b/src/renderer/symbol_bucket.cpp @@ -148,7 +148,8 @@ void SymbolBucket::addFeatures(const VectorTileLayer &layer, const FilterExpress // if feature has icon, get sprite atlas position if (feature.sprite.length()) { - image = spriteAtlas.waitForImage(feature.sprite, sprite); + sprite.waitUntilLoaded(); + image = spriteAtlas.getImage(feature.sprite); if (sprite.getSpritePosition(feature.sprite).sdf) { sdfIcons = true; From da8aa391d0a1079bbc697207803a48fce8ab916f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 21 Oct 2014 15:00:44 -0700 Subject: [PATCH 10/20] Render map with a copy of TransformState --- include/mbgl/map/map.hpp | 8 -- include/mbgl/map/transform_state.hpp | 3 +- include/mbgl/renderer/painter.hpp | 20 ++- src/map/map.cpp | 154 +--------------------- src/map/transform.cpp | 11 +- src/map/transform_state.cpp | 11 ++ src/renderer/painter.cpp | 188 ++++++++++++++++++++++++--- src/renderer/painter_debug.cpp | 10 +- src/renderer/painter_fill.cpp | 16 +-- src/renderer/painter_line.cpp | 25 ++-- src/renderer/painter_raster.cpp | 7 +- src/renderer/painter_symbol.cpp | 28 ++-- 12 files changed, 248 insertions(+), 233 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index bc67e5b35..8378b2737 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -55,8 +55,6 @@ public: // Triggers a lazy rerender: only performs a render when the map is not clean. void rerender(); - void renderLayer(util::ptr layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); - // Forces a map update: always triggers a rerender. void update(); @@ -156,18 +154,14 @@ private: void updateSources(); void updateSources(const util::ptr &group); - void updateRenderState(); - size_t countLayers(const std::vector& layers); // Prepares a map render by updating the tiles we need for the current view, as well as updating // the stylesheet. void prepare(); - // Unconditionally performs a render with the current map state. void render(); - void renderLayers(util::ptr group); private: bool async = false; @@ -224,8 +218,6 @@ private: bool debug = false; timestamp animationTime = 0; - int indent = 0; - std::set> activeSources; }; diff --git a/include/mbgl/map/transform_state.hpp b/include/mbgl/map/transform_state.hpp index ed49dc3e9..bb330c101 100644 --- a/include/mbgl/map/transform_state.hpp +++ b/include/mbgl/map/transform_state.hpp @@ -33,6 +33,7 @@ public: float lngX(float lon) const; float latY(float lat) const; std::array locationCoordinate(float lon, float lat) const; + void getLonLat(double &lon, double &lat) const; // Zoom float getNormalizedZoom() const; @@ -69,7 +70,7 @@ private: // map position double x = 0, y = 0; double angle = 0; - double scale = std::numeric_limits::infinity(); + double scale = 1; }; } diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index a8229a097..2b0ac070f 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -35,9 +35,12 @@ enum class RenderPass : bool { Opaque, Translucent }; class Transform; class Style; class Tile; +class Sprite; +class SpriteAtlas; class GlyphAtlas; class Source; class StyleSource; +class StyleLayerGroup; class FillBucket; class LineBucket; @@ -53,10 +56,9 @@ class RasterTileData; class Painter : private util::noncopyable { public: - Painter(Map &map); + Painter(SpriteAtlas&, GlyphAtlas&); ~Painter(); - void setup(); // Perform cleanup tasks that prepare shutting down the app. This doesn't mean that the @@ -73,6 +75,14 @@ public: // Updates the default matrices to the current viewport dimensions. void changeMatrix(); + void render(const Style& style, + const std::set>& sources, + TransformState state, + timestamp time); + + void renderLayers(util::ptr group); + void renderLayer(util::ptr layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); + // Renders a particular layer from a tile. void renderTileLayer(const Tile& tile, util::ptr layer_desc, const mat4 &matrix); @@ -167,9 +177,10 @@ public: }(); private: - Map& map; + TransformState state; bool debug = false; + int indent = 0; uint32_t gl_program = 0; float gl_lineWidth = 0; @@ -183,6 +194,9 @@ private: public: FrameHistory frameHistory; + SpriteAtlas& spriteAtlas; + GlyphAtlas& glyphAtlas; + std::unique_ptr plainShader; std::unique_ptr outlineShader; std::unique_ptr lineShader; diff --git a/src/map/map.cpp b/src/map/map.cpp index 82108d000..fd5468d4e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -44,7 +44,7 @@ Map::Map(View& view_) glyphAtlas(std::make_shared(1024, 1024)), spriteAtlas(std::make_shared(512, 512)), texturepool(std::make_shared()), - painter(*this) { + painter(*spriteAtlas, *glyphAtlas) { view.initialize(this); @@ -598,15 +598,6 @@ void Map::updateTiles() { } } -void Map::updateRenderState() { - // Update all clipping IDs. - ClipIDGenerator generator; - for (const util::ptr &source : getActiveSources()) { - generator.update(source->source->getLoadedTiles()); - source->source->updateMatrices(painter.projMatrix, state); - } -} - void Map::prepare() { if (!fileSource) { fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); @@ -654,152 +645,13 @@ void Map::prepare() { void Map::render() { view.make_active(); - painter.clear(); - - painter.resize(); - - painter.changeMatrix(); - - updateRenderState(); - - painter.drawClippingMasks(getActiveSources()); - - painter.frameHistory.record(getAnimationTime(), getState().getNormalizedZoom()); - - // Actually render the layers - if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } - renderLayers(style->layers); - if (debug::renderTree) { std::cout << "}" << std::endl; indent--; } - - // Finalize the rendering, e.g. by calling debug render calls per tile. - // This guarantees that we have at least one function per tile called. - // When only rendering layers via the stylesheet, it's possible that we don't - // ever visit a tile during rendering. - for (const util::ptr &source : getActiveSources()) { - source->source->finishRender(painter); - } + painter.render(*style, getActiveSources(), + getState(), getAnimationTime()); // Schedule another rerender when we definitely need a next frame. if (transform.needsTransition() || style->hasTransitions()) { update(); } - glFlush(); - view.make_inactive(); } - -void Map::renderLayers(util::ptr group) { - if (!group) { - // Make sure that we actually do have a layer group. - return; - } - - // TODO: Correctly compute the number of layers recursively beforehand. - float strata_thickness = 1.0f / (group->layers.size() + 1); - - // - FIRST PASS ------------------------------------------------------------ - // Render everything top-to-bottom by using reverse iterators. Render opaque - // objects first. - - if (debug::renderTree) { - std::cout << std::string(indent++ * 4, ' ') << "OPAQUE {" << std::endl; - } - int i = 0; - for (auto it = group->layers.rbegin(), end = group->layers.rend(); it != end; ++it, ++i) { - painter.setOpaque(); - painter.setStrata(i * strata_thickness); - renderLayer(*it, RenderPass::Opaque); - } - if (debug::renderTree) { - std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; - } - - // - SECOND PASS ----------------------------------------------------------- - // Make a second pass, rendering translucent objects. This time, we render - // bottom-to-top. - if (debug::renderTree) { - std::cout << std::string(indent++ * 4, ' ') << "TRANSLUCENT {" << std::endl; - } - --i; - for (auto it = group->layers.begin(), end = group->layers.end(); it != end; ++it, --i) { - painter.setTranslucent(); - painter.setStrata(i * strata_thickness); - renderLayer(*it, RenderPass::Translucent); - } - if (debug::renderTree) { - std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; - } -} - -void Map::renderLayer(util::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 (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) { - fprintf(stderr, "[WARNING] layer '%s' is missing bucket\n", layer_desc->id.c_str()); - return; - } - - if (!layer_desc->bucket->style_source) { - fprintf(stderr, "[WARNING] can't find source for layer '%s'\n", layer_desc->id.c_str()); - return; - } - - StyleSource &style_source = *layer_desc->bucket->style_source; - - // Skip this layer if there is no data. - if (!style_source.source) { - return; - } - - // Skip this layer if it's outside the range of min/maxzoom. - // This may occur when there /is/ a bucket created for this layer, but the min/max-zoom - // is set to a fractional value, or value that is larger than the source maxzoom. - const double zoom = state.getZoom(); - if (layer_desc->bucket->min_zoom > zoom || - layer_desc->bucket->max_zoom <= zoom) { - return; - } - - // Abort early if we can already deduce from the bucket type that - // we're not going to render anything anyway during this pass. - switch (layer_desc->type) { - case StyleLayerType::Fill: - if (!layer_desc->getProperties().isVisible()) return; - break; - case StyleLayerType::Line: - if (pass == RenderPass::Opaque) return; - if (!layer_desc->getProperties().isVisible()) return; - break; - case StyleLayerType::Symbol: - if (pass == RenderPass::Opaque) return; - if (!layer_desc->getProperties().isVisible()) return; - break; - case StyleLayerType::Raster: - if (pass == RenderPass::Opaque) return; - if (!layer_desc->getProperties().isVisible()) return; - break; - default: - break; - } - - if (debug::renderTree) { - std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " (" - << layer_desc->type << ")" << std::endl; - } - if (!id) { - style_source.source->render(painter, layer_desc); - } else { - style_source.source->render(painter, layer_desc, *id, *matrix); - } - } -} diff --git a/src/map/transform.cpp b/src/map/transform.cpp index b42f24a83..9619305dd 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -13,13 +13,13 @@ using namespace mbgl; const double D2R = M_PI / 180.0; -const double R2D = 180.0 / M_PI; const double M2PI = 2 * M_PI; const double MIN_ROTATE_SCALE = 8; -Transform::Transform(View &view_) : view(view_), mtx(std::make_unique()) { - setScale(current.scale); - setAngle(current.angle); +Transform::Transform(View &view_) + : view(view_) + , mtx(std::make_unique()) +{ } #pragma mark - Map View @@ -123,8 +123,7 @@ void Transform::setLonLatZoom(const double lon, const double lat, const double z void Transform::getLonLat(double &lon, double &lat) const { uv::readlock lock(mtx); - lon = -final.x / Bc; - lat = R2D * (2 * std::atan(std::exp(final.y / Cc)) - 0.5 * M_PI); + final.getLonLat(lon, lat); } void Transform::getLonLatZoom(double &lon, double &lat, double &zoom) const { diff --git a/src/map/transform_state.cpp b/src/map/transform_state.cpp index 0a858bce6..afc5b59ef 100644 --- a/src/map/transform_state.cpp +++ b/src/map/transform_state.cpp @@ -3,6 +3,8 @@ using namespace mbgl; +const double R2D = 180.0 / M_PI; + #pragma mark - Matrix void TransformState::matrixFor(mat4& matrix, const Tile::ID& id) const { @@ -108,6 +110,15 @@ std::array TransformState::locationCoordinate(float lon, float lat) co }}; } +void TransformState::getLonLat(double &lon, double &lat) const { + const double s = scale * util::tileSize; + const double Bc = s / 360; + const double Cc = s / (2 * M_PI); + + lon = -x / Bc; + lat = R2D * (2 * std::atan(std::exp(y / Cc)) - 0.5 * M_PI); +} + #pragma mark - Zoom diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index a5f4a5b00..7d636669d 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -1,7 +1,8 @@ #include -#include #include #include +#include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #if defined(DEBUG) #include @@ -16,13 +18,16 @@ #include #include +#include using namespace mbgl; #define BUFFER_OFFSET(i) ((char *)nullptr + (i)) -Painter::Painter(Map &map_) - : map(map_) { +Painter::Painter(SpriteAtlas& spriteAtlas_, GlyphAtlas& glyphAtlas_) + : spriteAtlas(spriteAtlas_) + , glyphAtlas(glyphAtlas_) +{ } Painter::~Painter() { @@ -109,7 +114,6 @@ void Painter::terminate() { } void Painter::resize() { - const TransformState &state = map.getState(); if (gl_viewport != state.getFramebufferDimensions()) { gl_viewport = state.getFramebufferDimensions(); assert(gl_viewport[0] > 0 && gl_viewport[1] > 0); @@ -152,12 +156,12 @@ void Painter::depthRange(const float near, const float far) { void Painter::changeMatrix() { // Initialize projection matrix - matrix::ortho(projMatrix, 0, map.getState().getWidth(), map.getState().getHeight(), 0, 0, 1); + matrix::ortho(projMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, 1); // The extrusion matrix. matrix::identity(extrudeMatrix); matrix::multiply(extrudeMatrix, projMatrix, extrudeMatrix); - matrix::rotate_z(extrudeMatrix, extrudeMatrix, map.getState().getAngle()); + matrix::rotate_z(extrudeMatrix, extrudeMatrix, state.getAngle()); // The native matrix is a 1:1 matrix that paints the coordinates at the // same screen position as the vertex specifies. @@ -200,6 +204,156 @@ void Painter::prepareTile(const Tile& tile) { glStencilFunc(GL_EQUAL, ref, mask); } +void Painter::render(const Style& style, const std::set>& sources, + TransformState state_, timestamp time) { + state = state_; + + clear(); + resize(); + changeMatrix(); + + // Update all clipping IDs. + ClipIDGenerator generator; + for (const util::ptr &source : sources) { + generator.update(source->source->getLoadedTiles()); + source->source->updateMatrices(projMatrix, state); + } + + drawClippingMasks(sources); + + frameHistory.record(time, state.getNormalizedZoom()); + + // Actually render the layers + if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } + renderLayers(style.layers); + if (debug::renderTree) { std::cout << "}" << std::endl; indent--; } + + // Finalize the rendering, e.g. by calling debug render calls per tile. + // This guarantees that we have at least one function per tile called. + // When only rendering layers via the stylesheet, it's possible that we don't + // ever visit a tile during rendering. + for (const util::ptr &source : sources) { + source->source->finishRender(*this); + } + + glFlush(); +} + +void Painter::renderLayers(util::ptr group) { + if (!group) { + // Make sure that we actually do have a layer group. + return; + } + + // TODO: Correctly compute the number of layers recursively beforehand. + float strata_thickness = 1.0f / (group->layers.size() + 1); + + // - FIRST PASS ------------------------------------------------------------ + // Render everything top-to-bottom by using reverse iterators. Render opaque + // objects first. + + if (debug::renderTree) { + std::cout << std::string(indent++ * 4, ' ') << "OPAQUE {" << std::endl; + } + int i = 0; + for (auto it = group->layers.rbegin(), end = group->layers.rend(); it != end; ++it, ++i) { + setOpaque(); + setStrata(i * strata_thickness); + renderLayer(*it, RenderPass::Opaque); + } + if (debug::renderTree) { + std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; + } + + // - SECOND PASS ----------------------------------------------------------- + // Make a second pass, rendering translucent objects. This time, we render + // bottom-to-top. + if (debug::renderTree) { + std::cout << std::string(indent++ * 4, ' ') << "TRANSLUCENT {" << std::endl; + } + --i; + for (auto it = group->layers.begin(), end = group->layers.end(); it != end; ++it, --i) { + setTranslucent(); + setStrata(i * strata_thickness); + renderLayer(*it, RenderPass::Translucent); + } + if (debug::renderTree) { + std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; + } +} + +void Painter::renderLayer(util::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 (debug::renderTree) { + std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " (" + << layer_desc->type << ")" << std::endl; + } + + renderBackground(layer_desc); + } else { + // This is a singular layer. + if (!layer_desc->bucket) { + fprintf(stderr, "[WARNING] layer '%s' is missing bucket\n", layer_desc->id.c_str()); + return; + } + + if (!layer_desc->bucket->style_source) { + fprintf(stderr, "[WARNING] can't find source for layer '%s'\n", layer_desc->id.c_str()); + return; + } + + StyleSource &style_source = *layer_desc->bucket->style_source; + + // Skip this layer if there is no data. + if (!style_source.source) { + return; + } + + // Skip this layer if it's outside the range of min/maxzoom. + // This may occur when there /is/ a bucket created for this layer, but the min/max-zoom + // is set to a fractional value, or value that is larger than the source maxzoom. + const double zoom = state.getZoom(); + if (layer_desc->bucket->min_zoom > zoom || + layer_desc->bucket->max_zoom <= zoom) { + return; + } + + // Abort early if we can already deduce from the bucket type that + // we're not going to render anything anyway during this pass. + switch (layer_desc->type) { + case StyleLayerType::Fill: + if (!layer_desc->getProperties().isVisible()) return; + break; + case StyleLayerType::Line: + if (pass == RenderPass::Opaque) return; + if (!layer_desc->getProperties().isVisible()) return; + break; + case StyleLayerType::Symbol: + if (pass == RenderPass::Opaque) return; + if (!layer_desc->getProperties().isVisible()) return; + break; + case StyleLayerType::Raster: + if (pass == RenderPass::Opaque) return; + if (!layer_desc->getProperties().isVisible()) return; + break; + default: + break; + } + + if (debug::renderTree) { + std::cout << std::string(indent * 4, ' ') << "- " << layer_desc->id << " (" + << layer_desc->type << ")" << std::endl; + } + if (!id) { + style_source.source->render(*this, layer_desc); + } else { + style_source.source->render(*this, layer_desc, *id, *matrix); + } + } +} + void Painter::renderTileLayer(const Tile& tile, util::ptr layer_desc, const mat4 &matrix) { assert(tile.data); if (tile.data->hasData(layer_desc) || layer_desc->type == StyleLayerType::Raster) { @@ -211,15 +365,13 @@ void Painter::renderTileLayer(const Tile& tile, util::ptr layer_desc void Painter::renderBackground(util::ptr layer_desc) { const BackgroundProperties& properties = layer_desc->getProperties(); - const std::shared_ptr sprite = map.getSprite(); - if (properties.image.size() && sprite) { + if (properties.image.size()) { if ((properties.opacity >= 1.0f) != (pass == RenderPass::Opaque)) return; - SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, true); - float zoomFraction = map.getState().getZoomFraction(); + float zoomFraction = state.getZoomFraction(); useProgram(patternShader->program); patternShader->u_matrix = identityMatrix; @@ -230,8 +382,8 @@ void Painter::renderBackground(util::ptr layer_desc) { std::array size = imagePos.size; double lon, lat; - map.getLonLat(lon, lat); - std::array center = map.getState().locationCoordinate(lon, lat); + state.getLonLat(lon, lat); + std::array center = state.locationCoordinate(lon, lat); float scale = 1 / std::pow(2, zoomFraction); mat3 matrix; @@ -242,10 +394,10 @@ void Painter::renderBackground(util::ptr layer_desc) { matrix::translate(matrix, matrix, std::fmod(center[0] * 512, size[0]), std::fmod(center[1] * 512, size[1])); - matrix::rotate(matrix, matrix, -map.getState().getAngle()); + matrix::rotate(matrix, matrix, -state.getAngle()); matrix::scale(matrix, matrix, - scale * map.getState().getWidth() / 2, - -scale * map.getState().getHeight() / 2); + scale * state.getWidth() / 2, + -scale * state.getHeight() / 2); patternShader->u_patternmatrix = matrix; backgroundBuffer.bind(); @@ -278,12 +430,12 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array &t 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); + const double factor = ((double)(1 << id.z)) / state.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()); + const double sin_a = std::sin(-state.getAngle()); + const double cos_a = std::cos(-state.getAngle()); matrix::translate(vtxMatrix, matrix, factor * (translation[0] * cos_a - translation[1] * sin_a), factor * (translation[0] * sin_a + translation[1] * cos_a), diff --git a/src/renderer/painter_debug.cpp b/src/renderer/painter_debug.cpp index f12053383..5bc36a233 100644 --- a/src/renderer/painter_debug.cpp +++ b/src/renderer/painter_debug.cpp @@ -25,7 +25,7 @@ void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) { // Draw white outline plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; - lineWidth(4.0f * map.getState().getPixelRatio()); + lineWidth(4.0f * state.getPixelRatio()); bucket.drawLines(*plainShader); #ifndef GL_ES_VERSION_2_0 @@ -36,7 +36,7 @@ void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) { // Draw black text. plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; - lineWidth(2.0f * map.getState().getPixelRatio()); + lineWidth(2.0f * state.getPixelRatio()); bucket.drawLines(*plainShader); glEnable(GL_DEPTH_TEST); @@ -56,7 +56,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) { // draw tile outline tileBorderArray.bind(*plainShader, tileBorderBuffer, BUFFER_OFFSET(0)); plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }}; - lineWidth(4.0f * map.getState().getPixelRatio()); + lineWidth(4.0f * state.getPixelRatio()); glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()); glEnable(GL_DEPTH_TEST); @@ -87,14 +87,14 @@ void Painter::renderDebugText(const std::vector &strings) { VertexArrayObject debugFontArray; debugFontArray.bind(*plainShader, debugFontBuffer, BUFFER_OFFSET(0)); plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; - lineWidth(4.0f * map.getState().getPixelRatio()); + lineWidth(4.0f * state.getPixelRatio()); glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index()); #ifndef GL_ES_VERSION_2_0 glPointSize(2); glDrawArrays(GL_POINTS, 0, (GLsizei)debugFontBuffer.index()); #endif plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; - lineWidth(2.0f * map.getState().getPixelRatio()); + lineWidth(2.0f * state.getPixelRatio()); glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index()); } diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp index 0f7eadce6..f2759ffd6 100644 --- a/src/renderer/painter_fill.cpp +++ b/src/renderer/painter_fill.cpp @@ -49,8 +49,8 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c // Draw the entire line outlineShader->u_world = {{ - static_cast(map.getState().getFramebufferWidth()), - static_cast(map.getState().getFramebufferHeight()) + static_cast(state.getFramebufferWidth()), + static_cast(state.getFramebufferHeight()) }}; depthRange(strata, 1.0f); bucket.drawVertices(*outlineShader); @@ -58,12 +58,10 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c if (pattern) { // Image fill. - Sprite &sprite = *map.getSprite(); - if (pass == RenderPass::Translucent && sprite) { - SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); + if (pass == RenderPass::Translucent) { const SpriteAtlasPosition pos = spriteAtlas.getPosition(properties.image, true); - const float mix = std::fmod(float(map.getState().getZoom()), 1.0f); - const float factor = 8.0 / std::pow(2, map.getState().getIntegerZoom() - id.z); + const float mix = std::fmod(float(state.getZoom()), 1.0f); + const float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); mat3 patternMatrix; matrix::identity(patternMatrix); @@ -114,8 +112,8 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c // Draw the entire line outlineShader->u_world = {{ - static_cast(map.getState().getFramebufferWidth()), - static_cast(map.getState().getFramebufferHeight()) + static_cast(state.getFramebufferWidth()), + static_cast(state.getFramebufferHeight()) }}; depthRange(strata + strata_epsilon, 1.0f); diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp index cd973b46d..9893f032d 100644 --- a/src/renderer/painter_line.cpp +++ b/src/renderer/painter_line.cpp @@ -15,7 +15,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c const LineProperties &properties = layer_desc->getProperties(); - float antialiasing = 1 / map.getState().getPixelRatio(); + float antialiasing = 1 / state.getPixelRatio(); float width = properties.width; float offset = properties.offset / 2; float blur = properties.blur + antialiasing; @@ -34,7 +34,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c float dash_length = properties.dash_array[0]; float dash_gap = properties.dash_array[1]; - float ratio = map.getState().getPixelRatio(); + float ratio = state.getPixelRatio(); mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); depthRange(strata, 1.0f); @@ -45,15 +45,15 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linejoinShader->u_matrix = vtxMatrix; linejoinShader->u_color = color; linejoinShader->u_world = {{ - map.getState().getFramebufferWidth() * 0.5f, - map.getState().getFramebufferHeight() * 0.5f + state.getFramebufferWidth() * 0.5f, + state.getFramebufferHeight() * 0.5f }}; linejoinShader->u_linewidth = {{ - ((outset - 0.25f) * map.getState().getPixelRatio()), - ((inset - 0.25f) * map.getState().getPixelRatio()) + ((outset - 0.25f) * state.getPixelRatio()), + ((inset - 0.25f) * state.getPixelRatio()) }}; - float pointSize = std::ceil(map.getState().getPixelRatio() * outset * 2.0); + float pointSize = std::ceil(state.getPixelRatio() * outset * 2.0); #if defined(GL_ES_VERSION_2_0) linejoinShader->u_size = pointSize; #else @@ -62,12 +62,11 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c bucket.drawPoints(*linejoinShader); } - const util::ptr &sprite = map.getSprite(); - if (properties.image.size() && sprite) { - SpriteAtlasPosition imagePos = map.getSpriteAtlas()->getPosition(properties.image, *sprite); + if (properties.image.size()) { + SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image); - float factor = 8.0 / std::pow(2, map.getState().getIntegerZoom() - id.z); - float fade = std::fmod(map.getState().getZoom(), 1.0); + float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); + float fade = std::fmod(state.getZoom(), 1.0); useProgram(linepatternShader->program); @@ -82,7 +81,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linepatternShader->u_pattern_br = imagePos.br; linepatternShader->u_fade = fade; - map.getSpriteAtlas()->bind(true); + spriteAtlas.bind(true); glDepthRange(strata + strata_epsilon, 1.0f); // may or may not matter bucket.drawLinePatterns(*linepatternShader); diff --git a/src/renderer/painter_raster.cpp b/src/renderer/painter_raster.cpp index c362042e5..3e05a2bef 100644 --- a/src/renderer/painter_raster.cpp +++ b/src/renderer/painter_raster.cpp @@ -31,14 +31,11 @@ void Painter::renderRaster(RasterBucket& bucket, util::ptr layer_des return vtxMatrix; }(); - // call updateTiles to get parsed data for sublayers - map.updateTiles(); - for (const util::ptr &layer : layer_desc->layers->layers) { setOpaque(); - map.renderLayer(layer, RenderPass::Opaque, &id, &preMatrix); + renderLayer(layer, RenderPass::Opaque, &id, &preMatrix); setTranslucent(); - map.renderLayer(layer, RenderPass::Translucent, &id, &preMatrix); + renderLayer(layer, RenderPass::Translucent, &id, &preMatrix); } if (bucket.properties.blur > 0) { diff --git a/src/renderer/painter_symbol.cpp b/src/renderer/painter_symbol.cpp index 8ca8624ad..79625f168 100644 --- a/src/renderer/painter_symbol.cpp +++ b/src/renderer/painter_symbol.cpp @@ -24,8 +24,9 @@ void Painter::renderSDF(SymbolBucket &bucket, mat4 exMatrix; matrix::copy(exMatrix, projMatrix); + bool aligned_with_map = (bucketProperties.rotation_alignment == RotationAlignmentType::Map); - const float angleOffset = aligned_with_map ? map.getState().getAngle() : 0; + const float angleOffset = aligned_with_map ? state.getAngle() : 0; if (angleOffset) { matrix::rotate_z(exMatrix, exMatrix, angleOffset); @@ -42,24 +43,24 @@ void Painter::renderSDF(SymbolBucket &bucket, sdfShader.u_texsize = texsize; // Convert the -pi..pi to an int8 range. - float angle = std::round(map.getState().getAngle() / M_PI * 128); + float angle = std::round(state.getAngle() / M_PI * 128); // adjust min/max zooms for variable font sies float zoomAdjust = std::log(fontSize / bucketProperties.max_size) / std::log(2); sdfShader.u_flip = (aligned_with_map && bucketProperties.keep_upright) ? 1 : 0; sdfShader.u_angle = (int32_t)(angle + 256) % 256; - sdfShader.u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level + sdfShader.u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level FadeProperties f = frameHistory.getFadeProperties(300_milliseconds); sdfShader.u_fadedist = f.fadedist * 10; sdfShader.u_minfadezoom = std::floor(f.minfadezoom * 10); sdfShader.u_maxfadezoom = std::floor(f.maxfadezoom * 10); - sdfShader.u_fadezoom = (map.getState().getNormalizedZoom() + f.bump) * 10; + sdfShader.u_fadezoom = (state.getNormalizedZoom() + f.bump) * 10; // The default gamma value has to be adjust for the current pixelratio so that we're not // drawing blurry font on retina screens. - const float gamma = 0.105 * sdfFontSize / fontSize / map.getState().getPixelRatio(); + const float gamma = 0.105 * sdfFontSize / fontSize / state.getPixelRatio(); const float sdfPx = 8.0f; const float blurOffset = 1.19f; @@ -124,15 +125,14 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des const float angleOffset = bucket.properties.icon.rotation_alignment == RotationAlignmentType::Map - ? map.getState().getAngle() + ? state.getAngle() : 0; // If layerStyle.size > bucket.info.fontSize then labels may collide const float fontSize = properties.icon.size != 0 ? properties.icon.size : bucket.properties.icon.max_size; const float fontScale = fontSize / 1.0f; - SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); - spriteAtlas.bind(map.getState().isChanging() || bucket.properties.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf); + spriteAtlas.bind(state.isChanging() || bucket.properties.placement == PlacementType::Line || angleOffset != 0 || fontScale != 1 || sdf); std::array texsize = {{ float(spriteAtlas.getWidth()), @@ -167,7 +167,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des iconShader->u_texsize = texsize; // Convert the -pi..pi to an int8 range. - const float angle = std::round(map.getState().getAngle() / M_PI * 128); + const float angle = std::round(state.getAngle() / M_PI * 128); // adjust min/max zooms for variable font sies float zoomAdjust = std::log(fontSize / bucket.properties.icon.max_size) / std::log(2); @@ -177,12 +177,12 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des bool flip = (bucket.properties.icon.rotation_alignment == RotationAlignmentType::Map) && bucket.properties.icon.keep_upright; iconShader->u_flip = flip ? 1 : 0; - iconShader->u_zoom = (map.getState().getNormalizedZoom() - zoomAdjust) * 10; // current zoom level + iconShader->u_zoom = (state.getNormalizedZoom() - zoomAdjust) * 10; // current zoom level iconShader->u_fadedist = 0 * 10; - iconShader->u_minfadezoom = map.getState().getNormalizedZoom() * 10; - iconShader->u_maxfadezoom = map.getState().getNormalizedZoom() * 10; - iconShader->u_fadezoom = map.getState().getNormalizedZoom() * 10; + iconShader->u_minfadezoom = state.getNormalizedZoom() * 10; + iconShader->u_maxfadezoom = state.getNormalizedZoom() * 10; + iconShader->u_fadezoom = state.getNormalizedZoom() * 10; iconShader->u_opacity = properties.icon.opacity; depthRange(strata, 1.0f); @@ -191,7 +191,6 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des } if (bucket.hasTextData()) { - GlyphAtlas &glyphAtlas = *map.getGlyphAtlas(); glyphAtlas.bind(); renderSDF(bucket, @@ -204,5 +203,6 @@ void Painter::renderSymbol(SymbolBucket &bucket, util::ptr layer_des *sdfGlyphShader, &SymbolBucket::drawGlyphs); } + glEnable(GL_STENCIL_TEST); } From 8ae0dcb5a46acb7a268fbc1086b5aeebb0b6da4c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 22 Oct 2014 16:03:58 -0700 Subject: [PATCH 11/20] Replace uv::rwlock with std::recursive_mutex Fixes #491 --- include/mbgl/map/transform.hpp | 6 ++-- src/map/transform.cpp | 57 +++++++++++++++++----------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index 4801ff109..e3604edd8 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -3,14 +3,12 @@ #include #include - #include -#include #include #include #include -#include +#include namespace mbgl { @@ -80,7 +78,7 @@ private: private: View &view; - std::unique_ptr mtx; + mutable std::recursive_mutex mtx; // This reflects the current state of the transform, representing the actual position of the // map. After calling a transform function with a timer, this will likely remain the same until diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 9619305dd..25aacd483 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -5,9 +5,9 @@ #include #include #include -#include #include #include + #include using namespace mbgl; @@ -18,7 +18,6 @@ const double MIN_ROTATE_SCALE = 8; Transform::Transform(View &view_) : view(view_) - , mtx(std::make_unique()) { } @@ -26,7 +25,7 @@ Transform::Transform(View &view_) bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, const uint16_t fb_w, const uint16_t fb_h) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); if (final.width != w || final.height != h || final.pixelRatio != ratio || final.framebuffer[0] != fb_w || final.framebuffer[1] != fb_h) { @@ -52,7 +51,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, #pragma mark - Position void Transform::moveBy(const double dx, const double dy, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _moveBy(dx, dy, duration); } @@ -94,7 +93,7 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati } void Transform::setLonLat(const double lon, const double lat, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999); double xn = -lon * Bc; @@ -105,7 +104,7 @@ void Transform::setLonLat(const double lon, const double lat, const timestamp du void Transform::setLonLatZoom(const double lon, const double lat, const double zoom, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); double new_scale = std::pow(2.0, zoom); @@ -121,20 +120,20 @@ void Transform::setLonLatZoom(const double lon, const double lat, const double z } void Transform::getLonLat(double &lon, double &lat) const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); final.getLonLat(lon, lat); } void Transform::getLonLatZoom(double &lon, double &lat, double &zoom) const { - getLonLat(lon, lat); + std::lock_guard lock(mtx); - uv::readlock lock(mtx); + getLonLat(lon, lat); zoom = getZoom(); } void Transform::startPanning() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearPanning(); @@ -146,7 +145,7 @@ void Transform::startPanning() { } void Transform::stopPanning() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearPanning(); } @@ -162,7 +161,7 @@ void Transform::_clearPanning() { #pragma mark - Zoom void Transform::scaleBy(const double ds, const double cx, const double cy, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); // clamp scale to min/max values double new_scale = current.scale * ds; @@ -177,31 +176,31 @@ void Transform::scaleBy(const double ds, const double cx, const double cy, const void Transform::setScale(const double scale, const double cx, const double cy, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _setScale(scale, cx, cy, duration); } void Transform::setZoom(const double zoom, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _setScale(std::pow(2.0, zoom), -1, -1, duration); } double Transform::getZoom() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return std::log(final.scale) / M_LN2; } double Transform::getScale() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return final.scale; } void Transform::startScaling() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearScaling(); @@ -213,7 +212,7 @@ void Transform::startScaling() { } void Transform::stopScaling() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearScaling(); } @@ -332,7 +331,7 @@ void Transform::constrain(double& scale, double& y) const { void Transform::rotateBy(const double start_x, const double start_y, const double end_x, const double end_y, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); double center_x = current.width / 2, center_y = current.height / 2; @@ -362,13 +361,13 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl } void Transform::setAngle(const double new_angle, const timestamp duration) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _setAngle(new_angle, duration); } void Transform::setAngle(const double new_angle, const double cx, const double cy) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); double dx = 0, dy = 0; @@ -417,13 +416,13 @@ void Transform::_setAngle(double new_angle, const timestamp duration) { } double Transform::getAngle() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return final.angle; } void Transform::startRotating() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearRotating(); @@ -435,7 +434,7 @@ void Transform::startRotating() { } void Transform::stopRotating() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); _clearRotating(); } @@ -457,13 +456,13 @@ bool Transform::canRotate() { #pragma mark - Transition bool Transform::needsTransition() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return !transitions.empty(); } void Transform::updateTransitions(const timestamp now) { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); transitions.remove_if([now](const util::ptr &transition) { return transition->update(now) == util::transition::complete; @@ -471,7 +470,7 @@ void Transform::updateTransitions(const timestamp now) { } void Transform::cancelTransitions() { - uv::writelock lock(mtx); + std::lock_guard lock(mtx); transitions.clear(); } @@ -479,13 +478,13 @@ void Transform::cancelTransitions() { #pragma mark - Transform state const TransformState Transform::currentState() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return current; } const TransformState Transform::finalState() const { - uv::readlock lock(mtx); + std::lock_guard lock(mtx); return final; } From 7caac537b8277b083d0a5ba374ddfa43d7047df0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 29 Oct 2014 10:12:41 -0400 Subject: [PATCH 12/20] Fix variable shadowing --- include/mbgl/renderer/painter.hpp | 2 +- src/renderer/painter.cpp | 6 +++--- src/renderer/painter_raster.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/mbgl/renderer/painter.hpp b/include/mbgl/renderer/painter.hpp index 2b0ac070f..be4bd1271 100644 --- a/include/mbgl/renderer/painter.hpp +++ b/include/mbgl/renderer/painter.hpp @@ -81,7 +81,7 @@ public: timestamp time); void renderLayers(util::ptr group); - void renderLayer(util::ptr layer_desc, RenderPass pass, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); + void renderLayer(util::ptr layer_desc, const Tile::ID* id = nullptr, const mat4* matrix = nullptr); // Renders a particular layer from a tile. void renderTileLayer(const Tile& tile, util::ptr layer_desc, const mat4 &matrix); diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 7d636669d..bdc883b5b 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -259,7 +259,7 @@ void Painter::renderLayers(util::ptr group) { for (auto it = group->layers.rbegin(), end = group->layers.rend(); it != end; ++it, ++i) { setOpaque(); setStrata(i * strata_thickness); - renderLayer(*it, RenderPass::Opaque); + renderLayer(*it); } if (debug::renderTree) { std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; @@ -275,14 +275,14 @@ void Painter::renderLayers(util::ptr group) { for (auto it = group->layers.begin(), end = group->layers.end(); it != end; ++it, --i) { setTranslucent(); setStrata(i * strata_thickness); - renderLayer(*it, RenderPass::Translucent); + renderLayer(*it); } if (debug::renderTree) { std::cout << std::string(--indent * 4, ' ') << "}" << std::endl; } } -void Painter::renderLayer(util::ptr layer_desc, RenderPass pass, const Tile::ID* id, const mat4* matrix) { +void Painter::renderLayer(util::ptr layer_desc, const Tile::ID* id, const mat4* matrix) { if (layer_desc->type == StyleLayerType::Background) { // This layer defines a background color/image. diff --git a/src/renderer/painter_raster.cpp b/src/renderer/painter_raster.cpp index 3e05a2bef..df655cdae 100644 --- a/src/renderer/painter_raster.cpp +++ b/src/renderer/painter_raster.cpp @@ -33,9 +33,9 @@ void Painter::renderRaster(RasterBucket& bucket, util::ptr layer_des for (const util::ptr &layer : layer_desc->layers->layers) { setOpaque(); - renderLayer(layer, RenderPass::Opaque, &id, &preMatrix); + renderLayer(layer, &id, &preMatrix); setTranslucent(); - renderLayer(layer, RenderPass::Translucent, &id, &preMatrix); + renderLayer(layer, &id, &preMatrix); } if (bucket.properties.blur > 0) { From 372348131989aacedb1e24bf26fb7f92cdba5fe5 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 29 Oct 2014 11:57:39 -0400 Subject: [PATCH 13/20] c++ - use const qualifier --- src/renderer/painter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index bdc883b5b..6abd51390 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -304,7 +304,7 @@ void Painter::renderLayer(util::ptr layer_desc, const Tile::ID* id, return; } - StyleSource &style_source = *layer_desc->bucket->style_source; + StyleSource const& style_source = *layer_desc->bucket->style_source; // Skip this layer if there is no data. if (!style_source.source) { From 3b5b15a4e4b1b86c9576969d868caa48520f8d8c Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 29 Oct 2014 13:44:26 -0400 Subject: [PATCH 14/20] store glyphAtlas by value in Map object, pass by ref change hasData signiture to expect ```StyleLayer const&``` --- include/mbgl/map/map.hpp | 8 +++----- include/mbgl/map/raster_tile_data.hpp | 2 +- include/mbgl/map/tile_data.hpp | 2 +- include/mbgl/map/tile_parser.hpp | 4 ++-- include/mbgl/map/vector_tile_data.hpp | 2 +- src/map/map.cpp | 5 ++--- src/map/raster_tile_data.cpp | 2 +- src/map/tile_parser.cpp | 6 +++--- src/map/vector_tile_data.cpp | 15 ++++++--------- src/renderer/painter.cpp | 2 +- src/renderer/symbol_bucket.cpp | 2 +- 11 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 8378b2737..d5e725241 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -3,12 +3,11 @@ #include #include - +#include #include #include #include #include - #include #include #include @@ -17,7 +16,6 @@ namespace mbgl { -class GlyphAtlas; class GlyphStore; class LayerDescription; class SpriteAtlas; @@ -131,7 +129,7 @@ public: inline const TransformState &getState() const { return state; } inline util::ptr getFileSource() const { return fileSource; } inline util::ptr