Merge pull request #1325 from mapbox/1325-simplify-render-path

Simplify render path
This commit is contained in:
Konstantin Käfer
2015-05-04 17:49:26 +02:00
57 changed files with 851 additions and 328 deletions

View File

@@ -12,6 +12,7 @@
'sources': [
'../platform/android/log_android.cpp',
'../platform/android/asset_root.cpp',
'../platform/default/thread.cpp',
'../platform/default/string_stdlib.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',

View File

@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
'../platform/darwin/reachability.m',
'../include/mbgl/ios/MapboxGL.h',
'../include/mbgl/ios/MGLMapboxEvents.h',

View File

@@ -14,6 +14,7 @@
'../platform/default/string_stdlib.cpp',
'../platform/default/application_root.cpp',
'../platform/default/asset_root.cpp',
'../platform/default/thread.cpp',
'../platform/default/image.cpp',
'../platform/default/image_reader.cpp',
'../platform/default/png_reader.cpp',

View File

@@ -15,6 +15,7 @@
'../platform/darwin/application_root.mm',
'../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
],
'variables': {

View File

@@ -159,7 +159,7 @@ inline void start_group(const std::string &str) {
if (gl::PushDebugGroup != nullptr) {
MBGL_CHECK_ERROR(gl::PushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, GLsizei(str.size()), str.c_str()));
} else if (gl::PushGroupMarkerEXT != nullptr) {
MBGL_CHECK_ERROR(gl::PushGroupMarkerEXT(GLsizei(str.size()), str.c_str()));
MBGL_CHECK_ERROR(gl::PushGroupMarkerEXT(GLsizei(str.size() + 1), str.c_str()));
}
// fprintf(stderr, "%s%s\n", std::string(indent * 4, ' ').c_str(), str.c_str());
// indent++;

View File

@@ -21,6 +21,9 @@ const std::string &applicationRoot();
// Returns the path to the asset location.
const std::string &assetRoot();
// Makes the current thread low priority.
void makeThreadLowPriority();
// Shows an alpha image with the specified dimensions in a named window.
void showDebugImage(std::string name, const char *data, size_t width, size_t height);

View File

@@ -0,0 +1,87 @@
#ifndef MBGL_UTIL_GL_HELPER
#define MBGL_UTIL_GL_HELPER
#include <mbgl/platform/gl.hpp>
#include <array>
namespace {
template <typename T, T (*Create)(), void (*Destroy)(const T&)>
class Preserve {
public:
Preserve() : data(Create()) {}
~Preserve() { Destroy(data); }
private:
const T data;
};
inline bool getBlend() {
return glIsEnabled(GL_BLEND);
}
inline void setBlend(const bool& enabled) {
enabled ? MBGL_CHECK_ERROR(glEnable(GL_BLEND)) : MBGL_CHECK_ERROR(glDisable(GL_BLEND));
}
inline std::array<double, 4> getClearColor() {
std::array<double, 4> color;
MBGL_CHECK_ERROR(glGetDoublev(GL_COLOR_CLEAR_VALUE, color.data()));
return color;
}
inline void setClearColor(const std::array<double, 4>& color) {
MBGL_CHECK_ERROR(glClearColor(color[0], color[1], color[2], color[3]));
}
inline std::array<GLenum, 2> getBlendFunc() {
GLint func[2];
glGetIntegerv(GL_BLEND_SRC, &func[0]);
glGetIntegerv(GL_BLEND_DST, &func[1]);
return {{ static_cast<GLenum>(func[0]), static_cast<GLenum>(func[1]) }};
}
inline void setBlendFunc(const std::array<GLenum, 2>& func) {
MBGL_CHECK_ERROR(glBlendFunc(func[0], func[1]));
}
inline std::array<double, 2> getPixelZoom() {
std::array<double, 2> zoom;
glGetDoublev(GL_ZOOM_X, &zoom[0]);
glGetDoublev(GL_ZOOM_Y, &zoom[1]);
return zoom;
}
inline void setPixelZoom(const std::array<double, 2>& func) {
MBGL_CHECK_ERROR(glPixelZoom(func[0], func[1]));
}
inline std::array<double, 4> getRasterPos() {
std::array<double, 4> pos;
MBGL_CHECK_ERROR(glGetDoublev(GL_CURRENT_RASTER_POSITION, pos.data()));
return pos;
}
inline void setRasterPos(const std::array<double, 4>& pos) {
MBGL_CHECK_ERROR(glRasterPos4d(pos[0], pos[1], pos[2], pos[3]));
}
} // end anonymous namespace
namespace mbgl {
namespace gl {
using PreserveBlend = Preserve<bool, getBlend, setBlend>;
using PreserveClearColor = Preserve<std::array<double, 4>, getClearColor, setClearColor>;
using PreserveBlendFunc = Preserve<std::array<GLenum, 2>, getBlendFunc, setBlendFunc>;
using PreservePixelZoom = Preserve<std::array<double, 2>, getPixelZoom, setPixelZoom>;
using PreserveRasterPos = Preserve<std::array<double, 4>, getRasterPos, setRasterPos>;
}
}
#endif

View File

@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
#include <mbgl/platform/platform.hpp>
namespace mbgl {
namespace platform {
void makeThreadLowPriority() {
[[NSThread currentThread] setThreadPriority:0.0];
}
}
}

View File

@@ -1,6 +1,7 @@
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/gl_helper.hpp>
#include <cassert>
#include <pthread.h>
@@ -333,15 +334,20 @@ void showDebugImage(std::string name, const char *data, size_t width, size_t hei
glfwGetFramebufferSize(debugWindow, &fbWidth, &fbHeight);
float scale = static_cast<float>(fbWidth) / static_cast<float>(width);
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data));
{
gl::PreservePixelZoom pixelZoom;
gl::PreserveRasterPos rasterPos;
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data));
}
glfwSwapBuffers(debugWindow);
glfwMakeContextCurrent(currentWindow);
}
void showColorDebugImage(std::string name, const char *data, size_t logicalWidth, size_t logicalHeight, size_t width, size_t height) {
glfwInit();
@@ -365,14 +371,22 @@ void showColorDebugImage(std::string name, const char *data, size_t logicalWidth
float xScale = static_cast<float>(fbWidth) / static_cast<float>(width);
float yScale = static_cast<float>(fbHeight) / static_cast<float>(height);
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
{
gl::PreserveClearColor clearColor;
gl::PreserveBlend blend;
gl::PreserveBlendFunc blendFunc;
gl::PreservePixelZoom pixelZoom;
gl::PreserveRasterPos rasterPos;
MBGL_CHECK_ERROR(glClearColor(0.8, 0.8, 0.8, 1));
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data));
}
MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data));
glfwSwapBuffers(debugWindow);
glfwMakeContextCurrent(currentWindow);

View File

