diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-12-13 20:29:14 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-01-11 16:43:52 +0200 |
commit | d37918c169b2f688c96fb766fc671066c88fc1a2 (patch) | |
tree | 20cdfe0a824bf128053aab7c8ad4f69676f66f49 /src/mbgl/programs/programs.cpp | |
parent | 2bdab82dedf545b4272c534b067c68614d0355b7 (diff) | |
download | qtlocation-mapboxgl-d37918c169b2f688c96fb766fc671066c88fc1a2.tar.gz |
[core] Split layer type specific code in mbgl::Programs
Progams code for a certain layer type is encapsulted within
a dedicated `<layer type>Programs` class, inherited from
the generic base `LayerTypePrograms` class.
`mbgl::Programs::get<layer type>Programs()` lazily initializes the
layer type-specific programs code using pointer to the base class,
which allows LTO to remove this code from binaries (if the corresponding
`get<layer type>Programs()` method can never be invoked).
Diffstat (limited to 'src/mbgl/programs/programs.cpp')
-rw-r--r-- | src/mbgl/programs/programs.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/mbgl/programs/programs.cpp b/src/mbgl/programs/programs.cpp new file mode 100644 index 0000000000..f3b3af8ac9 --- /dev/null +++ b/src/mbgl/programs/programs.cpp @@ -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 |