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

Commit

Permalink
Refactor to PaintPropertyBinders-like strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Apr 4, 2017
1 parent 9152784 commit f219d8c
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 173 deletions.
38 changes: 4 additions & 34 deletions src/mbgl/layout/symbol_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
if (glyphScale < collisionTile.maxScale) {
for (const auto& symbol : symbolInstance.glyphQuads) {
addSymbol(
bucket->text, bucket->textSizeData, symbol, feature, textSize, placementZoom,
bucket->text, *bucket->textSizeBinder, symbol, feature, placementZoom,
keepUpright, textPlacement, collisionTile.config.angle, symbolInstance.writingModes);
}
}
Expand All @@ -517,7 +517,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
collisionTile.insertFeature(symbolInstance.iconCollisionFeature, iconScale, layout.get<IconIgnorePlacement>());
if (iconScale < collisionTile.maxScale && symbolInstance.iconQuad) {
addSymbol(
bucket->icon, bucket->iconSizeData, *symbolInstance.iconQuad, feature, iconSize, placementZoom,
bucket->icon, *bucket->iconSizeBinder, *symbolInstance.iconQuad, feature, placementZoom,
keepUpright, iconPlacement, collisionTile.config.angle, symbolInstance.writingModes);
}
}
Expand All @@ -537,10 +537,9 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)