@@ -62,7 +62,7 @@ std::string unifyMapboxURLs(const std::string &url) {
using namespace mapbox::sqlite;
SQLiteCache::SQLiteCache(const std::string& path_)
: thread(util::make_unique<util::Thread<Impl>>("SQLite Cache", path_)) {
: thread(util::make_unique<util::Thread<Impl>>("SQLite Cache", util::ThreadPriority::Low, path_)) {
}
SQLiteCache::~SQLiteCache() = default;

View File

@@ -0,0 +1,11 @@
#include <mbgl/platform/platform.hpp>
namespace mbgl {
namespace platform {
void makeThreadLowPriority() {
// no-op
}
}
}

View File

@@ -249,6 +249,12 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
gl::IsVertexArray = glIsVertexArrayOES;
}
if (extensions.find("GL_EXT_debug_marker") != std::string::npos) {
gl::InsertEventMarkerEXT = glInsertEventMarkerEXT;
gl::PushGroupMarkerEXT = glPushGroupMarkerEXT;
gl::PopGroupMarkerEXT = glPopGroupMarkerEXT;
}
if (extensions.find("GL_OES_packed_depth_stencil") != std::string::npos) {
gl::isPackedDepthStencilSupported = YES;
}

View File

@@ -2,6 +2,7 @@
#define MBGL_GEOMETRY_BUFFER
#include <mbgl/platform/gl.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/map/environment.hpp>
@@ -38,17 +39,16 @@ public:
}
// Transfers this buffer to the GPU and binds the buffer to the GL context.
void bind(bool force = false) {
if (buffer == 0) {
void bind() {
if (buffer) {
MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
} else {
MBGL_CHECK_ERROR(glGenBuffers(1, &buffer));
force = true;
}
MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
if (force) {
MBGL_CHECK_ERROR(glBindBuffer(bufferType, buffer));
if (array == nullptr) {
throw std::runtime_error("Buffer was already deleted or doesn't contain elements");
Log::Debug(Event::OpenGL, "Buffer doesn't contain elements");
pos = 0;
}
MBGL_CHECK_ERROR(glBufferData(bufferType, pos, array, GL_STATIC_DRAW));
if (!retainAfterUpload) {
cleanup();
@@ -67,6 +67,13 @@ public:
return buffer;
}
// Uploads the buffer to the GPU to be available when we need it.
inline void upload() {
if (!buffer) {
bind();
}
}
protected:
// increase the buffer size by at least /required/ bytes.
inline void *addElement() {

View File

@@ -124,8 +124,6 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
}
}
dirty = true;
bin.release(rect);
// Make sure to post-increment the iterator: This will return the
@@ -140,6 +138,47 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) {
}
}
void GlyphAtlas::upload() {
if (dirty) {
const bool first = !texture;
bind();
std::lock_guard<std::mutex> lock(mtx);
if (first) {
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
GL_ALPHA, // GLint internalformat
width, // GLsizei width
height, // GLsizei height
0, // GLint border
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data.get() // const GLvoid* data
));
} else {
MBGL_CHECK_ERROR(glTexSubImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
0, // GLint xoffset
0, // GLint yoffset
width, // GLsizei width
height, // GLsizei height
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data.get() // const GLvoid* data
));
}
dirty = false;
#if defined(DEBUG)
// platform::showDebugImage("Glyph Atlas", data.get(), width, height);
#endif
}
}
void GlyphAtlas::bind() {
if (!texture) {
MBGL_CHECK_ERROR(glGenTextures(1, &texture));
@@ -154,14 +193,4 @@ void GlyphAtlas::bind() {
} else {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
if (dirty) {
std::lock_guard<std::mutex> lock(mtx);
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data.get()));
dirty = false;
#if defined(DEBUG)
// platform::showDebugImage("Glyph Atlas", data, width, height);
#endif
}
};

View File

@@ -24,8 +24,13 @@ public:
GlyphPositions&);
void removeGlyphs(uintptr_t tileUID);
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
void bind();
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
void upload();
const uint16_t width = 0;
const uint16_t height = 0;

View File

