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

Adiciona PlatformImplementation em RasterizerState

This commit is contained in:
Danilo 2024-11-15 20:14:51 -03:00
parent 1955962ae8
commit cdc628d3c1
5 changed files with 78 additions and 74 deletions

View File

@ -54,6 +54,11 @@ namespace xna {
UINT vSyncValue = 1;
};
struct RasterizerStateImplementation {
comptr<ID3D11RasterizerState> RasterizerState;
D3D11_RASTERIZER_DESC Description{};
};
struct SamplerStateImplementation {
comptr<ID3D11SamplerState> SamplerState;
D3D11_SAMPLER_DESC Description;
@ -107,11 +112,6 @@ namespace xna {
}
uptr<DirectX::Mouse> _dxMouse = nullptr;
};
struct RasterizerState::PlatformImplementation {
comptr<ID3D11RasterizerState> dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{};
};
struct SwapChain::PlatformImplementation {

View File

@ -54,13 +54,7 @@ namespace xna {
DepthBuffer,
Stencil,
Target,
};
enum class CullMode {
None,
CullClockwiseFace,
CullCounterClockwiseFace,
};
};
enum class DepthWriteMask {
Zero,
@ -93,13 +87,7 @@ namespace xna {
Texture3D,
TextureCube,
Void
};
enum class FillMode
{
WireFrame,
Solid,
};
};
enum class GameComponentType {
Updatable,

View File

@ -1,15 +1,37 @@
#ifndef XNA_GRAPHICS_RASTERIZER_HPP
#define XNA_GRAPHICS_RASTERIZER_HPP
#include "../default.hpp"
#include "gresource.hpp"
#include "../platform.hpp"
namespace xna {
//Defines winding orders that may be used to identify back faces for culling.
enum class CullMode {
//Do not cull back faces.
None,
//Cull back faces with clockwise vertices.
CullClockwiseFace,
//Cull back faces with counterclockwise vertices.
CullCounterClockwiseFace,
};
//Describes options for filling the vertices and lines that define a primitive.
enum class FillMode
{
//Draw lines connecting the vertices that define a primitive face.
WireFrame,
//Draw solid faces for each primitive.
Solid,
};
struct RasterizerStateImplementation;
//Contains rasterizer state, which determines how to convert vector data (shapes) into raster data (pixels).
class RasterizerState : public GraphicsResource {
class RasterizerState : public GraphicsResource, public PlatformImplementation<RasterizerStateImplementation> {
public:
RasterizerState();
RasterizerState(sptr<GraphicsDevice> const& device);
RasterizerState(std::shared_ptr<GraphicsDevice> const& device);
//Specifies the conditions for culling or removing triangles. The default value is CullMode.CounterClockwise.
xna::CullMode CullMode() const;
@ -45,21 +67,15 @@ namespace xna {
void ScissorTestEnable(bool value);
//A built-in state object with settings for not culling any primitives.
static uptr<RasterizerState> CullNone();
static std::unique_ptr<RasterizerState> CullNone();
//A built-in state object with settings for culling primitives with clockwise winding order.
static uptr<RasterizerState> CullClockwise();
static std::unique_ptr<RasterizerState> CullClockwise();
//A built-in state object with settings for culling primitives with counter-clockwise winding order.
static uptr<RasterizerState> CullCounterClockwise();
static std::unique_ptr<RasterizerState> CullCounterClockwise();
bool Initialize();
bool Apply();
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl = nullptr;
};
using PRasterizerState = sptr<RasterizerState>;
bool Apply();
};
}
#endif

View File

@ -6,28 +6,28 @@ namespace xna {
RasterizerState::RasterizerState() : RasterizerState(nullptr){}
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;
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 (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
}
if (impl->dxRasterizerState) {
impl->dxRasterizerState = nullptr;
if (Implementation->RasterizerState) {
Implementation->RasterizerState = nullptr;
}
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateRasterizerState(
&impl->dxDescription,
impl->dxRasterizerState.GetAddressOf());
&Implementation->Description,
Implementation->RasterizerState.GetAddressOf());
if (FAILED(hr)) {
Exception::Throw(Exception::FAILED_TO_CREATE);
@ -38,103 +38,103 @@ namespace xna {
bool RasterizerState::Apply()
{
if (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
}
if (!impl->dxRasterizerState) {
if (!Implementation->RasterizerState) {
Exception::Throw(Exception::INVALID_OPERATION);
}
BaseGraphicsDevice->Implementation->Context->RSSetState(impl->dxRasterizerState.Get());
BaseGraphicsDevice->Implementation->Context->RSSetState(Implementation->RasterizerState.Get());
return true;
}
bool RasterizerState::ScissorTestEnable() const {
return impl->dxDescription.ScissorEnable;
return Implementation->Description.ScissorEnable;
}
void RasterizerState::ScissorTestEnable(bool value) {
impl->dxDescription.ScissorEnable = value;
Implementation->Description.ScissorEnable = value;
}
bool RasterizerState::MultiSampleAntiAlias() const {
return impl->dxDescription.MultisampleEnable;
return Implementation->Description.MultisampleEnable;
}
void RasterizerState::MultiSampleAntiAlias(bool value) {
impl->dxDescription.MultisampleEnable = value;
Implementation->Description.MultisampleEnable = value;
}
float RasterizerState::DepthBias() const {
return static_cast<float>(impl->dxDescription.DepthBias);
return static_cast<float>(Implementation->Description.DepthBias);
}
void RasterizerState::DepthBias(float value) {
impl->dxDescription.DepthBias = static_cast<INT>(value);
Implementation->Description.DepthBias = static_cast<INT>(value);
}
float RasterizerState::SlopeScaleDepthBias() const {
return impl->dxDescription.SlopeScaledDepthBias;
return Implementation->Description.SlopeScaledDepthBias;
}
void RasterizerState::SlopeScaleDepthBias(float value) {
impl->dxDescription.SlopeScaledDepthBias = value;
Implementation->Description.SlopeScaledDepthBias = value;
}
uptr<RasterizerState> RasterizerState::CullNone()
{
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;
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->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
raster->impl->dxDescription.DepthClipEnable = true;
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->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
raster->impl->dxDescription.DepthClipEnable = true;
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 (!impl)
if (!Implementation)
return xna::CullMode::None;
return static_cast<xna::CullMode>(static_cast<int>(impl->dxDescription.CullMode) - 1);
return static_cast<xna::CullMode>(static_cast<int>(Implementation->Description.CullMode) - 1);
}
void RasterizerState::CullMode(xna::CullMode value) {
if (!impl)
if (!Implementation)
return;
impl->dxDescription.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
Implementation->Description.CullMode = static_cast<D3D11_CULL_MODE>(static_cast<int>(value) + 1);
}
xna::FillMode RasterizerState::FillMode() const {
if (!impl)
if (!Implementation)
return xna::FillMode::WireFrame;
return static_cast<xna::FillMode>(static_cast<int>(impl->dxDescription.FillMode) - 2);
return static_cast<xna::FillMode>(static_cast<int>(Implementation->Description.FillMode) - 2);
}
void RasterizerState::FillMode(xna::FillMode value) {
if (!impl)
if (!Implementation)
return;
impl->dxDescription.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
Implementation->Description.FillMode = static_cast<D3D11_FILL_MODE>(static_cast<int>(value) + 2);
}
}

View File

@ -161,7 +161,7 @@ namespace xna {
blendState ? blendState->Implementation->BlendState.Get() : nullptr,
samplerState ? samplerState->Implementation->SamplerState.Get() : nullptr,
depthStencil ? depthStencil->Implementation->DepthStencil.Get() : nullptr,
rasterizerState ? rasterizerState->impl->dxRasterizerState.Get() : nullptr,
rasterizerState ? rasterizerState->Implementation->RasterizerState.Get() : nullptr,
effectFunc,
_transformMatrix
);