Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Per-bucket glyph and icon atlases #9213

Merged
merged 9 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mason_use(pixelmatch VERSION 0.10.0 HEADER_ONLY)
mason_use(geojson VERSION 0.4.0 HEADER_ONLY)
mason_use(polylabel VERSION 1.0.2 HEADER_ONLY)
mason_use(wagyu VERSION 0.4.1 HEADER_ONLY)
mason_use(shelf-pack VERSION 2.0.1 HEADER_ONLY)
mason_use(shelf-pack VERSION 2.1.0 HEADER_ONLY)

add_definitions(-DRAPIDJSON_HAS_STDSTRING=1)

Expand Down
11 changes: 7 additions & 4 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ set(MBGL_CORE_FILES

# geometry
src/mbgl/geometry/anchor.hpp
src/mbgl/geometry/binpack.hpp
src/mbgl/geometry/debug_font_data.hpp
src/mbgl/geometry/feature_index.cpp
src/mbgl/geometry/feature_index.hpp
Expand Down Expand Up @@ -167,6 +166,10 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/frame_history.hpp
src/mbgl/renderer/group_by_layout.cpp
src/mbgl/renderer/group_by_layout.hpp
src/mbgl/renderer/image_atlas.cpp
src/mbgl/renderer/image_atlas.hpp
src/mbgl/renderer/image_manager.cpp
src/mbgl/renderer/image_manager.hpp
src/mbgl/renderer/paint_parameters.hpp
src/mbgl/renderer/paint_property_binder.hpp
src/mbgl/renderer/paint_property_statistics.hpp
Expand Down Expand Up @@ -291,8 +294,6 @@ set(MBGL_CORE_FILES
src/mbgl/shaders/symbol_sdf.hpp

# sprite
src/mbgl/sprite/sprite_atlas.cpp
src/mbgl/sprite/sprite_atlas.hpp
src/mbgl/sprite/sprite_loader.cpp
src/mbgl/sprite/sprite_loader.hpp
src/mbgl/sprite/sprite_loader_observer.hpp
Expand Down Expand Up @@ -473,7 +474,9 @@ set(MBGL_CORE_FILES
src/mbgl/text/glyph.hpp
src/mbgl/text/glyph_atlas.cpp
src/mbgl/text/glyph_atlas.hpp
src/mbgl/text/glyph_atlas_observer.hpp
src/mbgl/text/glyph_manager.cpp
src/mbgl/text/glyph_manager.hpp
src/mbgl/text/glyph_manager_observer.hpp
src/mbgl/text/glyph_pbf.cpp
src/mbgl/text/glyph_pbf.hpp
src/mbgl/text/glyph_range.hpp
Expand Down
7 changes: 2 additions & 5 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ set(MBGL_TEST_FILES
test/api/render_missing.test.cpp
test/api/repeated_render.test.cpp

# geometry
test/geometry/binpack.test.cpp

# gl
test/gl/bucket.test.cpp
test/gl/object.test.cpp
Expand All @@ -43,9 +40,9 @@ set(MBGL_TEST_FILES

# renderer
test/renderer/group_by_layout.test.cpp
test/renderer/image_manager.test.cpp

# sprite
test/sprite/sprite_atlas.test.cpp
test/sprite/sprite_loader.test.cpp
test/sprite/sprite_parser.test.cpp

Expand Down Expand Up @@ -106,7 +103,7 @@ set(MBGL_TEST_FILES
test/style/style_parser.test.cpp

# text
test/text/glyph_atlas.test.cpp
test/text/glyph_loader.test.cpp
test/text/glyph_pbf.test.cpp
test/text/quads.test.cpp

Expand Down
17 changes: 17 additions & 0 deletions include/mbgl/util/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,27 @@ class Image : private util::noncopyable {
std::fill(data.get(), data.get() + bytes(), value);
}

void resize(Size size_) {
if (size == size_) {
return;
}
Image newImage(size_);
newImage.fill(0);
copy(*this, newImage, {0, 0}, {0, 0}, {
std::min(size.width, size_.width),
std::min(size.height, size_.height)
});
operator=(std::move(newImage));
}

// Copy image data within `rect` from `src` to the rectangle of the same size at `pt`
// in `dst`. If the specified bounds exceed the bounds of the source or destination,
// throw `std::out_of_range`. Must not be used to move data within a single Image.
static void copy(const Image& srcImg, Image& dstImg, const Point<uint32_t>& srcPt, const Point<uint32_t>& dstPt, const Size& size) {
if (size.isEmpty()) {
return;
}

if (!srcImg.valid()) {
throw std::invalid_argument("invalid source for image copy");
}
Expand Down
2 changes: 1 addition & 1 deletion platform/node/test/suite_implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function (style, options, callback) {
applyOperations(operations.slice(1), callback);
});

} else if (operation[0] === 'addImage') {
} else if (operation[0] === 'addImage' || operation[0] === 'updateImage') {
var img = PNG.sync.read(fs.readFileSync(path.join(__dirname, '../../../mapbox-gl-js/test/integration', operation[2])));

map.addImage(operation[1], img.data, {
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/annotation/render_annotation_source.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <mbgl/annotation/render_annotation_source.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/renderer/painter.hpp>

#include <mbgl/algorithm/generate_clip_ids.hpp>
#include <mbgl/algorithm/generate_clip_ids_impl.hpp>
Expand Down Expand Up @@ -43,9 +44,9 @@ void RenderAnnotationSource::update(Immutable<style::Source::Impl> baseImpl_,
});
}

void RenderAnnotationSource::startRender(algorithm::ClipIDGenerator& generator, const mat4& projMatrix, const mat4& clipMatrix, const TransformState& transform) {
generator.update(tilePyramid.getRenderTiles());
tilePyramid.startRender(projMatrix, clipMatrix, transform);
void RenderAnnotationSource::startRender(Painter& painter) {
painter.clipIDGenerator.update(tilePyramid.getRenderTiles());
tilePyramid.startRender(painter);
}

void RenderAnnotationSource::finishRender(Painter& painter) {
Expand Down
5 changes: 1 addition & 4 deletions src/mbgl/annotation/render_annotation_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class RenderAnnotationSource : public RenderSource {
bool needsRelayout,
const TileParameters&) final;

void startRender(algorithm::ClipIDGenerator&,
const mat4& projMatrix,
const mat4& clipMatrix,
const TransformState&) final;
void startRender(Painter&) final;
void finishRender(Painter&) final;

std::map<UnwrappedTileID, RenderTile>& getRenderTiles() final;
Expand Down
101 changes: 0 additions & 101 deletions src/mbgl/geometry/binpack.hpp

This file was deleted.

7 changes: 3 additions & 4 deletions src/mbgl/gl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,9 @@ std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const Textu
const size_t stride = size.width * (format == TextureFormat::RGBA ? 4 : 1);
auto data = std::make_unique<uint8_t[]>(stride * size.height);

#if not MBGL_USE_GLES2
// When reading data from the framebuffer, make sure that we are storing the values
// tightly packed into the buffer to avoid buffer overruns.
pixelStorePack = { 1 };
#endif // MBGL_USE_GLES2

MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height, static_cast<GLenum>(format),
GL_UNSIGNED_BYTE, data.get()));
Expand Down Expand Up @@ -399,6 +397,7 @@ Context::createFramebuffer(const Texture& color,
UniqueTexture
Context::createTexture(const Size size, const void* data, TextureFormat format, TextureUnit unit) {
auto obj = createTexture();
pixelStoreUnpack = { 1 };
updateTexture(obj, size, data, format, unit);
// We are using clamp to edge here since OpenGL ES doesn't allow GL_REPEAT on NPOT textures.
// We use those when the pixelRatio isn't a power of two, e.g. on iPhone 6 Plus.
Expand Down Expand Up @@ -489,12 +488,12 @@ void Context::setDirtyState() {
program.setDirty();
lineWidth.setDirty();
activeTexture.setDirty();
pixelStorePack.setDirty();
pixelStoreUnpack.setDirty();
#if not MBGL_USE_GLES2
pointSize.setDirty();
pixelZoom.setDirty();
rasterPos.setDirty();
pixelStorePack.setDirty();
pixelStoreUnpack.setDirty();
pixelTransferDepth.setDirty();
pixelTransferStencil.setDirty();
#endif // MBGL_USE_GLES2
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/gl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ class Context : private util::noncopyable {
State<value::BindVertexBuffer> vertexBuffer;
State<value::BindElementBuffer> elementBuffer;

State<value::PixelStorePack> pixelStorePack;
State<value::PixelStoreUnpack> pixelStoreUnpack;

#if not MBGL_USE_GLES2
State<value::PixelZoom> pixelZoom;
State<value::RasterPos> rasterPos;
State<value::PixelStorePack> pixelStorePack;
State<value::PixelStoreUnpack> pixelStoreUnpack;
State<value::PixelTransferDepth> pixelTransferDepth;
State<value::PixelTransferStencil> pixelTransferStencil;
#endif // MBGL_USE_GLES2
Expand Down
4 changes: 0 additions & 4 deletions src/mbgl/gl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ enum class PrimitiveType {
TriangleFan = 0x0006
};

#if not MBGL_USE_GLES2

struct PixelStorageType {
int32_t alignment;
};
Expand All @@ -76,8 +74,6 @@ constexpr bool operator!=(const PixelStorageType& a, const PixelStorageType& b)
return a.alignment != b.alignment;
}

#endif // MBGL_USE_GLES2

using BinaryProgramFormat = uint32_t;

} // namespace gl
Expand Down
56 changes: 28 additions & 28 deletions src/mbgl/gl/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,34 @@ BindVertexArray::Type BindVertexArray::Get(const Context& context) {
return binding;
}

const constexpr PixelStorePack::Type PixelStorePack::Default;

void PixelStorePack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, value.alignment));
}

PixelStorePack::Type PixelStorePack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_PACK_ALIGNMENT, &value.alignment));
return value;
}

const constexpr PixelStoreUnpack::Type PixelStoreUnpack::Default;

void PixelStoreUnpack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, value.alignment));
}

