1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00
xn65/framework/platform/depthstencilstate-dx.cpp

67 lines
1.7 KiB
C++
Raw Normal View History

2024-04-15 09:48:16 -03:00
#include "depthstencilstate-dx.hpp"
#include "device-dx.hpp"
namespace xna {
2024-04-25 14:51:33 -03:00
bool DepthStencilState::Initialize(xna_error_ptr_arg)
2024-04-15 09:48:16 -03:00
{
2024-04-25 14:51:33 -03:00
if (!m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
2024-04-15 09:48:16 -03:00
return false;
}
2024-04-25 14:51:33 -03:00
if (dxDepthStencil) {
dxDepthStencil->Release();
dxDepthStencil = nullptr;
2024-04-15 09:48:16 -03:00
}
2024-04-25 14:51:33 -03:00
const auto hr = m_device->_device->CreateDepthStencilState(&dxDescription, &dxDepthStencil);
2024-04-15 09:48:16 -03:00
if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
return false;
}
return true;
}
2024-04-25 14:51:33 -03:00
bool DepthStencilState::Apply(xna_error_ptr_arg)
2024-04-15 09:48:16 -03:00
{
2024-04-25 14:51:33 -03:00
if (!m_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
2024-04-15 09:48:16 -03:00
return false;
}
2024-04-25 14:51:33 -03:00
if (!dxDepthStencil) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
return false;
2024-04-15 09:48:16 -03:00
}
2024-04-25 14:51:33 -03:00
m_device->_context->OMSetDepthStencilState(dxDepthStencil, 0);
2024-04-15 09:48:16 -03:00
return true;
}
2024-04-25 14:51:33 -03:00
uptr<DepthStencilState> DepthStencilState::None() {
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
stencil->dxDescription.DepthEnable = false;
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
2024-04-15 09:48:16 -03:00
return stencil;
}
2024-04-25 14:51:33 -03:00
uptr<DepthStencilState> DepthStencilState::Default() {
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
stencil->dxDescription.DepthEnable = true;
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2024-04-15 09:48:16 -03:00
return stencil;
}
2024-04-25 14:51:33 -03:00
uptr<DepthStencilState> DepthStencilState::DepthRead() {
auto stencil = std::unique_ptr<DepthStencilState>(new DepthStencilState());
stencil->dxDescription.DepthEnable = true;
stencil->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
2024-04-15 09:48:16 -03:00
return stencil;
}
}