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

Commit

Permalink
[core] Introduce variable text placement for point labels - Placement…
Browse files Browse the repository at this point in the history
… part
  • Loading branch information
pozdnyakov committed Mar 21, 2019
1 parent cefa35b commit ab1f820
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ void SymbolLayout::addToDebugBuffers(SymbolBucket& bucket) {

// Dynamic vertices are initialized so that the vertex count always agrees with
// the layout vertex buffer, but they will always be updated before rendering happens
auto dynamicVertex = CollisionBoxProgram::dynamicVertex(false, false);
auto dynamicVertex = CollisionBoxProgram::dynamicVertex(false, false, {});
collisionBuffer.dynamicVertices.emplace_back(dynamicVertex);
collisionBuffer.dynamicVertices.emplace_back(dynamicVertex);
collisionBuffer.dynamicVertices.emplace_back(dynamicVertex);
Expand Down
18 changes: 5 additions & 13 deletions src/mbgl/programs/collision_box_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace mbgl {
using CollisionBoxLayoutAttributes = TypeList<
attributes::pos,
attributes::anchor_pos,
attributes::extrude,
attributes::shift>;
attributes::extrude>;

using CollisionBoxDynamicAttributes = TypeList<attributes::placed>;
using CollisionBoxDynamicAttributes = TypeList<attributes::placed, attributes::shift>;

class CollisionBoxProgram : public Program<
CollisionBoxProgram,
Expand Down Expand Up @@ -45,17 +44,14 @@ class CollisionBoxProgram : public Program<
{{
static_cast<int16_t>(::round(o.x)),
static_cast<int16_t>(::round(o.y))
}},
{{
0.0f,
0.0f
}}
};
}