@@ -129,6 +129,12 @@ LinePatternPos LineAtlas::addDash(const std::vector<float> &dasharray, bool roun
return position;
};
void LineAtlas::upload() {
if (dirty) {
bind();
}
}
void LineAtlas::bind() {
std::lock_guard<std::recursive_mutex> lock(mtx);
@@ -147,7 +153,7 @@ void LineAtlas::bind() {
if (dirty) {
if (first) {
glTexImage2D(
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
GL_ALPHA, // GLint internalformat
@@ -157,9 +163,9 @@ void LineAtlas::bind() {
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid * data
);
));
} else {
glTexSubImage2D(
MBGL_CHECK_ERROR(glTexSubImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
0, // GLint xoffset
@@ -169,7 +175,7 @@ void LineAtlas::bind() {
GL_ALPHA, // GLenum format
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid *pixels
);
));
}

View File

@@ -19,8 +19,13 @@ public:
LineAtlas(uint16_t width, uint16_t height);
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
void bind();
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
void upload();
LinePatternPos getDashPosition(const std::vector<float>&, bool);
LinePatternPos addDash(const std::vector<float> &dasharray, bool round);

View File

@@ -58,6 +58,7 @@ bool SpriteAtlas::resize(const float newRatio) {
::operator delete(old_data);
dirty = true;
fullUploadRequired = true;
// Mark all sprite images as in need of update
for (const auto &pair : images) {
@@ -230,8 +231,13 @@ void SpriteAtlas::setSprite(util::ptr<Sprite> sprite_) {
});
}
void SpriteAtlas::upload() {
if (dirty) {
bind();
}
}
void SpriteAtlas::bind(bool linear) {
bool first = false;
if (!texture) {
MBGL_CHECK_ERROR(glGenTextures(1, &texture));
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
@@ -242,7 +248,7 @@ void SpriteAtlas::bind(bool linear) {
// We use those when the pixelRatio isn't a power of two, e.g. on iPhone 6 Plus.
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
first = true;
fullUploadRequired = true;
} else {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
@@ -258,7 +264,7 @@ void SpriteAtlas::bind(bool linear) {
std::lock_guard<std::recursive_mutex> lock(mtx);
allocate();
if (first) {
if (fullUploadRequired) {
MBGL_CHECK_ERROR(glTexImage2D(
GL_TEXTURE_2D, // GLenum target
0, // GLint level
@@ -270,6 +276,7 @@ void SpriteAtlas::bind(bool linear) {
GL_UNSIGNED_BYTE, // GLenum type
data // const GLvoid * data
));
fullUploadRequired = false;
} else {
MBGL_CHECK_ERROR(glTexSubImage2D(
GL_TEXTURE_2D, // GLenum target

View File

@@ -50,10 +50,13 @@ public:
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.
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
void bind(bool linear = false);
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
void upload();
inline float getWidth() const { return width; }
inline float getHeight() const { return height; }
inline float getTextureWidth() const { return width * pixelRatio; }
@@ -76,6 +79,7 @@ private:
std::set<std::string> uninitialized;
uint32_t *data = nullptr;
std::atomic<bool> dirty;
bool fullUploadRequired = true;
uint32_t texture = 0;
uint32_t filter = 0;
static const int buffer = 1;

View File

@@ -11,7 +11,7 @@ namespace mbgl {
Map::Map(View& view, FileSource& fileSource, MapMode mode, bool startPaused)
: data(util::make_unique<MapData>(view, mode)),
context(util::make_unique<util::Thread<MapContext>>("Map", view, fileSource, *data, startPaused))
context(util::make_unique<util::Thread<MapContext>>("Map", util::ThreadPriority::Regular, view, fileSource, *data, startPaused))
{
view.initialize(this);
}

View File

@@ -23,10 +23,6 @@ void RasterTileData::parse() {
}
}
void RasterTileData::render(Painter &painter, const StyleLayer &layer_desc, const mat4 &matrix) {
bucket.render(painter, layer_desc, id, matrix);
}
bool RasterTileData::hasData(StyleLayer const& /*layer_desc*/) const {
return bucket.hasData();
Bucket* RasterTileData::getBucket(StyleLayer const&) {
return &bucket;
}

View File

@@ -20,8 +20,7 @@ public:
~RasterTileData();
void parse() override;
void render(Painter &painter, const StyleLayer &layer_desc, const mat4 &matrix) override;
bool hasData(StyleLayer const &layer_desc) const override;
Bucket* getBucket(StyleLayer const &layer_desc) override;
protected:
StyleLayoutRaster layout;

View File

@@ -184,16 +184,6 @@ void Source::drawClippingMasks(Painter &painter) {
}
}
void Source::render(Painter &painter, const StyleLayer &layer_desc) {
gl::group group(std::string { "layer: " } + layer_desc.id);
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
if (tile.data && tile.data->state == TileData::State::parsed) {
painter.renderTileLayer(tile, layer_desc, tile.matrix);
}
}
}
void Source::finishRender(Painter &painter) {
for (const auto& pair : tiles) {
Tile &tile = *pair.second;
@@ -212,6 +202,9 @@ std::forward_list<Tile *> Source::getLoadedTiles() const {
return ptrs;
}
const std::vector<Tile*>& Source::getTiles() const {
return tilePtrs;
}
TileData::State Source::hasTile(const TileID& id) {
auto it = tiles.find(id);
@@ -455,6 +448,8 @@ void Source::update(MapData& data,
}
});
updateTilePtrs();
updated = data.getAnimationTime();
}
@@ -464,6 +459,14 @@ void Source::invalidateTiles(const std::vector<TileID>& ids) {
tiles.erase(id);
tile_data.erase(id);
}
updateTilePtrs();
}
void Source::updateTilePtrs() {
tilePtrs.clear();
for (const auto& pair : tiles) {
tilePtrs.push_back(pair.second.get());
}
}
void Source::setCacheSize(size_t size) {

View File

@@ -29,7 +29,6 @@ class Sprite;
class TexturePool;
class Style;
class Painter;
class StyleLayer;
class TransformState;
class Tile;
struct ClipID;
@@ -76,10 +75,10 @@ public:
void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
void render(Painter &painter, const StyleLayer &layer_desc);
void finishRender(Painter &painter);
std::forward_list<Tile *> getLoadedTiles() const;
const std::vector<Tile*>& getTiles() const;
void setCacheSize(size_t);
void onLowMemory();
@@ -105,6 +104,7 @@ private:
std::function<void()> callback);
TileData::State hasTile(const TileID& id);
void updateTilePtrs();
double getZoom(const TransformState &state) const;
@@ -114,6 +114,7 @@ private:
TimePoint updated = TimePoint::min();
std::map<TileID, std::unique_ptr<Tile>> tiles;
std::vector<Tile*> tilePtrs;
std::map<TileID, std::weak_ptr<TileData>> tile_data;
TileCache cache;
};

View File

@@ -47,8 +47,7 @@ public:
// Override this in the child class.
virtual void parse() = 0;
virtual void render(Painter &painter, const StyleLayer &layer_desc, const mat4 &matrix) = 0;
virtual bool hasData(StyleLayer const &layer_desc) const = 0;
virtual Bucket* getBucket(StyleLayer const &layer_desc) = 0;
const TileID id;
const std::string name;

View File

@@ -157,7 +157,7 @@ std::unique_ptr<Bucket> TileParser::createFillBucket(const GeometryTileLayer& la
tile.triangleElementsBuffer,
tile.lineElementsBuffer);
addBucketGeometries(bucket, layer, bucket_desc.filter);
return std::move(bucket);
return bucket->hasData() ? std::move(bucket) : nullptr;
}
std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& layer,
@@ -174,7 +174,7 @@ std::unique_ptr<Bucket> TileParser::createLineBucket(const GeometryTileLayer& la
applyLayoutProperty(PropertyKey::LineRoundLimit, bucket_desc.layout, layout.round_limit, z);
addBucketGeometries(bucket, layer, bucket_desc.filter);
return std::move(bucket);
return bucket->hasData() ? std::move(bucket) : nullptr;
}
std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer& layer,
@@ -224,6 +224,6 @@ std::unique_ptr<Bucket> TileParser::createSymbolBucket(const GeometryTileLayer&
bucket->addFeatures(
layer, bucket_desc.filter, reinterpret_cast<uintptr_t>(&tile), spriteAtlas, *sprite, glyphAtlas, glyphStore);
return std::move(bucket);
return bucket->hasData() ? std::move(bucket) : nullptr;
}
}

View File

@@ -55,23 +55,13 @@ void VectorTileData::parse() {
}
}
void VectorTileData::render(Painter &painter, const StyleLayer &layer_desc, const mat4 &matrix) {
if (state == State::parsed && layer_desc.bucket) {
auto databucket_it = buckets.find(layer_desc.bucket->name);
if (databucket_it != buckets.end()) {
assert(databucket_it->second);
databucket_it->second->render(painter, layer_desc, id, matrix);
Bucket* VectorTileData::getBucket(StyleLayer const& layer) {
if (state == State::parsed && layer.bucket) {
const auto it = buckets.find(layer.bucket->name);
if (it != buckets.end()) {
assert(it->second);
return it->second.get();
}
}
}
bool VectorTileData::hasData(const StyleLayer &layer_desc) const {
if (state == State::parsed && layer_desc.bucket) {
auto databucket_it = buckets.find(layer_desc.bucket->name);
if (databucket_it != buckets.end()) {
assert(databucket_it->second);
return databucket_it->second->hasData();
}
}
return false;
return nullptr;
}

View File

@@ -40,8 +40,7 @@ public:
~VectorTileData();
void parse() override;
void render(Painter &painter, const StyleLayer &layer_desc, const mat4 &matrix) override;
bool hasData(StyleLayer const& layer_desc) const override;
virtual Bucket* getBucket(StyleLayer const &layer_desc) override;
protected:
// Holds the actual geometries in this tile.

View File

@@ -1,6 +1,7 @@
#ifndef MBGL_RENDERER_BUCKET
#define MBGL_RENDERER_BUCKET
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/mat4.hpp>
@@ -12,10 +13,23 @@ class TileID;
class Bucket : private util::noncopyable {
public:
// As long as this bucket has a Prepare render pass, this function is getting called. Typically,
// this only happens once when the bucket is being rendered for the first time.
virtual void upload() = 0;
// Every time this bucket is getting rendered, this function is called. This happens either
// once or twice (for Opaque and Transparent render passes).
virtual void render(Painter&, const StyleLayer&, const TileID&, const mat4&) = 0;
virtual bool hasData() const = 0;
virtual ~Bucket() {}
inline bool needsUpload() const {
return !uploaded;
}
protected:
bool uploaded = false;
};
}

View File

@@ -16,13 +16,14 @@ DebugBucket::DebugBucket(DebugFontBuffer& fontBuffer_)
: fontBuffer(fontBuffer_) {
}
void DebugBucket::render(Painter &painter, const StyleLayer & /*layer_desc*/,
const TileID & /*id*/, const mat4 &matrix) {
painter.renderDebugText(*this, matrix);
void DebugBucket::upload() {
fontBuffer.upload();
uploaded = true;
}
bool DebugBucket::hasData() const {
return fontBuffer.index() > 0;
void DebugBucket::render(Painter& painter, const StyleLayer&, const TileID&, const mat4& matrix) {
painter.renderDebugText(*this, matrix);
}
void DebugBucket::drawLines(PlainShader& shader) {

View File

@@ -15,9 +15,8 @@ class DebugBucket : public Bucket {
public:
DebugBucket(DebugFontBuffer& fontBuffer);
void render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) override;
bool hasData() const override;
void upload() override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
void drawLines(PlainShader& shader);
void drawPoints(PlainShader& shader);

View File

@@ -200,8 +200,19 @@ void FillBucket::tessellate() {
lineGroup.vertex_length += total_vertex_count;
}
void FillBucket::render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) {
void FillBucket::upload() {
vertexBuffer.upload();
triangleElementsBuffer.upload();
lineElementsBuffer.upload();
// From now on, we're going to render during the opaque and translucent pass.
uploaded = true;
}
void FillBucket::render(Painter& painter,
const StyleLayer& layer_desc,
const TileID& id,
const mat4& matrix) {
painter.renderFill(*this, layer_desc, id, matrix);
}

View File

@@ -33,9 +33,9 @@ public:
LineElementsBuffer &lineElementsBuffer);
~FillBucket() override;
void render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) override;
bool hasData() const override;
void upload() override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const;
void addGeometry(const GeometryCollection&);
void tessellate();

View File

@@ -0,0 +1,19 @@
#include "gl_config.hpp"
namespace mbgl {
namespace gl {
const ClearDepth::Type ClearDepth::Default = 0;
const ClearColor::Type ClearColor::Default = { 0, 0, 0, 0 };
const ClearStencil::Type ClearStencil::Default = 0;
const StencilMask::Type StencilMask::Default = ~0u;
const DepthMask::Type DepthMask::Default = GL_TRUE;
const ColorMask::Type ColorMask::Default = { false, false, false, false };
const StencilFunc::Type StencilFunc::Default = { GL_ALWAYS, 0, ~0u };
const StencilTest::Type StencilTest::Default = false;
const DepthRange::Type DepthRange::Default = { 0, 1 };
const DepthTest::Type DepthTest::Default = false;
const Blend::Type Blend::Default = false;
}
}

View File

@@ -0,0 +1,149 @@
#ifndef MBGL_RENDERER_GL_CONFIG
#define MBGL_RENDERER_GL_CONFIG
#include <cstdint>
#include <tuple>
#include <array>
#include <mbgl/platform/gl.hpp>
namespace mbgl {
namespace gl {
template <typename T>
class Value {
public:
inline void operator=(const typename T::Type& value) {
if (current != value) {
current = value;
MBGL_CHECK_ERROR(T::Set(current));
}
}
private:
typename T::Type current = T::Default;
};
struct ClearDepth {
using Type = GLfloat;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glClearDepth(value));
}
};
struct ClearColor {
struct Type { float r, g, b, a; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a));
}
};
inline bool operator!=(const ClearColor::Type& a, const ClearColor::Type& b) {
return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
}
struct ClearStencil {
using Type = GLint;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glClearStencil(value));
}
};
struct StencilMask {
using Type = GLuint;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glStencilMask(value));
}
};
struct DepthMask {
using Type = GLboolean;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glDepthMask(value));
}
};
struct ColorMask {
struct Type { bool r, g, b, a; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glColorMask(value.r, value.g, value.b, value.a));
}
};
inline bool operator!=(const ColorMask::Type& a, const ColorMask::Type& b) {
return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
}
struct StencilFunc {
struct Type { GLenum func; GLint ref; GLuint mask; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glStencilFunc(value.func, value.ref, value.mask));
}
};
inline bool operator!=(const StencilFunc::Type& a, const StencilFunc::Type& b) {
return a.func != b.func || a.ref != b.ref || a.mask != b.mask;
}
struct StencilTest {
using Type = bool;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(value ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST));
}
};
struct DepthRange {
struct Type { GLfloat near, far; };
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glDepthRange(value.near, value.far));
}
};
inline bool operator!=(const DepthRange::Type& a, const DepthRange::Type& b) {
return a.near != b.near || a.far != b.far;
}
struct DepthTest {
using Type = bool;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(value ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST));
}
};
struct Blend {
using Type = bool;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(value ? glEnable(GL_BLEND) : glDisable(GL_BLEND));
}
};
class Config {
public:
Value<StencilFunc> stencilFunc;
Value<StencilMask> stencilMask;
Value<StencilTest> stencilTest;
Value<DepthRange> depthRange;
Value<DepthMask> depthMask;
Value<DepthTest> depthTest;
Value<Blend> blend;
Value<ColorMask> colorMask;
Value<ClearDepth> clearDepth;
Value<ClearColor> clearColor;
Value<ClearStencil> clearStencil;
};
}
}
#endif

