[core] Add DDS support for {text,icon}-size (#8593)
* Update gl-js and generate style code
* Factor out packUint8Pair() helper function
* Draft implementation of DDS for {text,icon}-size
Ports https://github.com/mapbox/mapbox-gl-js/pull/4455
* Fix text-size/composite-function-line-placement test
* Refactor to PaintPropertyBinders-like strategy
* Dedupe gl::Program construction
* Use exponential function base for interpolation
* Dedupe coveringZoomStops method
* Fixup tests
* Fix CI errors (hidden within #if block)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/map/transform_state.hpp>
|
||||
#include <mbgl/style/layers/symbol_layer_impl.hpp>
|
||||
#include <mbgl/util/enum.hpp>
|
||||
#include <mbgl/math/clamp.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -10,51 +11,66 @@ 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 style::SymbolPropertyValues& values,
|
||||
Values makeValues(const bool isText,
|
||||
const style::SymbolPropertyValues& values,
|
||||
const Size& texsize,
|
||||
const std::array<float, 2>& pixelsToGLUnits,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state,
|
||||
Args&&... args) {
|
||||
std::array<float, 2> extrudeScale;
|
||||
|
||||
const float scale = values.paintSize / values.sdfScale;
|
||||
|
||||
if (values.pitchAlignment == AlignmentType::Map) {
|
||||
extrudeScale.fill(tile.id.pixelsToTileUnits(1, state.getZoom()) * scale);
|
||||
extrudeScale.fill(tile.id.pixelsToTileUnits(1, state.getZoom()));
|
||||
} else {
|
||||
extrudeScale = {{
|
||||
pixelsToGLUnits[0] * scale * state.getCameraToCenterDistance(),
|
||||
pixelsToGLUnits[1] * scale * state.getCameraToCenterDistance()
|
||||
pixelsToGLUnits[0] * state.getCameraToCenterDistance(),
|
||||
pixelsToGLUnits[1] * state.getCameraToCenterDistance()
|
||||
}};
|
||||
}
|
||||
|
||||
// adjust min/max zooms for variable font sies
|
||||
float zoomAdjust = std::log(values.paintSize / values.layoutSize) / std::log(2);
|
||||
|
||||
|
||||
return Values {
|
||||
uniforms::u_matrix::Value{ tile.translatedMatrix(values.translate,
|
||||
values.translateAnchor,
|
||||
state) },
|
||||
uniforms::u_extrude_scale::Value{ extrudeScale },
|
||||
uniforms::u_texsize::Value{ std::array<float, 2> {{ float(texsize.width) / 4, float(texsize.height) / 4 }} },
|
||||
uniforms::u_zoom::Value{ float((state.getZoom() - zoomAdjust) * 10) },
|
||||
uniforms::u_zoom::Value{ float(state.getZoom()) },
|
||||
uniforms::u_rotate_with_map::Value{ values.rotationAlignment == AlignmentType::Map },
|
||||
uniforms::u_texture::Value{ 0 },
|
||||
uniforms::u_fadetexture::Value{ 1 },
|
||||
uniforms::u_is_text::Value{ isText },
|
||||
std::forward<Args>(args)...
|
||||
};
|
||||
}
|
||||
|
||||
SymbolIconProgram::UniformValues
|
||||
SymbolIconProgram::uniformValues(const style::SymbolPropertyValues& values,
|
||||
SymbolIconProgram::uniformValues(const bool isText,
|
||||
const style::SymbolPropertyValues& values,
|
||||
const Size& texsize,
|
||||
const std::array<float, 2>& pixelsToGLUnits,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state)
|
||||
{
|
||||
return makeValues<SymbolIconProgram::UniformValues>(
|
||||
isText,
|
||||
values,
|
||||
texsize,
|
||||
pixelsToGLUnits,
|
||||
@@ -64,26 +80,26 @@ SymbolIconProgram::uniformValues(const style::SymbolPropertyValues& values,
|
||||
}
|
||||
|
||||
template <class PaintProperties>
|
||||
typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<PaintProperties>::uniformValues(const style::SymbolPropertyValues& values,
|
||||
const Size& texsize,
|
||||
const std::array<float, 2>& pixelsToGLUnits,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state,
|
||||
const SymbolSDFPart part)
|
||||
typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<PaintProperties>::uniformValues(
|
||||
const bool isText,
|
||||
const style::SymbolPropertyValues& values,
|
||||
const Size& texsize,
|
||||
const std::array<float, 2>& pixelsToGLUnits,
|
||||
const RenderTile& tile,
|
||||
const TransformState& state,
|
||||
const SymbolSDFPart part)
|
||||
{
|
||||
const float scale = values.paintSize / values.sdfScale;
|
||||
|
||||
const float gammaScale = scale * (values.pitchAlignment == AlignmentType::Map
|
||||
const float gammaScale = (values.pitchAlignment == AlignmentType::Map
|
||||
? std::cos(state.getPitch())
|
||||
: 1.0) * state.getCameraToCenterDistance();
|
||||
|
||||
return makeValues<SymbolSDFProgram<PaintProperties>::UniformValues>(
|
||||
isText,
|
||||
values,
|
||||
texsize,
|
||||
pixelsToGLUnits,
|
||||
tile,
|
||||
state,
|
||||
uniforms::u_font_scale::Value{ scale },
|
||||
uniforms::u_gamma_scale::Value{ gammaScale },
|
||||
uniforms::u_pitch::Value{ state.getPitch() },
|
||||
uniforms::u_bearing::Value{ -1.0f * state.getAngle() },
|
||||
|
||||
Reference in New Issue
Block a user