| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsModule.h"
- #include "BsBlendState.h"
- #include "BsRasterizerState.h"
- #include "BsDepthStencilState.h"
- #include "BsSamplerState.h"
- namespace BansheeEngine
- {
- /**
- * @brief Common methods and data for both sim and core thread versions
- * of RenderStateManager.
- */
- template<bool Core>
- class BS_CORE_EXPORT TRenderStateManager
- {
- public:
- virtual ~TRenderStateManager() { }
- protected:
- template<bool Core> struct TSamplerStateType { };
- template<> struct TSamplerStateType < false > { typedef SamplerState Type; };
- template<> struct TSamplerStateType < true > { typedef SamplerStateCore Type; };
- template<bool Core> struct TBlendStateType { };
- template<> struct TBlendStateType < false > { typedef BlendState Type; };
- template<> struct TBlendStateType < true > { typedef BlendStateCore Type; };
- template<bool Core> struct TRasterizerStateType { };
- template<> struct TRasterizerStateType < false > { typedef RasterizerState Type; };
- template<> struct TRasterizerStateType < true > { typedef RasterizerStateCore Type; };
- template<bool Core> struct TDepthStencilStateType { };
- template<> struct TDepthStencilStateType < false > { typedef DepthStencilState Type; };
- template<> struct TDepthStencilStateType < true > { typedef DepthStencilStateCore Type; };
- typedef typename TSamplerStateType<Core>::Type SamplerStateType;
- typedef typename TBlendStateType<Core>::Type BlendStateType;
- typedef typename TRasterizerStateType<Core>::Type RasterizerStateType;
- typedef typename TDepthStencilStateType<Core>::Type DepthStencilStateType;
- /**
- * @brief Triggered when a new sampler state is created.
- */
- void notifySamplerStateCreated(const SAMPLER_STATE_DESC& desc, const SPtr<SamplerStateType>& state) const;
- /**
- * @brief Triggered when a new sampler state is created.
- */
- void notifyBlendStateCreated(const BLEND_STATE_DESC& desc, const SPtr<BlendStateType>& state) const;
- /**
- * @brief Triggered when a new sampler state is created.
- */
- void notifyRasterizerStateCreated(const RASTERIZER_STATE_DESC& desc, const SPtr<RasterizerStateType>& state) const;
- /**
- * @brief Triggered when a new sampler state is created.
- */
- void notifyDepthStencilStateCreated(const DEPTH_STENCIL_STATE_DESC& desc, const SPtr<DepthStencilStateType>& state) const;
- /**
- * @brief Triggered when the last reference to a specific sampler state is destroyed, which
- * means we must clear our cached version as well.
- */
- void notifySamplerStateDestroyed(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @brief Triggered when the last reference to a specific blend state is destroyed, which
- * means we must clear our cached version as well.
- */
- void notifyBlendStateDestroyed(const BLEND_STATE_DESC& desc) const;
- /**
- * @brief Triggered when the last reference to a specific rasterizer state is destroyed, which
- * means we must clear our cached version as well.
- */
- void notifyRasterizerStateDestroyed(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @brief Triggered when the last reference to a specific depth stencil state is destroyed, which
- * means we must clear our cached version as well.
- */
- void notifyDepthStencilStateDestroyed(const DEPTH_STENCIL_STATE_DESC& desc) const;
- /**
- * @brief Attempts to find a cached sampler state corresponding to the provided descriptor.
- * Returns null if one doesn't exist.
- */
- SPtr<SamplerStateType> findCachedState(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @brief Attempts to find a cached blend state corresponding to the provided descriptor.
- * Returns null if one doesn't exist.
- */
- SPtr<BlendStateType> findCachedState(const BLEND_STATE_DESC& desc) const;
- /**
- * @brief Attempts to find a cached rasterizer state corresponding to the provided descriptor.
- * Returns null if one doesn't exist.
- */
- SPtr<RasterizerStateType> findCachedState(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @brief Attempts to find a cached depth-stencil state corresponding to the provided descriptor.
- * Returns null if one doesn't exist.
- */
- SPtr<DepthStencilStateType> findCachedState(const DEPTH_STENCIL_STATE_DESC& desc) const;
- mutable UnorderedMap<SAMPLER_STATE_DESC, std::weak_ptr<SamplerStateType>> mCachedSamplerStates;
- mutable UnorderedMap<BLEND_STATE_DESC, std::weak_ptr<BlendStateType>> mCachedBlendStates;
- mutable UnorderedMap<RASTERIZER_STATE_DESC, std::weak_ptr<RasterizerStateType>> mCachedRasterizerStates;
- mutable UnorderedMap<DEPTH_STENCIL_STATE_DESC, std::weak_ptr<DepthStencilStateType>> mCachedDepthStencilStates;
- BS_MUTEX(mMutex);
- };
- /**
- * @brief Handles creation of various render states.
- */
- class BS_CORE_EXPORT RenderStateManager : public Module <RenderStateManager>, TRenderStateManager<false>
- {
- public:
- /**
- * @brief Creates and initializes a new SamplerState.
- */
- SamplerStatePtr createSamplerState(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @brief Creates and initializes a new DepthStencilState.
- */
- DepthStencilStatePtr createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
- /**
- * @brief Creates and initializes a new RasterizerState.
- */
- RasterizerStatePtr createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @brief Creates and initializes a new BlendState.
- */
- BlendStatePtr createBlendState(const BLEND_STATE_DESC& desc) const;
- /**
- * @brief Creates an uninitialized sampler state. Requires manual initialization
- * after creation.
- *
- * @note Internal method.
- */
- SamplerStatePtr _createSamplerStatePtr(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @brief Creates an uninitialized depth-stencil state. Requires manual initialization
- * after creation.
- *
- * @note Internal method.
- */
- DepthStencilStatePtr _createDepthStencilStatePtr(const DEPTH_STENCIL_STATE_DESC& desc) const;
- /**
- * @brief Creates an uninitialized rasterizer state. Requires manual initialization
- * after creation.
- *
- * @note Internal method.
- */
- RasterizerStatePtr _createRasterizerStatePtr(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @brief Creates an uninitialized blend state. Requires manual initialization
- * after creation.
- *
- * @note Internal method.
- */
- BlendStatePtr _createBlendStatePtr(const BLEND_STATE_DESC& desc) const;
- /**
- * @brief Gets a sampler state initialized with default options.
- */
- const SamplerStatePtr& getDefaultSamplerState() const;
- /**
- * @brief Gets a blend state initialized with default options.
- */
- const BlendStatePtr& getDefaultBlendState() const;
- /**
- * @brief Gets a rasterizer state initialized with default options.
- */
- const RasterizerStatePtr& getDefaultRasterizerState() const;
- /**
- * @brief Gets a depth stencil state initialized with default options.
- */
- const DepthStencilStatePtr& getDefaultDepthStencilState() const;
- private:
- friend class SamplerState;
- friend class BlendState;
- friend class RasterizerState;
- friend class DepthStencilState;
- mutable SamplerStatePtr mDefaultSamplerState;
- mutable BlendStatePtr mDefaultBlendState;
- mutable RasterizerStatePtr mDefaultRasterizerState;
- mutable DepthStencilStatePtr mDefaultDepthStencilState;
- };
- /**
- * @brief Handles creation of various render states.
- */
- class BS_CORE_EXPORT RenderStateCoreManager : public Module<RenderStateCoreManager>, TRenderStateManager<true>
- {
- public:
- /**
- * @copydoc RenderStateManager::createSamplerState
- */
- SPtr<SamplerStateCore> createSamplerState(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @copydoc RenderStateManager::createDepthStencilState
- */
- SPtr<DepthStencilStateCore> createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const;
- /**
- * @copydoc RenderStateManager::createRasterizerState
- */
- SPtr<RasterizerStateCore> createRasterizerState(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @copydoc RenderStateManager::createBlendState
- */
- SPtr<BlendStateCore> createBlendState(const BLEND_STATE_DESC& desc) const;
- /**
- * @brief Gets a sampler state initialized with default options.
- */
- const SPtr<SamplerStateCore>& getDefaultSamplerState() const;
- /**
- * @brief Gets a blend state initialized with default options.
- */
- const SPtr<BlendStateCore>& getDefaultBlendState() const;
- /**
- * @brief Gets a rasterizer state initialized with default options.
- */
- const SPtr<RasterizerStateCore>& getDefaultRasterizerState() const;
- /**
- * @brief Gets a depth stencil state initialized with default options.
- */
- const SPtr<DepthStencilStateCore>& getDefaultDepthStencilState() const;
- private:
- mutable SPtr<SamplerStateCore> mDefaultSamplerState;
- mutable SPtr<BlendStateCore> mDefaultBlendState;
- mutable SPtr<RasterizerStateCore> mDefaultRasterizerState;
- mutable SPtr<DepthStencilStateCore> mDefaultDepthStencilState;
- protected:
- friend class SamplerState;
- friend class BlendState;
- friend class RasterizerState;
- friend class DepthStencilState;
- friend class SamplerStateCore;
- friend class BlendStateCore;
- friend class RasterizerStateCore;
- friend class DepthStencilStateCore;
- /**
- * @copydoc createSamplerState
- */
- virtual SPtr<SamplerStateCore> createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const;
- /**
- * @copydoc createBlendState
- */
- virtual SPtr<BlendStateCore> createBlendStateInternal(const BLEND_STATE_DESC& desc) const;
- /**
- * @copydoc createRasterizerState
- */
- virtual SPtr<RasterizerStateCore> createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const;
- /**
- * @copydoc createDepthStencilState
- */
- virtual SPtr<DepthStencilStateCore> createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const;
- };
- }
|