|
|
@@ -6,128 +6,114 @@
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifySamplerStateCreated(const SAMPLER_STATE_DESC& desc, const SPtr<SamplerStateType>& state) const
|
|
|
+ SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ SPtr<SamplerState> state = _createSamplerStatePtr(desc);
|
|
|
+ state->initialize();
|
|
|
|
|
|
- mCachedSamplerStates[desc] = state;
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyBlendStateCreated(const BLEND_STATE_DESC& desc, const SPtr<BlendStateType>& state) const
|
|
|
+ DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ SPtr<DepthStencilState> state = _createDepthStencilStatePtr(desc);
|
|
|
+ state->initialize();
|
|
|
|
|
|
- mCachedBlendStates[desc] = state;
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyRasterizerStateCreated(const RASTERIZER_STATE_DESC& desc, const SPtr<RasterizerStateType>& state) const
|
|
|
+ RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ SPtr<RasterizerState> state = _createRasterizerStatePtr(desc);
|
|
|
+ state->initialize();
|
|
|
|
|
|
- mCachedRasterizerStates[desc] = state;
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyDepthStencilStateCreated(const DEPTH_STENCIL_STATE_DESC& desc, const SPtr<DepthStencilStateType>& state) const
|
|
|
+ BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ SPtr<BlendState> state = _createBlendStatePtr(desc);
|
|
|
+ state->initialize();
|
|
|
|
|
|
- mCachedDepthStencilStates[desc] = state;
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifySamplerStateDestroyed(const SAMPLER_STATE_DESC& desc) const
|
|
|
+ SamplerStatePtr RenderStateManager::_createSamplerStatePtr(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ SamplerStatePtr samplerState = bs_core_ptr<SamplerState>(new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
+ samplerState->_setThisPtr(samplerState);
|
|
|
|
|
|
- mCachedSamplerStates.erase(desc);
|
|
|
+ return samplerState;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyBlendStateDestroyed(const BLEND_STATE_DESC& desc) const
|
|
|
+ DepthStencilStatePtr RenderStateManager::_createDepthStencilStatePtr(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState>(new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
+ depthStencilState->_setThisPtr(depthStencilState);
|
|
|
|
|
|
- mCachedBlendStates.erase(desc);
|
|
|
+ return depthStencilState;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyRasterizerStateDestroyed(const RASTERIZER_STATE_DESC& desc) const
|
|
|
+ RasterizerStatePtr RenderStateManager::_createRasterizerStatePtr(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState>(new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
+ rasterizerState->_setThisPtr(rasterizerState);
|
|
|
|
|
|
- mCachedRasterizerStates.erase(desc);
|
|
|
+ return rasterizerState;
|
|
|
}
|
|
|
|
|
|
- template<bool Core>
|
|
|
- void TRenderStateManager<Core>::notifyDepthStencilStateDestroyed(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
+ BlendStatePtr RenderStateManager::_createBlendStatePtr(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BS_LOCK_MUTEX(mMutex);
|
|
|
+ BlendStatePtr blendState = bs_core_ptr<BlendState>(new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
+ blendState->_setThisPtr(blendState);
|
|
|
|
|
|
- mCachedDepthStencilStates.erase(desc);
|
|
|
+ return blendState;
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ const SamplerStatePtr& RenderStateManager::getDefaultSamplerState() const
|
|
|
+ {
|
|
|
+ if(mDefaultSamplerState == nullptr)
|
|
|
+ mDefaultSamplerState = createSamplerState(SAMPLER_STATE_DESC());
|
|
|
|
|
|
- return nullptr;
|
|
|
+ return mDefaultSamplerState;
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ const BlendStatePtr& RenderStateManager::getDefaultBlendState() const
|
|
|
+ {
|
|
|
+ if(mDefaultBlendState == nullptr)
|
|
|
+ mDefaultBlendState = createBlendState(BLEND_STATE_DESC());
|
|
|
|
|
|
- return nullptr;
|
|
|
+ return mDefaultBlendState;
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ const RasterizerStatePtr& RenderStateManager::getDefaultRasterizerState() const
|
|
|
+ {
|
|
|
+ if(mDefaultRasterizerState == nullptr)
|
|
|
+ mDefaultRasterizerState = createRasterizerState(RASTERIZER_STATE_DESC());
|
|
|
|
|
|
- return nullptr;
|
|
|
+ return mDefaultRasterizerState;
|
|
|
}
|
|
|
|
|
|
- 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();
|
|
|
+ const DepthStencilStatePtr& RenderStateManager::getDefaultDepthStencilState() const
|
|
|
+ {
|
|
|
+ if(mDefaultDepthStencilState == nullptr)
|
|
|
+ mDefaultDepthStencilState = createDepthStencilState(DEPTH_STENCIL_STATE_DESC());
|
|
|
|
|
|
- return nullptr;
|
|
|
+ return mDefaultDepthStencilState;
|
|
|
}
|
|
|
|
|
|
- template class TRenderStateManager < true > ;
|
|
|
- template class TRenderStateManager < false >;
|
|
|
+ RenderStateCoreManager::RenderStateCoreManager()
|
|
|
+ :mNextBlendStateId(0), mNextDepthStencilStateId(0), mNextRasterizerStateId(0)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- SamplerStatePtr RenderStateManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
+ SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SPtr<SamplerState> state = findCachedState(desc);
|
|
|
+ SPtr<SamplerStateCore> state = findCachedState(desc);
|
|
|
if (state == nullptr)
|
|
|
{
|
|
|
- state = bs_core_ptr<SamplerState>(new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ state = createSamplerStateInternal(desc);
|
|
|
state->initialize();
|
|
|
|
|
|
notifySamplerStateCreated(desc, state);
|
|
|
@@ -136,235 +122,293 @@ namespace BansheeEngine
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- DepthStencilStatePtr RenderStateManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
+ SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SPtr<DepthStencilState> state = findCachedState(desc);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<DepthStencilStateCore> state = findCachedState(desc, id);
|
|
|
if (state == nullptr)
|
|
|
{
|
|
|
- state = bs_core_ptr<DepthStencilState>(new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ state = createDepthStencilStateInternal(desc, id);
|
|
|
state->initialize();
|
|
|
|
|
|
- notifyDepthStencilStateCreated(desc, state);
|
|
|
+ CachedDepthStencilState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyDepthStencilStateCreated(desc, cachedData);
|
|
|
}
|
|
|
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- RasterizerStatePtr RenderStateManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
+ SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SPtr<RasterizerState> state = findCachedState(desc);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<RasterizerStateCore> state = findCachedState(desc, id);
|
|
|
if (state == nullptr)
|
|
|
{
|
|
|
- state = bs_core_ptr<RasterizerState>(new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ state = createRasterizerStateInternal(desc, id);
|
|
|
state->initialize();
|
|
|
|
|
|
- notifyRasterizerStateCreated(desc, state);
|
|
|
+ CachedRasterizerState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyRasterizerStateCreated(desc, cachedData);
|
|
|
}
|
|
|
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- BlendStatePtr RenderStateManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
+ SPtr<BlendStateCore> RenderStateCoreManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SPtr<BlendState> state = findCachedState(desc);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<BlendStateCore> state = findCachedState(desc, id);
|
|
|
if (state == nullptr)
|
|
|
{
|
|
|
- state = bs_core_ptr<BlendState>(new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ state = createBlendStateInternal(desc, id);
|
|
|
state->initialize();
|
|
|
|
|
|
- notifyBlendStateCreated(desc, state);
|
|
|
+ CachedBlendState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyBlendStateCreated(desc, cachedData);
|
|
|
}
|
|
|
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- SamplerStatePtr RenderStateManager::_createSamplerStatePtr(const SAMPLER_STATE_DESC& desc) const
|
|
|
+ SPtr<SamplerStateCore> RenderStateCoreManager::_createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SamplerStatePtr samplerState = bs_core_ptr<SamplerState>(
|
|
|
- new (bs_alloc<SamplerState>()) SamplerState(desc));
|
|
|
- samplerState->_setThisPtr(samplerState);
|
|
|
+ SPtr<SamplerStateCore> state = findCachedState(desc);
|
|
|
+ if (state == nullptr)
|
|
|
+ {
|
|
|
+ state = createSamplerStateInternal(desc);
|
|
|
|
|
|
- return samplerState;
|
|
|
+ notifySamplerStateCreated(desc, state);
|
|
|
+ }
|
|
|
+
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- DepthStencilStatePtr RenderStateManager::_createDepthStencilStatePtr(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
+ SPtr<DepthStencilStateCore> RenderStateCoreManager::_createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
{
|
|
|
- DepthStencilStatePtr depthStencilState = bs_core_ptr<DepthStencilState>(
|
|
|
- new (bs_alloc<DepthStencilState>()) DepthStencilState(desc));
|
|
|
- depthStencilState->_setThisPtr(depthStencilState);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<DepthStencilStateCore> state = findCachedState(desc, id);
|
|
|
+ if (state == nullptr)
|
|
|
+ {
|
|
|
+ state = createDepthStencilStateInternal(desc, id);
|
|
|
|
|
|
- return depthStencilState;
|
|
|
+ CachedDepthStencilState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyDepthStencilStateCreated(desc, cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- RasterizerStatePtr RenderStateManager::_createRasterizerStatePtr(const RASTERIZER_STATE_DESC& desc) const
|
|
|
+ SPtr<RasterizerStateCore> RenderStateCoreManager::_createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- RasterizerStatePtr rasterizerState = bs_core_ptr<RasterizerState>(
|
|
|
- new (bs_alloc<RasterizerState>()) RasterizerState(desc));
|
|
|
- rasterizerState->_setThisPtr(rasterizerState);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<RasterizerStateCore> state = findCachedState(desc, id);
|
|
|
+ if (state == nullptr)
|
|
|
+ {
|
|
|
+ state = createRasterizerStateInternal(desc, id);
|
|
|
|
|
|
- return rasterizerState;
|
|
|
+ CachedRasterizerState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyRasterizerStateCreated(desc, cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- BlendStatePtr RenderStateManager::_createBlendStatePtr(const BLEND_STATE_DESC& desc) const
|
|
|
+ SPtr<BlendStateCore> RenderStateCoreManager::_createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
{
|
|
|
- BlendStatePtr blendState = bs_core_ptr<BlendState>(
|
|
|
- new (bs_alloc<BlendState>()) BlendState(desc));
|
|
|
- blendState->_setThisPtr(blendState);
|
|
|
+ UINT32 id = 0;
|
|
|
+ SPtr<BlendStateCore> state = findCachedState(desc, id);
|
|
|
+ if (state == nullptr)
|
|
|
+ {
|
|
|
+ state = createBlendStateInternal(desc, id);
|
|
|
|
|
|
- return blendState;
|
|
|
+ CachedBlendState cachedData(id);
|
|
|
+ cachedData.state = state;
|
|
|
+
|
|
|
+ notifyBlendStateCreated(desc, cachedData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return state;
|
|
|
}
|
|
|
|
|
|
- const SamplerStatePtr& RenderStateManager::getDefaultSamplerState() const
|
|
|
- {
|
|
|
- if(mDefaultSamplerState == nullptr)
|
|
|
+ const SPtr<SamplerStateCore>& RenderStateCoreManager::getDefaultSamplerState() const
|
|
|
+ {
|
|
|
+ if (mDefaultSamplerState == nullptr)
|
|
|
mDefaultSamplerState = createSamplerState(SAMPLER_STATE_DESC());
|
|
|
|
|
|
- return mDefaultSamplerState;
|
|
|
+ return mDefaultSamplerState;
|
|
|
}
|
|
|
|
|
|
- const BlendStatePtr& RenderStateManager::getDefaultBlendState() const
|
|
|
- {
|
|
|
- if(mDefaultBlendState == nullptr)
|
|
|
+ const SPtr<BlendStateCore>& RenderStateCoreManager::getDefaultBlendState() const
|
|
|
+ {
|
|
|
+ if (mDefaultBlendState == nullptr)
|
|
|
mDefaultBlendState = createBlendState(BLEND_STATE_DESC());
|
|
|
|
|
|
- return mDefaultBlendState;
|
|
|
+ return mDefaultBlendState;
|
|
|
}
|
|
|
|
|
|
- const RasterizerStatePtr& RenderStateManager::getDefaultRasterizerState() const
|
|
|
- {
|
|
|
- if(mDefaultRasterizerState == nullptr)
|
|
|
+ const SPtr<RasterizerStateCore>& RenderStateCoreManager::getDefaultRasterizerState() const
|
|
|
+ {
|
|
|
+ if (mDefaultRasterizerState == nullptr)
|
|
|
mDefaultRasterizerState = createRasterizerState(RASTERIZER_STATE_DESC());
|
|
|
|
|
|
- return mDefaultRasterizerState;
|
|
|
+ return mDefaultRasterizerState;
|
|
|
}
|
|
|
|
|
|
- const DepthStencilStatePtr& RenderStateManager::getDefaultDepthStencilState() const
|
|
|
- {
|
|
|
- if(mDefaultDepthStencilState == nullptr)
|
|
|
+ const SPtr<DepthStencilStateCore>& RenderStateCoreManager::getDefaultDepthStencilState() const
|
|
|
+ {
|
|
|
+ if (mDefaultDepthStencilState == nullptr)
|
|
|
mDefaultDepthStencilState = createDepthStencilState(DEPTH_STENCIL_STATE_DESC());
|
|
|
|
|
|
- return mDefaultDepthStencilState;
|
|
|
+ return mDefaultDepthStencilState;
|
|
|
}
|
|
|
|
|
|
- SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerState(const SAMPLER_STATE_DESC& desc) const
|
|
|
+ void RenderStateCoreManager::notifySamplerStateCreated(const SAMPLER_STATE_DESC& desc, const SPtr<SamplerStateCore>& state) const
|
|
|
{
|
|
|
- SPtr<SamplerStateCore> samplerState = createSamplerStateInternal(desc);
|
|
|
- samplerState->initialize();
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return samplerState;
|
|
|
+ mCachedSamplerStates[desc] = state;
|
|
|
}
|
|
|
|
|
|
- SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilState(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
+ void RenderStateCoreManager::notifyBlendStateCreated(const BLEND_STATE_DESC& desc, const CachedBlendState& state) const
|
|
|
{
|
|
|
- SPtr<DepthStencilStateCore> depthStencilState = createDepthStencilStateInternal(desc);
|
|
|
- depthStencilState->initialize();
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return depthStencilState;
|
|
|
+ mCachedBlendStates[desc] = state;
|
|
|
}
|
|
|
|
|
|
- SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerState(const RASTERIZER_STATE_DESC& desc) const
|
|
|
+ void RenderStateCoreManager::notifyRasterizerStateCreated(const RASTERIZER_STATE_DESC& desc, const CachedRasterizerState& state) const
|
|
|
{
|
|
|
- SPtr<RasterizerStateCore> rasterizerState = createRasterizerStateInternal(desc);
|
|
|
- rasterizerState->initialize();
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return rasterizerState;
|
|
|
+ mCachedRasterizerStates[desc] = state;
|
|
|
}
|
|
|
|
|
|
- SPtr<BlendStateCore> RenderStateCoreManager::createBlendState(const BLEND_STATE_DESC& desc) const
|
|
|
+ void RenderStateCoreManager::notifyDepthStencilStateCreated(const DEPTH_STENCIL_STATE_DESC& desc, const CachedDepthStencilState& state) const
|
|
|
{
|
|
|
- SPtr<BlendStateCore> blendState = createBlendStateInternal(desc);
|
|
|
- blendState->initialize();
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return blendState;
|
|
|
+ mCachedDepthStencilStates[desc] = state;
|
|
|
}
|
|
|
|
|
|
- const SPtr<SamplerStateCore>& RenderStateCoreManager::getDefaultSamplerState() const
|
|
|
+ void RenderStateCoreManager::notifySamplerStateDestroyed(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- if (mDefaultSamplerState == nullptr)
|
|
|
- mDefaultSamplerState = createSamplerState(SAMPLER_STATE_DESC());
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return mDefaultSamplerState;
|
|
|
+ mCachedSamplerStates.erase(desc);
|
|
|
}
|
|
|
|
|
|
- const SPtr<BlendStateCore>& RenderStateCoreManager::getDefaultBlendState() const
|
|
|
+ SPtr<SamplerStateCore> RenderStateCoreManager::findCachedState(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- if (mDefaultBlendState == nullptr)
|
|
|
- mDefaultBlendState = createBlendState(BLEND_STATE_DESC());
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return mDefaultBlendState;
|
|
|
+ auto iterFind = mCachedSamplerStates.find(desc);
|
|
|
+ if (iterFind != mCachedSamplerStates.end())
|
|
|
+ return iterFind->second.lock();
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- const SPtr<RasterizerStateCore>& RenderStateCoreManager::getDefaultRasterizerState() const
|
|
|
+ SPtr<BlendStateCore> RenderStateCoreManager::findCachedState(const BLEND_STATE_DESC& desc, UINT32& id) const
|
|
|
{
|
|
|
- if (mDefaultRasterizerState == nullptr)
|
|
|
- mDefaultRasterizerState = createRasterizerState(RASTERIZER_STATE_DESC());
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
|
|
|
- return mDefaultRasterizerState;
|
|
|
- }
|
|
|
+ auto iterFind = mCachedBlendStates.find(desc);
|
|
|
+ if (iterFind != mCachedBlendStates.end())
|
|
|
+ {
|
|
|
+ id = iterFind->second.id;
|
|
|
|
|
|
- const SPtr<DepthStencilStateCore>& RenderStateCoreManager::getDefaultDepthStencilState() const
|
|
|
- {
|
|
|
- if (mDefaultDepthStencilState == nullptr)
|
|
|
- mDefaultDepthStencilState = createDepthStencilState(DEPTH_STENCIL_STATE_DESC());
|
|
|
+ if (!iterFind->second.state.expired())
|
|
|
+ return iterFind->second.state.lock();
|
|
|
|
|
|
- return mDefaultDepthStencilState;
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ id = mNextBlendStateId++;
|
|
|
+ assert(id <= 0x3FF); // 10 bits maximum
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
|
|
|
+ SPtr<RasterizerStateCore> RenderStateCoreManager::findCachedState(const RASTERIZER_STATE_DESC& desc, UINT32& id) const
|
|
|
{
|
|
|
- SPtr<SamplerStateCore> state = findCachedState(desc);
|
|
|
- if (state == nullptr)
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
+
|
|
|
+ auto iterFind = mCachedRasterizerStates.find(desc);
|
|
|
+ if (iterFind != mCachedRasterizerStates.end())
|
|
|
{
|
|
|
- state = bs_shared_ptr<SamplerStateCore>(new (bs_alloc<SamplerStateCore>()) SamplerStateCore(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ id = iterFind->second.id;
|
|
|
|
|
|
- notifySamplerStateCreated(desc, state);
|
|
|
+ if (!iterFind->second.state.expired())
|
|
|
+ return iterFind->second.state.lock();
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- return state;
|
|
|
+ id = mNextRasterizerStateId++;
|
|
|
+ assert(id <= 0x3FF); // 10 bits maximum
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc) const
|
|
|
+ SPtr<DepthStencilStateCore> RenderStateCoreManager::findCachedState(const DEPTH_STENCIL_STATE_DESC& desc, UINT32& id) const
|
|
|
{
|
|
|
- SPtr<DepthStencilStateCore> state = findCachedState(desc);
|
|
|
- if (state == nullptr)
|
|
|
+ BS_LOCK_MUTEX(mMutex);
|
|
|
+
|
|
|
+ auto iterFind = mCachedDepthStencilStates.find(desc);
|
|
|
+ if (iterFind != mCachedDepthStencilStates.end())
|
|
|
{
|
|
|
- SPtr<DepthStencilStateCore> state = bs_shared_ptr<DepthStencilStateCore>(new (bs_alloc<DepthStencilStateCore>()) DepthStencilStateCore(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ id = iterFind->second.id;
|
|
|
|
|
|
- notifyDepthStencilStateCreated(desc, state);
|
|
|
+ if (!iterFind->second.state.expired())
|
|
|
+ return iterFind->second.state.lock();
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- return state;
|
|
|
+ id = mNextDepthStencilStateId++;
|
|
|
+ assert(id <= 0x3FF); // 10 bits maximum
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
- SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc) const
|
|
|
+ SPtr<SamplerStateCore> RenderStateCoreManager::createSamplerStateInternal(const SAMPLER_STATE_DESC& desc) const
|
|
|
{
|
|
|
- SPtr<RasterizerStateCore> state = findCachedState(desc);
|
|
|
- if (state == nullptr)
|
|
|
- {
|
|
|
- SPtr<RasterizerStateCore> state = bs_shared_ptr<RasterizerStateCore>(new (bs_alloc<RasterizerStateCore>()) RasterizerStateCore(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ SPtr<SamplerStateCore> state = bs_shared_ptr<SamplerStateCore>(new (bs_alloc<SamplerStateCore>()) SamplerStateCore(desc));
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
- notifyRasterizerStateCreated(desc, state);
|
|
|
- }
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+ SPtr<DepthStencilStateCore> RenderStateCoreManager::createDepthStencilStateInternal(const DEPTH_STENCIL_STATE_DESC& desc, UINT32 id) const
|
|
|
+ {
|
|
|
+ SPtr<DepthStencilStateCore> state = bs_shared_ptr<DepthStencilStateCore>(new (bs_alloc<DepthStencilStateCore>()) DepthStencilStateCore(desc, id));
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- SPtr<BlendStateCore> RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc) const
|
|
|
+ SPtr<RasterizerStateCore> RenderStateCoreManager::createRasterizerStateInternal(const RASTERIZER_STATE_DESC& desc, UINT32 id) const
|
|
|
{
|
|
|
- SPtr<BlendStateCore> state = findCachedState(desc);
|
|
|
- if (state == nullptr)
|
|
|
- {
|
|
|
- state = bs_shared_ptr<BlendStateCore>(new (bs_alloc<BlendStateCore>()) BlendStateCore(desc));
|
|
|
- state->_setThisPtr(state);
|
|
|
+ SPtr<RasterizerStateCore> state = bs_shared_ptr<RasterizerStateCore>(new (bs_alloc<RasterizerStateCore>()) RasterizerStateCore(desc, id));
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
- notifyBlendStateCreated(desc, state);
|
|
|
- }
|
|
|
+ return state;
|
|
|
+ }
|
|
|
+
|
|
|
+ SPtr<BlendStateCore> RenderStateCoreManager::createBlendStateInternal(const BLEND_STATE_DESC& desc, UINT32 id) const
|
|
|
+ {
|
|
|
+ SPtr<BlendStateCore> state = bs_shared_ptr<BlendStateCore>(new (bs_alloc<BlendStateCore>()) BlendStateCore(desc, id));
|
|
|
+ state->_setThisPtr(state);
|
|
|
|
|
|
return state;
|
|
|
}
|