static gfx::Vertex<CollisionBoxDynamicAttributes> dynamicVertex(bool placed, bool notUsed) {
static gfx::Vertex<CollisionBoxDynamicAttributes> dynamicVertex(bool placed, bool notUsed, Point<float> shift) {
return {
{{ static_cast<uint8_t>(placed), static_cast<uint8_t>(notUsed) }}
{{ static_cast<uint8_t>(placed), static_cast<uint8_t>(notUsed) }},
{{ shift.x, shift.y }}
};
}

Expand Down Expand Up @@ -139,10 +135,6 @@ class CollisionCircleProgram : public Program<
{{
static_cast<int16_t>(::round(o.x)),
static_cast<int16_t>(::round(o.y))
}},
{{
0.0f,
0.0f
}}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/layers/render_symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
for (const PlacedSymbol& symbol : bucket.text.placedSymbols) {
optional<VariableOffset> variableOffset;
if (!symbol.hidden && symbol.crossTileID != 0u) {
auto it = parameters.variableOffsets.find(symbol.crossTileID);
if (it != parameters.variableOffsets.end()) {
auto it = parameters.variableOffsets.get().find(symbol.crossTileID);
if (it != parameters.variableOffsets.get().end()) {
variableOffset = it->second;
hasVariablePacement |= true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/renderer/paint_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ PaintParameters::PaintParameters(gfx::Context& context_,
const EvaluatedLight& evaluatedLight_,
RenderStaticData& staticData_,
ImageManager& imageManager_,
LineAtlas& lineAtlas_)
LineAtlas& lineAtlas_,
Placement::VariableOffsets variableOffsets_)
: context(context_),
backend(backend_),
state(updateParameters.transformState),
Expand All @@ -26,6 +27,7 @@ PaintParameters::PaintParameters(gfx::Context& context_,
contextMode(contextMode_),
timePoint(updateParameters.timePoint),
pixelRatio(pixelRatio_),
variableOffsets(variableOffsets_),
#ifndef NDEBUG
programs((debugOptions & MapDebugOptions::Overdraw) ? staticData_.overdrawPrograms : staticData_.programs)
#else
Expand Down
5 changes: 3 additions & 2 deletions src/mbgl/renderer/paint_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class PaintParameters {
const EvaluatedLight&,
RenderStaticData&,
ImageManager&,
LineAtlas&);
LineAtlas&,
Placement::VariableOffsets);

gfx::Context& context;
RendererBackend& backend;
Expand All @@ -57,7 +58,7 @@ class PaintParameters {
TimePoint timePoint;

float pixelRatio;
std::unordered_map<uint32_t, VariableOffset> variableOffsets;
Placement::VariableOffsets variableOffsets;
std::array<float, 2> pixelsToGLUnits;
algorithm::ClipIDGenerator clipIDGenerator;

Expand Down
16 changes: 8 additions & 8 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
renderLight.getEvaluated(),
*staticData,
*imageManager,
*lineAtlas
*lineAtlas,
placement->getVariableOffsets()
};

bool loaded = updateParameters.styleLoaded && isLoaded();
Expand Down Expand Up @@ -344,26 +345,25 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {

bool symbolBucketsChanged = false;
const bool placementChanged = !placement->stillRecent(parameters.timePoint);
std::unique_ptr<Placement> newPlacement;
std::set<std::string> usedSymbolLayers;

if (placementChanged) {
newPlacement = std::make_unique<Placement>(parameters.state, parameters.mapMode, updateParameters.transitionOptions, updateParameters.crossSourceCollisions);
placement = std::make_unique<Placement>(parameters.state, parameters.mapMode, updateParameters.transitionOptions, updateParameters.crossSourceCollisions, std::move(placement));
}

for (const auto& item : renderItemsWithSymbols) {
if (crossTileSymbolIndex.addLayer(*item.layer.getSymbolInterface(), parameters.state.getLatLng().longitude())) symbolBucketsChanged = true;

if (newPlacement) {
if (placementChanged) {
usedSymbolLayers.insert(item.layer.getID());
newPlacement->placeLayer(*item.layer.getSymbolInterface(), parameters.projMatrix, parameters.debugOptions & MapDebugOptions::Collision);
placement->placeLayer(*item.layer.getSymbolInterface(), parameters.projMatrix, parameters.debugOptions & MapDebugOptions::Collision);
}
}

if (newPlacement) {
newPlacement->commit(*placement, parameters.timePoint);
if (placementChanged) {
placement->commit(parameters.timePoint);
crossTileSymbolIndex.pruneUnusedLayers(usedSymbolLayers);
placement = std::move(newPlacement);
parameters.variableOffsets = placement->getVariableOffsets();
updateFadingTiles();
} else {
placement->setStale();
Expand Down
9 changes: 5 additions & 4 deletions src/mbgl/text/collision_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ bool CollisionIndex::isInsideTile(const CollisionBox& box, const CollisionTileBo


std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
Point<float> shift,
const mat4& posMatrix,
const mat4& labelPlaneMatrix,
const float textPixelRatio,
Expand All @@ -95,10 +96,10 @@ std::pair<bool,bool> CollisionIndex::placeFeature(CollisionFeature& feature,
CollisionBox& box = feature.boxes.front();
const auto projectedPoint = projectAndGetPerspectiveRatio(posMatrix, box.anchor);
const float tileToViewport = textPixelRatio * projectedPoint.second;
box.px1 = box.x1 * tileToViewport + projectedPoint.first.x;
box.py1 = box.y1 * tileToViewport + projectedPoint.first.y;
box.px2 = box.x2 * tileToViewport + projectedPoint.first.x;
box.py2 = box.y2 * tileToViewport + projectedPoint.first.y;
box.px1 = (box.x1 + shift.x) * tileToViewport + projectedPoint.first.x;
box.py1 = (box.y1 + shift.y) * tileToViewport + projectedPoint.first.y;
box.px2 = (box.x2 + shift.x) * tileToViewport + projectedPoint.first.x;
box.py2 = (box.y2 + shift.y) * tileToViewport + projectedPoint.first.y;


if ((avoidEdges && !isInsideTile(box, *avoidEdges)) ||
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/text/collision_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CollisionIndex {
explicit CollisionIndex(const TransformState&);

std::pair<bool,bool> placeFeature(CollisionFeature& feature,
Point<float> shift,
const mat4& posMatrix,
const mat4& labelPlaneMatrix,
const float textPixelRatio,
Expand Down
Loading

0 comments on commit ab1f820

Please sign in to comment.