View File

@@ -342,6 +342,14 @@ void LineBucket::addCurrentVertex(const Coordinate& currentVertex,
e2 = e3;
}
void LineBucket::upload() {
vertexBuffer.upload();
triangleElementsBuffer.upload();
// From now on, we're only going to render during the translucent pass.
uploaded = true;
}
void LineBucket::render(Painter& painter,
const StyleLayer& layer_desc,
const TileID& id,

View File

@@ -28,9 +28,9 @@ public:
LineBucket(LineVertexBuffer &vertexBuffer, TriangleElementsBuffer &triangleElementsBuffer);
~LineBucket() override;
void render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) override;
bool hasData() const override;
void upload() override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const;
void addGeometry(const GeometryCollection&);
void addGeometry(const std::vector<Coordinate>& line);

View File

@@ -10,6 +10,8 @@
#include <mbgl/style/style_bucket.hpp>
#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/geometry/line_atlas.hpp>
#include <mbgl/geometry/glyph_atlas.hpp>
#include <mbgl/shader/pattern_shader.hpp>
#include <mbgl/shader/plain_shader.hpp>
@@ -23,7 +25,6 @@
#include <mbgl/shader/dot_shader.hpp>
#include <mbgl/shader/gaussian_shader.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/mat3.hpp>
@@ -87,16 +88,15 @@ void Painter::setup() {
// We are blending new pixels on top of old pixels. Since we have depth testing
// and are drawing opaque fragments first front-to-back, then translucent
// fragments back-to-front, this shades the fewest fragments possible.
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
config.blend = true;
MBGL_CHECK_ERROR(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// Set clear values
MBGL_CHECK_ERROR(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
MBGL_CHECK_ERROR(glClearDepth(1.0f));
MBGL_CHECK_ERROR(glClearStencil(0x0));
config.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
config.clearDepth = 1.0f;
config.clearStencil = 0x0;
// Stencil test
MBGL_CHECK_ERROR(glEnable(GL_STENCIL_TEST));
MBGL_CHECK_ERROR(glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE));
// Depth test
@@ -144,21 +144,6 @@ void Painter::lineWidth(float line_width) {
}
}
void Painter::depthMask(bool value) {
if (gl_depthMask != value) {
MBGL_CHECK_ERROR(glDepthMask(value ? GL_TRUE : GL_FALSE));
gl_depthMask = value;
}
}
void Painter::depthRange(const float near, const float far) {
if (gl_depthRange[0] != near || gl_depthRange[1] != far) {
MBGL_CHECK_ERROR(glDepthRange(near, far));
gl_depthRange = {{ near, far }};
}
}
void Painter::changeMatrix() {
// Initialize projection matrix
matrix::ortho(projMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, 1);
@@ -176,24 +161,25 @@ void Painter::changeMatrix() {
void Painter::clear() {
gl::group group("clear");
MBGL_CHECK_ERROR(glStencilMask(0xFF));
depthMask(true);
MBGL_CHECK_ERROR(glClearColor(0, 0, 0, 0));
config.stencilTest = true;
config.stencilMask = 0xFF;
config.depthTest = false;
config.depthMask = GL_TRUE;
config.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
}
void Painter::setOpaque() {
if (pass != RenderPass::Opaque) {
pass = RenderPass::Opaque;
MBGL_CHECK_ERROR(glDisable(GL_BLEND));
config.blend = false;
}
}
void Painter::setTranslucent() {
if (pass != RenderPass::Translucent) {
pass = RenderPass::Translucent;
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
config.blend = true;
}
}
@@ -204,16 +190,12 @@ void Painter::setStrata(float value) {
void Painter::prepareTile(const Tile& tile) {
const GLint ref = (GLint)tile.clip.reference.to_ulong();
const GLuint mask = (GLuint)tile.clip.mask.to_ulong();
MBGL_CHECK_ERROR(glStencilFunc(GL_EQUAL, ref, mask));
config.stencilFunc = { GL_EQUAL, ref, mask };
}
void Painter::render(const Style& style, TransformState state_, TimePoint time) {
state = state_;
clear();
resize();
changeMatrix();
std::set<Source*> sources;
for (const auto& source : style.sources) {
if (source->enabled) {
@@ -221,14 +203,46 @@ void Painter::render(const Style& style, TransformState state_, TimePoint time)
}
}
// Update all clipping IDs.
ClipIDGenerator generator;
for (const auto& source : sources) {
generator.update(source->getLoadedTiles());
source->updateMatrices(projMatrix, state);
// Figure out what buckets we have to draw and what order we have to draw them in.
const auto order = determineRenderOrder(style);
// - UPLOAD PASS -------------------------------------------------------------------------------
// Uploads all required buffers and images before we do any actual rendering.
{
const gl::group upload("upload");
tileStencilBuffer.upload();
tileBorderBuffer.upload();
spriteAtlas.upload();
lineAtlas.upload();
glyphAtlas.upload();
for (const auto& item : order) {
if (item.bucket && item.bucket->needsUpload()) {
item.bucket->upload();
}
}
}
drawClippingMasks(sources);
// - CLIPPING MASKS ----------------------------------------------------------------------------
// Draws the clipping masks to the stencil buffer.
{
const gl::group clip("clip");
// Update all clipping IDs.
ClipIDGenerator generator;
for (const auto& source : sources) {
generator.update(source->getLoadedTiles());
source->updateMatrices(projMatrix, state);
}
clear();
resize();
changeMatrix();
drawClippingMasks(sources);
}
frameHistory.record(time, state.getNormalizedZoom());
@@ -236,122 +250,169 @@ void Painter::render(const Style& style, TransformState state_, TimePoint time)
if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; }
// TODO: Correctly compute the number of layers recursively beforehand.
float strata_thickness = 1.0f / (style.layers.size() + 1);
const float strata_thickness = 1.0f / (order.size() + 1);
// - FIRST PASS ------------------------------------------------------------
// Render everything top-to-bottom by using reverse iterators. Render opaque
// objects first.
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", indent++ * 4, "", "OPAQUE {");
}
// Layer index
int i = 0;
for (auto it = style.layers.rbegin(), end = style.layers.rend(); it != end; ++it, ++i) {
// - OPAQUE PASS -------------------------------------------------------------------------------
// Render everything top-to-bottom by using reverse iterators. Render opaque objects first.
{
const gl::group _("opaque");
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", indent++ * 4, "", "OPAQUE {");
}
i = 0;
setOpaque();
setStrata(i * strata_thickness);
renderLayer(**it);
}
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}");
for (auto it = order.rbegin(), end = order.rend(); it != end; ++it, ++i) {
const auto& item = *it;
if (item.bucket && item.tile) {
if (item.hasRenderPass(RenderPass::Opaque)) {
const gl::group group(item.layer.id + " - " + std::string(item.tile->id));
setStrata(i * strata_thickness);
prepareTile(*item.tile);
item.bucket->render(*this, item.layer, item.tile->id, item.tile->matrix);
}
} else {
const gl::group group("background");
renderBackground(item.layer);
}
}
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}");
}
}
// - SECOND PASS -----------------------------------------------------------
// Make a second pass, rendering translucent objects. This time, we render
// bottom-to-top.
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", indent++ * 4, "", "TRANSLUCENT {");
}
--i;
for (auto it = style.layers.begin(), end = style.layers.end(); it != end; ++it, --i) {
// - TRANSLUCENT PASS --------------------------------------------------------------------------
// Make a second pass, rendering translucent objects. This time, we render bottom-to-top.
{
const gl::group _("translucent");
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", indent++ * 4, "", "TRANSLUCENT {");
}
--i; // After the last iteration, this is incremented, so we have to decrement it again.
setTranslucent();
setStrata(i * strata_thickness);
renderLayer(**it);
}
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}");
for (auto it = order.begin(), end = order.end(); it != end; ++it, --i) {
const auto& item = *it;
if (item.bucket && item.tile) {
if (item.hasRenderPass(RenderPass::Translucent)) {
const gl::group group(item.layer.id + " - " + std::string(item.tile->id));
setStrata(i * strata_thickness);
prepareTile(*item.tile);
item.bucket->render(*this, item.layer, item.tile->id, item.tile->matrix);
}
}
}
if (debug::renderTree) {
Log::Info(Event::Render, "%*s%s", --indent * 4, "", "}");
}
}
if (debug::renderTree) { Log::Info(Event::Render, "}"); 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 auto& source : sources) {
source->finishRender(*this);
// - DEBUG PASS --------------------------------------------------------------------------------
// Renders debug overlays.
{
const gl::group _("debug");
// 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 auto& source : sources) {
source->finishRender(*this);
}
}
// TODO: Find a better way to unbind VAOs after we're done with them without introducing
// unnecessary bind(0)/bind(N) sequences.
{
const gl::group _("cleanup");
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, 0));
MBGL_CHECK_ERROR(gl::BindVertexArray(0));
}
}
void Painter::renderLayer(const StyleLayer &layer_desc) {
if (layer_desc.bucket->visibility == VisibilityType::None) return;
if (layer_desc.type == StyleLayerType::Background) {
// This layer defines a background color/image.
std::vector<RenderItem> Painter::determineRenderOrder(const Style& style) {
std::vector<RenderItem> order;
if (debug::renderTree) {
Log::Info(Event::Render, "%*s- %s (%s)", indent * 4, "", layer_desc.id.c_str(),
StyleLayerTypeClass(layer_desc.type).c_str());
for (const auto& layerPtr : style.layers) {
const auto& layer = *layerPtr;
if (layer.bucket->visibility == VisibilityType::None) continue;
if (layer.type == StyleLayerType::Background) {
// This layer defines a background color/image.
order.emplace_back(layer);
continue;
}
renderBackground(layer_desc);
} else {
// This is a singular layer.
if (!layer_desc.bucket) {
Log::Warning(Event::Render, "layer '%s' is missing bucket", layer_desc.id.c_str());
return;
if (!layer.bucket) {
Log::Warning(Event::Render, "layer '%s' is missing bucket", layer.id.c_str());
continue;
}
if (!layer_desc.bucket->source) {
Log::Warning(Event::Render, "can't find source for layer '%s'", layer_desc.id.c_str());
return;
if (!layer.bucket->source) {
Log::Warning(Event::Render, "can't find source for layer '%s'", layer.id.c_str());
continue;
}
// 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;
if (layer.bucket->min_zoom > zoom ||
layer.bucket->max_zoom <= zoom) {
continue;
}
// 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<FillProperties>().isVisible()) return;
break;
case StyleLayerType::Line:
if (pass == RenderPass::Opaque) return;
if (!layer_desc.getProperties<LineProperties>().isVisible()) return;
break;
case StyleLayerType::Symbol:
if (pass == RenderPass::Opaque) return;
if (!layer_desc.getProperties<SymbolProperties>().isVisible()) return;
break;
case StyleLayerType::Raster:
if (pass == RenderPass::Opaque) return;
if (!layer_desc.getProperties<RasterProperties>().isVisible()) return;
break;
default:
break;
// Don't include invisible layers.
if (!layer.isVisible()) {
continue;
}
if (debug::renderTree) {
Log::Info(Event::Render, "%*s- %s (%s)", indent * 4, "", layer_desc.id.c_str(),
StyleLayerTypeClass(layer_desc.type).c_str());
}
// Determine what render passes we need for this layer.
const RenderPass passes = determineRenderPasses(layer);
layer_desc.bucket->source->render(*this, layer_desc);
const auto& tiles = layer.bucket->source->getTiles();
for (auto tile : tiles) {
assert(tile);
if (!tile->data && !tile->data->ready()) {
continue;
}
auto bucket = tile->data->getBucket(layer);
if (bucket) {
order.emplace_back(layer, tile, bucket, passes);
}
}
}
return order;
}
void Painter::renderTileLayer(const Tile& tile, const StyleLayer &layer_desc, const mat4 &matrix) {
assert(tile.data);
if (tile.data->hasData(layer_desc) || layer_desc.type == StyleLayerType::Raster) {
gl::group group(std::string { "render " } + tile.data->name);
prepareTile(tile);
tile.data->render(*this, layer_desc, matrix);
RenderPass Painter::determineRenderPasses(const StyleLayer& layer) {
RenderPass passes = RenderPass::None;
if (layer.properties.is<FillProperties>()) {
const FillProperties &properties = layer.properties.get<FillProperties>();
const float alpha = properties.fill_color[3] * properties.opacity;
if (properties.antialias) {
passes |= RenderPass::Translucent;
}
if (properties.image.from.size() || alpha < 1.0f) {
passes |= RenderPass::Translucent;
} else {
passes |= RenderPass::Opaque;
}
} else {
passes |= RenderPass::Translucent;
}
return passes;
}
void Painter::renderBackground(const StyleLayer &layer_desc) {
@@ -428,10 +489,10 @@ void Painter::renderBackground(const StyleLayer &layer_desc) {
backgroundArray.bind(*plainShader, backgroundBuffer, BUFFER_OFFSET(0));
}
MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST));
depthRange(strata + strata_epsilon, 1.0f);
config.stencilTest = false;
config.depthTest = true;
config.depthRange = { strata + strata_epsilon, 1.0f };
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
MBGL_CHECK_ERROR(glEnable(GL_STENCIL_TEST));
}
mat4 Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const TileID &id, TranslateAnchorType anchor) {

View File

@@ -4,10 +4,13 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/renderer/frame_history.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/geometry/vao.hpp>
#include <mbgl/geometry/static_vertex_buffer.hpp>
#include <mbgl/renderer/gl_config.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/platform/gl.hpp>
@@ -21,8 +24,6 @@
namespace mbgl {
enum class RenderPass : bool { Opaque, Translucent };
class Style;
class StyleLayer;
class Tile;
@@ -57,6 +58,24 @@ class GaussianShader;
struct ClipID;
struct RenderItem {
inline RenderItem(const StyleLayer& layer_,
const Tile* tile_ = nullptr,
Bucket* bucket_ = nullptr,
RenderPass passes_ = RenderPass::Opaque)
: tile(tile_), bucket(bucket_), layer(layer_), passes(passes_) {
}
const Tile* const tile;
Bucket* const bucket;
const StyleLayer& layer;
const RenderPass passes;
inline bool hasRenderPass(RenderPass pass) const {
return bool(passes & pass);
}
};
class Painter : private util::noncopyable {
public:
Painter(SpriteAtlas&, GlyphAtlas&, LineAtlas&);
@@ -75,11 +94,6 @@ public:
TransformState state,
TimePoint time);
void renderLayer(const StyleLayer&);
// Renders a particular layer from a tile.
void renderTileLayer(const Tile& tile, const StyleLayer &layer_desc, const mat4 &matrix);
// Renders debug information for a tile.
void renderTileDebug(const Tile& tile);
@@ -131,6 +145,9 @@ private:
void setupShaders();
mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const TileID &id, TranslateAnchorType anchor);
std::vector<RenderItem> determineRenderOrder(const Style& style);
static RenderPass determineRenderPasses(const StyleLayer&);
void prepareTile(const Tile& tile);
template <typename BucketProperties, typename StyleProperties>
@@ -147,8 +164,6 @@ private:
public:
void useProgram(uint32_t program);
void lineWidth(float lineWidth);
void depthMask(bool value);
void depthRange(float near, float far);
public:
mat4 projMatrix;
@@ -175,11 +190,11 @@ private:
bool debug = false;
int indent = 0;
gl::Config config;
uint32_t gl_program = 0;
float gl_lineWidth = 0;
bool gl_depthMask = true;
std::array<uint16_t, 2> gl_viewport = {{ 0, 0 }};
std::array<float, 2> gl_depthRange = {{ 0, 1 }};
float strata = 0;
RenderPass pass = RenderPass::Opaque;
const float strata_epsilon = 1.0f / (1 << 16);

View File

@@ -13,10 +13,11 @@ void Painter::drawClippingMasks(const std::set<Source*>& sources) {
gl::group group("clipping masks");
useProgram(plainShader->program);
MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
depthMask(false);
MBGL_CHECK_ERROR(glColorMask(false, false, false, false));
depthRange(1.0f, 1.0f);
config.stencilTest = true;
config.depthTest = true;
config.depthMask = GL_FALSE;
config.colorMask = { false, false, false, false };
config.depthRange = { 1.0f, 1.0f };
coveringPlainArray.bind(*plainShader, tileStencilBuffer, BUFFER_OFFSET(0));
@@ -24,10 +25,10 @@ void Painter::drawClippingMasks(const std::set<Source*>& sources) {
source->drawClippingMasks(*this);
}
MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
MBGL_CHECK_ERROR(glColorMask(true, true, true, true));
depthMask(true);
MBGL_CHECK_ERROR(glStencilMask(0x0));
config.depthTest = true;
config.colorMask = { true, true, true, true };
config.depthMask = GL_TRUE;
config.stencilMask = 0x0;
}
void Painter::drawClippingMask(const mat4& matrix, const ClipID &clip) {
@@ -35,8 +36,7 @@ void Painter::drawClippingMask(const mat4& matrix, const ClipID &clip) {
const GLint ref = (GLint)(clip.reference.to_ulong());
const GLuint mask = (GLuint)(clip.mask.to_ulong());
MBGL_CHECK_ERROR(glStencilFunc(GL_ALWAYS, ref, mask));
MBGL_CHECK_ERROR(glStencilMask(mask));
config.stencilFunc = { GL_ALWAYS, ref, mask };
config.stencilMask = mask;
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)tileStencilBuffer.index()));
}

View File

@@ -24,7 +24,7 @@ void Painter::renderTileDebug(const Tile& tile) {
void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) {
gl::group group("debug text");
MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
config.depthTest = false;
useProgram(plainShader->program);
plainShader->u_matrix = matrix;
@@ -45,7 +45,7 @@ void Painter::renderDebugText(DebugBucket& bucket, const mat4 &matrix) {
lineWidth(2.0f * state.getPixelRatio());
bucket.drawLines(*plainShader);
MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
config.depthTest = true;
}
void Painter::renderDebugFrame(const mat4 &matrix) {
@@ -54,7 +54,8 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
// Disable depth test and don't count this towards the depth buffer,
// but *don't* disable stencil test, as we want to clip the red tile border
// to the tile viewport.
MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
config.depthTest = false;
config.stencilTest = true;
useProgram(plainShader->program);
plainShader->u_matrix = matrix;
@@ -64,8 +65,6 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }};
lineWidth(4.0f * state.getPixelRatio());
MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));
MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
}
void Painter::renderDebugText(const std::vector<std::string> &strings) {
@@ -75,8 +74,9 @@ void Painter::renderDebugText(const std::vector<std::string> &strings) {
gl::group group("debug text");
MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
MBGL_CHECK_ERROR(glStencilFunc(GL_ALWAYS, 0xFF, 0xFF));
config.depthTest = false;
config.stencilTest = true;
config.stencilFunc = { GL_ALWAYS, 0xFF, 0xFF };
useProgram(plainShader->program);
plainShader->u_matrix = nativeMatrix;
@@ -103,6 +103,4 @@ void Painter::renderDebugText(const std::vector<std::string> &strings) {
lineWidth(2.0f * state.getPixelRatio());
MBGL_CHECK_ERROR(glDrawArrays(GL_LINES, 0, (GLsizei)debugFontBuffer.index()));
}
MBGL_CHECK_ERROR(glEnable(GL_DEPTH_TEST));
}

View File

@@ -15,9 +15,6 @@
using namespace mbgl;
void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const TileID& id, const mat4 &matrix) {
// Abort early.
if (!bucket.hasData()) return;
const FillProperties &properties = layer_desc.getProperties<FillProperties>();
mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor);
@@ -42,6 +39,9 @@ void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const
bool outline = properties.antialias && !pattern && stroke_color != fill_color;
bool fringeline = properties.antialias && !pattern && stroke_color == fill_color;
config.stencilTest = true;
config.depthTest = true;
// Because we're drawing top-to-bottom, and we update the stencil mask
// befrom, we have to draw the outline first (!)
if (outline && pass == RenderPass::Translucent) {
@@ -56,7 +56,7 @@ void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const
static_cast<float>(state.getFramebufferWidth()),
static_cast<float>(state.getFramebufferHeight())
}};
depthRange(strata, 1.0f);
config.depthRange = { strata, 1.0f };
bucket.drawVertices(*outlineShader);
}
@@ -95,8 +95,8 @@ void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const
spriteAtlas.bind(true);
// Draw the actual triangles into the color & stencil buffer.
depthMask(true);
depthRange(strata, 1.0f);
config.depthMask = GL_TRUE;
config.depthRange = { strata, 1.0f };
bucket.drawElements(*patternShader);
}
}
@@ -112,8 +112,8 @@ void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const
plainShader->u_color = fill_color;
// Draw the actual triangles into the color & stencil buffer.
depthMask(true);
depthRange(strata + strata_epsilon, 1.0f);
config.depthMask = GL_TRUE;
config.depthRange = { strata + strata_epsilon, 1.0f };
bucket.drawElements(*plainShader);
}
}
@@ -133,7 +133,7 @@ void Painter::renderFill(FillBucket& bucket, const StyleLayer &layer_desc, const
static_cast<float>(state.getFramebufferHeight())
}};
depthRange(strata + strata_epsilon + strata_epsilon, 1.0f);
config.depthRange = { strata + strata_epsilon + strata_epsilon, 1.0f };
bucket.drawVertices(*outlineShader);
}
}

