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

141 lines
4.3 KiB
C++

#include "xna/graphics/rasterizerstate.hpp"
#include "xna-dx/framework.hpp"
namespace xna {
RasterizerState::RasterizerState() : RasterizerState(nullptr){}
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;
}
bool RasterizerState::Initialize()
{
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
throw csharp::InvalidOperationException();
}
if (Implementation->RasterizerState) {
Implementation->RasterizerState = nullptr;
}
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateRasterizerState(
&Implementation->Description,
Implementation->RasterizerState.GetAddressOf());
if (FAILED(hr)) {
throw csharp::InvalidOperationException();
}
return true;
}
bool RasterizerState::Apply()
{
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
throw csharp::InvalidOperationException();
}
if (!Implementation->RasterizerState) {
throw csharp::InvalidOperationException();
}
BaseGraphicsDevice->Implementation->Context->RSSetState(Implementation->RasterizerState.Get());
return true;
}
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;
}
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;
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;
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;
return raster;
}
xna::CullMode RasterizerState::CullMode() const {
if (!Implementation)
return xna::CullMode::None;
return static_cast<xna::CullMode>(static_cast<int>(Implementation->Description.CullMode) - 1);
}
void RasterizerState::CullMode(xna::CullMode value) {
if (!Implementation)
return;
Implementation->Description.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
}
xna::FillMode RasterizerState::FillMode() const {
if (!Implementation)
return xna::FillMode::WireFrame;
return static_cast<xna::FillMode>(static_cast<int>(Implementation->Description.FillMode) - 2);
}
void RasterizerState::FillMode(xna::FillMode value) {
if (!Implementation)
return;
Implementation->Description.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
}
}