#pragma once #include "drape/gpu_program.hpp" #include "drape/graphics_context.hpp" #include "drape/pointers.hpp" #include "drape/texture.hpp" #include "base/assert.hpp" #include #include namespace dp { struct AlphaBlendingState { static void Apply(ref_ptr context); }; struct Blending { explicit Blending(bool isEnabled = true); void Apply(ref_ptr context, ref_ptr program) const; bool operator<(Blending const & other) const; bool operator==(Blending const & other) const; bool m_isEnabled; }; class BaseRenderStateExtension { public: virtual ~BaseRenderStateExtension() = default; virtual bool Less(ref_ptr other) const = 0; virtual bool Equal(ref_ptr other) const = 0; }; class RenderState { public: template RenderState(ProgramType gpuProgram, ref_ptr renderStateExtension) : m_renderStateExtension(std::move(renderStateExtension)) , m_gpuProgram(static_cast(gpuProgram)) , m_gpuProgram3d(static_cast(gpuProgram)) { ASSERT(m_renderStateExtension != nullptr, ()); } template ref_ptr GetRenderStateExtension() const { ASSERT(dynamic_cast(m_renderStateExtension.get()) != nullptr, ()); return make_ref(static_cast(m_renderStateExtension.get())); } void SetColorTexture(ref_ptr tex); ref_ptr GetColorTexture() const; void SetMaskTexture(ref_ptr tex); ref_ptr GetMaskTexture() const; void SetTexture(std::string const & name, ref_ptr tex); ref_ptr GetTexture(std::string const & name) const; std::map> const & GetTextures() const; void SetBlending(Blending const & blending) { m_blending = blending; } Blending const & GetBlending() const { return m_blending; } template ProgramType GetProgram() const { return static_cast(m_gpuProgram); } template void SetProgram3d(ProgramType gpuProgram3d) { m_gpuProgram3d = static_cast(gpuProgram3d); } template ProgramType GetProgram3d() const { return static_cast(m_gpuProgram3d); } TestFunction GetDepthFunction() const; void SetDepthFunction(TestFunction depthFunction); bool GetDepthTestEnabled() const; void SetDepthTestEnabled(bool enabled); TextureFilter GetTextureFilter() const; void SetTextureFilter(TextureFilter filter); bool GetDrawAsLine() const; void SetDrawAsLine(bool drawAsLine); int GetLineWidth() const; void SetLineWidth(int width); bool operator<(RenderState const & other) const; bool operator==(RenderState const & other) const; bool operator!=(RenderState const & other) const; private: ref_ptr m_renderStateExtension; size_t m_gpuProgram; size_t m_gpuProgram3d; Blending m_blending; bool m_depthTestEnabled = true; TestFunction m_depthFunction = TestFunction::LessOrEqual; TextureFilter m_textureFilter = TextureFilter::Linear; std::map> m_textures; bool m_drawAsLine = false; int m_lineWidth = 1; }; class TextureState { public: static void ApplyTextures(ref_ptr context, RenderState const & state, ref_ptr program); static uint8_t GetLastUsedSlots(); private: static uint8_t m_usedSlots; }; void ApplyState(ref_ptr context, ref_ptr program, RenderState const & state); } // namespace dp