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

141 lines
4.3 KiB
C++
Raw Permalink Normal View History

2024-06-03 21:55:09 -03:00
#include "xna/graphics/rasterizerstate.hpp"
2024-09-06 22:23:32 -03:00
#include "xna-dx/framework.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) {
Implementation = unew<RasterizerStateImplementation>();
Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
Implementation->Description.FillMode = D3D11_FILL_MODE::D3D11_FILL_SOLID;
Implementation->Description.MultisampleEnable = true;
Implementation->Description.DepthBias = 0;
Implementation->Description.SlopeScaledDepthBias = 0;
Implementation->Description.ScissorEnable = false;
2024-05-22 11:55:13 -03:00
}
bool RasterizerState::Initialize()
2024-04-10 09:51:03 -03:00
{
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
throw csharp::InvalidOperationException();
2024-04-25 14:51:33 -03:00
}
if (Implementation->RasterizerState) {
Implementation->RasterizerState = nullptr;
2024-05-22 11:55:13 -03:00
}
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateRasterizerState(
&Implementation->Description,
Implementation->RasterizerState.GetAddressOf());
2024-04-10 09:51:03 -03:00
if (FAILED(hr)) {
throw csharp::InvalidOperationException();
2024-04-25 14:51:33 -03:00
}
return true;
}
bool RasterizerState::Apply()
2024-04-25 14:51:33 -03:00
{
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
throw csharp::InvalidOperationException();
2024-04-10 09:51:03 -03:00
}
if (!Implementation->RasterizerState) {
throw csharp::InvalidOperationException();
2024-04-25 14:51:33 -03:00
}
BaseGraphicsDevice->Implementation->Context->RSSetState(Implementation->RasterizerState.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 Implementation->Description.ScissorEnable;
}
void RasterizerState::ScissorTestEnable(bool value) {
Implementation->Description.ScissorEnable = value;
}
bool RasterizerState::MultiSampleAntiAlias() const {
return Implementation->Description.MultisampleEnable;
}
void RasterizerState::MultiSampleAntiAlias(bool value) {
Implementation->Description.MultisampleEnable = value;
}
float RasterizerState::DepthBias() const {
return static_cast<float>(Implementation->Description.DepthBias);
}
void RasterizerState::DepthBias(float value) {
Implementation->Description.DepthBias = static_cast<INT>(value);
}
float RasterizerState::SlopeScaleDepthBias() const {
return Implementation->Description.SlopeScaledDepthBias;
}
void RasterizerState::SlopeScaleDepthBias(float value) {
Implementation->Description.SlopeScaledDepthBias = value;
}
2024-04-25 14:51:33 -03:00
uptr<RasterizerState> RasterizerState::CullNone()
{
auto raster = unew<RasterizerState>();
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
raster->Implementation->Description.DepthClipEnable = true;
2024-04-25 14:51:33 -03:00
return raster;
}
uptr<RasterizerState> RasterizerState::CullClockwise()
{
auto raster = unew<RasterizerState>();
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
raster->Implementation->Description.DepthClipEnable = true;
2024-04-25 14:51:33 -03:00
return raster;
}
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
{
auto raster = unew<RasterizerState>();
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
raster->Implementation->Description.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 (!Implementation)
2024-05-22 10:56:16 -03:00
return xna::CullMode::None;
return static_cast<xna::CullMode>(static_cast<int>(Implementation->Description.CullMode) - 1);
2024-05-22 10:56:16 -03:00
}
void RasterizerState::CullMode(xna::CullMode value) {
if (!Implementation)
2024-05-22 10:56:16 -03:00
return;
Implementation->Description.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
2024-05-22 10:56:16 -03:00
}
xna::FillMode RasterizerState::FillMode() const {
if (!Implementation)
2024-05-22 10:56:16 -03:00
return xna::FillMode::WireFrame;
return static_cast<xna::FillMode>(static_cast<int>(Implementation->Description.FillMode) - 2);
2024-05-22 10:56:16 -03:00
}
void RasterizerState::FillMode(xna::FillMode value) {
if (!Implementation)
2024-05-22 10:56:16 -03:00
return;
Implementation->Description.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
2024-05-22 10:56:16 -03:00
}
2024-04-10 09:51:03 -03:00
}