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

[core] Split layer type specific code in mbgl::Programs #13577

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"src/mbgl/programs/hillshade_program.cpp",
"src/mbgl/programs/line_program.cpp",
"src/mbgl/programs/program_parameters.cpp",
"src/mbgl/programs/programs.cpp",
"src/mbgl/programs/raster_program.cpp",
"src/mbgl/programs/symbol_program.cpp",
"src/mbgl/renderer/backend_scope.cpp",
Expand Down
9 changes: 9 additions & 0 deletions src/mbgl/programs/background_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ class BackgroundPatternProgram : public Program<
using BackgroundLayoutVertex = BackgroundProgram::LayoutVertex;
using BackgroundAttributes = BackgroundProgram::Attributes;

class BackgroundLayerPrograms final : public LayerTypePrograms {
public:
BackgroundLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: background(context, programParameters),
backgroundPattern(context, programParameters) {}
BackgroundProgram background;
BackgroundPatternProgram backgroundPattern;
};

} // namespace mbgl
7 changes: 7 additions & 0 deletions src/mbgl/programs/circle_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ class CircleProgram : public Program<
using CircleLayoutVertex = CircleProgram::LayoutVertex;
using CircleAttributes = CircleProgram::Attributes;

class CircleLayerPrograms final : public LayerTypePrograms {
public:
CircleLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: circle(context, programParameters) {}
ProgramMap<CircleProgram> circle;
};

} // namespace mbgl
13 changes: 13 additions & 0 deletions src/mbgl/programs/fill_extrusion_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/extrusion_texture_program.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/fill_extrusion.hpp>
#include <mbgl/shaders/fill_extrusion_pattern.hpp>
Expand Down Expand Up @@ -112,4 +113,16 @@ class FillExtrusionPatternProgram : public Program<
using FillExtrusionLayoutVertex = FillExtrusionProgram::LayoutVertex;
using FillExtrusionAttributes = FillExtrusionProgram::Attributes;


class FillExtrusionLayerPrograms final : public LayerTypePrograms {
public:
FillExtrusionLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: fillExtrusion(context, programParameters),
fillExtrusionPattern(context, programParameters),
extrusionTexture(context, programParameters) {}
ProgramMap<FillExtrusionProgram> fillExtrusion;
ProgramMap<FillExtrusionPatternProgram> fillExtrusionPattern;
ExtrusionTextureProgram extrusionTexture;
};

} // namespace mbgl
13 changes: 13 additions & 0 deletions src/mbgl/programs/fill_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ class FillOutlinePatternProgram : public Program<
using FillLayoutVertex = FillProgram::LayoutVertex;
using FillAttributes = FillProgram::Attributes;

class FillLayerPrograms final : public LayerTypePrograms {
public:
FillLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: fill(context, programParameters),
fillPattern(context, programParameters),
fillOutline(context, programParameters),
fillOutlinePattern(context, programParameters) {}
ProgramMap<FillProgram> fill;
ProgramMap<FillPatternProgram> fillPattern;
ProgramMap<FillOutlineProgram> fillOutline;
ProgramMap<FillOutlinePatternProgram> fillOutlinePattern;
};

} // namespace mbgl
10 changes: 10 additions & 0 deletions src/mbgl/programs/heatmap_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/heatmap_texture_program.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/heatmap.hpp>
#include <mbgl/util/geometry.hpp>
Expand Down Expand Up @@ -46,4 +47,13 @@ class HeatmapProgram : public Program<
using HeatmapLayoutVertex = HeatmapProgram::LayoutVertex;
using HeatmapAttributes = HeatmapProgram::Attributes;

