#pragma once #include "drape/gl_constants.hpp" #include "drape/graphics_context.hpp" #include "drape/pointers.hpp" #include "drape/texture_types.hpp" #include namespace dp { class HWTextureAllocator; class HWTexture { public: virtual ~HWTexture(); struct Params { uint32_t m_width = 0; uint32_t m_height = 0; TextureFilter m_filter = TextureFilter::Linear; TextureWrapping m_wrapSMode = TextureWrapping::ClampToEdge; TextureWrapping m_wrapTMode = TextureWrapping::ClampToEdge; TextureFormat m_format = TextureFormat::Unspecified; bool m_usePixelBuffer = false; bool m_isRenderTarget = false; bool m_isMutable = false; ref_ptr m_allocator; }; void Create(ref_ptr context, Params const & params); virtual void Create(ref_ptr context, Params const & params, ref_ptr data) = 0; virtual void UploadData(ref_ptr context, uint32_t x, uint32_t y, uint32_t width, uint32_t height, ref_ptr data) = 0; virtual void Bind(ref_ptr context) const = 0; // For OpenGL the texture must be bound before calling this method. virtual void SetFilter(TextureFilter filter) = 0; virtual bool Validate() const = 0; TextureFormat GetFormat() const; uint32_t GetWidth() const; uint32_t GetHeight() const; float GetS(uint32_t x) const; float GetT(uint32_t y) const; Params const & GetParams() const { return m_params; } uint32_t GetID() const; protected: Params m_params; uint32_t m_textureID = 0; uint32_t m_pixelBufferID = 0; uint32_t m_pixelBufferSize = 0; uint32_t m_pixelBufferElementSize = 0; }; class HWTextureAllocator { public: virtual ~HWTextureAllocator() = default; virtual drape_ptr CreateTexture(ref_ptr context) = 0; virtual void Flush() = 0; }; class OpenGLHWTexture : public HWTexture { using Base = HWTexture; public: ~OpenGLHWTexture() override; void Create(ref_ptr context, Params const & params, ref_ptr data) override; void UploadData(ref_ptr context, uint32_t x, uint32_t y, uint32_t width, uint32_t height, ref_ptr data) override; void Bind(ref_ptr context) const override; void SetFilter(TextureFilter filter) override; bool Validate() const override; private: glConst m_unpackedLayout = 0; glConst m_unpackedPixelType = 0; }; class OpenGLHWTextureAllocator : public HWTextureAllocator { public: drape_ptr CreateTexture(ref_ptr context) override; void Flush() override; }; ref_ptr GetDefaultAllocator(ref_ptr context); drape_ptr CreateAllocator(ref_ptr context); void UnpackFormat(ref_ptr context, TextureFormat format, glConst & layout, glConst & pixelType); glConst DecodeTextureFilter(TextureFilter filter); glConst DecodeTextureWrapping(TextureWrapping wrapping); } // namespace dp