From 48a310406621957db4154e844d28e98f460a0226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 16 Oct 2014 18:58:23 +0200 Subject: Update README.md use master branch for travis icon [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ad7966e9..ee9d1bacb0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Travis](https://api.travis-ci.org/mapbox/mapbox-gl-native.svg)](https://travis-ci.org/mapbox/mapbox-gl-native/builds) +[![Travis](https://api.travis-ci.org/mapbox/mapbox-gl-native.svg?branch=master)](https://travis-ci.org/mapbox/mapbox-gl-native/builds) An OpenGL renderer for [Mapbox Vector Tiles](https://www.mapbox.com/blog/vector-tiles), implemented in C++11, currently targeting iOS, OS X, and Ubuntu Linux. -- cgit v1.2.1 From 4603ca037cab2d0f732285ce9e006744ad3118d6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 26 Aug 2014 15:24:16 -0700 Subject: background-image support --- include/mbgl/map/transform_state.hpp | 8 +++- include/mbgl/style/property_key.hpp | 3 +- include/mbgl/style/style_properties.hpp | 1 + include/mbgl/util/mat3.hpp | 2 + src/map/transform_state.cpp | 30 +++++++++++++-- src/renderer/painter.cpp | 67 +++++++++++++++++++++++++++------ src/style/style_layer.cpp | 1 + src/style/style_parser.cpp | 1 + src/util/mat3.cpp | 46 +++++++++++++++++++++- 9 files changed, 142 insertions(+), 17 deletions(-) diff --git a/include/mbgl/map/transform_state.hpp b/include/mbgl/map/transform_state.hpp index 5b3b7d3755..ed49dc3e99 100644 --- a/include/mbgl/map/transform_state.hpp +++ b/include/mbgl/map/transform_state.hpp @@ -29,10 +29,16 @@ public: const std::array getFramebufferDimensions() const; float getPixelRatio() const; + float worldSize() const; + float lngX(float lon) const; + float latY(float lat) const; + std::array locationCoordinate(float lon, float lat) const; + // Zoom float getNormalizedZoom() const; - int32_t getIntegerZoom() const; double getZoom() const; + int32_t getIntegerZoom() const; + double getZoomFraction() const; double getScale() const; // Rotation diff --git a/include/mbgl/style/property_key.hpp b/include/mbgl/style/property_key.hpp index 28aa800607..cbf9ad2ac5 100644 --- a/include/mbgl/style/property_key.hpp +++ b/include/mbgl/style/property_key.hpp @@ -61,7 +61,8 @@ enum class PropertyKey { RasterFade, BackgroundOpacity, - BackgroundColor + BackgroundColor, + BackgroundImage }; } diff --git a/include/mbgl/style/style_properties.hpp b/include/mbgl/style/style_properties.hpp index 20200a0dd7..0a5e993411 100644 --- a/include/mbgl/style/style_properties.hpp +++ b/include/mbgl/style/style_properties.hpp @@ -94,6 +94,7 @@ struct BackgroundProperties { inline BackgroundProperties() {} float opacity = 1.0f; Color color = {{ 0, 0, 0, 1 }}; + std::string image; }; typedef mapbox::util::variant< diff --git a/include/mbgl/util/mat3.hpp b/include/mbgl/util/mat3.hpp index d44b1435d3..fa40751764 100644 --- a/include/mbgl/util/mat3.hpp +++ b/include/mbgl/util/mat3.hpp @@ -32,6 +32,8 @@ typedef std::array mat3; namespace matrix { void identity(mat3& out); +void translate(mat3& out, const mat3& a, float x, float y); +void rotate(mat3& out, const mat3& a, float rad); void scale(mat3& out, const mat3& a, float x, float y); } diff --git a/src/map/transform_state.cpp b/src/map/transform_state.cpp index d103897375..4b1bc4161e 100644 --- a/src/map/transform_state.cpp +++ b/src/map/transform_state.cpp @@ -83,11 +83,31 @@ const std::array TransformState::getFramebufferDimensions() const { return framebuffer; } - float TransformState::getPixelRatio() const { return pixelRatio; } +float TransformState::worldSize() const { + return scale * util::tileSize; +} + +float TransformState::lngX(float lon) const { + return (180 + lon) * worldSize() / 360; +} + +float TransformState::latY(float lat) const { + float y = 180 / M_PI * std::log(std::tan(M_PI / 4 + lat * M_PI / 360)); + return (180 - y) * worldSize() / 360; +} + +std::array TransformState::locationCoordinate(float lon, float lat) const { + float k = std::pow(2, getIntegerZoom()) / worldSize(); + return {{ + lngX(lon) * k, + latY(lat) * k + }}; +} + #pragma mark - Zoom @@ -95,12 +115,16 @@ float TransformState::getNormalizedZoom() const { return std::log(scale * util::tileSize / 512.0f) / M_LN2; } +double TransformState::getZoom() const { + return std::log(scale) / M_LN2; +} + int32_t TransformState::getIntegerZoom() const { return std::floor(getZoom()); } -double TransformState::getZoom() const { - return std::log(scale) / M_LN2; +double TransformState::getZoomFraction() const { + return getZoom() - getIntegerZoom(); } double TransformState::getScale() const { diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 9643fb1561..474b7b954f 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include + #if defined(DEBUG) #include #endif @@ -188,24 +191,66 @@ 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.opacity >= 1.0f) != (pass == RenderPass::Opaque)) + return; + + SpriteAtlas &spriteAtlas = *map.getSpriteAtlas(); + SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, *sprite, true); + float zoomFraction = map.getState().getZoomFraction(); + + useProgram(patternShader->program); + patternShader->u_matrix = identityMatrix; + patternShader->u_pattern_tl = imagePos.tl; + patternShader->u_pattern_br = imagePos.br; + patternShader->u_mix = zoomFraction; + patternShader->u_opacity = properties.opacity; + + std::array size = imagePos.size; + double lon, lat; + map.getLonLat(lon, lat); + std::array center = map.getState().locationCoordinate(lon, lat); + float scale = 1 / std::pow(2, zoomFraction); + + mat3 matrix; + matrix::identity(matrix); + matrix::scale(matrix, matrix, + 1.0f / size[0], + 1.0f / size[1]); + 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::scale(matrix, matrix, + scale * map.getState().getWidth() / 2, + -scale * map.getState().getHeight() / 2); + patternShader->u_patternmatrix = matrix; + + 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; - 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; - if ((color[3] >= 1.0f) == (pass == RenderPass::Opaque)) { useProgram(plainShader->program); plainShader->u_matrix = identityMatrix; plainShader->u_color = 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); } + + 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 &translation, const Tile::ID &id, TranslateAnchorType anchor) { diff --git a/src/style/style_layer.cpp b/src/style/style_layer.cpp index 4f758fe723..d78750195b 100644 --- a/src/style/style_layer.cpp +++ b/src/style/style_layer.cpp @@ -235,6 +235,7 @@ void StyleLayer::applyStyleProperties(const float z, const BackgroundProperties &background = properties.get(); applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now); applyTransitionedStyleProperty(PropertyKey::BackgroundColor, background.color, z, now); + applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now); } void StyleLayer::updateProperties(float z, const timestamp now) { diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index c2247d51b2..3aa12a6670 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -640,6 +640,7 @@ void StyleParser::parseStyle(JSVal value, ClassProperties &klass) { parseOptionalProperty>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty>("background-color", Key::BackgroundColor, klass, value); + parseOptionalProperty("background-image", Key::BackgroundImage, klass, value); } void StyleParser::parseReference(JSVal value, util::ptr &layer) { diff --git a/src/util/mat3.cpp b/src/util/mat3.cpp index 38858d2385..263768ee41 100644 --- a/src/util/mat3.cpp +++ b/src/util/mat3.cpp @@ -38,7 +38,51 @@ void matrix::identity(mat3& out) { out[8] = 1.0f; } -void matrix::scale(mat3& out, const mat3& a, const float x, const float y) { +void matrix::translate(mat3& out, const mat3& a, float x, float y) { + float a00 = a[0], a01 = a[1], a02 = a[2], + a10 = a[3], a11 = a[4], a12 = a[5], + a20 = a[6], a21 = a[7], a22 = a[8]; + + out[0] = a00; + out[1] = a01; + out[2] = a02; + + out[3] = a10; + out[4] = a11; + out[5] = a12; + + out[6] = x * a00 + y * a10 + a20; + out[7] = x * a01 + y * a11 + a21; + out[8] = x * a02 + y * a12 + a22; +} + +void matrix::rotate(mat3& out, const mat3& a, float rad) { + float s = std::sin(rad), + c = std::cos(rad), + a00 = a[0], + a01 = a[1], + a02 = a[2], + a10 = a[3], + a11 = a[4], + a12 = a[5], + a20 = a[6], + a21 = a[7], + a22 = a[8]; + + out[0] = c * a00 + s * a10; + out[1] = c * a01 + s * a11; + out[2] = c * a02 + s * a12; + + out[3] = c * a10 - s * a00; + out[4] = c * a11 - s * a01; + out[5] = c * a12 - s * a02; + + out[6] = a20; + out[7] = a21; + out[8] = a22; +}; + +void matrix::scale(mat3& out, const mat3& a, float x, float y) { out[0] = x * a[0]; out[1] = x * a[1]; out[2] = x * a[2]; -- cgit v1.2.1 From 4e9688e430037b9a454320d8b29a5c99a9616fba Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 17 Oct 2014 11:11:24 -0700 Subject: Fix compiler warnings --- include/mbgl/platform/event.hpp | 6 ++++-- test/fixtures/fixture_request.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/mbgl/platform/event.hpp b/include/mbgl/platform/event.hpp index d2a06618a3..576e9e5b85 100644 --- a/include/mbgl/platform/event.hpp +++ b/include/mbgl/platform/event.hpp @@ -58,8 +58,10 @@ struct EventPermutation { }; constexpr EventSeverity disabledEventSeverities[] = { -#if !DEBUG - EventSeverity::Debug, +#if DEBUG + EventSeverity(-1) // Avoid zero size array +#else + EventSeverity::Debug #endif }; diff --git a/test/fixtures/fixture_request.cpp b/test/fixtures/fixture_request.cpp index 3f72b890db..be944eb071 100644 --- a/test/fixtures/fixture_request.cpp +++ b/test/fixtures/fixture_request.cpp @@ -48,7 +48,7 @@ void HTTPRequestBaton::start(const util::ptr &baton) { uv_async_send(baton->async); } -void HTTPRequestBaton::stop(const util::ptr &baton) { +void HTTPRequestBaton::stop(const util::ptr &/*baton*/) { fprintf(stderr, "HTTP request cannot be canceled because it is answered immediately"); abort(); } -- cgit v1.2.1 From d54809b04adf0b64e13b97852cfed860f92682a9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 17 Oct 2014 12:02:51 -0700 Subject: Fix log message filtering Taking the sizeof a pointer doesn't give you the array length! --- include/mbgl/platform/log.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/mbgl/platform/log.hpp b/include/mbgl/platform/log.hpp index dc000b4d52..406b3eea37 100644 --- a/include/mbgl/platform/log.hpp +++ b/include/mbgl/platform/log.hpp @@ -19,9 +19,9 @@ public: class Log { private: - template - constexpr static bool includes(const T e, T const *l, const size_t i = 0) { - return i >= sizeof l ? false : *(l + i) == e ? true : includes(e, l, i + 1); + template + constexpr static bool includes(const T e, const T (&l)[N], const size_t i = 0) { + return i < N && (l[i] == e || includes(e, l, i + 1)); } public: -- cgit v1.2.1 From 251fafe2bf6dff34868a4e32953adcb73cb20db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 22 Oct 2014 15:05:33 +0200 Subject: don't check for node in the current bash. we are using our own anyway --- Makefile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c74a328068..06b38ec34b 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,10 @@ config-ios.gypi: MASON_PLATFORM=ios ./configure config-ios.gypi # Builds the regular library -mbgl: config.gypi mapboxgl.gyp node +mbgl: config.gypi mapboxgl.gyp deps/run_gyp mapboxgl.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/mbgl -f make $(MAKE) -C build/mbgl BUILDTYPE=$(BUILDTYPE) V=$(V) mapboxgl -node: - @if [ ! `which node` ]; then echo 'error: depends on node.js. please make sure node is on your PATH'; exit 1; fi; - ##### Test cases ############################################################### build/test/Makefile: src common config.gypi test/test.gyp @@ -31,7 +28,7 @@ test_%: build/test/Makefile (cd build/$(BUILDTYPE) && exec ./test_$*) # build Mac OS X project for Xcode -xtest: config.gypi clear_xcode_cache node +xtest: config.gypi clear_xcode_cache deps/run_gyp test/test.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build -f xcode open ./build/test/test.xcodeproj @@ -39,7 +36,7 @@ xtest: config.gypi clear_xcode_cache node # Builds the linux app with make. -linux: config.gypi linux/mapboxgl-app.gyp node +linux: config.gypi linux/mapboxgl-app.gyp deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/linux -f make $(MAKE) -C build/linux BUILDTYPE=$(BUILDTYPE) V=$(V) linuxapp @@ -50,7 +47,7 @@ run-linux: linux # Builds the OS X app with make. -osx: config.gypi macosx/mapboxgl-app.gyp node +osx: config.gypi macosx/mapboxgl-app.gyp deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi --depth=. -Goutput_dir=.. --generator-output=./build/macosx -f make $(MAKE) -C build/macosx BUILDTYPE=$(BUILDTYPE) V=$(V) osxapp @@ -72,21 +69,21 @@ clear_xcode_cache: fi # build Mac OS X project for Xcode -xproj-cli: config.gypi macosx/mapboxgl-app.gyp clear_xcode_cache node +xproj-cli: config.gypi macosx/mapboxgl-app.gyp clear_xcode_cache deps/run_gyp macosx/mapboxgl-app.gyp -Iconfig.gypi --depth=. --generator-output=./build -f xcode xproj: xproj-cli open ./build/macosx/mapboxgl-app.xcodeproj # build iOS project for Xcode -iproj-cli: config-ios.gypi ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp clear_xcode_cache node +iproj-cli: config-ios.gypi ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp clear_xcode_cache deps/run_gyp ios/mapbox-gl-cocoa/app/mapboxgl-app.gyp -Iconfig-ios.gypi --depth=. --generator-output=./build -f xcode iproj: iproj-cli open ./build/ios/mapbox-gl-cocoa/app/mapboxgl-app.xcodeproj # build Linux project for Xcode (Runs on Mac OS X too, but without platform-specific code) -lproj: config.gypi linux/mapboxgl-app.gyp clear_xcode_cache node +lproj: config.gypi linux/mapboxgl-app.gyp clear_xcode_cache deps/run_gyp linux/mapboxgl-app.gyp -Iconfig.gypi --depth=. --generator-output=./build -f xcode open ./build/linux/mapboxgl-app.xcodeproj -- cgit v1.2.1