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

Corrige RasterizerState

This commit is contained in:
Danilo 2024-05-22 10:56:16 -03:00
parent f2e613b051
commit 20c29b4c3c
8 changed files with 99 additions and 88 deletions

View File

@ -1,15 +1,27 @@
#include "platform-dx/rasterizerstate-dx.hpp" #include "graphics/rasterizerstate.hpp"
#include "platform-dx/implementations.hpp"
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
namespace xna { namespace xna {
RasterizerState::RasterizerState() : GraphicsResource(nullptr){}
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {}
RasterizerState::~RasterizerState() {
impl = nullptr;
}
bool RasterizerState::Initialize(xna_error_ptr_arg) bool RasterizerState::Initialize(xna_error_ptr_arg)
{ {
if (!m_device || !m_device->_device) { if (!impl || !m_device || !m_device->_device) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false; return false;
} }
const auto hr = m_device->_device->CreateRasterizerState(&dxDescription, &dxRasterizerState); const auto hr = m_device->_device->CreateRasterizerState(
&impl->dxDescription,
&impl->dxRasterizerState);
if (FAILED(hr)) { if (FAILED(hr)) {
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
@ -21,45 +33,73 @@ namespace xna {
bool RasterizerState::Apply(xna_error_ptr_arg) bool RasterizerState::Apply(xna_error_ptr_arg)
{ {
if (!m_device || !m_device->_context) { if (!impl || !m_device || !m_device->_context) {
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
return false; return false;
} }
if (!dxRasterizerState) { if (!impl->dxRasterizerState) {
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
return false; return false;
} }
m_device->_context->RSSetState(dxRasterizerState); m_device->_context->RSSetState(impl->dxRasterizerState);
return true; return true;
} }
uptr<RasterizerState> RasterizerState::CullNone() uptr<RasterizerState> RasterizerState::CullNone()
{ {
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState()); auto raster = uNew<RasterizerState>();
raster->dxDescription.FillMode = D3D11_FILL_SOLID; raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE; raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
raster->dxDescription.DepthClipEnable = true; raster->impl->dxDescription.DepthClipEnable = true;
return raster; return raster;
} }
uptr<RasterizerState> RasterizerState::CullClockwise() uptr<RasterizerState> RasterizerState::CullClockwise()
{ {
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState()); auto raster = uNew<RasterizerState>();
raster->dxDescription.FillMode = D3D11_FILL_SOLID; raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT; raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
raster->dxDescription.DepthClipEnable = true; raster->impl->dxDescription.DepthClipEnable = true;
return raster; return raster;
} }
uptr<RasterizerState> RasterizerState::CullCounterClockwise() uptr<RasterizerState> RasterizerState::CullCounterClockwise()
{ {
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState()); auto raster = uNew<RasterizerState>();
raster->dxDescription.FillMode = D3D11_FILL_SOLID; raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK; raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
raster->dxDescription.DepthClipEnable = true; raster->impl->dxDescription.DepthClipEnable = true;
return raster; return raster;
} }
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);
}
} }

View File

@ -1,5 +1,5 @@
#include "platform-dx/device-dx.hpp" #include "platform-dx/device-dx.hpp"
#include "platform-dx/rasterizerstate-dx.hpp" #include "graphics/rasterizerstate.hpp"
#include "platform-dx/samplerstate-dx.hpp" #include "platform-dx/samplerstate-dx.hpp"
#include "platform-dx/texture-dx.hpp" #include "platform-dx/texture-dx.hpp"
#include "common/color.hpp" #include "common/color.hpp"
@ -81,7 +81,7 @@ namespace xna {
blendState ? blendState->impl->dxBlendState : nullptr, blendState ? blendState->impl->dxBlendState : nullptr,
samplerState ? samplerState->_samplerState : nullptr, samplerState ? samplerState->_samplerState : nullptr,
depthStencil ? depthStencil->impl->dxDepthStencil : nullptr, depthStencil ? depthStencil->impl->dxDepthStencil : nullptr,
rasterizerState ? rasterizerState->dxRasterizerState : nullptr, rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr,
nullptr, nullptr,
matrix matrix
); );

View File