View File

@@ -16,9 +16,10 @@ using namespace mbgl;
void Painter::renderLine(LineBucket& bucket, const StyleLayer &layer_desc, const TileID& id, const mat4 &matrix) {
// Abort early.
if (pass == RenderPass::Opaque) return;
if (!bucket.hasData()) return;
depthMask(false);
config.stencilTest = true;
config.depthTest = true;
config.depthMask = GL_FALSE;
const auto &properties = layer_desc.getProperties<LineProperties>();
const auto &layout = bucket.layout;
@@ -52,7 +53,7 @@ void Painter::renderLine(LineBucket& bucket, const StyleLayer &layer_desc, const
float ratio = state.getPixelRatio();
mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor);
depthRange(strata, 1.0f);
config.depthRange = { strata, 1.0f };
if (properties.dash_array.from.size()) {
@@ -110,7 +111,7 @@ void Painter::renderLine(LineBucket& bucket, const StyleLayer &layer_desc, const
MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0));
spriteAtlas.bind(true);
MBGL_CHECK_ERROR(glDepthRange(strata + strata_epsilon, 1.0f)); // may or may not matter
config.depthRange = { strata + strata_epsilon, 1.0f }; // may or may not matter
bucket.drawLinePatterns(*linepatternShader);

View File

@@ -23,8 +23,9 @@ void Painter::renderRaster(RasterBucket& bucket, const StyleLayer &layer_desc, c
rasterShader->u_contrast_factor = contrastFactor(properties.contrast);
rasterShader->u_spin_weights = spinWeights(properties.hue_rotate);
depthRange(strata + strata_epsilon, 1.0f);
config.stencilTest = true;
config.depthTest = true;
config.depthRange = { strata + strata_epsilon, 1.0f };
bucket.drawRaster(*rasterShader, tileStencilBuffer, coveringRasterArray);
}
}