class HeatmapLayerPrograms final : public LayerTypePrograms {
public:
HeatmapLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: heatmap(context, programParameters),
heatmapTexture(context, programParameters) {}
ProgramMap<HeatmapProgram> heatmap;
HeatmapTextureProgram heatmapTexture;
};

} // namespace mbgl
10 changes: 10 additions & 0 deletions src/mbgl/programs/hillshade_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/hillshade_prepare_program.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/hillshade.hpp>
#include <mbgl/util/geometry.hpp>
Expand Down Expand Up @@ -52,4 +53,13 @@ class HillshadeProgram : public Program<
using HillshadeLayoutVertex = HillshadeProgram::LayoutVertex;
using HillshadeAttributes = HillshadeProgram::Attributes;

class HillshadeLayerPrograms final : public LayerTypePrograms {
public:
HillshadeLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: hillshade(context, programParameters),
hillshadePrepare(context, programParameters) {}
HillshadeProgram hillshade;
HillshadePrepareProgram hillshadePrepare;
};

} // namespace mbgl
13 changes: 13 additions & 0 deletions src/mbgl/programs/line_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,17 @@ class LineGradientProgram : public Program<
using LineLayoutVertex = LineProgram::LayoutVertex;
using LineAttributes = LineProgram::Attributes;

class LineLayerPrograms final : public LayerTypePrograms {
public:
LineLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: line(context, programParameters),
lineGradient(context, programParameters),
lineSDF(context, programParameters),
linePattern(context, programParameters) {}
ProgramMap<LineProgram> line;
ProgramMap<LineGradientProgram> lineGradient;
ProgramMap<LineSDFProgram> lineSDF;
ProgramMap<LinePatternProgram> linePattern;
};

} // namespace mbgl
5 changes: 5 additions & 0 deletions src/mbgl/programs/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ class ProgramMap {
std::unordered_map<Bitset, Program> programs;
};

class LayerTypePrograms {
public:
virtual ~LayerTypePrograms() = default;
};

} // namespace mbgl
87 changes: 87 additions & 0 deletions src/mbgl/programs/programs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <mbgl/programs/programs.hpp>

#include <mbgl/programs/background_program.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/programs/heatmap_program.hpp>
#include <mbgl/programs/hillshade_program.hpp>
#include <mbgl/programs/fill_extrusion_program.hpp>
#include <mbgl/programs/fill_program.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/programs/symbol_program.hpp>

namespace mbgl {

Programs::Programs(gl::Context& context_, const ProgramParameters& programParameters_)
: debug(context_, programParameters_),
clippingMask(context_, programParameters_),
context(context_),
programParameters(std::move(programParameters_)) {
}

Programs::~Programs() = default;

BackgroundLayerPrograms& Programs::getBackgroundLayerPrograms() noexcept {
if (!backgroundPrograms) {
backgroundPrograms = std::make_unique<BackgroundLayerPrograms>(context, programParameters);
}
return static_cast<BackgroundLayerPrograms&>(*backgroundPrograms);
}

RasterLayerPrograms& Programs::getRasterLayerPrograms() noexcept {
if (!rasterPrograms) {
rasterPrograms = std::make_unique<RasterLayerPrograms>(context, programParameters);
}
return static_cast<RasterLayerPrograms&>(*rasterPrograms);
}

HeatmapLayerPrograms& Programs::getHeatmapLayerPrograms() noexcept {
if (!heatmapPrograms) {
heatmapPrograms = std::make_unique<HeatmapLayerPrograms>(context, programParameters);
}
return static_cast<HeatmapLayerPrograms&>(*heatmapPrograms);
}

HillshadeLayerPrograms& Programs::getHillshadeLayerPrograms() noexcept {
if (!hillshadePrograms) {
hillshadePrograms = std::make_unique<HillshadeLayerPrograms>(context, programParameters);
}
return static_cast<HillshadeLayerPrograms&>(*hillshadePrograms);
}

FillLayerPrograms& Programs::getFillLayerPrograms() noexcept {
if (!fillPrograms) {
fillPrograms = std::make_unique<FillLayerPrograms>(context, programParameters);
}
return static_cast<FillLayerPrograms&>(*fillPrograms);
}

FillExtrusionLayerPrograms& Programs::getFillExtrusionLayerPrograms() noexcept {
if (!fillExtrusionPrograms) {
fillExtrusionPrograms = std::make_unique<FillExtrusionLayerPrograms>(context, programParameters);
}
return static_cast<FillExtrusionLayerPrograms&>(*fillExtrusionPrograms);
}

CircleLayerPrograms& Programs::getCircleLayerPrograms() noexcept {
if (!circlePrograms) {
circlePrograms = std::make_unique<CircleLayerPrograms>(context, programParameters);
}
return static_cast<CircleLayerPrograms&>(*circlePrograms);
}

LineLayerPrograms& Programs::getLineLayerPrograms() noexcept {
if (!linePrograms) {
linePrograms = std::make_unique<LineLayerPrograms>(context, programParameters);
}
return static_cast<LineLayerPrograms&>(*linePrograms);
}

SymbolLayerPrograms& Programs::getSymbolLayerPrograms() noexcept {
if (!symbolPrograms) {
symbolPrograms = std::make_unique<SymbolLayerPrograms>(context, programParameters);
}
return static_cast<SymbolLayerPrograms&>(*symbolPrograms);
}

} // namespace mbgl
102 changes: 37 additions & 65 deletions src/mbgl/programs/programs.hpp
Original file line number Diff line number Diff line change
@@ -1,82 +1,54 @@
#pragma once

