|
@@ -6,73 +6,212 @@
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifySamplerStateCreated(const SAMPLER_STATE_DESC& desc, const SPtr<SamplerStateType>& state) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedSamplerStates[desc] = state;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyBlendStateCreated(const BLEND_STATE_DESC& desc, const SPtr<BlendStateType>& state) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedBlendStates[desc] = state;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyRasterizerStateCreated(const RASTERIZER_STATE_DESC& desc, const SPtr<RasterizerStateType>& state) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedRasterizerStates[desc] = state;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyDepthStencilStateCreated(const DEPTH_STENCIL_STATE_DESC& desc, const SPtr<DepthStencilStateType>& state) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedDepthStencilStates[desc] = state;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifySamplerStateDestroyed(const SAMPLER_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedSamplerStates.erase(desc);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyBlendStateDestroyed(const BLEND_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedBlendStates.erase(desc);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyRasterizerStateDestroyed(const RASTERIZER_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedRasterizerStates.erase(desc);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TRenderStateManager<Core>::notifyDepthStencilStateDestroyed(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ mCachedDepthStencilStates.erase(desc);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ SPtr<typename TRenderStateManager<Core>::SamplerStateType> TRenderStateManager<Core>::findCachedState(const SAMPLER_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ auto iterFind = mCachedSamplerStates.find(desc);
|
|
|
|
|
+ if (iterFind != mCachedSamplerStates.end())
|
|
|
|
|
+ return iterFind->second.lock();
|
|
|
|
|
+
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ SPtr<typename TRenderStateManager<Core>::BlendStateType> TRenderStateManager<Core>::findCachedState(const BLEND_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ auto iterFind = mCachedBlendStates.find(desc);
|
|
|
|
|
+ if (iterFind != mCachedBlendStates.end())
|
|
|
|
|
+ return iterFind->second.lock();
|
|
|
|
|
+
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ SPtr<typename TRenderStateManager<Core>::RasterizerStateType> TRenderStateManager<Core>::findCachedState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ auto iterFind = mCachedRasterizerStates.find(desc);
|
|
|
|
|
+ if (iterFind != mCachedRasterizerStates.end())
|
|
|
|
|
+ return iterFind->second.lock();
|
|
|
|
|
+
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ SPtr<typename TRenderStateManager<Core>::DepthStencilStateType> TRenderStateManager<Core>::findCachedState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
+
|
|
|
|
|
+ auto iterFind = mCachedDepthStencilStates.find(desc);
|
|
|
|
|
+ if (iterFind != mCachedDepthStencilStates.end())
|
|
|
|
|
+ return iterFind->second.lock();
|
|
|
|
|
+
|
|
|
|
|
+ return nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template class TRenderStateManager < true > ;
|
|
|
|
|
+ template class TRenderStateManager < false >;
|
|
|
|
|
+
|
|
|
SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- SamplerStatePtr samplerState = bs_core_ptr<SamplerState, GenAlloc>(new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
|
|
- samplerState->_setThisPtr(samplerState);
|
|
|
|
|
- samplerState->initialize();
|
|
|
|
|
|
|
+ SPtr<SamplerState> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_core_ptr<SamplerState, GenAlloc>(new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
+ state->initialize();
|
|
|
|
|
|
|
|
- return samplerState;
|
|
|
|
|
|
|
+ notifySamplerStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState, GenAlloc>(new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
|
|
- depthStencilState->_setThisPtr(depthStencilState);
|
|
|
|
|
- depthStencilState->initialize();
|
|
|
|
|
|
|
+ SPtr<DepthStencilState> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_core_ptr<DepthStencilState, GenAlloc>(new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
+ state->initialize();
|
|
|
|
|
|
|
|
- return depthStencilState;
|
|
|
|
|
|
|
+ notifyDepthStencilStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState, GenAlloc>(new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
|
|
- rasterizerState->_setThisPtr(rasterizerState);
|
|
|
|
|
- rasterizerState->initialize();
|
|
|
|
|
|
|
+ SPtr<RasterizerState> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_core_ptr<RasterizerState, GenAlloc>(new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
+ state->initialize();
|
|
|
|
|
|
|
|
- return rasterizerState;
|
|
|
|
|
|
|
+ notifyRasterizerStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- BlendStatePtr blendState = bs_core_ptr<BlendState, GenAlloc>(new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
|
|
- blendState->_setThisPtr(blendState);
|
|
|
|
|
- blendState->initialize();
|
|
|
|
|
|
|
+ SPtr<BlendState> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_core_ptr<BlendState, GenAlloc>(new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
+ state->initialize();
|
|
|
|
|
|
|
|
- return blendState;
|
|
|
|
|
|
|
+ notifyBlendStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SamplerStatePtr RenderStateManager::createEmptySamplerState() const
|
|
|
|
|
|
|
+ SamplerStatePtr RenderStateManager::_createSamplerStatePtr(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
SamplerStatePtr samplerState = bs_core_ptr<SamplerState, GenAlloc>(
|
|
SamplerStatePtr samplerState = bs_core_ptr<SamplerState, GenAlloc>(
|
|
|
- new (bs_alloc<SamplerState>()) SamplerState(SAMPLER_STATE_DESC()));
|
|
|
|
|
|
|
+ new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
samplerState->_setThisPtr(samplerState);
|
|
samplerState->_setThisPtr(samplerState);
|
|
|
|
|
|
|
|
return samplerState;
|
|
return samplerState;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- DepthStencilStatePtr RenderStateManager::createEmptyDepthStencilState() const
|
|
|
|
|
|
|
+ DepthStencilStatePtr RenderStateManager::_createDepthStencilStatePtr(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState, GenAlloc>(
|
|
DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState, GenAlloc>(
|
|
|
- new (bs_alloc<DepthStencilState>()) DepthStencilState(DEPTH_STENCIL_STATE_DESC()));
|
|
|
|
|
|
|
+ new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
depthStencilState->_setThisPtr(depthStencilState);
|
|
depthStencilState->_setThisPtr(depthStencilState);
|
|
|
|
|
|
|
|
return depthStencilState;
|
|
return depthStencilState;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- RasterizerStatePtr RenderStateManager::createEmptyRasterizerState() const
|
|
|
|
|
|
|
+ RasterizerStatePtr RenderStateManager::_createRasterizerStatePtr(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState, GenAlloc>(
|
|
RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState, GenAlloc>(
|
|
|
- new (bs_alloc<RasterizerState>()) RasterizerState(RASTERIZER_STATE_DESC()));
|
|
|
|
|
|
|
+ new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
rasterizerState->_setThisPtr(rasterizerState);
|
|
rasterizerState->_setThisPtr(rasterizerState);
|
|
|
|
|
|
|
|
return rasterizerState;
|
|
return rasterizerState;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- BlendStatePtr RenderStateManager::createEmptyBlendState() const
|
|
|
|
|
|
|
+ BlendStatePtr RenderStateManager::_createBlendStatePtr(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
BlendStatePtr blendState = bs_core_ptr<BlendState, GenAlloc>(
|
|
BlendStatePtr blendState = bs_core_ptr<BlendState, GenAlloc>(
|
|
|
- new (bs_alloc<BlendState>()) BlendState(BLEND_STATE_DESC()));
|
|
|
|
|
|
|
+ new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
blendState->_setThisPtr(blendState);
|
|
blendState->_setThisPtr(blendState);
|
|
|
|
|
|
|
|
return blendState;
|
|
return blendState;
|
|
@@ -176,33 +315,57 @@ namespace BansheeEngine
|
|
|
|
|
|
|
|
SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
|
|
SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- SPtr<SamplerStateCore> samplerState = bs_shared_ptr<SamplerStateCore, GenAlloc>(new (bs_alloc<SamplerStateCore>()) SamplerStateCore(desc));
|
|
|
|
|
- samplerState->_setThisPtr(samplerState);
|
|
|
|
|
|
|
+ SPtr<SamplerStateCore> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_shared_ptr<SamplerStateCore, GenAlloc>(new (bs_alloc<SamplerStateCore>()) SamplerStateCore(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
|
|
- return samplerState;
|
|
|
|
|
|
|
+ notifySamplerStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- SPtr<DepthStencilStateCore> depthStencilState = bs_shared_ptr<DepthStencilStateCore, GenAlloc>(new (bs_alloc<DepthStencilStateCore>()) DepthStencilStateCore(desc));
|
|
|
|
|
- depthStencilState->_setThisPtr(depthStencilState);
|
|
|
|
|
|
|
+ SPtr<DepthStencilStateCore> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ SPtr<DepthStencilStateCore> state = bs_shared_ptr<DepthStencilStateCore, GenAlloc>(new (bs_alloc<DepthStencilStateCore>()) DepthStencilStateCore(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
|
|
- return depthStencilState;
|
|
|
|
|
|
|
+ notifyDepthStencilStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const
|
|
SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- SPtr<RasterizerStateCore> rasterizerState = bs_shared_ptr<RasterizerStateCore, GenAlloc>(new (bs_alloc<RasterizerStateCore>()) RasterizerStateCore(desc));
|
|
|
|
|
- rasterizerState->_setThisPtr(rasterizerState);
|
|
|
|
|
|
|
+ SPtr<RasterizerStateCore> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ SPtr<RasterizerStateCore> state = bs_shared_ptr<RasterizerStateCore, GenAlloc>(new (bs_alloc<RasterizerStateCore>()) RasterizerStateCore(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
|
|
- return rasterizerState;
|
|
|
|
|
|
|
+ notifyRasterizerStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SPtr<BlendStateCore> RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc) const
|
|
SPtr<BlendStateCore> RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
{
|
|
|
- SPtr<BlendStateCore> blendState = bs_shared_ptr<BlendStateCore, GenAlloc>(new (bs_alloc<BlendStateCore>()) BlendStateCore(desc));
|
|
|
|
|
- blendState->_setThisPtr(blendState);
|
|
|
|
|
|
|
+ SPtr<BlendStateCore> state = findCachedState(desc);
|
|
|
|
|
+ if (state == nullptr)
|
|
|
|
|
+ {
|
|
|
|
|
+ state = bs_shared_ptr<BlendStateCore, GenAlloc>(new (bs_alloc<BlendStateCore>()) BlendStateCore(desc));
|
|
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
|
|
- return blendState;
|
|
|
|
|
|
|
+ notifyBlendStateCreated(desc, state);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return state;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|