View File

@@ -87,7 +87,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
sdfShader.u_buffer = (haloOffset - styleProperties.halo_width / fontScale) / sdfPx;
depthRange(strata, 1.0f);
config.depthRange = { strata, 1.0f };
(bucket.*drawSDF)(sdfShader);
}
@@ -108,7 +108,7 @@ void Painter::renderSDF(SymbolBucket &bucket,
sdfShader.u_buffer = (256.0f - 64.0f) / 256.0f;
depthRange(strata + strata_epsilon, 1.0f);
config.depthRange = { strata + strata_epsilon, 1.0f };
(bucket.*drawSDF)(sdfShader);
}
}
@@ -122,8 +122,9 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
const auto &properties = layer_desc.getProperties<SymbolProperties>();
const auto &layout = bucket.layout;
MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST));
depthMask(false);
config.stencilTest = false;
config.depthTest = true;
config.depthMask = GL_FALSE;
if (bucket.hasIconData()) {
bool sdf = bucket.sdfIcons;
@@ -185,7 +186,7 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
iconShader->u_fadezoom = state.getNormalizedZoom() * 10;
iconShader->u_opacity = properties.icon.opacity;
depthRange(strata, 1.0f);
config.depthRange = { strata, 1.0f };
bucket.drawIcons(*iconShader);
}
}
@@ -203,6 +204,4 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
*sdfGlyphShader,
&SymbolBucket::drawGlyphs);
}
MBGL_CHECK_ERROR(glEnable(GL_STENCIL_TEST));
}

