| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsIReflectable.h"
- #include "BsCoreObject.h"
- namespace BansheeEngine
- {
- /**
- * @brief Descriptor structured used for initializing DepthStencilState.
- *
- * @see DepthStencilState
- */
- struct BS_CORE_EXPORT DEPTH_STENCIL_STATE_DESC
- {
- DEPTH_STENCIL_STATE_DESC()
- : depthReadEnable(true)
- , depthWriteEnable(true)
- , depthComparisonFunc(CMPF_LESS)
- , stencilEnable(false)
- , stencilReadMask(0xFF)
- , stencilWriteMask(0xFF)
- , frontStencilFailOp(SOP_KEEP)
- , frontStencilZFailOp(SOP_KEEP)
- , frontStencilPassOp(SOP_KEEP)
- , frontStencilComparisonFunc(CMPF_ALWAYS_PASS)
- , backStencilFailOp(SOP_KEEP)
- , backStencilZFailOp(SOP_KEEP)
- , backStencilPassOp(SOP_KEEP)
- , backStencilComparisonFunc(CMPF_ALWAYS_PASS)
- { }
- bool depthReadEnable;
- bool depthWriteEnable;
- CompareFunction depthComparisonFunc;
- bool stencilEnable;
- UINT8 stencilReadMask;
- UINT8 stencilWriteMask;
- StencilOperation frontStencilFailOp;
- StencilOperation frontStencilZFailOp;
- StencilOperation frontStencilPassOp;
- CompareFunction frontStencilComparisonFunc;
- StencilOperation backStencilFailOp;
- StencilOperation backStencilZFailOp;
- StencilOperation backStencilPassOp;
- CompareFunction backStencilComparisonFunc;
- };
- BS_ALLOW_MEMCPY_SERIALIZATION(DEPTH_STENCIL_STATE_DESC);
- /**
- * @brief Information about a depth stencil state.
- */
- class BS_CORE_EXPORT DepthStencilProperties
- {
- public:
- DepthStencilProperties(const DEPTH_STENCIL_STATE_DESC& desc);
- /**
- * @brief If enabled, any pixel about to be written will be tested against the depth value
- * currently in the buffer. If the depth test passes (depending on the set value
- * and chosen depth comparison function), that pixel is written and depth is
- * updated (if depth write is enabled).
- */
- bool getDepthReadEnable() const { return mData.depthReadEnable; }
- /**
- * @brief If enabled rendering pixels will update the depth buffer value.
- */
- bool getDepthWriteEnable() const { return mData.depthWriteEnable; }
- /**
- * @brief Determines what operation should the renderer use when comparing previous and
- * current depth value. If the operation passes, pixel with the current depth
- * value will be considered visible.
- */
- CompareFunction getDepthComparisonFunc() const { return mData.depthComparisonFunc; }
- /**
- * @brief If true then stencil buffer will also be updated when a pixel is written, and
- * pixels will be tested against the stencil buffer before rendering.
- */
- bool getStencilEnable() const { return mData.stencilEnable; }
- /**
- * @brief Mask to apply to any value read from the stencil buffer, before applying the
- * stencil comparison function.
- */
- UINT8 getStencilReadMask() const { return mData.stencilReadMask; }
- /**
- * @brief Mask to apply to any value about to be written in the stencil buffer.
- */
- UINT8 getStencilWriteMask() const { return mData.stencilWriteMask; }
- /**
- * @brief Operation that happens when stencil comparison function fails on a front facing polygon.
- */
- StencilOperation getStencilFrontFailOp() const { return mData.frontStencilFailOp; }
- /**
- * @brief Operation that happens when stencil comparison function passes but depth test fails
- * on a front facing polygon.
- */
- StencilOperation getStencilFrontZFailOp() const { return mData.frontStencilZFailOp; }
- /**
- * @brief Operation that happens when stencil comparison function passes on a front facing polygon.
- */
- StencilOperation getStencilFrontPassOp() const { return mData.frontStencilPassOp; }
- /**
- * @brief Stencil comparison function used for front facing polygons. Stencil buffer will be modified according
- * to previously set stencil operations depending whether this comparison passes or fails.
- */
- CompareFunction getStencilFrontCompFunc() const { return mData.frontStencilComparisonFunc; }
- /**
- * @brief Operation that happens when stencil comparison function fails on a back facing polygon.
- */
- StencilOperation getStencilBackFailOp() const { return mData.backStencilFailOp; }
- /**
- * @brief Operation that happens when stencil comparison function passes but depth test fails
- * on a back facing polygon.
- */
- StencilOperation getStencilBackZFailOp() const { return mData.backStencilZFailOp; }
- /**
- * @brief Operation that happens when stencil comparison function passes on a back facing polygon.
- */
- StencilOperation getStencilBackPassOp() const { return mData.backStencilPassOp; }
- /**
- * @brief Stencil comparison function used for back facing polygons. Stencil buffer will be modified according
- * to previously set stencil operations depending whether this comparison passes or fails.
- */
- CompareFunction getStencilBackCompFunc() const { return mData.backStencilComparisonFunc; }
- protected:
- friend class DepthStencilState;
- friend class DepthStencilStateRTTI;
- DEPTH_STENCIL_STATE_DESC mData;
- };
- /**
- * @brief Core thread version of the depth stencil state.
- *
- * @see DepthStencilState
- *
- * @note Core thread.
- */
- class BS_CORE_EXPORT DepthStencilStateCore : public CoreObjectCore
- {
- public:
- virtual ~DepthStencilStateCore() {}
- /**
- * @brief Returns information about the depth stencil state.
- */
- const DepthStencilProperties& getProperties() const;
- /**
- * @brief Returns the default depth stencil state that you may use when no other is available.
- */
- static const SPtr<DepthStencilStateCore>& getDefault();
- protected:
- friend class RenderStateCoreManager;
- DepthStencilStateCore(const DEPTH_STENCIL_STATE_DESC& desc);
- DepthStencilProperties mProperties;
- };
- /**
- * @brief Render system pipeline state that allows you to modify how an object is rendered.
- * More exactly this state allows to you to control how are depth and stencil buffers
- * modified upon rendering.
- *
- * @note Depth stencil states are immutable. Sim thread only.
- */
- class BS_CORE_EXPORT DepthStencilState : public IReflectable, public CoreObject
- {
- public:
- virtual ~DepthStencilState() {}
- /**
- * @brief Returns information about the depth stencil state.
- */
- const DepthStencilProperties& getProperties() const;
- /**
- * @brief Retrieves a core implementation of a sampler state usable only from the
- * core thread.
- */
- SPtr<DepthStencilStateCore> getCore() const;
- /**
- * @brief Creates a new depth stencil state using the specified depth stencil state description structure.
- */
- static DepthStencilStatePtr create(const DEPTH_STENCIL_STATE_DESC& desc);
- /**
- * @brief Returns the default depth stencil state that you may use when no other is available.
- */
- static const DepthStencilStatePtr& getDefault();
- protected:
- friend class RenderStateManager;
- DepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc);
- /**
- * @copydoc CoreObjectCore::createCore
- */
- SPtr<CoreObjectCore> createCore() const;
- DepthStencilProperties mProperties;
- /************************************************************************/
- /* RTTI */
- /************************************************************************/
- public:
- friend class DepthStencilStateRTTI;
- static RTTITypeBase* getRTTIStatic();
- virtual RTTITypeBase* getRTTI() const;
- };
- }
|