#pragma once #include "drape/attribute_provider.hpp" #include "drape/graphics_context.hpp" #include "drape/overlay_handle.hpp" #include "drape/pointers.hpp" #include "drape/render_bucket.hpp" #include "drape/render_state.hpp" #include "drape/vertex_array_buffer.hpp" #include "base/macros.hpp" #include #include #include namespace dp { class RenderBucket; class AttributeProvider; class OverlayHandle; class Batcher { public: static uint32_t const IndexPerTriangle = 3; static uint32_t const IndexPerQuad = 6; static uint32_t const VertexPerQuad = 4; Batcher(uint32_t indexBufferSize, uint32_t vertexBufferSize); ~Batcher(); void InsertTriangleList(ref_ptr context, RenderState const & state, ref_ptr params); IndicesRange InsertTriangleList(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && handle); void InsertTriangleStrip(ref_ptr context, RenderState const & state, ref_ptr params); IndicesRange InsertTriangleStrip(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && handle); void InsertTriangleFan(ref_ptr context, RenderState const & state, ref_ptr params); IndicesRange InsertTriangleFan(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && handle); void InsertListOfStrip(ref_ptr context, RenderState const & state, ref_ptr params, uint8_t vertexStride); IndicesRange InsertListOfStrip(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && handle, uint8_t vertexStride); void InsertLineStrip(ref_ptr context, RenderState const & state, ref_ptr params); IndicesRange InsertLineStrip(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && handle); void InsertLineRaw(ref_ptr context, RenderState const & state, ref_ptr params, std::vector const & indices); IndicesRange InsertLineRaw(ref_ptr context, RenderState const & state, ref_ptr params, std::vector const & indices, drape_ptr && handle); using TFlushFn = std::function &&)>; void StartSession(TFlushFn const & flusher); void EndSession(ref_ptr context); void ResetSession(); void SetBatcherHash(uint64_t batcherHash); void SetFeatureMinZoom(int minZoom); private: template IndicesRange InsertPrimitives(ref_ptr context, RenderState const & state, ref_ptr params, drape_ptr && transferHandle, uint8_t vertexStride, TArgs... batcherArgs); class CallbacksWrapper; void ChangeBuffer(ref_ptr context, ref_ptr wrapper); ref_ptr GetBucket(RenderState const & state); void FinalizeBucket(ref_ptr context, RenderState const & state); void Flush(ref_ptr context); uint32_t const m_indexBufferSize; uint32_t const m_vertexBufferSize; uint64_t m_batcherHash = 0; TFlushFn m_flushInterface; using TBuckets = std::map>; TBuckets m_buckets; int m_featureMinZoom = 0; }; class BatcherFactory { public: BatcherFactory(uint32_t indexBufferSize, uint32_t vertexBufferSize) : m_indexBufferSize(indexBufferSize) , m_vertexBufferSize(vertexBufferSize) {} Batcher * GetNew() const; private: uint32_t const m_indexBufferSize; uint32_t const m_vertexBufferSize; }; class SessionGuard { public: SessionGuard(ref_ptr context, Batcher & batcher, Batcher::TFlushFn const & flusher); ~SessionGuard(); private: ref_ptr m_context; Batcher & m_batcher; DISALLOW_COPY_AND_MOVE(SessionGuard); }; } // namespace dp