template <typename Buffer>
void SymbolLayout::addSymbol(Buffer& buffer,
SymbolSizeData& sizeData,
SymbolSizeBinder& sizeBinder,
const SymbolQuad& symbol,
const SymbolFeature& feature,
const style::DataDrivenPropertyValue<float>& size,
const float placementZoom,
const bool keepUpright,
const style::SymbolPlacementType placement,
Expand Down Expand Up @@ -603,36 +602,7 @@ void SymbolLayout::addSymbol(Buffer& buffer,
buffer.vertices.emplace_back(SymbolLayoutAttributes::vertex(anchorPoint, br, tex.x + tex.w, tex.y + tex.h,
minZoom, maxZoom, placementZoom, glyphAngle));

size.match(
[&] (const style::CompositeFunction<float>& fn) {
const auto sizeVertex = SymbolSizeAttributes::Vertex {
{{
static_cast<uint16_t>(fn.evaluate(sizeData.coveringZoomStops->min, feature, sizeData.defaultSize) * 10),
static_cast<uint16_t>(fn.evaluate(sizeData.coveringZoomStops->max, feature, sizeData.defaultSize) * 10),
static_cast<uint16_t>(fn.evaluate(zoom + 1, feature, sizeData.defaultSize) * 10)
}}
};
auto& vertexVector = sizeData.vertices.get<gl::VertexVector<SymbolSizeAttributes::Vertex>>();
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
},
[&] (const style::SourceFunction<float>& fn) {
const auto sizeVertex = SymbolSizeAttributes::SourceFunctionVertex {
{{ static_cast<uint16_t>(fn.evaluate(feature, sizeData.defaultSize) * 10) }}
};

auto& vertexVector = sizeData.vertices.get<gl::VertexVector<SymbolSizeAttributes::SourceFunctionVertex>>();
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
vertexVector.emplace_back(sizeVertex);
},
[] (const auto&) {
mbgl::Log::Debug(mbgl::Event::General, "feature-constant symbol");
}
);
sizeBinder.populateVertexVector(feature);

// add the two triangles, referencing the four coordinates we just inserted.
buffer.triangles.emplace_back(index + 0, index + 1, index + 2);
Expand Down
13 changes: 9 additions & 4 deletions src/mbgl/layout/symbol_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ class SymbolLayout {

// Adds placed items to the buffer.
template <typename Buffer>
void addSymbol(Buffer&, SymbolSizeData& sizeData, const SymbolQuad&, const SymbolFeature& feature,
const style::DataDrivenPropertyValue<float>& size, float scale,
const bool keepUpright, const style::SymbolPlacementType, const float placementAngle,
WritingModeType writingModes);
void addSymbol(Buffer&,
SymbolSizeBinder& sizeBinder,
const SymbolQuad&,
const SymbolFeature& feature,
float scale,
const bool keepUpright,
const style::SymbolPlacementType,
const float placementAngle,
WritingModeType writingModes);

const std::string sourceLayerName;
const std::string bucketName;
Expand Down
45 changes: 16 additions & 29 deletions src/mbgl/programs/symbol_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@ using namespace style;

static_assert(sizeof(SymbolLayoutVertex) == 16, "expected SymbolLayoutVertex size");

std::unique_ptr<SymbolSizeBinder> SymbolSizeBinder::create(const float tileZoom,
const style::DataDrivenPropertyValue<float>& sizeProperty,
const float defaultValue) {
return sizeProperty.match(
[&] (const style::CompositeFunction<float>& function) -> std::unique_ptr<SymbolSizeBinder> {
return std::make_unique<CompositeFunctionSymbolSizeBinder>(tileZoom, function, defaultValue);
},
[&] (const style::SourceFunction<float>& function) {
return std::make_unique<SourceFunctionSymbolSizeBinder>(tileZoom, function, defaultValue);
},
[&] (const auto& value) -> std::unique_ptr<SymbolSizeBinder> {
return std::make_unique<ConstantSymbolSizeBinder>(tileZoom, value, defaultValue);
}
);
}

template <class Values, class...Args>
Values makeValues(const bool isText,
const style::SymbolPropertyValues& values,
const SymbolSizeData& sizeData,
const Size& texsize,
const std::array<float, 2>& pixelsToGLUnits,
const RenderTile& tile,
Expand All @@ -30,25 +45,6 @@ Values makeValues(const bool isText,
pixelsToGLUnits[1] * state.getCameraToCenterDistance()
}};
}

float sizeInterpolationT;
float renderSize = sizeData.layoutSize;
float layoutSize = sizeData.layoutSize;
sizeData.sizePropertyValue.match(
[&] (const CompositeFunction<float>&) {
const auto& coveringStops = *sizeData.coveringZoomStops;
const float t = (state.getZoom() - coveringStops.min) / (coveringStops.max - coveringStops.min);
sizeInterpolationT = util::clamp(t, 0.0f, 1.0f);
},
[&] (const CameraFunction<float>& fn) {
const auto& coveringStops = *sizeData.coveringZoomStops;
const float t = (state.getZoom() - coveringStops.min) / (coveringStops.max - coveringStops.min);
const float lowerValue = fn.evaluate(coveringStops.min);
const float upperValue = fn.evaluate(coveringStops.max);
renderSize = lowerValue + (upperValue - lowerValue) * util::clamp(t, 0.0f, 1.0f);
},
[&] (const auto&) {}
);

return Values {
uniforms::u_matrix::Value{ tile.translatedMatrix(values.translate,
Expand All @@ -61,19 +57,13 @@ Values makeValues(const bool isText,
uniforms::u_texture::Value{ 0 },
uniforms::u_fadetexture::Value{ 1 },
uniforms::u_is_text::Value{ isText },
uniforms::u_is_size_zoom_constant::Value{ sizeData.sizePropertyValue.isZoomConstant() },
uniforms::u_is_size_feature_constant::Value{ !sizeData.sizePropertyValue.isDataDriven() },
uniforms::u_size_t::Value{ sizeInterpolationT },
uniforms::u_size::Value{ renderSize },
uniforms::u_layout_size::Value{ layoutSize },
std::forward<Args>(args)...
};
}

SymbolIconProgram::UniformValues
SymbolIconProgram::uniformValues(const bool isText,
const style::SymbolPropertyValues& values,
const SymbolSizeData& sizeData,
const Size& texsize,
const std::array<float, 2>& pixelsToGLUnits,
const RenderTile& tile,
Expand All @@ -82,7 +72,6 @@ SymbolIconProgram::uniformValues(const bool isText,
return makeValues<SymbolIconProgram::UniformValues>(
isText,
values,
sizeData,
texsize,
pixelsToGLUnits,
tile,
Expand All @@ -94,7 +83,6 @@ template <class PaintProperties>
typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<PaintProperties>::uniformValues(
const bool isText,
const style::SymbolPropertyValues& values,
const SymbolSizeData& sizeData,
const Size& texsize,
const std::array<float, 2>& pixelsToGLUnits,
const RenderTile& tile,
Expand All @@ -108,7 +96,6 @@ typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<Paint
return makeValues<SymbolSDFProgram<PaintProperties>::UniformValues>(
isText,
values,
sizeData,
texsize,
pixelsToGLUnits,
tile,
Expand Down
Loading

0 comments on commit f219d8c

Please sign in to comment.