#pragma once #import #include "drape/graphics_context.hpp" #include "drape/metal/metal_gpu_program.hpp" #include "drape/pointers.hpp" #include "drape/texture_types.hpp" #include #include namespace dp { namespace metal { class MetalStates { public: struct DepthStencilKey { void SetDepthTestEnabled(bool enabled); void SetDepthTestFunction(TestFunction depthFunction); void SetStencilTestEnabled(bool enabled); void SetStencilFunction(StencilFace face, TestFunction stencilFunction); void SetStencilActions(StencilFace face, StencilAction stencilFailAction, StencilAction depthFailAction, StencilAction passAction); bool operator<(DepthStencilKey const & rhs) const; MTLDepthStencilDescriptor * BuildDescriptor() const; bool m_depthEnabled = false; bool m_stencilEnabled = false; TestFunction m_depthFunction = TestFunction::Always; uint64_t m_stencil = 0; }; struct PipelineKey { PipelineKey() = default; PipelineKey(ref_ptr program, MTLPixelFormat colorFormat, MTLPixelFormat depthStencilFormat, bool blendingEnabled); bool operator<(PipelineKey const & rhs) const; MTLRenderPipelineDescriptor * BuildDescriptor() const; ref_ptr m_program; MTLPixelFormat m_colorFormat = MTLPixelFormatInvalid; MTLPixelFormat m_depthStencilFormat = MTLPixelFormatInvalid; bool m_blendingEnabled = false; }; struct SamplerKey { SamplerKey() = default; SamplerKey(TextureFilter filter, TextureWrapping wrapSMode, TextureWrapping wrapTMode); void Set(TextureFilter filter, TextureWrapping wrapSMode, TextureWrapping wrapTMode); bool operator<(SamplerKey const & rhs) const; MTLSamplerDescriptor * BuildDescriptor() const; uint32_t m_sampler = 0; }; id GetDepthStencilState(id device, DepthStencilKey const & key); id GetPipelineState(id device, PipelineKey const & key); id GetSamplerState(id device, SamplerKey const & key); void ResetPipelineStatesCache(); private: using DepthStencilCache = std::map>; DepthStencilCache m_depthStencilCache; using PipelineCache = std::map>; PipelineCache m_pipelineCache; using SamplerCache = std::map>; SamplerCache m_samplerCache; }; } // namespace metal } // namespace dp