2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-22 23:45:56 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Log.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/GfxState.h"
|
2010-06-22 23:45:56 +00:00
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
namespace DX11
|
|
|
|
{
|
|
|
|
|
2010-06-22 23:45:56 +00:00
|
|
|
namespace D3D
|
|
|
|
{
|
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
StateManager* stateman;
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> AutoState<T>::AutoState(const T* object) : state(object)
|
|
|
|
{
|
|
|
|
((IUnknown*)state)->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T> AutoState<T>::AutoState(const AutoState<T> &source)
|
|
|
|
{
|
|
|
|
state = source.GetPtr();
|
|
|
|
((T*)state)->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T> AutoState<T>::~AutoState()
|
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (state) ((T*)state)->Release();
|
2014-03-09 20:14:26 +00:00
|
|
|
state = nullptr;
|
2011-06-11 19:37:21 +00:00
|
|
|
}
|
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
StateManager::StateManager() : cur_blendstate(nullptr), cur_depthstate(nullptr), cur_raststate(nullptr) {}
|
2011-06-11 19:37:21 +00:00
|
|
|
|
|
|
|
void StateManager::PushBlendState(const ID3D11BlendState* state) { blendstates.push(AutoBlendState(state)); }
|
|
|
|
void StateManager::PushDepthState(const ID3D11DepthStencilState* state) { depthstates.push(AutoDepthStencilState(state)); }
|
|
|
|
void StateManager::PushRasterizerState(const ID3D11RasterizerState* state) { raststates.push(AutoRasterizerState(state)); }
|
|
|
|
void StateManager::PopBlendState() { blendstates.pop(); }
|
|
|
|
void StateManager::PopDepthState() { depthstates.pop(); }
|
|
|
|
void StateManager::PopRasterizerState() { raststates.pop(); }
|
2010-06-22 23:45:56 +00:00
|
|
|
|
|
|
|
void StateManager::Apply()
|
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
if (!blendstates.empty())
|
|
|
|
{
|
|
|
|
if (cur_blendstate != blendstates.top().GetPtr())
|
|
|
|
{
|
|
|
|
cur_blendstate = (ID3D11BlendState*)blendstates.top().GetPtr();
|
2014-03-09 20:14:26 +00:00
|
|
|
D3D::context->OMSetBlendState(cur_blendstate, nullptr, 0xFFFFFFFF);
|
2011-06-11 19:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else ERROR_LOG(VIDEO, "Tried to apply without blend state!");
|
|
|
|
|
|
|
|
if (!depthstates.empty())
|
2010-06-22 23:45:56 +00:00
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
if (cur_depthstate != depthstates.top().GetPtr())
|
|
|
|
{
|
|
|
|
cur_depthstate = (ID3D11DepthStencilState*)depthstates.top().GetPtr();
|
|
|
|
D3D::context->OMSetDepthStencilState(cur_depthstate, 0);
|
|
|
|
}
|
2010-06-22 23:45:56 +00:00
|
|
|
}
|
2011-06-11 19:37:21 +00:00
|
|
|
else ERROR_LOG(VIDEO, "Tried to apply without depth state!");
|
2010-06-22 23:45:56 +00:00
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
if (!raststates.empty())
|
|
|
|
{
|
|
|
|
if (cur_raststate != raststates.top().GetPtr())
|
|
|
|
{
|
|
|
|
cur_raststate = (ID3D11RasterizerState*)raststates.top().GetPtr();
|
|
|
|
D3D::context->RSSetState(cur_raststate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else ERROR_LOG(VIDEO, "Tried to apply without rasterizer state!");
|
2010-06-22 23:45:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 13:14:51 +00:00
|
|
|
} // namespace
|
2011-01-29 20:16:51 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
} // namespace DX11
|