|
@@ -4,87 +4,237 @@
|
|
|
#include "BsCoreThreadAccessor.h"
|
|
#include "BsCoreThreadAccessor.h"
|
|
|
#include "BsColor.h"
|
|
#include "BsColor.h"
|
|
|
#include "BsIReflectable.h"
|
|
#include "BsIReflectable.h"
|
|
|
|
|
+#include "BsCoreObject.h"
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Contains all data used by a pass, templated
|
|
|
|
|
+ * so it may contain both core and sim thread data.
|
|
|
|
|
+ */
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ struct PassData
|
|
|
|
|
+ { };
|
|
|
|
|
+
|
|
|
|
|
+ template<>
|
|
|
|
|
+ struct PassData < false >
|
|
|
|
|
+ {
|
|
|
|
|
+ typedef HBlendState BlendStateType;
|
|
|
|
|
+ typedef HRasterizerState RasterizerStateType;
|
|
|
|
|
+ typedef HDepthStencilState DepthStencilStateType;
|
|
|
|
|
+ typedef HGpuProgram GpuProgramType;
|
|
|
|
|
+
|
|
|
|
|
+ BlendStateType mBlendState;
|
|
|
|
|
+ RasterizerStateType mRasterizerState;
|
|
|
|
|
+ DepthStencilStateType mDepthStencilState;
|
|
|
|
|
+ UINT32 mStencilRefValue;
|
|
|
|
|
+
|
|
|
|
|
+ GpuProgramType mVertexProgram;
|
|
|
|
|
+ GpuProgramType mFragmentProgram;
|
|
|
|
|
+ GpuProgramType mGeometryProgram;
|
|
|
|
|
+ GpuProgramType mHullProgram;
|
|
|
|
|
+ GpuProgramType mDomainProgram;
|
|
|
|
|
+ GpuProgramType mComputeProgram;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ template<>
|
|
|
|
|
+ struct PassData < true >
|
|
|
|
|
+ {
|
|
|
|
|
+ typedef SPtr<BlendStateCore> BlendStateType;
|
|
|
|
|
+ typedef SPtr<RasterizerStateCore> RasterizerStateType;
|
|
|
|
|
+ typedef SPtr<DepthStencilStateCore> DepthStencilStateType;
|
|
|
|
|
+ typedef SPtr<GpuProgramCore> GpuProgramType;
|
|
|
|
|
+
|
|
|
|
|
+ BlendStateType mBlendState;
|
|
|
|
|
+ RasterizerStateType mRasterizerState;
|
|
|
|
|
+ DepthStencilStateType mDepthStencilState;
|
|
|
|
|
+ UINT32 mStencilRefValue;
|
|
|
|
|
+
|
|
|
|
|
+ GpuProgramType mVertexProgram;
|
|
|
|
|
+ GpuProgramType mFragmentProgram;
|
|
|
|
|
+ GpuProgramType mGeometryProgram;
|
|
|
|
|
+ GpuProgramType mHullProgram;
|
|
|
|
|
+ GpuProgramType mDomainProgram;
|
|
|
|
|
+ GpuProgramType mComputeProgram;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @brief Class defining a single pass of a technique (of a material), i.e.
|
|
* @brief Class defining a single pass of a technique (of a material), i.e.
|
|
|
- * a single rendering call.
|
|
|
|
|
- *
|
|
|
|
|
|
|
+ * a single rendering call.
|
|
|
|
|
+ *
|
|
|
* Pass may contain multiple GPU programs (vertex, fragment, geometry, etc.), and
|
|
* Pass may contain multiple GPU programs (vertex, fragment, geometry, etc.), and
|
|
|
* a set of pipeline states (blend, rasterizer, etc.).
|
|
* a set of pipeline states (blend, rasterizer, etc.).
|
|
|
*/
|
|
*/
|
|
|
- class BS_CORE_EXPORT Pass : public IReflectable
|
|
|
|
|
|
|
+ class BS_CORE_EXPORT PassBase
|
|
|
|
|
+ {
|
|
|
|
|
+ public:
|
|
|
|
|
+ virtual ~PassBase() { }
|
|
|
|
|
+
|
|
|
|
|
+ protected:
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc CoreObject::markCoreDirty
|
|
|
|
|
+ */
|
|
|
|
|
+ virtual void _markCoreDirty() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Returns true if the provided blend state has some element of transparency.
|
|
|
|
|
+ */
|
|
|
|
|
+ static bool hasBlending(const HBlendState& blendState);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Returns true if the provided blend state has some element of transparency.
|
|
|
|
|
+ */
|
|
|
|
|
+ static bool hasBlending(const SPtr<BlendStateCore>& blendState);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @see PassBase
|
|
|
|
|
+ *
|
|
|
|
|
+ * @note Templated so it can be used for both core and non-core versions of a pass.
|
|
|
|
|
+ */
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ class TPass : public PassBase
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
- Pass();
|
|
|
|
|
- Pass(const Pass& oth);
|
|
|
|
|
- Pass& operator=(const Pass& oth);
|
|
|
|
|
- virtual ~Pass();
|
|
|
|
|
-
|
|
|
|
|
- bool hasVertexProgram() const { return mVertexProgram != nullptr; }
|
|
|
|
|
- bool hasFragmentProgram() const { return mFragmentProgram != nullptr; }
|
|
|
|
|
- bool hasGeometryProgram() const { return mGeometryProgram != nullptr; }
|
|
|
|
|
- bool hasHullProgram() const { return mHullProgram != nullptr; }
|
|
|
|
|
- bool hasDomainProgram() const { return mDomainProgram != nullptr; }
|
|
|
|
|
- bool hasComputeProgram() const { return mComputeProgram != nullptr; }
|
|
|
|
|
|
|
+ typedef typename PassData<Core>::BlendStateType BlendStateType;
|
|
|
|
|
+ typedef typename PassData<Core>::RasterizerStateType RasterizerStateType;
|
|
|
|
|
+ typedef typename PassData<Core>::DepthStencilStateType DepthStencilStateType;
|
|
|
|
|
+ typedef typename PassData<Core>::GpuProgramType GpuProgramType;
|
|
|
|
|
+
|
|
|
|
|
+ virtual ~TPass() { }
|
|
|
|
|
+
|
|
|
|
|
+ bool hasVertexProgram() const { return mData.mVertexProgram != nullptr; }
|
|
|
|
|
+ bool hasFragmentProgram() const { return mData.mFragmentProgram != nullptr; }
|
|
|
|
|
+ bool hasGeometryProgram() const { return mData.mGeometryProgram != nullptr; }
|
|
|
|
|
+ bool hasHullProgram() const { return mData.mHullProgram != nullptr; }
|
|
|
|
|
+ bool hasDomainProgram() const { return mData.mDomainProgram != nullptr; }
|
|
|
|
|
+ bool hasComputeProgram() const { return mData.mComputeProgram != nullptr; }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @brief Returns true if this pass has some element of transparency.
|
|
* @brief Returns true if this pass has some element of transparency.
|
|
|
*/
|
|
*/
|
|
|
- bool hasBlending() const;
|
|
|
|
|
|
|
+ bool hasBlending() const { return PassBase::hasBlending(mData.mBlendState); }
|
|
|
|
|
|
|
|
- void setBlendState(HBlendState& blendState);
|
|
|
|
|
- HBlendState getBlendState() const;
|
|
|
|
|
|
|
+ void setBlendState(const BlendStateType& blendState) { mData.mBlendState = blendState; _markCoreDirty(); }
|
|
|
|
|
+ BlendStateType getBlendState() const { return mData.mBlendState; }
|
|
|
|
|
|
|
|
- void setRasterizerState(HRasterizerState& rasterizerState);
|
|
|
|
|
- HRasterizerState getRasterizerState() const;
|
|
|
|
|
|
|
+ void setRasterizerState(const RasterizerStateType& rasterizerState) { mData.mRasterizerState = rasterizerState; _markCoreDirty(); }
|
|
|
|
|
+ RasterizerStateType getRasterizerState() const { return mData.mRasterizerState; }
|
|
|
|
|
|
|
|
- void setDepthStencilState(HDepthStencilState& depthStencilState);
|
|
|
|
|
- HDepthStencilState getDepthStencilState() const;
|
|
|
|
|
|
|
+ void setDepthStencilState(const DepthStencilStateType& depthStencilState) { mData.mDepthStencilState = depthStencilState; _markCoreDirty(); }
|
|
|
|
|
+ DepthStencilStateType getDepthStencilState() const { return mData.mDepthStencilState; }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @brief Sets the stencil reference value that is used when performing operations using the
|
|
* @brief Sets the stencil reference value that is used when performing operations using the
|
|
|
* stencil buffer.
|
|
* stencil buffer.
|
|
|
*/
|
|
*/
|
|
|
- void setStencilRefValue(UINT32 refValue);
|
|
|
|
|
|
|
+ void setStencilRefValue(UINT32 refValue) { mData.mStencilRefValue = refValue; _markCoreDirty(); }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @brief Gets the stencil reference value that is used when performing operations using the
|
|
* @brief Gets the stencil reference value that is used when performing operations using the
|
|
|
* stencil buffer.
|
|
* stencil buffer.
|
|
|
*/
|
|
*/
|
|
|
- UINT32 getStencilRefValue() const;
|
|
|
|
|
|
|
+ UINT32 getStencilRefValue() const { return mData.mStencilRefValue; }
|
|
|
|
|
|
|
|
- void setVertexProgram(HGpuProgram gpuProgram) { mVertexProgram = gpuProgram; }
|
|
|
|
|
- const HGpuProgram& getVertexProgram() const { return mVertexProgram; }
|
|
|
|
|
|
|
+ void setVertexProgram(const GpuProgramType& gpuProgram) { mData.mVertexProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getVertexProgram() const { return mData.mVertexProgram; }
|
|
|
|
|
|
|
|
- void setFragmentProgram(HGpuProgram gpuProgram) { mFragmentProgram = gpuProgram; }
|
|
|
|
|
- const HGpuProgram& getFragmentProgram() const { return mFragmentProgram; }
|
|
|
|
|
|
|
+ void setFragmentProgram(const GpuProgramType& gpuProgram) { mData.mFragmentProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getFragmentProgram() const { return mData.mFragmentProgram; }
|
|
|
|
|
|
|
|
- void setGeometryProgram(HGpuProgram gpuProgram) { mGeometryProgram = gpuProgram; }
|
|
|
|
|
- const HGpuProgram& getGeometryProgram() const { return mGeometryProgram; }
|
|
|
|
|
|
|
+ void setGeometryProgram(const GpuProgramType& gpuProgram) { mData.mGeometryProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getGeometryProgram() const { return mData.mGeometryProgram; }
|
|
|
|
|
|
|
|
- void setHullProgram(HGpuProgram gpuProgram) { mHullProgram = gpuProgram; }
|
|
|
|
|
- const HGpuProgram& getHullProgram(void) const { return mHullProgram; }
|
|
|
|
|
|
|
+ void setHullProgram(const GpuProgramType& gpuProgram) { mData.mHullProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getHullProgram(void) const { return mData.mHullProgram; }
|
|
|
|
|
|
|
|
- void setDomainProgram(HGpuProgram gpuProgram) { mDomainProgram = gpuProgram;}
|
|
|
|
|
- const HGpuProgram& getDomainProgram(void) const { return mDomainProgram; }
|
|
|
|
|
|
|
+ void setDomainProgram(const GpuProgramType& gpuProgram) { mData.mDomainProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getDomainProgram(void) const { return mData.mDomainProgram; }
|
|
|
|
|
|
|
|
- void setComputeProgram(HGpuProgram gpuProgram) { mComputeProgram = gpuProgram; }
|
|
|
|
|
- const HGpuProgram& getComputeProgram(void) const { return mComputeProgram; }
|
|
|
|
|
|
|
+ void setComputeProgram(const GpuProgramType& gpuProgram) { mData.mComputeProgram = gpuProgram; _markCoreDirty(); }
|
|
|
|
|
+ const GpuProgramType& getComputeProgram(void) const { return mData.mComputeProgram; }
|
|
|
|
|
|
|
|
protected:
|
|
protected:
|
|
|
- HBlendState mBlendState;
|
|
|
|
|
- HRasterizerState mRasterizerState;
|
|
|
|
|
- HDepthStencilState mDepthStencilState;
|
|
|
|
|
- UINT32 mStencilRefValue;
|
|
|
|
|
|
|
+ TPass()
|
|
|
|
|
+ {
|
|
|
|
|
+ mData.mStencilRefValue = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ PassData<Core> mData;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc PassBase
|
|
|
|
|
+ *
|
|
|
|
|
+ * @note Core thread.
|
|
|
|
|
+ */
|
|
|
|
|
+ class BS_CORE_EXPORT PassCore : public CoreObjectCore, public TPass<true>
|
|
|
|
|
+ {
|
|
|
|
|
+ public:
|
|
|
|
|
+ virtual ~PassCore() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Creates a new empty pass.
|
|
|
|
|
+ */
|
|
|
|
|
+ static SPtr<PassCore> create();
|
|
|
|
|
+
|
|
|
|
|
+ protected:
|
|
|
|
|
+ friend class Pass;
|
|
|
|
|
+ friend class TechniqueCore;
|
|
|
|
|
|
|
|
- HGpuProgram mVertexProgram;
|
|
|
|
|
- HGpuProgram mFragmentProgram;
|
|
|
|
|
- HGpuProgram mGeometryProgram;
|
|
|
|
|
- HGpuProgram mHullProgram;
|
|
|
|
|
- HGpuProgram mDomainProgram;
|
|
|
|
|
- HGpuProgram mComputeProgram;
|
|
|
|
|
|
|
+ PassCore() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc CoreObjectCore::syncToCore
|
|
|
|
|
+ */
|
|
|
|
|
+ void syncToCore(const CoreSyncData& data);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc PassBase
|
|
|
|
|
+ *
|
|
|
|
|
+ * @note Sim thread.
|
|
|
|
|
+ */
|
|
|
|
|
+ class BS_CORE_EXPORT Pass : public IReflectable, public CoreObject, public TPass<false>
|
|
|
|
|
+ {
|
|
|
|
|
+ public:
|
|
|
|
|
+ virtual ~Pass() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Retrieves an implementation of a pass usable only from the
|
|
|
|
|
+ * core thread.
|
|
|
|
|
+ */
|
|
|
|
|
+ SPtr<PassCore> getCore() const;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Creates a new empty pass.
|
|
|
|
|
+ */
|
|
|
|
|
+ static PassPtr create();
|
|
|
|
|
+
|
|
|
|
|
+ protected:
|
|
|
|
|
+ friend class Technique;
|
|
|
|
|
+
|
|
|
|
|
+ Pass() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc CoreObject::createCore
|
|
|
|
|
+ */
|
|
|
|
|
+ SPtr<CoreObjectCore> createCore() const;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc CoreObject::markCoreDirty
|
|
|
|
|
+ */
|
|
|
|
|
+ void _markCoreDirty();
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @copydoc CoreObject::syncToCore
|
|
|
|
|
+ */
|
|
|
|
|
+ CoreSyncData syncToCore(FrameAlloc* allocator);
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @brief Creates a new empty pass but doesn't initialize it.
|
|
|
|
|
+ */
|
|
|
|
|
+ static PassPtr createEmpty();
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
/************************************************************************/
|
|
|
/* RTTI */
|
|
/* RTTI */
|