PixelStoreUnpack::Type PixelStoreUnpack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_UNPACK_ALIGNMENT, &value.alignment));
return value;
}

#if not MBGL_USE_GLES2

const constexpr PointSize::Type PointSize::Default;
Expand Down Expand Up @@ -392,34 +420,6 @@ RasterPos::Type RasterPos::Get() {
return { pos[0], pos[1], pos[2], pos[3] };
}

const constexpr PixelStorePack::Type PixelStorePack::Default;

void PixelStorePack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_PACK_ALIGNMENT, value.alignment));
}

PixelStorePack::Type PixelStorePack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_PACK_ALIGNMENT, &value.alignment));
return value;
}

const constexpr PixelStoreUnpack::Type PixelStoreUnpack::Default;

void PixelStoreUnpack::Set(const Type& value) {
assert(value.alignment == 1 || value.alignment == 2 || value.alignment == 4 ||
value.alignment == 8);
MBGL_CHECK_ERROR(glPixelStorei(GL_UNPACK_ALIGNMENT, value.alignment));
}

PixelStoreUnpack::Type PixelStoreUnpack::Get() {
Type value;
MBGL_CHECK_ERROR(glGetIntegerv(GL_UNPACK_ALIGNMENT, &value.alignment));
return value;
}

const constexpr PixelTransferDepth::Type PixelTransferDepth::Default;

void PixelTransferDepth::Set(const Type& value) {
Expand Down
Loading