#pragma once #include #include #include #include #include #include namespace mbgl { class LayerGroup; class PaintParameters; class RenderOrchestrator; class TileLayerGroup; using LayerGroupPtr = std::shared_ptr; namespace gfx { class Context; class Drawable; class UploadPass; using DrawablePtr = std::shared_ptr; using UniqueDrawable = std::unique_ptr; } // namespace gfx class LayerTweaker; using LayerTweakerPtr = std::shared_ptr; /** A layer-like group of drawables, not a group of layers. */ class LayerGroup : public util::SimpleIdentifiable { protected: LayerGroup(int32_t layerIndex); public: LayerGroup(const LayerGroup&) = delete; LayerGroup& operator=(const LayerGroup&) = delete; int32_t getLayerIndex() const { return layerIndex; } /// Called before starting each frame virtual void preRender(RenderOrchestrator&, PaintParameters&) {} /// Called during the upload pass virtual void upload(gfx::Context&, gfx::UploadPass&) {} /// Called during each render pass virtual void render(RenderOrchestrator&, PaintParameters&) {} /// Called at the end of each frame virtual void postRender(RenderOrchestrator&, PaintParameters&) {} /// Call the provided function for each drawable in undefined order virtual void observeDrawables(std::function) = 0; virtual void observeDrawables(std::function) const = 0; /// Call the provided function for each drawable in undefined order, allowing ownership to be taken. virtual void observeDrawables(std::function) = 0; /// Attach a tweaker to be run on this layer group for each frame void setLayerTweaker(LayerTweakerPtr tweaker) { layerTweaker = std::move(tweaker); } /// Get the tweaker attached to this layer group const LayerTweakerPtr& getLayerTweaker() const { return layerTweaker; } protected: int32_t layerIndex; LayerTweakerPtr layerTweaker; }; /** A layer group for tile-based drawables. */ class TileLayerGroup : public LayerGroup { public: TileLayerGroup(int32_t layerIndex, std::size_t initialCapacity); ~TileLayerGroup() override; std::size_t getDrawableCount() const; const gfx::UniqueDrawable& getDrawable(mbgl::RenderPass, const OverscaledTileID&) const; std::vector removeDrawables(mbgl::RenderPass, const OverscaledTileID&); void addDrawable(mbgl::RenderPass, const OverscaledTileID&, gfx::UniqueDrawable&&); void observeDrawables(std::function) override; void observeDrawables(std::function) const override; void observeDrawables(std::function) override; void clearDrawables(); protected: struct Impl; std::unique_ptr impl; }; } // namespace mbgl