2013-04-17 21:29:41 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2010-06-22 17:45:56 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/Log.h"
|
2011-01-25 09:43:08 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/GfxState.h"
|
2010-06-22 17:45:56 -06:00
|
|
|
|
2011-01-29 13:16:51 -07:00
|
|
|
namespace DX11
|
|
|
|
{
|
|
|
|
|
2010-06-22 17:45:56 -06:00
|
|
|
namespace D3D
|
|
|
|
{
|
|
|
|
|
2011-06-11 13:37:21 -06: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 05:30:55 -06:00
|
|
|
if (state) ((T*)state)->Release();
|
2014-03-09 14:14:26 -06:00
|
|
|
state = nullptr;
|
2011-06-11 13:37:21 -06:00
|
|
|
}
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
StateManager::StateManager() : cur_blendstate(nullptr), cur_depthstate(nullptr), cur_raststate(nullptr) {}
|
2011-06-11 13:37:21 -06: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 17:45:56 -06:00
|
|
|
|
|
|
|
void StateManager::Apply()
|
|
|
|
{
|
2011-06-11 13:37:21 -06:00
|
|
|
if (!blendstates.empty())
|
|
|
|
{
|
|
|
|
if (cur_blendstate != blendstates.top().GetPtr())
|
|
|
|
{
|
|
|
|
cur_blendstate = (ID3D11BlendState*)blendstates.top().GetPtr();
|
2014-03-09 14:14:26 -06:00
|
|
|
D3D::context->OMSetBlendState(cur_blendstate, nullptr, 0xFFFFFFFF);
|
2011-06-11 13:37:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else ERROR_LOG(VIDEO, "Tried to apply without blend state!");
|
|
|
|
|
|
|
|
if (!depthstates.empty())
|
2010-06-22 17:45:56 -06:00
|
|
|
{
|
2011-06-11 13:37:21 -06:00
|
|
|
if (cur_depthstate != depthstates.top().GetPtr())
|
|
|
|
{
|
|
|
|
cur_depthstate = (ID3D11DepthStencilState*)depthstates.top().GetPtr();
|
|
|
|
D3D::context->OMSetDepthStencilState(cur_depthstate, 0);
|
|
|
|
}
|
2010-06-22 17:45:56 -06:00
|
|
|
}
|
2011-06-11 13:37:21 -06:00
|
|
|
else ERROR_LOG(VIDEO, "Tried to apply without depth state!");
|
2010-06-22 17:45:56 -06:00
|
|
|
|
2011-06-11 13:37:21 -06: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 17:45:56 -06:00
|
|
|
}
|
|
|
|
|
2010-07-06 07:14:51 -06:00
|
|
|
} // namespace
|
2011-01-29 13:16:51 -07:00
|
|
|
|
2014-03-10 05:30:55 -06:00
|
|
|
} // namespace DX11
|