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

Commit

Permalink
Prototype approach to subsetting symbol attribute binding
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jun 2, 2017
1 parent 2652a4a commit 600fc99
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 101 deletions.
10 changes: 0 additions & 10 deletions src/mbgl/programs/attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ struct a_color {
using Type = gl::Attribute<float, 2>;
};

struct a_fill_color {
static auto name() { return "a_fill_color"; }
using Type = gl::Attribute<float, 2>;
};

struct a_halo_color {
static auto name() { return "a_halo_color"; }
using Type = gl::Attribute<float, 2>;
};

struct a_stroke_color {
static auto name() { return "a_stroke_color"; }
using Type = gl::Attribute<float, 2>;
Expand Down
12 changes: 8 additions & 4 deletions src/mbgl/programs/programs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class Programs {
linePattern(context, programParameters),
raster(context, programParameters),
symbolIcon(context, programParameters),
symbolIconSDF(context, programParameters),
symbolGlyph(context, programParameters),
symbolSDFIconFill(context, programParameters),
symbolSDFIconHalo(context, programParameters),
symbolSDFTextFill(context, programParameters),
symbolSDFTextHalo(context, programParameters),
debug(context, ProgramParameters(programParameters.pixelRatio, false, programParameters.cacheDir)),
collisionBox(context, ProgramParameters(programParameters.pixelRatio, false, programParameters.cacheDir)) {
}
Expand All @@ -48,8 +50,10 @@ class Programs {
LinePatternProgram linePattern;
RasterProgram raster;
SymbolIconProgram symbolIcon;
SymbolSDFIconProgram symbolIconSDF;
SymbolSDFTextProgram symbolGlyph;
SymbolSDFIconFillProgram symbolSDFIconFill;
SymbolSDFIconHaloProgram symbolSDFIconHalo;
SymbolSDFTextFillProgram symbolSDFTextFill;
SymbolSDFTextHaloProgram symbolSDFTextHalo;

DebugProgram debug;
CollisionBoxProgram collisionBox;
Expand Down
9 changes: 3 additions & 6 deletions src/mbgl/programs/symbol_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ SymbolIconProgram::uniformValues(const bool isText,
);
}

template <class PaintProperties>
typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<PaintProperties>::uniformValues(
SymbolSDFUniforms::Values
symbolSDFUniformValues(
const bool isText,
const style::SymbolPropertyValues& values,
const Size& texsize,
Expand All @@ -93,7 +93,7 @@ typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<Paint
? std::cos(state.getPitch())
: 1.0) * state.getCameraToCenterDistance();

return makeValues<SymbolSDFProgram<PaintProperties>::UniformValues>(
return makeValues<SymbolSDFUniforms::Values>(
isText,
values,
texsize,
Expand All @@ -109,7 +109,4 @@ typename SymbolSDFProgram<PaintProperties>::UniformValues SymbolSDFProgram<Paint
);
}

template class SymbolSDFProgram<style::IconPaintProperties>;
template class SymbolSDFProgram<style::TextPaintProperties>;

} // namespace mbgl
133 changes: 74 additions & 59 deletions src/mbgl/programs/symbol_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ class SymbolIconProgram : public SymbolProgram<
uniforms::u_texture,
uniforms::u_fadetexture,
uniforms::u_is_text>,
style::IconPaintProperties>
style::Properties<
style::IconOpacity,
style::IconTranslate,
style::IconTranslateAnchor>>
{
public:
using SymbolProgram::SymbolProgram;
Expand All @@ -417,69 +420,81 @@ enum class SymbolSDFPart {
Halo = 0
};

template <class PaintProperties>
class SymbolSDFProgram : public SymbolProgram<
using SymbolSDFUniforms = 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_is_text,
uniforms::u_gamma_scale,
uniforms::u_pitch,
uniforms::u_bearing,
uniforms::u_aspect_ratio,
uniforms::u_pitch_with_map,
uniforms::u_is_halo>;

SymbolSDFUniforms::Values
symbolSDFUniformValues(const bool isText,
const style::SymbolPropertyValues&,
const Size& texsize,
const std::array<float, 2>& pixelsToGLUnits,
const RenderTile&,
const TransformState&,
const SymbolSDFPart);

using SymbolSDFIconFillProgram = SymbolProgram<
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_is_text,
uniforms::u_gamma_scale,
uniforms::u_pitch,
uniforms::u_bearing,
uniforms::u_aspect_ratio,
uniforms::u_pitch_with_map,
uniforms::u_is_halo>,
PaintProperties>
{
public:
using BaseProgram = SymbolProgram<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_is_text,
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;



using BaseProgram::BaseProgram;

static UniformValues uniformValues(const bool isText,
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>;
SymbolSDFUniforms,
style::Properties<
style::IconOpacity,
style::IconTranslate,
style::IconTranslateAnchor,
style::IconColor>>;

using SymbolSDFIconHaloProgram = SymbolProgram<
shaders::symbol_sdf,
gl::Triangle,
SymbolLayoutAttributes,
SymbolSDFUniforms,
style::Properties<
style::IconOpacity,
style::IconTranslate,
style::IconTranslateAnchor,
style::IconHaloColor,
style::IconHaloWidth,
style::IconHaloBlur>>;

using SymbolSDFTextFillProgram = SymbolProgram<
shaders::symbol_sdf,
gl::Triangle,
SymbolLayoutAttributes,
SymbolSDFUniforms,
style::Properties<
style::TextOpacity,
style::TextTranslate,
style::TextTranslateAnchor,
style::TextColor>>;

using SymbolSDFTextHaloProgram = SymbolProgram<
shaders::symbol_sdf,
gl::Triangle,
SymbolLayoutAttributes,
SymbolSDFUniforms,
style::Properties<
style::TextOpacity,
style::TextTranslate,
style::TextTranslateAnchor,
style::TextHaloColor,
style::TextHaloWidth,
style::TextHaloBlur>>;

using SymbolLayoutVertex = SymbolLayoutAttributes::Vertex;
using SymbolIconAttributes = SymbolIconProgram::Attributes;
using SymbolTextAttributes = SymbolSDFTextProgram::Attributes;
//using SymbolTextAttributes = SymbolSDFTextProgram::Attributes;

} // namespace mbgl
8 changes: 5 additions & 3 deletions src/mbgl/renderer/buckets/symbol_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ namespace mbgl {
class SymbolBucket : public Bucket {
public:
SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated,
const std::map<std::string, std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>>&,
const std::map<std::string, std::pair<
style::IconPaintProperties::PossiblyEvaluated,
style::TextPaintProperties::PossiblyEvaluated>>&,
const style::DataDrivenPropertyValue<float>& textSize,
const style::DataDrivenPropertyValue<float>& iconSize,
float zoom,
Expand All @@ -37,8 +39,8 @@ class SymbolBucket : public Bucket {
const bool iconsNeedLinear;

std::map<std::string, std::pair<
SymbolIconProgram::PaintPropertyBinders,
SymbolSDFTextProgram::PaintPropertyBinders>> paintPropertyBinders;
style::IconPaintProperties::Binders,
style::TextPaintProperties::Binders>> paintPropertyBinders;

std::unique_ptr<SymbolSizeBinder> textSizeBinder;

Expand Down
24 changes: 17 additions & 7 deletions src/mbgl/renderer/paint_property_binder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,36 @@ class PaintPropertyBinders<TypeList<Ps...>> {

template <class P>
using Attribute = ZoomInterpolatedAttribute<typename P::Attribute>;

using Attributes = gl::Attributes<Attribute<Ps>...>;
using AttributeBindings = typename Attributes::Bindings;

template <class P, class EvaluatedProperties>
auto attributeBinding(const EvaluatedProperties& currentProperties) const {
return binders.template get<P>()->attributeBinding(currentProperties.template get<P>());
}

template <class EvaluatedProperties>
AttributeBindings attributeBindings(const EvaluatedProperties& currentProperties) const {
return AttributeBindings {
binders.template get<Ps>()->attributeBinding(currentProperties.template get<Ps>())...
attributeBinding<Ps>(currentProperties)...
};
}

using Uniforms = gl::Uniforms<InterpolationUniform<typename Ps::Attribute>...>;
template <class P>
using Uniform = InterpolationUniform<typename P::Attribute>;
using Uniforms = gl::Uniforms<Uniform<Ps>...>;
using UniformValues = typename Uniforms::Values;

template <class P>
auto uniformValue(float currentZoom) const {
return typename Uniform<P>::Value {
binders.template get<P>()->interpolationFactor(currentZoom)
};
}

UniformValues uniformValues(float currentZoom) const {
(void)currentZoom; // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56958
return UniformValues {
typename InterpolationUniform<typename Ps::Attribute>::Value {
binders.template get<Ps>()->interpolationFactor(currentZoom)
}...
uniformValue<Ps>(currentZoom)...
};
}

Expand Down
16 changes: 8 additions & 8 deletions src/mbgl/renderer/painters/painter_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void Painter::renderSymbol(PaintParameters& parameters,

if (bucket.sdfIcons) {
if (values.hasHalo) {
draw(parameters.programs.symbolIconSDF,
SymbolSDFIconProgram::uniformValues(false, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Halo),
draw(parameters.programs.symbolSDFIconHalo,
symbolSDFUniformValues(false, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Halo),
bucket.icon,
bucket.iconSizeBinder,
values,
Expand All @@ -85,8 +85,8 @@ void Painter::renderSymbol(PaintParameters& parameters,
}

if (values.hasFill) {
draw(parameters.programs.symbolIconSDF,
SymbolSDFIconProgram::uniformValues(false, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Fill),
draw(parameters.programs.symbolSDFIconFill,
symbolSDFUniformValues(false, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Fill),
bucket.icon,
bucket.iconSizeBinder,
values,
Expand All @@ -113,8 +113,8 @@ void Painter::renderSymbol(PaintParameters& parameters,
const Size texsize = glyphAtlas->getSize();

if (values.hasHalo) {
draw(parameters.programs.symbolGlyph,
SymbolSDFTextProgram::uniformValues(true, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Halo),
draw(parameters.programs.symbolSDFTextHalo,
symbolSDFUniformValues(true, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Halo),
bucket.text,
bucket.textSizeBinder,
values,
Expand All @@ -123,8 +123,8 @@ void Painter::renderSymbol(PaintParameters& parameters,
}

if (values.hasFill) {
draw(parameters.programs.symbolGlyph,
SymbolSDFTextProgram::uniformValues(true, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Fill),
draw(parameters.programs.symbolSDFTextFill,
symbolSDFUniformValues(true, values, texsize, pixelsToGLUnits, tile, state, SymbolSDFPart::Fill),
bucket.text,
bucket.textSizeBinder,
values,
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/style/layers/symbol_layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ struct IconOpacity : DataDrivenPaintProperty<float, attributes::a_opacity> {
static float defaultValue() { return 1; }
};

struct IconColor : DataDrivenPaintProperty<Color, attributes::a_fill_color> {
struct IconColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};

struct IconHaloColor : DataDrivenPaintProperty<Color, attributes::a_halo_color> {
struct IconHaloColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return {}; }
};

Expand All @@ -213,11 +213,11 @@ struct TextOpacity : DataDrivenPaintProperty<float, attributes::a_opacity> {
static float defaultValue() { return 1; }
};

struct TextColor : DataDrivenPaintProperty<Color, attributes::a_fill_color> {
struct TextColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return Color::black(); }
};

struct TextHaloColor : DataDrivenPaintProperty<Color, attributes::a_halo_color> {
struct TextHaloColor : DataDrivenPaintProperty<Color, attributes::a_color> {
static Color defaultValue() { return {}; }
};

Expand Down

0 comments on commit 600fc99

Please sign in to comment.