make collision debug boxes toggleable
This commit is contained in:
@@ -131,6 +131,9 @@ public:
|
||||
void setDebug(bool value);
|
||||
void toggleDebug();
|
||||
bool getDebug() const;
|
||||
void setCollisionDebug(bool value);
|
||||
void toggleCollisionDebug();
|
||||
bool getCollisionDebug() const;
|
||||
bool isFullyLoaded() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -87,6 +87,9 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
|
||||
case GLFW_KEY_TAB:
|
||||
view->map->toggleDebug();
|
||||
break;
|
||||
case GLFW_KEY_C:
|
||||
view->map->toggleCollisionDebug();
|
||||
break;
|
||||
case GLFW_KEY_X:
|
||||
if (!mods)
|
||||
view->map->resetPosition();
|
||||
|
||||
@@ -17,9 +17,10 @@ LiveTileData::LiveTileData(const TileID& id_,
|
||||
SpriteAtlas& spriteAtlas_,
|
||||
util::ptr<Sprite> sprite_,
|
||||
const SourceInfo& source_,
|
||||
float angle_)
|
||||
float angle_,
|
||||
bool collisionDebug_)
|
||||
: VectorTileData::VectorTileData(id_, mapMaxZoom, style_, glyphAtlas_, glyphStore_,
|
||||
spriteAtlas_, sprite_, source_, angle_),
|
||||
spriteAtlas_, sprite_, source_, angle_, collisionDebug_),
|
||||
annotationManager(annotationManager_) {
|
||||
// live features are always ready
|
||||
setState(State::loaded);
|
||||
|
||||
@@ -18,7 +18,8 @@ public:
|
||||
SpriteAtlas&,
|
||||
util::ptr<Sprite>,
|
||||
const SourceInfo&,
|
||||
float);
|
||||
float,
|
||||
bool);
|
||||
~LiveTileData();
|
||||
|
||||
void parse() override;
|
||||
|
||||
@@ -290,6 +290,20 @@ bool Map::getDebug() const {
|
||||
return data->getDebug();
|
||||
}
|
||||
|
||||
void Map::setCollisionDebug(bool value) {
|
||||
data->setCollisionDebug(value);
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::toggleCollisionDebug() {
|
||||
data->toggleCollisionDebug();
|
||||
update();
|
||||
}
|
||||
|
||||
bool Map::getCollisionDebug() const {
|
||||
return data->getCollisionDebug();
|
||||
}
|
||||
|
||||
bool Map::isFullyLoaded() const {
|
||||
return data->getFullyLoaded();
|
||||
}
|
||||
|
||||
@@ -41,4 +41,4 @@ std::vector<std::string> MapData::getClasses() const {
|
||||
return classes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,16 @@ public:
|
||||
debug = value;
|
||||
}
|
||||
|
||||
inline bool getCollisionDebug() const {
|
||||
return collisionDebug;
|
||||
}
|
||||
inline bool toggleCollisionDebug() {
|
||||
return collisionDebug ^= 1u;
|
||||
}
|
||||
inline void setCollisionDebug(bool value) {
|
||||
collisionDebug = value;
|
||||
}
|
||||
|
||||
inline bool getFullyLoaded() const {
|
||||
return loaded;
|
||||
}
|
||||
@@ -98,6 +108,7 @@ private:
|
||||
std::string accessToken;
|
||||
std::vector<std::string> classes;
|
||||
std::atomic<uint8_t> debug { false };
|
||||
std::atomic<uint8_t> collisionDebug { false };
|
||||
std::atomic<bool> loaded { false };
|
||||
std::atomic<Duration> animationTime;
|
||||
std::atomic<Duration> defaultTransitionDuration;
|
||||
|
||||
@@ -288,7 +288,7 @@ TileData::State Source::addTile(MapData& data,
|
||||
if (info.type == SourceType::Vector) {
|
||||
new_tile.data =
|
||||
std::make_shared<VectorTileData>(normalized_id, data.transform.getMaxZoom(), style, glyphAtlas,
|
||||
glyphStore, spriteAtlas, sprite, info, transformState.getAngle());
|
||||
glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug());
|
||||
new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Raster) {
|
||||
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
|
||||
@@ -296,7 +296,7 @@ TileData::State Source::addTile(MapData& data,
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
|
||||
data.transform.getMaxZoom(), style, glyphAtlas,
|
||||
glyphStore, spriteAtlas, sprite, info, transformState.getAngle());
|
||||
glyphStore, spriteAtlas, sprite, info, transformState.getAngle(), data.getCollisionDebug());
|
||||
new_tile.data->reparse(style.workers, callback);
|
||||
} else {
|
||||
throw std::runtime_error("source type not implemented");
|
||||
@@ -497,7 +497,7 @@ bool Source::update(MapData& data,
|
||||
|
||||
updateTilePtrs();
|
||||
|
||||
redoPlacement(transformState);
|
||||
redoPlacement(transformState, data.getCollisionDebug());
|
||||
|
||||
updated = data.getAnimationTime();
|
||||
|
||||
@@ -520,9 +520,9 @@ void Source::updateTilePtrs() {
|
||||
}
|
||||
}
|
||||
|
||||
void Source::redoPlacement(const TransformState& transformState) {
|
||||
void Source::redoPlacement(const TransformState& transformState, bool collisionDebug) {
|
||||
for (auto& tilePtr : tilePtrs) {
|
||||
tilePtr->data->redoPlacement(transformState.getAngle());
|
||||
tilePtr->data->redoPlacement(transformState.getAngle(), collisionDebug);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
bool enabled;
|
||||
|
||||
private:
|
||||
void redoPlacement(const TransformState& transformState);
|
||||
void redoPlacement(const TransformState& transformState, bool collisionDebug);
|
||||
void emitSourceLoaded();
|
||||
void emitTileLoaded(bool isNewTile);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
virtual void parse() = 0;
|
||||
virtual Bucket* getBucket(StyleLayer const &layer_desc) = 0;
|
||||
|
||||
virtual void redoPlacement(float) {}
|
||||
virtual void redoPlacement(float, bool) {}
|
||||
|
||||
const TileID id;
|
||||
const std::string name;
|
||||
|
||||
@@ -22,7 +22,8 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
SpriteAtlas& spriteAtlas_,
|
||||
util::ptr<Sprite> sprite_,
|
||||
const SourceInfo& source_,
|
||||
float angle)
|
||||
float angle,
|
||||
bool collisionDebug)
|
||||
: TileData(id_, source_),
|
||||
depth(id_.z >= source_.max_zoom ? mapMaxZoom - id_.z : 1),
|
||||
glyphAtlas(glyphAtlas_),
|
||||
@@ -30,7 +31,7 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
spriteAtlas(spriteAtlas_),
|
||||
sprite(sprite_),
|
||||
style(style_),
|
||||
collision(util::make_unique<CollisionTile>(id_.z, 4096, source_.tile_size, angle)),
|
||||
collision(util::make_unique<CollisionTile>(id_.z, 4096, source_.tile_size, angle, collisionDebug)),
|
||||
lastAngle(angle),
|
||||
currentAngle(angle) {
|
||||
}
|
||||
@@ -116,26 +117,29 @@ void VectorTileData::setState(const State& state_) {
|
||||
}
|
||||
|
||||
void VectorTileData::redoPlacement() {
|
||||
redoPlacement(lastAngle);
|
||||
redoPlacement(lastAngle, lastCollisionDebug);
|
||||
}
|
||||
|
||||
void VectorTileData::redoPlacement(float angle) {
|
||||
if (angle != currentAngle) {
|
||||
void VectorTileData::redoPlacement(float angle, bool collisionDebug) {
|
||||
if (angle != currentAngle || collisionDebug != currentCollisionDebug) {
|
||||
lastAngle = angle;
|
||||
lastCollisionDebug = collisionDebug;
|
||||
|
||||
if (getState() != State::parsed || redoingPlacement) return;
|
||||
|
||||
redoingPlacement = true;
|
||||
currentAngle = angle;
|
||||
currentCollisionDebug = collisionDebug;
|
||||
|
||||
auto callback = std::bind(&VectorTileData::endRedoPlacement, this);
|
||||
workRequest = style.workers.send([this, angle] { workerRedoPlacement(angle); }, callback);
|
||||
workRequest = style.workers.send([this, angle, collisionDebug] { workerRedoPlacement(angle, collisionDebug); }, callback);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void VectorTileData::workerRedoPlacement(float angle) {
|
||||
void VectorTileData::workerRedoPlacement(float angle, bool collisionDebug) {
|
||||
collision->reset(angle, 0);
|
||||
collision->setDebug(collisionDebug);
|
||||
for (const auto& layer_desc : style.layers) {
|
||||
auto bucket = getBucket(*layer_desc);
|
||||
if (bucket) {
|
||||
|
||||
@@ -40,11 +40,12 @@ public:
|
||||
SpriteAtlas&,
|
||||
util::ptr<Sprite>,
|
||||
const SourceInfo&,
|
||||
float);
|
||||
float,
|
||||
bool);
|
||||
~VectorTileData();
|
||||
|
||||
void parse() override;
|
||||
void redoPlacement(float angle) override;
|
||||
void redoPlacement(float angle, bool collisionDebug) override;
|
||||
virtual Bucket* getBucket(StyleLayer const &layer_desc) override;
|
||||
|
||||
size_t countBuckets() const;
|
||||
@@ -88,9 +89,11 @@ private:
|
||||
|
||||
float lastAngle = 0;
|
||||
float currentAngle;
|
||||
bool lastCollisionDebug = 0;
|
||||
bool currentCollisionDebug = 0;
|
||||
bool redoingPlacement = false;
|
||||
void endRedoPlacement();
|
||||
void workerRedoPlacement(float angle);
|
||||
void workerRedoPlacement(float angle, bool collisionDebug);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -193,7 +193,9 @@ void Painter::renderSymbol(SymbolBucket &bucket, const StyleLayer &layer_desc, c
|
||||
&SymbolBucket::drawGlyphs);
|
||||
}
|
||||
|
||||
if (bucket.hasCollisionBoxData()) {
|
||||
if (bucket.hasCollisionBoxData() && (
|
||||
(bucket.hasIconData() && properties.icon.opacity) ||
|
||||
(bucket.hasTextData() && properties.text.opacity))) {
|
||||
config.stencilTest = true;
|
||||
|
||||
useProgram(collisionBoxShader->program);
|
||||
|
||||
@@ -385,7 +385,7 @@ void SymbolBucket::placeFeatures(bool swapImmediately) {
|
||||
}
|
||||
}
|
||||
|
||||
addToDebugBuffers();
|
||||
if (collision.getDebug()) addToDebugBuffers();
|
||||
|
||||
if (swapImmediately) swapRenderData();
|
||||
}
|
||||
|
||||
@@ -34,13 +34,16 @@ namespace mbgl {
|
||||
class CollisionTile {
|
||||
|
||||
public:
|
||||
inline explicit CollisionTile(float _zoom, float tileExtent, float tileSize, float angle_) :
|
||||
zoom(_zoom), tilePixelRatio(tileExtent / tileSize) { reset(angle_, 0); }
|
||||
inline explicit CollisionTile(float _zoom, float tileExtent, float tileSize, float angle_, bool debug_) :
|
||||
zoom(_zoom), tilePixelRatio(tileExtent / tileSize), debug(debug_) { reset(angle_, 0); }
|
||||
|
||||
void reset(const float angle, const float pitch);
|
||||
float placeFeature(const CollisionFeature &feature);
|
||||
void insertFeature(CollisionFeature &feature, const float minPlacementScale);
|
||||
|
||||
void setDebug(bool debug_) { debug = debug_; }
|
||||
bool getDebug() { return debug; }
|
||||
|
||||
const float zoom;
|
||||
const float tilePixelRatio;
|
||||
float angle = 0;
|
||||
@@ -55,6 +58,7 @@ class CollisionTile {
|
||||
Tree tree;
|
||||
std::array<float, 4> rotationMatrix;
|
||||
float yStretch;
|
||||
bool debug;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user