View File

@@ -13,8 +13,17 @@ RasterBucket::RasterBucket(TexturePool& texturePool, const StyleLayoutRaster& la
raster(texturePool) {
}
void RasterBucket::render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) {
void RasterBucket::upload() {
if (hasData()) {
raster.upload();
uploaded = true;
}
}
void RasterBucket::render(Painter& painter,
const StyleLayer& layer_desc,
const TileID& id,
const mat4& matrix) {
painter.renderRaster(*this, layer_desc, id, matrix);
}
@@ -29,13 +38,6 @@ void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()));
}
void RasterBucket::drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture_) {
raster.bind(texture_);
shader.u_image = 0;
array.bind(shader, vertices, BUFFER_OFFSET(0));
MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertices.index()));
}
bool RasterBucket::hasData() const {
return raster.isLoaded();
}

View File

@@ -16,9 +16,9 @@ class RasterBucket : public Bucket {
public:
RasterBucket(TexturePool&, const StyleLayoutRaster&);
void render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) override;
bool hasData() const override;
void upload() override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const;
bool setImage(const std::string &data);
@@ -26,8 +26,6 @@ public:
void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array);
void drawRaster(RasterShader& shader, StaticVertexBuffer &vertices, VertexArrayObject &array, GLuint texture);
Raster raster;
};

