Files
dolphin/Source/Core/VideoBackends/D3D/GfxState.cpp
T

81 lines
2.2 KiB
C++
Raw Normal View History

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