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

227 lines
8.2 KiB
C++
Raw Permalink Normal View History

2024-06-03 21:55:09 -03:00
#include "xna/graphics/depthstencilstate.hpp"
2024-09-06 22:23:32 -03:00
#include "xna-dx/framework.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;
_description.StencilReadMask = static_cast<UINT8>(IntMaxValue);
_description.StencilWriteMask = static_cast<UINT8>(IntMaxValue);
2024-06-23 23:14:06 -03:00
_description.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2024-05-20 10:29:20 -03:00
return _description;
}
DepthStencilState::DepthStencilState() : GraphicsResource(nullptr) {
Implementation = unew<DepthStencilStateImplementation>();
Implementation->Description = defaultDesc();
2024-05-20 10:29:20 -03:00
}
DepthStencilState::DepthStencilState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
Implementation = unew<DepthStencilStateImplementation>();
Implementation->Description = 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
{
if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
throw csharp::InvalidOperationException();
2024-04-15 09:48:16 -03:00
}
if (Implementation->DepthStencil) {
Implementation->DepthStencil = nullptr;
2024-04-15 09:48:16 -03:00
}
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateDepthStencilState(
&Implementation->Description,
Implementation->DepthStencil.GetAddressOf());
2024-04-15 09:48:16 -03:00
if (FAILED(hr)) {
throw csharp::InvalidOperationException();
2024-04-15 09:48:16 -03:00
}
return true;
}
bool DepthStencilState::Apply()
2024-04-15 09:48:16 -03:00
{
if (!BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
throw csharp::InvalidOperationException();
2024-04-15 09:48:16 -03:00
}
if (!Implementation->DepthStencil) {
2024-08-02 16:40:06 -03:00
Initialize();
2024-04-15 09:48:16 -03:00
}
BaseGraphicsDevice->Implementation->Context->OMSetDepthStencilState(Implementation->DepthStencil.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>();
stencil->Implementation->Description.DepthEnable = false;
stencil->Implementation->Description.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>();
stencil->Implementation->Description.DepthEnable = true;
stencil->Implementation->Description.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>();
stencil->Implementation->Description.DepthEnable = true;
stencil->Implementation->Description.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) {
Implementation->Description.DepthEnable = value;
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::DepthBufferWriteEnable(bool value) {
Implementation->Description.DepthWriteMask = static_cast<D3D11_DEPTH_WRITE_MASK>(value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilEnable(bool value) {
Implementation->Description.StencilEnable = value;
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
void DepthStencilState::StencilMask(int value) {
Implementation->Description.StencilReadMask = static_cast<UINT8>(value);
2024-05-20 10:29:20 -03:00
}
void DepthStencilState::StencilWriteMask(Int value) {
Implementation->Description.StencilWriteMask = static_cast<UINT8>(value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.FrontFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.FrontFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.FrontFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.FrontFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.BackFace.StencilPassOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.BackFace.StencilFailOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.BackFace.StencilDepthFailOp = static_cast<D3D11_STENCIL_OP>(_value);
2024-05-20 10:29:20 -03:00
}
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;
Implementation->Description.BackFace.StencilFunc = static_cast<D3D11_COMPARISON_FUNC>(_value);
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::DepthBufferEnable() const {
return Implementation->Description.DepthEnable;
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::DepthBufferWriteEnable() const {
return static_cast<bool>(Implementation->Description.DepthWriteMask);
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::DepthBufferFunction() const {
const auto _value = static_cast<int>(Implementation->Description.DepthFunc) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<ComparisonFunction>(_value);
}
2024-06-23 23:14:06 -03:00
bool DepthStencilState::StencilEnable() const {
return Implementation->Description.StencilEnable;
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
Int DepthStencilState::StencilMask() const {
return static_cast<int>(Implementation->Description.StencilReadMask);
2024-05-20 10:29:20 -03:00
}
Int DepthStencilState::StencilWriteMask() const {
return static_cast<int>(Implementation->Description.StencilWriteMask);
2024-05-20 10:29:20 -03:00
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilPass() const {
const auto _value = static_cast<int>(Implementation->Description.FrontFace.StencilPassOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilFail() const {
const auto _value = static_cast<int>(Implementation->Description.FrontFace.StencilFailOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::StencilDepthBufferFail() const {
const auto _value = static_cast<int>(Implementation->Description.FrontFace.StencilDepthFailOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::StencilFunction() const {
const auto _value = static_cast<int>(Implementation->Description.FrontFace.StencilFunc) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<ComparisonFunction>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilPass() const {
const auto _value = static_cast<int>(Implementation->Description.BackFace.StencilPassOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilFail() const {
const auto _value = static_cast<int>(Implementation->Description.BackFace.StencilFailOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
StencilOperation DepthStencilState::CounterClockwiseStencilDepthBufferFail() const {
const auto _value = static_cast<int>(Implementation->Description.BackFace.StencilDepthFailOp) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<StencilOperation>(_value);
}
2024-06-23 23:14:06 -03:00
ComparisonFunction DepthStencilState::CounterClockwiseStencilFunction() const {
const auto _value = static_cast<int>(Implementation->Description.BackFace.StencilFunc) - 1;
2024-05-20 10:29:20 -03:00
return static_cast<ComparisonFunction>(_value);
}
2024-04-15 09:48:16 -03:00
}