diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-13 16:05:26 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-14 16:28:12 -0600 |
commit | d819ece74c52658c68d4e297c9bef5a74f739e28 (patch) | |
tree | 3f5af4a976546db7b811522c62c5ab0b504837a2 /src | |
parent | 58de1e15c5e3f4983f445eacefb2fcc931371788 (diff) | |
download | qtlocation-mapboxgl-d819ece74c52658c68d4e297c9bef5a74f739e28.tar.gz |
[core] Combine SpriteAtlas::getPosition with SpriteAtlas::getImage
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/programs/fill_program.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/programs/fill_program.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/programs/line_program.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/programs/line_program.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_background.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_line.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.cpp | 50 | ||||
-rw-r--r-- | src/mbgl/sprite/sprite_atlas.hpp | 20 |
9 files changed, 45 insertions, 57 deletions
diff --git a/src/mbgl/programs/fill_program.cpp b/src/mbgl/programs/fill_program.cpp index 6998d56232..eebcffd2cb 100644 --- a/src/mbgl/programs/fill_program.cpp +++ b/src/mbgl/programs/fill_program.cpp @@ -13,8 +13,8 @@ static_assert(sizeof(FillLayoutVertex) == 4, "expected FillLayoutVertex size"); FillPatternUniforms::Values FillPatternUniforms::values(mat4 matrix, Size framebufferSize, - const SpriteAtlasPosition& a, - const SpriteAtlasPosition& b, + const SpriteAtlasElement& a, + const SpriteAtlasElement& b, const Faded<std::string>& fading, const UnwrappedTileID& tileID, const TransformState& state) diff --git a/src/mbgl/programs/fill_program.hpp b/src/mbgl/programs/fill_program.hpp index 5406a5999c..84ca2748d6 100644 --- a/src/mbgl/programs/fill_program.hpp +++ b/src/mbgl/programs/fill_program.hpp @@ -16,7 +16,7 @@ namespace mbgl { -class SpriteAtlasPosition; +class SpriteAtlasElement; class UnwrappedTileID; class TransformState; @@ -61,8 +61,8 @@ struct FillPatternUniforms : gl::Uniforms< { static Values values(mat4 matrix, Size framebufferSize, - const SpriteAtlasPosition&, - const SpriteAtlasPosition&, + const SpriteAtlasElement&, + const SpriteAtlasElement&, const style::Faded<std::string>&, const UnwrappedTileID&, const TransformState&); diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index 8a26c88aea..d9778ba7ce 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -88,8 +88,8 @@ LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properti const RenderTile& tile, const TransformState& state, const std::array<float, 2>& pixelsToGLUnits, - const SpriteAtlasPosition& posA, - const SpriteAtlasPosition& posB) { + const SpriteAtlasElement& posA, + const SpriteAtlasElement& posB) { std::array<float, 2> sizeA {{ tile.id.pixelsToTileUnits(posA.size[0] * properties.get<LinePattern>().fromScale, state.getIntegerZoom()), posA.size[1] diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index 76329a463f..842b4cc602 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -16,7 +16,7 @@ namespace mbgl { class RenderTile; class TransformState; class LinePatternPos; -class SpriteAtlasPosition; +class SpriteAtlasElement; namespace uniforms { MBGL_DEFINE_UNIFORM_SCALAR(float, u_ratio); @@ -123,8 +123,8 @@ public: const RenderTile&, const TransformState&, const std::array<float, 2>& pixelsToGLUnits, - const SpriteAtlasPosition& posA, - const SpriteAtlasPosition& posB); + const SpriteAtlasElement& posA, + const SpriteAtlasElement& posB); }; class LineSDFProgram : public Program< diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index e8a5342f4a..6ce3b59358 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -24,9 +24,9 @@ void Painter::renderBackground(PaintParameters& parameters, const BackgroundLaye const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); if (!background.get<BackgroundPattern>().to.empty()) { - optional<SpriteAtlasPosition> imagePosA = spriteAtlas->getPosition( + optional<SpriteAtlasElement> imagePosA = spriteAtlas->getImage( background.get<BackgroundPattern>().from, SpritePatternMode::Repeating); - optional<SpriteAtlasPosition> imagePosB = spriteAtlas->getPosition( + optional<SpriteAtlasElement> imagePosB = spriteAtlas->getImage( background.get<BackgroundPattern>().to, SpritePatternMode::Repeating); if (!imagePosA || !imagePosB) diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index d98cb2b57c..bdc99d42f0 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -24,9 +24,9 @@ void Painter::renderFill(PaintParameters& parameters, return; } - optional<SpriteAtlasPosition> imagePosA = spriteAtlas->getPosition( + optional<SpriteAtlasElement> imagePosA = spriteAtlas->getImage( properties.get<FillPattern>().from, SpritePatternMode::Repeating); - optional<SpriteAtlasPosition> imagePosB = spriteAtlas->getPosition( + optional<SpriteAtlasElement> imagePosB = spriteAtlas->getImage( properties.get<FillPattern>().to, SpritePatternMode::Repeating); if (!imagePosA || !imagePosB) { diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 0fbff94ff7..545f01ce88 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -61,9 +61,9 @@ void Painter::renderLine(PaintParameters& parameters, lineAtlas->getSize().width)); } else if (!properties.get<LinePattern>().from.empty()) { - optional<SpriteAtlasPosition> posA = spriteAtlas->getPosition( + optional<SpriteAtlasElement> posA = spriteAtlas->getImage( properties.get<LinePattern>().from, SpritePatternMode::Repeating); - optional<SpriteAtlasPosition> posB = spriteAtlas->getPosition( + optional<SpriteAtlasElement> posB = spriteAtlas->getImage( properties.get<LinePattern>().to, SpritePatternMode::Repeating); if (!posA || !posB) diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp index 1ca40f6c2d..b712fc8742 100644 --- a/src/mbgl/sprite/sprite_atlas.cpp +++ b/src/mbgl/sprite/sprite_atlas.cpp @@ -27,6 +27,23 @@ struct SpriteAtlas::Loader { std::unique_ptr<AsyncRequest> spriteRequest; }; +SpriteAtlasElement::SpriteAtlasElement(Rect<uint16_t> rect_, + std::shared_ptr<const SpriteImage> image_, + Size size_, float pixelRatio) + : pos(std::move(rect_)), + spriteImage(std::move(image_)), + relativePixelRatio(spriteImage->pixelRatio / pixelRatio) { + + const float padding = 1; + + const float w = spriteImage->getWidth() * relativePixelRatio; + const float h = spriteImage->getHeight() * relativePixelRatio; + + size = {{ float(spriteImage->getWidth()), spriteImage->getHeight() }}; + tl = {{ float(pos.x + padding) / size_.width, float(pos.y + padding) / size_.height }}; + br = {{ float(pos.x + padding + w) / size_.width, float(pos.y + padding + h) / size_.height }}; +} + SpriteAtlas::SpriteAtlas(Size size_, float pixelRatio_) : size(std::move(size_)), pixelRatio(pixelRatio_), @@ -192,7 +209,8 @@ optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, return SpriteAtlasElement { *entry.iconRect, entry.spriteImage, - entry.spriteImage->pixelRatio / pixelRatio + size, + pixelRatio }; } @@ -200,7 +218,8 @@ optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, return SpriteAtlasElement { *entry.patternRect, entry.spriteImage, - entry.spriteImage->pixelRatio / pixelRatio + size, + pixelRatio }; } @@ -233,31 +252,8 @@ optional<SpriteAtlasElement> SpriteAtlas::getImage(const std::string& name, return SpriteAtlasElement { rect, entry.spriteImage, - entry.spriteImage->pixelRatio / pixelRatio - }; -} - -optional<SpriteAtlasPosition> SpriteAtlas::getPosition(const std::string& name, - const SpritePatternMode mode) { - std::lock_guard<std::recursive_mutex> lock(mutex); - - auto img = getImage(name, mode); - if (!img) { - return {}; - } - - auto rect = (*img).pos; - - const float padding = 1; - auto spriteImage = (*img).spriteImage; - - const float w = spriteImage->getWidth() * (*img).relativePixelRatio; - const float h = spriteImage->getHeight() * (*img).relativePixelRatio; - - return SpriteAtlasPosition { - {{ float(spriteImage->getWidth()), spriteImage->getHeight() }}, - {{ float(rect.x + padding) / size.width, float(rect.y + padding) / size.height }}, - {{ float(rect.x + padding + w) / size.width, float(rect.y + padding + h) / size.height }} + size, + pixelRatio }; } diff --git a/src/mbgl/sprite/sprite_atlas.hpp b/src/mbgl/sprite/sprite_atlas.hpp index d839109a24..124d0ae294 100644 --- a/src/mbgl/sprite/sprite_atlas.hpp +++ b/src/mbgl/sprite/sprite_atlas.hpp @@ -23,21 +23,17 @@ namespace gl { class Context; } // namespace gl -class SpriteImage; -class SpritePosition; - -class SpriteAtlasPosition { -public: - std::array<float, 2> size = {{ 0, 0 }}; - std::array<float, 2> tl = {{ 0, 0 }}; - std::array<float, 2> br = {{ 0, 0 }}; -}; - class SpriteAtlasElement { public: + SpriteAtlasElement(Rect<uint16_t>, std::shared_ptr<const SpriteImage>, Size size, float pixelRatio); + Rect<uint16_t> pos; std::shared_ptr<const SpriteImage> spriteImage; + float relativePixelRatio; + std::array<float, 2> size; + std::array<float, 2> tl; + std::array<float, 2> br; }; enum class SpritePatternMode : bool { @@ -78,10 +74,6 @@ public: // the resulting icon measurements. If not, returns an empty optional. optional<SpriteAtlasElement> getImage(const std::string& name, SpritePatternMode mode); - // This function is used for getting the position during render time. - optional<SpriteAtlasPosition> getPosition(const std::string& name, - SpritePatternMode mode = SpritePatternMode::Single); - // Binds the atlas texture to the GPU, and uploads data if it is out of date. void bind(bool linear, gl::Context&, gl::TextureUnit unit); |