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

141 lines
3.8 KiB
C++
Raw Normal View History

2024-06-03 21:55:09 -03:00
#include "xna/graphics/rasterizerstate.hpp"
2024-07-13 22:55:36 -03:00
#include "xna/xna-dx.hpp"
2024-04-10 09:51:03 -03:00
namespace xna {
2024-05-22 10:56:16 -03:00
RasterizerState::RasterizerState() : RasterizerState(nullptr){}
2024-05-22 10:56:16 -03:00
2024-05-22 11:55:13 -03:00
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
impl = unew<PlatformImplementation>();
impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
impl->dxDescription.FillMode = D3D11_FILL_MODE::D3D11_FILL_SOLID;
impl->dxDescription.MultisampleEnable = true;
impl->dxDescription.DepthBias = 0;
impl->dxDescription.SlopeScaledDepthBias = 0;
impl->dxDescription.ScissorEnable = false;
2024-05-22 11:55:13 -03:00
}
bool RasterizerState::Initialize()
2024-04-10 09:51:03 -03:00
{
2024-05-24 22:26:10 -03:00
if (!impl || !m_device || !m_device->impl->_device) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
2024-04-25 14:51:33 -03:00
}
2024-05-22 11:55:13 -03:00
if (impl->dxRasterizerState) {
impl->dxRasterizerState = nullptr;
}
2024-05-24 22:26:10 -03:00
const auto hr = m_device->impl->_device->CreateRasterizerState(
2024-05-22 10:56:16 -03:00
&impl->dxDescription,
2024-06-25 17:06:37 -03:00
impl->dxRasterizerState.GetAddressOf());
2024-04-10 09:51:03 -03:00
if (FAILED(hr)) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::FAILED_TO_CREATE);
2024-04-25 14:51:33 -03:00
}
return true;
}
bool RasterizerState::Apply()
2024-04-25 14:51:33 -03:00
{
2024-05-24 22:26:10 -03:00
if (!impl || !m_device || !m_device->impl->_context) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
2024-04-10 09:51:03 -03:00
}
2024-05-22 10:56:16 -03:00
if (!impl->dxRasterizerState) {
2024-07-06 12:20:54 -03:00
Exception::Throw(Exception::INVALID_OPERATION);
2024-04-25 14:51:33 -03:00
}
2024-06-25 17:06:37 -03:00
m_device->impl->_context->RSSetState(impl->dxRasterizerState.Get());
2024-04-25 14:51:33 -03:00
2024-04-10 09:51:03 -03:00
return true;
}
2024-04-25 14:51:33 -03:00
bool RasterizerState::ScissorTestEnable() const {
return impl->dxDescription.ScissorEnable;
}
void RasterizerState::ScissorTestEnable(bool value) {
impl->dxDescription.ScissorEnable = value;
}
bool RasterizerState::MultiSampleAntiAlias() const {
return impl->dxDescription.MultisampleEnable;
}
void RasterizerState::MultiSampleAntiAlias(bool value) {
impl->dxDescription.MultisampleEnable = value;
}
float RasterizerState::DepthBias() const {
return static_cast<float>(impl->dxDescription.DepthBias);
}
void RasterizerState::DepthBias(float value) {
2024-07-16 09:33:57 -03:00
impl->dxDescription.DepthBias = static_cast<INT>(value);
}
float RasterizerState::SlopeScaleDepthBias() const {
return impl->dxDescription.SlopeScaledDepthBias;
}
void RasterizerState::SlopeScaleDepthBias(float value) {
impl->dxDescription.SlopeScaledDepthBias = value;
}
2024-04-25 14:51:33 -03:00
uptr<RasterizerState> RasterizerState::CullNone()
{
auto raster = unew<RasterizerState>();
2024-05-22 10:56:16 -03:00
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
raster->impl->dxDescription.DepthClipEnable = true;
2024-04-25 14:51:33 -03:00
return raster;
}
uptr<RasterizerState> RasterizerState::CullClockwise()
{
auto raster = unew<RasterizerState>();
2024-05-22 10:56:16 -03:00
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
raster->impl->dxDescription.DepthClipEnable = true;
2024-04-25 14:51:33 -03:00
return raster;
}
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
{
auto raster = unew<RasterizerState>();
2024-05-22 10:56:16 -03:00
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
raster->impl->dxDescription.DepthClipEnable = true;
2024-04-25 14:51:33 -03:00
return raster;
}
2024-05-22 10:56:16 -03:00
xna::CullMode RasterizerState::CullMode() const {
if (!impl)
return xna::CullMode::None;
return static_cast<xna::CullMode>(static_cast<int>(impl->dxDescription.CullMode) - 1);
}
void RasterizerState::CullMode(xna::CullMode value) {
if (!impl)
return;
impl->dxDescription.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
}
xna::FillMode RasterizerState::FillMode() const {
if (!impl)
return xna::FillMode::WireFrame;
return static_cast<xna::FillMode>(static_cast<int>(impl->dxDescription.FillMode) - 2);
}
void RasterizerState::FillMode(xna::FillMode value) {
if (!impl)
return;
impl->dxDescription.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
}
2024-04-10 09:51:03 -03:00
}