1 #pragma once 2 3 #include <mbgl/renderer/render_pass.hpp> 4 #include <mbgl/style/layer_impl.hpp> 5 #include <mbgl/style/layer_type.hpp> 6 #include <mbgl/tile/geometry_tile_data.hpp> 7 #include <mbgl/util/mat4.hpp> 8 9 #include <memory> 10 #include <string> 11 12 namespace mbgl { 13 14 class Bucket; 15 class BucketParameters; 16 class TransitionParameters; 17 class PropertyEvaluationParameters; 18 class PaintParameters; 19 class RenderSource; 20 class RenderTile; 21 class TransformState; 22 23 class RenderLayer { 24 protected: 25 RenderLayer(style::LayerType, Immutable<style::Layer::Impl>); 26 27 const style::LayerType type; 28 29 public: 30 static std::unique_ptr<RenderLayer> create(Immutable<style::Layer::Impl>); 31 32 virtual ~RenderLayer() = default; 33 34 // Begin transitions for any properties that have changed since the last frame. 35 virtual void transition(const TransitionParameters&) = 0; 36 37 // Fully evaluate possibly-transitioning paint properties based on a zoom level. 38 virtual void evaluate(const PropertyEvaluationParameters&) = 0; 39 40 // Returns true if any paint properties have active transitions. 41 virtual bool hasTransition() const = 0; 42 43 // Check whether this layer is of the given subtype. 44 template <class T> 45 bool is() const; 46 47 // Dynamically cast this layer to the given subtype. 48 template <class T> as()49 T* as() { 50 return is<T>() ? reinterpret_cast<T*>(this) : nullptr; 51 } 52 53 template <class T> as() const54 const T* as() const { 55 return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; 56 } 57 58 const std::string& getID() const; 59 60 // Checks whether this layer needs to be rendered in the given render pass. 61 bool hasRenderPass(RenderPass) const; 62 63 // Checks whether this layer can be rendered. 64 bool needsRendering(float zoom) const; 65 66 virtual void render(PaintParameters&, RenderSource*) = 0; 67 68 // Check wether the given geometry intersects 69 // with the feature queryIntersectsFeature(const GeometryCoordinates &,const GeometryTileFeature &,const float,const TransformState &,const float,const mat4 &) const70 virtual bool queryIntersectsFeature( 71 const GeometryCoordinates&, 72 const GeometryTileFeature&, 73 const float, 74 const TransformState&, 75 const float, 76 const mat4&) const { return false; }; 77 78 virtual std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const = 0; 79 80 void setRenderTiles(std::vector<std::reference_wrapper<RenderTile>>); 81 // Private implementation 82 Immutable<style::Layer::Impl> baseImpl; 83 void setImpl(Immutable<style::Layer::Impl>); 84 85 friend std::string layoutKey(const RenderLayer&); 86 87 protected: 88 // Checks whether the current hardware can render this layer. If it can't, we'll show a warning 89 // in the console to inform the developer. 90 void checkRenderability(const PaintParameters&, uint32_t activeBindingCount); 91 92 protected: 93 // renderTiles are exposed directly to CrossTileSymbolIndex and Placement so they 94 // can update opacities in the symbol buckets immediately before rendering 95 friend class CrossTileSymbolIndex; 96 friend class Placement; 97 // Stores current set of tiles to be rendered for this layer. 98 std::vector<std::reference_wrapper<RenderTile>> renderTiles; 99 100 // Stores what render passes this layer is currently enabled for. This depends on the 101 // evaluated StyleProperties object and is updated accordingly. 102 RenderPass passes = RenderPass::None; 103 104 private: 105 // Some layers may not render correctly on some hardware when the vertex attribute limit of 106 // that GPU is exceeded. More attributes are used when adding many data driven paint properties 107 // to a layer. 108 bool hasRenderFailures = false; 109 }; 110 111 } // namespace mbgl 112