@ -11,7 +11,7 @@ namespace xna {
virtual ~GraphicsResource(){} virtual ~GraphicsResource(){}
virtual bool Bind(sptr<GraphicsDevice> const& device) { virtual bool Bind(sptr<GraphicsDevice> const& device) {
if (device == m_device) if (!device || device == m_device)
return false; return false;
m_device = device; m_device = device;

View File

@ -2,17 +2,28 @@
#define XNA_GRAPHICS_RASTERIZER_HPP #define XNA_GRAPHICS_RASTERIZER_HPP
#include "../default.hpp" #include "../default.hpp"
#include "gresource.hpp"
namespace xna { namespace xna {
class IRasterizerState { class RasterizerState : GraphicsResource {
public: public:
virtual ~IRasterizerState() {} RasterizerState();
virtual bool Initialize(xna_error_nullarg) = 0; RasterizerState(sptr<GraphicsDevice> const& device);
virtual bool Apply(xna_error_nullarg) = 0; ~RasterizerState();
virtual xna::CullMode CullMode() const = 0; bool Initialize(xna_error_nullarg);
virtual void CullMode(xna::CullMode value) = 0; bool Apply(xna_error_nullarg);
virtual xna::FillMode FillMode() const = 0; xna::CullMode CullMode() const;
virtual void FillMode(xna::FillMode value) = 0; void CullMode(xna::CullMode value);
xna::FillMode FillMode() const;
void FillMode(xna::FillMode value);
static uptr<RasterizerState> CullNone();
static uptr<RasterizerState> CullClockwise();
static uptr<RasterizerState> CullCounterClockwise();
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
}; };
} }

View File

@ -221,12 +221,12 @@ namespace xna {
return !IsButtonDown(button); return !IsButtonDown(button);
} }
GamePadButtons Buttons; GamePadButtons Buttons{};
GamePadDPad Dpad; GamePadDPad Dpad{};
bool IsConnected; bool IsConnected{false};
Ulong PackedNumber; Ulong PackedNumber{0};
GamePadThumbSticks Sticks; GamePadThumbSticks Sticks{};
GamePadTriggers Triggers; GamePadTriggers Triggers{};
}; };
class GamePad { class GamePad {

View File

@ -9,6 +9,7 @@
#include "input/gamepad.hpp" #include "input/gamepad.hpp"
#include "input/keyboard.hpp" #include "input/keyboard.hpp"
#include "input/mouse.hpp" #include "input/mouse.hpp"
#include "graphics/rasterizerstate.hpp"
#include "graphics/presentparams.hpp" #include "graphics/presentparams.hpp"
#include "platform-dx/rendertarget-dx.hpp" #include "platform-dx/rendertarget-dx.hpp"
#include "platform-dx/swapchain-dx.hpp" #include "platform-dx/swapchain-dx.hpp"
@ -201,4 +202,16 @@ namespace xna {
_dxMouse->ProcessMessage(message, wParam, lParam); _dxMouse->ProcessMessage(message, wParam, lParam);
} }
}; };
struct RasterizerState::PlatformImplementation {
~PlatformImplementation() {
if (dxRasterizerState) {
dxRasterizerState->Release();
dxRasterizerState = nullptr;
}
}
ID3D11RasterizerState* dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
};
} }

View File

@ -1,52 +0,0 @@
#ifndef XNA_PLATFORM_RASTERIZERSTATE_DX_HPP
#define XNA_PLATFORM_RASTERIZERSTATE_DX_HPP
#include "../graphics/rasterizerstate.hpp"
#include "../graphics/gresource.hpp"
#include "dxheaders.hpp"
namespace xna {
class RasterizerState : public IRasterizerState, public GraphicsResource {
public:
RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device){}
virtual ~RasterizerState() override {
if (dxRasterizerState) {
dxRasterizerState->Release();
dxRasterizerState = nullptr;
}
}
virtual bool Initialize(xna_error_nullarg) override;
virtual bool Apply(xna_error_nullarg) override;
virtual constexpr xna::CullMode CullMode() const override {
return static_cast<xna::CullMode>(static_cast<int>(dxDescription.CullMode) - 1);
}
virtual constexpr void CullMode(xna::CullMode value) override {
dxDescription.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
}
virtual constexpr xna::FillMode FillMode() const override {
return static_cast<xna::FillMode>(static_cast<int>(dxDescription.FillMode) - 2);
}
virtual constexpr void FillMode(xna::FillMode value) override {
dxDescription.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
}
static uptr<RasterizerState> CullNone();
static uptr<RasterizerState> CullClockwise();
static uptr<RasterizerState> CullCounterClockwise();
public:
ID3D11RasterizerState* dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
private:
RasterizerState() : GraphicsResource(nullptr){}
};
}
#endif

View File

@ -7,7 +7,6 @@
#include "gdeviceinfo-dx.hpp" #include "gdeviceinfo-dx.hpp"
#include "gdevicemanager-dx.hpp" #include "gdevicemanager-dx.hpp"
#include "init-dx.hpp" #include "init-dx.hpp"
#include "rasterizerstate-dx.hpp"
#include "rendertarget-dx.hpp" #include "rendertarget-dx.hpp"
#include "samplerstate-dx.hpp" #include "samplerstate-dx.hpp"
#include "shader-dx.hpp" #include "shader-dx.hpp"