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

227 lines
7.7 KiB
C++
Raw Normal View History

2024-06-03 21:55:09 -03:00
#include "xna/graphics/depthstencilstate.hpp"
2024-06-05 21:28:53 -03:00
#include "xna/platform-dx/dx.hpp"
2024-04-15 09:48:16 -03:00
namespace xna {
2024-05-20 10:29:20 -03:00
static D3D11_DEPTH_STENCIL_DESC defaultDesc() {
D3D11_DEPTH_STENCIL_DESC _description{};
_description.DepthEnable = true;
_description.StencilEnable = true;
_description.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
_description.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
_description.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
_description.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
_description.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
_description.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
_description.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
_description.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
_description.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2024-06-23 23:14:06 -03:00
_description.StencilReadMask = IntMaxValue;
_description.StencilWriteMask = IntMaxValue;
_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2024-05-20 10:29:20 -03:00
return _description;
}
DepthStencilState::DepthStencilState() : GraphicsResource(nullptr) {
impl = unew<PlatformImplementation>();
2024-05-20 10:29:20 -03:00
impl->dxDescription = defaultDesc();
}
DepthStencilState::DepthStencilState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
impl = unew<PlatformImplementation>();
2024-05-20 10:29:20 -03:00
impl->dxDescription = defaultDesc();
2024-06-23 23:14:06 -03:00
}
2024-05-20 10:29:20 -03:00
bool DepthStencilState::Initialize()
2024-04-15 09:48:16 -03:00
{
2024-05-24 22:26:10 -03:00
if (!m_device || !m_device->impl->_device) {
Exception::Throw(ExMessage::InitializeComponent);
2024-04-15 09:48:16 -03:00
}
2024-05-20 10:29:20 -03:00
if (impl->dxDepthStencil) {
impl->dxDepthStencil = nullptr;
2024-04-15 09:48:16 -03:00
}
2024-05-24 22:26:10 -03:00
const auto hr = m_device->impl->_device->CreateDepthStencilState(
2024-05-20 10:29:20 -03:00
&impl->dxDescription,
2024-06-25 17:06:37 -03:00
impl->dxDepthStencil.GetAddressOf());
2024-04-15 09:48:16 -03:00
if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent);
2024-04-15 09:48:16 -03:00
}
return true;
}
bool DepthStencilState::Apply()
2024-04-15 09:48:16 -03:00
{
2024-05-24 22:26:10 -03:00
if (!m_device || !m_device->impl->_context) {
Exception::Throw(ExMessage::InvalidOperation);
2024-04-15 09:48:16 -03:00
}
2024-05-20 10:29:20 -03:00
if (!impl->dxDepthStencil) {
Exception::Throw(ExMessage::UnintializedComponent);
2024-04-15 09:48:16 -03:00
}
2024-06-25 17:06:37 -03:00
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil.Get(), 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 = unew<DepthStencilState>();
2024-05-20 10:29:20 -03:00
stencil->impl->dxDescription.DepthEnable = false;
stencil->impl->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 = unew<DepthStencilState>();
2024-05-20 10:29:20 -03:00
stencil->impl->dxDescription.DepthEnable = true;
stencil->impl->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 = unew<DepthStencilState>();
2024-05-20 10:29:20 -03:00
stencil->impl->dxDescription.DepthEnable = true;
stencil->impl->dxDescription.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
2024-04-15 09:48:16 -03:00
return stencil;
}
2024-05-20 10:29:20 -03:00
2024-06-23 23:14:06 -03:00
void DepthStencilState::DepthBufferEnable(bool value) {
2024-05-20 10:29:20 -03:00
impl->dxDescription.DepthEnable = value;
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::DepthBufferWriteEnable(bool value) {
2024-05-20 10:29:20 -03:00
impl->dxDescription.DepthWriteMask = static_cast<D3D11_DEPTH_WRITE_MASK>(value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::DepthBufferFunction(ComparisonFunction value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilEnable(bool value) {
2024-05-20 10:29:20 -03:00
impl->dxDescription.StencilEnable = value;
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilMask(int value) {
2024-05-20 10:29:20 -03:00
impl->dxDescription.StencilReadMask = static_cast<UINT8>(value);
}
void DepthStencilState::StencilWriteMask(Int value) {
impl->dxDescription.StencilWriteMask = static_cast<UINT8>(value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilPass(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.FrontFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilFail(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.FrontFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilDepthBufferFail(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.FrontFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilFunction(ComparisonFunction value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.FrontFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::CounterClockwiseStencilPass(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.BackFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::CounterClockwiseStencilFail(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.BackFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::CounterClockwiseStencilDepthBufferFail(StencilOperation value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.BackFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::CounterClockwiseStencilFunction(ComparisonFunction value) {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(value) + 1;
impl->dxDescription.BackFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::DepthBufferEnable() const {
2024-05-20 10:29:20 -03:00
return impl->dxDescription.DepthEnable;
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::DepthBufferWriteEnable() const {
2024-05-20 10:29:20 -03:00
return static_cast<bool>(impl->dxDescription.DepthWriteMask);
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::DepthBufferFunction() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.DepthFunc) - 1;
return static_cast<ComparisonFunction>(_value);
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::StencilEnable() const {
2024-05-20 10:29:20 -03:00
return impl->dxDescription.StencilEnable;
}
2024-06-23 23:14:06 -03:00
Int DepthStencilState::StencilMask() const {
2024-05-20 10:29:20 -03:00
return static_cast<int>(impl->dxDescription.StencilReadMask);
}
Int DepthStencilState::StencilWriteMask() const {
return static_cast<int>(impl->dxDescription.StencilWriteMask);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilPass() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.FrontFace.StencilPassOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilFail() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.FrontFace.StencilFailOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilDepthBufferFail() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.FrontFace.StencilDepthFailOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::StencilFunction() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.FrontFace.StencilFunc) - 1;
return static_cast<ComparisonFunction>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilPass() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.BackFace.StencilPassOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilFail() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.BackFace.StencilFailOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilDepthBufferFail() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.BackFace.StencilDepthFailOp) - 1;
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::CounterClockwiseStencilFunction() const {
2024-05-20 10:29:20 -03:00
const auto _value = static_cast<int>(impl->dxDescription.BackFace.StencilFunc) - 1;
return static_cast<ComparisonFunction>(_value);
}
2024-04-15 09:48:16 -03:00
}