Files
MapLibreParticleLab/src/mbgl/renderer/symbol_bucket.cpp
Anand Thakker f901e776b3 [core] Implement data-driven styling for {text,icon}-{color,opacity,halo-color,halo-blur,halo-width} (#7939)
* Add symbol dds attributes and adapt style code generation

* Update to mapbox-gl-js/master

* Refactor SymbolFeature as a subclass of GeometryTileFeature

Prepares for enabling DDS on symbol paint properties by allowing the
SymbolFeatures, which we keep around after constructing SymbolLayout,
to be used in evaluating data-driven paint properties later in the
layout process.

* Draft approach for splitting icon/text paint properties

The `Program` types are set up to bind GL attributes to each of the
data-driven paint properties specified in the `PaintProperties` type
provided.  Since `SymbolPaintProperties` specifies both `Text*` and
`Icon*` properties, the symbolIcon, symbolIconSDF, and symbolGlyph
programs each attempt to bind roughly double the number of attributes
that they actually need.

This change addresses this by:
- Adding the more specific `IconPaintProperties` and `TextPaintProperties` types, which are subsets of the full `SymbolPaintProperties`.
- The symbol layer continues to use its `SymbolPaintProperties paint` member to track layer property state, but it provides helpers that construct objects of each the specific `{Icon,Text}PaintProperties::Evaluated` type, for use by the painter.
- The three symbol programs instantiate `Program<>` using the appropriate `{Icon,Text}PaintProperties` type.

* check in generated style code

* Populate paint buffers for symbol DDS properties

* Address first round of review comments

* Refactor VectorTile{Layer,Feature} to explicitly share data

* Update submodule
2017-02-28 19:54:24 -08:00

77 lines
2.6 KiB
C++

#include <mbgl/renderer/symbol_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
namespace mbgl {
using namespace style;
SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::Evaluated layout_,
const std::unordered_map<std::string, std::pair<
style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>& layerPaintProperties,
float zoom,
bool sdfIcons_,
bool iconsNeedLinear_)
: layout(std::move(layout_)),
sdfIcons(sdfIcons_),
iconsNeedLinear(iconsNeedLinear_) {
for (const auto& pair : layerPaintProperties) {
paintPropertyBinders.emplace(pair.first, std::make_pair(
SymbolIconProgram::PaintPropertyBinders(pair.second.first, zoom),
SymbolSDFTextProgram::PaintPropertyBinders(pair.second.second, zoom)
));
}
}
void SymbolBucket::upload(gl::Context& context) {
if (hasTextData()) {
text.vertexBuffer = context.createVertexBuffer(std::move(text.vertices));
text.indexBuffer = context.createIndexBuffer(std::move(text.triangles));
}
if (hasIconData()) {
icon.vertexBuffer = context.createVertexBuffer(std::move(icon.vertices));
icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles));
}
if (!collisionBox.vertices.empty()) {
collisionBox.vertexBuffer = context.createVertexBuffer(std::move(collisionBox.vertices));
collisionBox.indexBuffer = context.createIndexBuffer(std::move(collisionBox.lines));
}
for (auto& pair : paintPropertyBinders) {
pair.second.first.upload(context);
pair.second.second.upload(context);
}
uploaded = true;
}
void SymbolBucket::render(Painter& painter,
PaintParameters& parameters,
const Layer& layer,
const RenderTile& tile) {
painter.renderSymbol(parameters, *this, *layer.as<SymbolLayer>(), tile);
}
bool SymbolBucket::hasData() const {
assert(false); // Should be calling SymbolLayout::has{Text,Icon,CollisonBox}Data() instead.
return false;
}
bool SymbolBucket::hasTextData() const {
return !text.segments.empty();
}
bool SymbolBucket::hasIconData() const {
return !icon.segments.empty();
}
bool SymbolBucket::hasCollisionBoxData() const {
return !collisionBox.segments.empty();
}
} // namespace mbgl