View File

@@ -0,0 +1,31 @@
#ifndef MBGL_RENDERER_RENDER_PASS
#define MBGL_RENDERER_RENDER_PASS
#include <cstdint>
#include <type_traits>
namespace mbgl {
enum class RenderPass : uint8_t {
None = 0,
Opaque = 1 << 0,
Translucent = 1 << 1,
};
constexpr inline RenderPass operator|(RenderPass a, RenderPass b) {
return static_cast<RenderPass>(static_cast<std::underlying_type<RenderPass>::type>(a) |
static_cast<std::underlying_type<RenderPass>::type>(b));
}
inline RenderPass operator|=(RenderPass& a, RenderPass b) {
return (a = a | b);
}
constexpr inline RenderPass operator&(RenderPass a, RenderPass b) {
return static_cast<RenderPass>(static_cast<std::underlying_type<RenderPass>::type>(a) &
static_cast<std::underlying_type<RenderPass>::type>(b));
}
}
#endif

View File

@@ -36,8 +36,23 @@ SymbolBucket::~SymbolBucket() {
// Do not remove. header file only contains forward definitions to unique pointers.
}
void SymbolBucket::render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) {
void SymbolBucket::upload() {
if (hasTextData()) {
text.vertices.upload();
text.triangles.upload();
}
if (hasIconData()) {
icon.vertices.upload();
icon.triangles.upload();
}
uploaded = true;
}
void SymbolBucket::render(Painter& painter,
const StyleLayer& layer_desc,
const TileID& id,
const mat4& matrix) {
painter.renderSymbol(*this, layer_desc, id, matrix);
}

View File

@@ -55,9 +55,9 @@ public:
SymbolBucket(Collision &collision);
~SymbolBucket() override;
void render(Painter &painter, const StyleLayer &layer_desc, const TileID &id,
const mat4 &matrix) override;
bool hasData() const override;
void upload() override;
void render(Painter&, const StyleLayer&, const TileID&, const mat4&) override;
bool hasData() const;
bool hasTextData() const;
bool hasIconData() const;

View File

@@ -27,7 +27,7 @@ namespace algo = boost::algorithm;
namespace mbgl {
DefaultFileSource::DefaultFileSource(FileCache* cache, const std::string& root)
: thread(util::make_unique<util::Thread<Impl>>("FileSource", cache, root)) {
: thread(util::make_unique<util::Thread<Impl>>("FileSource", util::ThreadPriority::Low, cache, root)) {
}
DefaultFileSource::~DefaultFileSource() {

View File

@@ -13,6 +13,21 @@ bool StyleLayer::isBackground() const {
return type == StyleLayerType::Background;
}
bool StyleLayer::isVisible() const {
switch (type) {
case StyleLayerType::Fill:
return getProperties<FillProperties>().isVisible();
case StyleLayerType::Line:
return getProperties<LineProperties>().isVisible();
case StyleLayerType::Symbol:
return getProperties<SymbolProperties>().isVisible();
case StyleLayerType::Raster:
return getProperties<RasterProperties>().isVisible();
default:
return false;
}
}
void StyleLayer::setClasses(const std::vector<std::string> &class_names, const TimePoint now,
const PropertyTransition &defaultTransition) {
// Stores all keys that we have already added transitions for.

View File

@@ -35,6 +35,9 @@ public:
// Determines whether this layer is the background layer.
bool isBackground() const;
// Checks whether the layer is currently visible at all.
bool isVisible() const;
// Updates the StyleProperties information in this layer by evaluating all
// pending transitions and applied classes in order.
void updateProperties(float z, TimePoint now, ZoomHistory &zoomHistory);

View File

@@ -46,16 +46,7 @@ void Raster::bind(bool linear) {
}
if (img && !textured) {
texture = texturePool.getTextureID();
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#endif
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->getData()));
img.reset();
textured = true;
upload();
} else if (textured) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
}
@@ -68,24 +59,17 @@ void Raster::bind(bool linear) {
}
}
// overload ::bind for prerendered raster textures
void Raster::bind(const GLuint custom_texture) {
void Raster::upload() {
if (img && !textured) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, custom_texture));
texture = texturePool.getTextureID();
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture));
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#endif
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img->getData()));
img.reset();
textured = true;
} else if (textured) {
MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, custom_texture));
}
GLuint new_filter = GL_LINEAR;
if (new_filter != this->filter) {
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, new_filter));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, new_filter));
filter = new_filter;
}
}

View File

@@ -25,8 +25,8 @@ public:
// bind current texture
void bind(bool linear = false);
// bind prerendered texture
void bind(const GLuint texture);
// uploads the texture if it hasn't been uploaded yet.
void upload();
// loaded status
bool isLoaded() const;

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/platform/platform.hpp>
namespace {
@@ -34,11 +35,16 @@ namespace util {
// Thread<> constructor blocks until the thread and the Object are fully created, so after the
// object creation, it's safe to obtain the Object stored in this thread.
enum class ThreadPriority : bool {
Regular,
Low,
};
template <class Object>
class Thread {
public:
template <class... Args>
Thread(const std::string& name, Args&&... args);
Thread(const std::string& name, ThreadPriority priority, Args&&... args);
~Thread();
// Invoke object->fn(args...) in the runloop thread.
@@ -97,7 +103,7 @@ private:
template <class Object>
template <class... Args>
Thread<Object>::Thread(const std::string& name, Args&&... args) {
Thread<Object>::Thread(const std::string& name, ThreadPriority priority, Args&&... args) {
// Note: We're using std::tuple<> to store the arguments because GCC 4.9 has a bug
// when expanding parameters packs captured in lambdas.
std::tuple<Args...> params = std::forward_as_tuple(::std::forward<Args>(args)...);
@@ -109,6 +115,10 @@ Thread<Object>::Thread(const std::string& name, Args&&... args) {
(void(name));
#endif
if (priority == ThreadPriority::Low) {
platform::makeThreadLowPriority();
}
constexpr auto seq = typename integer_sequence<sizeof...(Args)>::type();
run(std::move(params), seq);
});

View File

@@ -1,4 +1,5 @@
#include <mbgl/util/worker.hpp>
#include <mbgl/platform/platform.hpp>
#include <cassert>
@@ -15,7 +16,7 @@ public:
Worker::Worker(std::size_t count) {
for (std::size_t i = 0; i < count; i++) {
threads.emplace_back(util::make_unique<util::Thread<Impl>>("Worker"));
threads.emplace_back(util::make_unique<util::Thread<Impl>>("Worker", util::ThreadPriority::Low));
}
}