diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2017-02-28 19:54:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 19:54:24 -0800 |
commit | f901e776b3e63aaaa6bc0cc4476624bf84127fe6 (patch) | |
tree | 3e311971d57109c64e5ace45c111fb5909e7fb7b /src/mbgl/programs | |
parent | c3ed1f51ca677c8c2045320fe13ec881cbd94772 (diff) | |
download | qtlocation-mapboxgl-f901e776b3e63aaaa6bc0cc4476624bf84127fe6.tar.gz |
[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
Diffstat (limited to 'src/mbgl/programs')
-rw-r--r-- | src/mbgl/programs/attributes.hpp | 46 | ||||
-rw-r--r-- | src/mbgl/programs/programs.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/programs/symbol_program.cpp | 88 | ||||
-rw-r--r-- | src/mbgl/programs/symbol_program.hpp | 77 |
4 files changed, 121 insertions, 94 deletions
diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index c4cc5dea8b..bb90f2c13c 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -64,6 +64,34 @@ struct a_color : gl::Attribute<gl::Normalized<uint8_t>, 4> { } }; +// used in the symbol sdf shader +struct a_fill_color : gl::Attribute<gl::Normalized<uint8_t>, 4> { + static auto name() { return "a_fill_color"; } + + static Value value(const Color& color) { + return {{ + gl::Normalized<uint8_t>(color.r), + gl::Normalized<uint8_t>(color.g), + gl::Normalized<uint8_t>(color.b), + gl::Normalized<uint8_t>(color.a) + }}; + } +}; + +// used in the symbol sdf shader +struct a_halo_color : gl::Attribute<gl::Normalized<uint8_t>, 4> { + static auto name() { return "a_halo_color"; } + + static Value value(const Color& color) { + return {{ + gl::Normalized<uint8_t>(color.r), + gl::Normalized<uint8_t>(color.g), + gl::Normalized<uint8_t>(color.b), + gl::Normalized<uint8_t>(color.a) + }}; + } +}; + struct a_stroke_color : gl::Attribute<gl::Normalized<uint8_t>, 4> { static auto name() { return "a_stroke_color"; } @@ -171,5 +199,23 @@ struct a_offset<1> : gl::Attribute<float, 1> { } }; +struct a_halo_width : gl::Attribute<float, 1> { + static auto name() { return "a_halo_width"; } + + static Value value(float width) { + return {{ width }}; + } +}; + +struct a_halo_blur : gl::Attribute<float, 1> { + static auto name() { return "a_halo_blur"; } + + static Value value(float blur) { + return {{ blur }}; + } +}; + + + } // namespace attributes } // namespace mbgl diff --git a/src/mbgl/programs/programs.hpp b/src/mbgl/programs/programs.hpp index dd71c2ce97..742c5a221b 100644 --- a/src/mbgl/programs/programs.hpp +++ b/src/mbgl/programs/programs.hpp @@ -40,8 +40,8 @@ public: LinePatternProgram linePattern; RasterProgram raster; SymbolIconProgram symbolIcon; - SymbolSDFProgram symbolIconSDF; - SymbolSDFProgram symbolGlyph; + SymbolSDFIconProgram symbolIconSDF; + SymbolSDFTextProgram symbolGlyph; DebugProgram debug; CollisionBoxProgram collisionBox; diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp index 3f59000b94..19fe2bc2f6 100644 --- a/src/mbgl/programs/symbol_program.cpp +++ b/src/mbgl/programs/symbol_program.cpp @@ -2,6 +2,7 @@ #include <mbgl/renderer/render_tile.hpp> #include <mbgl/map/transform_state.hpp> #include <mbgl/style/layers/symbol_layer_impl.hpp> +#include <mbgl/util/enum.hpp> namespace mbgl { @@ -19,6 +20,7 @@ Values makeValues(const style::SymbolPropertyValues& values, 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); } else { @@ -27,7 +29,7 @@ Values makeValues(const style::SymbolPropertyValues& values, pixelsToGLUnits[1] * scale * state.getCameraToCenterDistance() }}; } - + // adjust min/max zooms for variable font sies float zoomAdjust = std::log(values.paintSize / values.layoutSize) / std::log(2); @@ -35,7 +37,6 @@ Values makeValues(const style::SymbolPropertyValues& values, uniforms::u_matrix::Value{ tile.translatedMatrix(values.translate, values.translateAnchor, state) }, - uniforms::u_opacity::Value{ values.opacity }, 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) }, @@ -62,84 +63,37 @@ SymbolIconProgram::uniformValues(const style::SymbolPropertyValues& values, ); } -static SymbolSDFProgram::UniformValues makeSDFValues(const style::SymbolPropertyValues& values, - const Size& texsize, - const std::array<float, 2>& pixelsToGLUnits, - const RenderTile& tile, - const TransformState& state, - float pixelRatio, - Color color, - float buffer, - float gammaAdjust) -{ - // The default gamma value has to be adjust for the current pixelratio so that we're not - // drawing blurry font on retina screens. - const float gammaBase = 0.105 * values.sdfScale / values.paintSize / pixelRatio; - const float gammaScale = (values.pitchAlignment == AlignmentType::Map - ? 1.0 / std::cos(state.getPitch()) - : 1.0) / state.getCameraToCenterDistance(); - - return makeValues<SymbolSDFProgram::UniformValues>( - values, - texsize, - pixelsToGLUnits, - tile, - state, - uniforms::u_color::Value{ color }, - uniforms::u_buffer::Value{ buffer }, - uniforms::u_gamma::Value{ (gammaBase + gammaAdjust) * gammaScale }, - uniforms::u_pitch::Value{ state.getPitch() }, - uniforms::u_bearing::Value{ -1.0f * state.getAngle() }, - uniforms::u_aspect_ratio::Value{ (state.getSize().width * 1.0f) / (state.getSize().height * 1.0f) }, - uniforms::u_pitch_with_map::Value{ values.pitchAlignment == AlignmentType::Map } - ); -} - -SymbolSDFProgram::UniformValues -SymbolSDFProgram::haloUniformValues(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, - float pixelRatio) + const SymbolSDFPart part) { const float scale = values.paintSize / values.sdfScale; - const float sdfPx = 8.0f; - const float blurOffset = 1.19f; - const float haloOffset = 6.0f; - - return makeSDFValues( + + const float gammaScale = scale * (values.pitchAlignment == AlignmentType::Map + ? std::cos(state.getPitch()) + : 1.0) * state.getCameraToCenterDistance(); + + return makeValues<SymbolSDFProgram<PaintProperties>::UniformValues>( values, texsize, pixelsToGLUnits, tile, state, - pixelRatio, - values.haloColor, - (haloOffset - values.haloWidth / scale) / sdfPx, - values.haloBlur * blurOffset / scale / sdfPx + 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() }, + uniforms::u_aspect_ratio::Value{ (state.getSize().width * 1.0f) / (state.getSize().height * 1.0f) }, + uniforms::u_pitch_with_map::Value{ values.pitchAlignment == AlignmentType::Map }, + uniforms::u_is_halo::Value{ part == SymbolSDFPart::Halo } ); } -SymbolSDFProgram::UniformValues -SymbolSDFProgram::foregroundUniformValues(const style::SymbolPropertyValues& values, - const Size& texsize, - const std::array<float, 2>& pixelsToGLUnits, - const RenderTile& tile, - const TransformState& state, - float pixelRatio) -{ - return makeSDFValues( - values, - texsize, - pixelsToGLUnits, - tile, - state, - pixelRatio, - values.color, - (256.0f - 64.0f) / 256.0f, - 0 - ); -} +template class SymbolSDFProgram<style::IconPaintProperties>; +template class SymbolSDFProgram<style::TextPaintProperties>; } // namespace mbgl diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index e0e90f0fa4..0537c25a2c 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -8,6 +8,7 @@ #include <mbgl/util/geometry.hpp> #include <mbgl/util/size.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> +#include <mbgl/style/layers/symbol_layer_impl.hpp> #include <cmath> #include <array> @@ -27,9 +28,10 @@ MBGL_DEFINE_UNIFORM_SCALAR(bool, u_rotate_with_map); MBGL_DEFINE_UNIFORM_SCALAR(bool, u_pitch_with_map); MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_texture); MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_fadetexture); -MBGL_DEFINE_UNIFORM_SCALAR(float, u_buffer); -MBGL_DEFINE_UNIFORM_SCALAR(float, u_gamma); MBGL_DEFINE_UNIFORM_SCALAR(float, u_aspect_ratio); +MBGL_DEFINE_UNIFORM_SCALAR(bool, u_is_halo); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_font_scale); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_gamma_scale); } // namespace uniforms struct SymbolLayoutAttributes : gl::Attributes< @@ -75,14 +77,13 @@ class SymbolIconProgram : public Program< SymbolLayoutAttributes, gl::Uniforms< uniforms::u_matrix, - uniforms::u_opacity, uniforms::u_extrude_scale, uniforms::u_texsize, uniforms::u_zoom, uniforms::u_rotate_with_map, uniforms::u_texture, uniforms::u_fadetexture>, - style::SymbolPaintProperties> + style::IconPaintProperties> { public: using Program::Program; @@ -94,47 +95,73 @@ public: const TransformState&); }; +enum class SymbolSDFPart { + Fill = 1, + Halo = 0 +}; + +template <class PaintProperties> class SymbolSDFProgram : public Program< shaders::symbol_sdf, gl::Triangle, SymbolLayoutAttributes, gl::Uniforms< uniforms::u_matrix, - uniforms::u_opacity, uniforms::u_extrude_scale, uniforms::u_texsize, uniforms::u_zoom, uniforms::u_rotate_with_map, uniforms::u_texture, uniforms::u_fadetexture, - uniforms::u_color, - uniforms::u_buffer, - uniforms::u_gamma, + uniforms::u_font_scale, + uniforms::u_gamma_scale, uniforms::u_pitch, uniforms::u_bearing, uniforms::u_aspect_ratio, - uniforms::u_pitch_with_map>, - style::SymbolPaintProperties> + uniforms::u_pitch_with_map, + uniforms::u_is_halo>, + PaintProperties> { public: - using Program::Program; + using BaseProgram = Program<shaders::symbol_sdf, + gl::Triangle, + SymbolLayoutAttributes, + gl::Uniforms< + uniforms::u_matrix, + uniforms::u_extrude_scale, + uniforms::u_texsize, + uniforms::u_zoom, + uniforms::u_rotate_with_map, + uniforms::u_texture, + uniforms::u_fadetexture, + uniforms::u_font_scale, + uniforms::u_gamma_scale, + uniforms::u_pitch, + uniforms::u_bearing, + uniforms::u_aspect_ratio, + uniforms::u_pitch_with_map, + uniforms::u_is_halo>, + PaintProperties>; + + using UniformValues = typename BaseProgram::UniformValues; + - static UniformValues haloUniformValues(const style::SymbolPropertyValues&, - const Size& texsize, - const std::array<float, 2>& pixelsToGLUnits, - const RenderTile&, - const TransformState&, - float pixelRatio); - - static UniformValues foregroundUniformValues(const style::SymbolPropertyValues&, - const Size& texsize, - const std::array<float, 2>& pixelsToGLUnits, - const RenderTile&, - const TransformState&, - float pixelRatio); + + using BaseProgram::BaseProgram; + + static UniformValues uniformValues(const style::SymbolPropertyValues&, + const Size& texsize, + const std::array<float, 2>& pixelsToGLUnits, + const RenderTile&, + const TransformState&, + const SymbolSDFPart); }; +using SymbolSDFIconProgram = SymbolSDFProgram<style::IconPaintProperties>; +using SymbolSDFTextProgram = SymbolSDFProgram<style::TextPaintProperties>; + using SymbolLayoutVertex = SymbolLayoutAttributes::Vertex; -using SymbolAttributes = SymbolIconProgram::Attributes; +using SymbolIconAttributes = SymbolIconProgram::Attributes; +using SymbolTextAttributes = SymbolSDFTextProgram::Attributes; } // namespace mbgl |