#include <mbgl/programs/background_program.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/programs/clipping_mask_program.hpp>
#include <mbgl/programs/extrusion_texture_program.hpp>
#include <mbgl/programs/fill_program.hpp>
#include <mbgl/programs/fill_extrusion_program.hpp>
#include <mbgl/programs/heatmap_program.hpp>
#include <mbgl/programs/heatmap_texture_program.hpp>
#include <mbgl/programs/hillshade_program.hpp>
#include <mbgl/programs/hillshade_prepare_program.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/programs/raster_program.hpp>
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/programs/debug_program.hpp>
#include <mbgl/programs/collision_box_program.hpp>
#include <mbgl/programs/program_parameters.hpp>
#include <memory>

namespace mbgl {

class BackgroundLayerPrograms;

class CircleLayerPrograms;
class RasterLayerPrograms;
class HeatmapLayerPrograms;
class HillshadeLayerPrograms;
class FillLayerPrograms;
class FillExtrusionLayerPrograms;
class LineLayerPrograms;
class SymbolLayerPrograms;

class Programs {
public:
Programs(gl::Context& context, const ProgramParameters& programParameters)
: background(context, programParameters),
backgroundPattern(context, programParameters),
circle(context, programParameters),
extrusionTexture(context, programParameters),
fill(context, programParameters),
fillExtrusion(context, programParameters),
fillExtrusionPattern(context, programParameters),
fillPattern(context, programParameters),
fillOutline(context, programParameters),
fillOutlinePattern(context, programParameters),
heatmap(context, programParameters),
heatmapTexture(context, programParameters),
hillshade(context, programParameters),
hillshadePrepare(context, programParameters),
line(context, programParameters),
lineGradient(context, programParameters),
lineSDF(context, programParameters),
linePattern(context, programParameters),
raster(context, programParameters),
symbolIcon(context, programParameters),
symbolIconSDF(context, programParameters),
symbolGlyph(context, programParameters),
debug(context, programParameters),
collisionBox(context, programParameters),
collisionCircle(context, programParameters),
clippingMask(context, programParameters) {
}
Programs(gl::Context&, const ProgramParameters&);
~Programs();

BackgroundProgram background;
BackgroundPatternProgram backgroundPattern;
ProgramMap<CircleProgram> circle;
ExtrusionTextureProgram extrusionTexture;
ProgramMap<FillProgram> fill;
ProgramMap<FillExtrusionProgram> fillExtrusion;
ProgramMap<FillExtrusionPatternProgram> fillExtrusionPattern;
ProgramMap<FillPatternProgram> fillPattern;
ProgramMap<FillOutlineProgram> fillOutline;
ProgramMap<FillOutlinePatternProgram> fillOutlinePattern;
ProgramMap<HeatmapProgram> heatmap;
HeatmapTextureProgram heatmapTexture;
HillshadeProgram hillshade;
HillshadePrepareProgram hillshadePrepare;
ProgramMap<LineProgram> line;
ProgramMap<LineGradientProgram> lineGradient;
ProgramMap<LineSDFProgram> lineSDF;
ProgramMap<LinePatternProgram> linePattern;
RasterProgram raster;
ProgramMap<SymbolIconProgram> symbolIcon;
ProgramMap<SymbolSDFIconProgram> symbolIconSDF;
ProgramMap<SymbolSDFTextProgram> symbolGlyph;
BackgroundLayerPrograms& getBackgroundLayerPrograms() noexcept;
RasterLayerPrograms& getRasterLayerPrograms() noexcept;
HeatmapLayerPrograms& getHeatmapLayerPrograms() noexcept;
CircleLayerPrograms& getCircleLayerPrograms() noexcept;
HillshadeLayerPrograms& getHillshadeLayerPrograms() noexcept;
FillLayerPrograms& getFillLayerPrograms() noexcept;
FillExtrusionLayerPrograms& getFillExtrusionLayerPrograms() noexcept;
LineLayerPrograms& getLineLayerPrograms() noexcept;
SymbolLayerPrograms& getSymbolLayerPrograms() noexcept;

DebugProgram debug;
CollisionBoxProgram collisionBox;
CollisionCircleProgram collisionCircle;
ClippingMaskProgram clippingMask;

private:
std::unique_ptr<LayerTypePrograms> backgroundPrograms;
std::unique_ptr<LayerTypePrograms> circlePrograms;
std::unique_ptr<LayerTypePrograms> rasterPrograms;
std::unique_ptr<LayerTypePrograms> heatmapPrograms;
std::unique_ptr<LayerTypePrograms> hillshadePrograms;
std::unique_ptr<LayerTypePrograms> fillPrograms;
std::unique_ptr<LayerTypePrograms> fillExtrusionPrograms;
std::unique_ptr<LayerTypePrograms> linePrograms;
std::unique_ptr<LayerTypePrograms> symbolPrograms;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an abstract base class here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unique_ptr requires a destructor defined, so pointers to the concrete classes would prevent from LTO removing them from the binaries.


gl::Context& context;
ProgramParameters programParameters;
};

} // namespace mbgl
7 changes: 7 additions & 0 deletions src/mbgl/programs/raster_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ class RasterProgram : public Program<
using RasterLayoutVertex = RasterProgram::LayoutVertex;
using RasterAttributes = RasterProgram::Attributes;

