mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige RasterizerState
This commit is contained in:
parent
f2e613b051
commit
20c29b4c3c
@ -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"
|
||||
|
||||
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)
|
||||
{
|
||||
if (!m_device || !m_device->_device) {
|
||||
if (!impl || !m_device || !m_device->_device) {
|
||||
xna_error_apply(err, XnaErrorCode::INVALID_OPERATION);
|
||||
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)) {
|
||||
xna_error_apply(err, XnaErrorCode::FAILED_OPERATION);
|
||||
@ -21,45 +33,73 @@ namespace xna {
|
||||
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dxRasterizerState) {
|
||||
if (!impl->dxRasterizerState) {
|
||||
xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_device->_context->RSSetState(dxRasterizerState);
|
||||
m_device->_context->RSSetState(impl->dxRasterizerState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullNone()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
auto raster = uNew<RasterizerState>();
|
||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
||||
raster->impl->dxDescription.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullClockwise()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
auto raster = uNew<RasterizerState>();
|
||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
||||
raster->impl->dxDescription.DepthClipEnable = true;
|
||||
return raster;
|
||||
}
|
||||
|
||||
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
|
||||
{
|
||||
auto raster = std::unique_ptr<RasterizerState>(new RasterizerState());
|
||||
raster->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||
raster->dxDescription.DepthClipEnable = true;
|
||||
auto raster = uNew<RasterizerState>();
|
||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||
raster->impl->dxDescription.DepthClipEnable = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#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/texture-dx.hpp"
|
||||
#include "common/color.hpp"
|
||||
@ -81,7 +81,7 @@ namespace xna {
|
||||
blendState ? blendState->impl->dxBlendState : nullptr,
|
||||
samplerState ? samplerState->_samplerState : nullptr,
|
||||
depthStencil ? depthStencil->impl->dxDepthStencil : nullptr,
|
||||
rasterizerState ? rasterizerState->dxRasterizerState : nullptr,
|
||||
rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr,
|
||||
nullptr,
|
||||
matrix
|
||||
);
|
||||
|
@ -11,7 +11,7 @@ namespace xna {
|
||||
virtual ~GraphicsResource(){}
|
||||
|
||||
virtual bool Bind(sptr<GraphicsDevice> const& device) {
|
||||
if (device == m_device)
|
||||
if (!device || device == m_device)
|
||||
return false;
|
||||
|
||||
m_device = device;
|
||||
|
@ -2,17 +2,28 @@
|
||||
#define XNA_GRAPHICS_RASTERIZER_HPP
|
||||
|
||||
#include "../default.hpp"
|
||||
#include "gresource.hpp"
|
||||
|
||||
namespace xna {
|
||||
class IRasterizerState {
|
||||
class RasterizerState : GraphicsResource {
|
||||
public:
|
||||
virtual ~IRasterizerState() {}
|
||||
virtual bool Initialize(xna_error_nullarg) = 0;
|
||||
virtual bool Apply(xna_error_nullarg) = 0;
|
||||
virtual xna::CullMode CullMode() const = 0;
|
||||
virtual void CullMode(xna::CullMode value) = 0;
|
||||
virtual xna::FillMode FillMode() const = 0;
|
||||
virtual void FillMode(xna::FillMode value) = 0;
|
||||
RasterizerState();
|
||||
RasterizerState(sptr<GraphicsDevice> const& device);
|
||||
~RasterizerState();
|
||||
bool Initialize(xna_error_nullarg);
|
||||
bool Apply(xna_error_nullarg);
|
||||
xna::CullMode CullMode() const;
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -221,12 +221,12 @@ namespace xna {
|
||||
return !IsButtonDown(button);
|
||||
}
|
||||
|
||||
GamePadButtons Buttons;
|
||||
GamePadDPad Dpad;
|
||||
bool IsConnected;
|
||||
Ulong PackedNumber;
|
||||
GamePadThumbSticks Sticks;
|
||||
GamePadTriggers Triggers;
|
||||
GamePadButtons Buttons{};
|
||||
GamePadDPad Dpad{};
|
||||
bool IsConnected{false};
|
||||
Ulong PackedNumber{0};
|
||||
GamePadThumbSticks Sticks{};
|
||||
GamePadTriggers Triggers{};
|
||||
};
|
||||
|
||||
class GamePad {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "input/gamepad.hpp"
|
||||
#include "input/keyboard.hpp"
|
||||
#include "input/mouse.hpp"
|
||||
#include "graphics/rasterizerstate.hpp"
|
||||
#include "graphics/presentparams.hpp"
|
||||
#include "platform-dx/rendertarget-dx.hpp"
|
||||
#include "platform-dx/swapchain-dx.hpp"
|
||||
@ -201,4 +202,16 @@ namespace xna {
|
||||
_dxMouse->ProcessMessage(message, wParam, lParam);
|
||||
}
|
||||
};
|
||||
|
||||
struct RasterizerState::PlatformImplementation {
|
||||
~PlatformImplementation() {
|
||||
if (dxRasterizerState) {
|
||||
dxRasterizerState->Release();
|
||||
dxRasterizerState = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11RasterizerState* dxRasterizerState = nullptr;
|
||||
D3D11_RASTERIZER_DESC dxDescription{};
|
||||
};
|
||||
}
|
@ -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
|
@ -7,7 +7,6 @@
|
||||
#include "gdeviceinfo-dx.hpp"
|
||||
#include "gdevicemanager-dx.hpp"
|
||||
#include "init-dx.hpp"
|
||||
#include "rasterizerstate-dx.hpp"
|
||||
#include "rendertarget-dx.hpp"
|
||||
#include "samplerstate-dx.hpp"
|
||||
#include "shader-dx.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user