class RasterLayerPrograms final : public LayerTypePrograms {
public:
RasterLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: raster(context, programParameters) {}
RasterProgram raster;
};

} // namespace mbgl
16 changes: 16 additions & 0 deletions src/mbgl/programs/symbol_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mbgl/util/interpolate.hpp>

#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/collision_box_program.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/shaders/symbol_icon.hpp>
Expand Down Expand Up @@ -448,4 +449,19 @@ using SymbolLayoutVertex = SymbolLayoutAttributes::Vertex;
using SymbolIconAttributes = SymbolIconProgram::Attributes;
using SymbolTextAttributes = SymbolSDFTextProgram::Attributes;

class SymbolLayerPrograms final : public LayerTypePrograms {
public:
SymbolLayerPrograms(gl::Context& context, const ProgramParameters& programParameters)
: symbolIcon(context, programParameters),
symbolIconSDF(context, programParameters),
symbolGlyph(context, programParameters),
collisionBox(context, programParameters),
collisionCircle(context, programParameters) {}
ProgramMap<SymbolIconProgram> symbolIcon;
ProgramMap<SymbolSDFIconProgram> symbolIconSDF;
ProgramMap<SymbolSDFTextProgram> symbolGlyph;
CollisionBoxProgram collisionBox;
CollisionCircleProgram collisionCircle;
};

} // namespace mbgl
Loading