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:
parent
1955962ae8
commit
cdc628d3c1
@ -54,6 +54,11 @@ namespace xna {
|
|||||||
UINT vSyncValue = 1;
|
UINT vSyncValue = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RasterizerStateImplementation {
|
||||||
|
comptr<ID3D11RasterizerState> RasterizerState;
|
||||||
|
D3D11_RASTERIZER_DESC Description{};
|
||||||
|
};
|
||||||
|
|
||||||
struct SamplerStateImplementation {
|
struct SamplerStateImplementation {
|
||||||
comptr<ID3D11SamplerState> SamplerState;
|
comptr<ID3D11SamplerState> SamplerState;
|
||||||
D3D11_SAMPLER_DESC Description;
|
D3D11_SAMPLER_DESC Description;
|
||||||
@ -107,11 +112,6 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uptr<DirectX::Mouse> _dxMouse = nullptr;
|
uptr<DirectX::Mouse> _dxMouse = nullptr;
|
||||||
};
|
|
||||||
|
|
||||||
struct RasterizerState::PlatformImplementation {
|
|
||||||
comptr<ID3D11RasterizerState> dxRasterizerState = nullptr;
|
|
||||||
D3D11_RASTERIZER_DESC dxDescription{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwapChain::PlatformImplementation {
|
struct SwapChain::PlatformImplementation {
|
||||||
|
@ -54,13 +54,7 @@ namespace xna {
|
|||||||
DepthBuffer,
|
DepthBuffer,
|
||||||
Stencil,
|
Stencil,
|
||||||
Target,
|
Target,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class CullMode {
|
|
||||||
None,
|
|
||||||
CullClockwiseFace,
|
|
||||||
CullCounterClockwiseFace,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class DepthWriteMask {
|
enum class DepthWriteMask {
|
||||||
Zero,
|
Zero,
|
||||||
@ -93,13 +87,7 @@ namespace xna {
|
|||||||
Texture3D,
|
Texture3D,
|
||||||
TextureCube,
|
TextureCube,
|
||||||
Void
|
Void
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class FillMode
|
|
||||||
{
|
|
||||||
WireFrame,
|
|
||||||
Solid,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class GameComponentType {
|
enum class GameComponentType {
|
||||||
Updatable,
|
Updatable,
|
||||||
|
@ -1,15 +1,37 @@
|
|||||||
#ifndef XNA_GRAPHICS_RASTERIZER_HPP
|
#ifndef XNA_GRAPHICS_RASTERIZER_HPP
|
||||||
#define XNA_GRAPHICS_RASTERIZER_HPP
|
#define XNA_GRAPHICS_RASTERIZER_HPP
|
||||||
|
|
||||||
#include "../default.hpp"
|
|
||||||
#include "gresource.hpp"
|
#include "gresource.hpp"
|
||||||
|
#include "../platform.hpp"
|
||||||
|
|
||||||
namespace xna {
|
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).
|
//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:
|
public:
|
||||||
RasterizerState();
|
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.
|
//Specifies the conditions for culling or removing triangles. The default value is CullMode.CounterClockwise.
|
||||||
xna::CullMode CullMode() const;
|
xna::CullMode CullMode() const;
|
||||||
@ -45,21 +67,15 @@ namespace xna {
|
|||||||
void ScissorTestEnable(bool value);
|
void ScissorTestEnable(bool value);
|
||||||
|
|
||||||
//A built-in state object with settings for not culling any primitives.
|
//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.
|
//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.
|
//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 Initialize();
|
||||||
bool Apply();
|
bool Apply();
|
||||||
|
};
|
||||||
public:
|
|
||||||
struct PlatformImplementation;
|
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
using PRasterizerState = sptr<RasterizerState>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -6,28 +6,28 @@ namespace xna {
|
|||||||
RasterizerState::RasterizerState() : RasterizerState(nullptr){}
|
RasterizerState::RasterizerState() : RasterizerState(nullptr){}
|
||||||
|
|
||||||
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
RasterizerState::RasterizerState(sptr<GraphicsDevice> const& device) : GraphicsResource(device) {
|
||||||
impl = unew<PlatformImplementation>();
|
Implementation = unew<RasterizerStateImplementation>();
|
||||||
impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||||
impl->dxDescription.FillMode = D3D11_FILL_MODE::D3D11_FILL_SOLID;
|
Implementation->Description.FillMode = D3D11_FILL_MODE::D3D11_FILL_SOLID;
|
||||||
impl->dxDescription.MultisampleEnable = true;
|
Implementation->Description.MultisampleEnable = true;
|
||||||
impl->dxDescription.DepthBias = 0;
|
Implementation->Description.DepthBias = 0;
|
||||||
impl->dxDescription.SlopeScaledDepthBias = 0;
|
Implementation->Description.SlopeScaledDepthBias = 0;
|
||||||
impl->dxDescription.ScissorEnable = false;
|
Implementation->Description.ScissorEnable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasterizerState::Initialize()
|
bool RasterizerState::Initialize()
|
||||||
{
|
{
|
||||||
if (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
|
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Device) {
|
||||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (impl->dxRasterizerState) {
|
if (Implementation->RasterizerState) {
|
||||||
impl->dxRasterizerState = nullptr;
|
Implementation->RasterizerState = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateRasterizerState(
|
const auto hr = BaseGraphicsDevice->Implementation->Device->CreateRasterizerState(
|
||||||
&impl->dxDescription,
|
&Implementation->Description,
|
||||||
impl->dxRasterizerState.GetAddressOf());
|
Implementation->RasterizerState.GetAddressOf());
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
@ -38,103 +38,103 @@ namespace xna {
|
|||||||
|
|
||||||
bool RasterizerState::Apply()
|
bool RasterizerState::Apply()
|
||||||
{
|
{
|
||||||
if (!impl || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
|
if (!Implementation || !BaseGraphicsDevice || !BaseGraphicsDevice->Implementation->Context) {
|
||||||
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
Exception::Throw(Exception::UNABLE_TO_INITIALIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!impl->dxRasterizerState) {
|
if (!Implementation->RasterizerState) {
|
||||||
Exception::Throw(Exception::INVALID_OPERATION);
|
Exception::Throw(Exception::INVALID_OPERATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseGraphicsDevice->Implementation->Context->RSSetState(impl->dxRasterizerState.Get());
|
BaseGraphicsDevice->Implementation->Context->RSSetState(Implementation->RasterizerState.Get());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasterizerState::ScissorTestEnable() const {
|
bool RasterizerState::ScissorTestEnable() const {
|
||||||
return impl->dxDescription.ScissorEnable;
|
return Implementation->Description.ScissorEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerState::ScissorTestEnable(bool value) {
|
void RasterizerState::ScissorTestEnable(bool value) {
|
||||||
impl->dxDescription.ScissorEnable = value;
|
Implementation->Description.ScissorEnable = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasterizerState::MultiSampleAntiAlias() const {
|
bool RasterizerState::MultiSampleAntiAlias() const {
|
||||||
return impl->dxDescription.MultisampleEnable;
|
return Implementation->Description.MultisampleEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerState::MultiSampleAntiAlias(bool value) {
|
void RasterizerState::MultiSampleAntiAlias(bool value) {
|
||||||
impl->dxDescription.MultisampleEnable = value;
|
Implementation->Description.MultisampleEnable = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float RasterizerState::DepthBias() const {
|
float RasterizerState::DepthBias() const {
|
||||||
return static_cast<float>(impl->dxDescription.DepthBias);
|
return static_cast<float>(Implementation->Description.DepthBias);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerState::DepthBias(float value) {
|
void RasterizerState::DepthBias(float value) {
|
||||||
impl->dxDescription.DepthBias = static_cast<INT>(value);
|
Implementation->Description.DepthBias = static_cast<INT>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float RasterizerState::SlopeScaleDepthBias() const {
|
float RasterizerState::SlopeScaleDepthBias() const {
|
||||||
return impl->dxDescription.SlopeScaledDepthBias;
|
return Implementation->Description.SlopeScaledDepthBias;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerState::SlopeScaleDepthBias(float value) {
|
void RasterizerState::SlopeScaleDepthBias(float value) {
|
||||||
impl->dxDescription.SlopeScaledDepthBias = value;
|
Implementation->Description.SlopeScaledDepthBias = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<RasterizerState> RasterizerState::CullNone()
|
uptr<RasterizerState> RasterizerState::CullNone()
|
||||||
{
|
{
|
||||||
auto raster = unew<RasterizerState>();
|
auto raster = unew<RasterizerState>();
|
||||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
|
||||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_NONE;
|
||||||
raster->impl->dxDescription.DepthClipEnable = true;
|
raster->Implementation->Description.DepthClipEnable = true;
|
||||||
return raster;
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<RasterizerState> RasterizerState::CullClockwise()
|
uptr<RasterizerState> RasterizerState::CullClockwise()
|
||||||
{
|
{
|
||||||
auto raster = unew<RasterizerState>();
|
auto raster = unew<RasterizerState>();
|
||||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
|
||||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_FRONT;
|
||||||
raster->impl->dxDescription.DepthClipEnable = true;
|
raster->Implementation->Description.DepthClipEnable = true;
|
||||||
return raster;
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
|
uptr<RasterizerState> RasterizerState::CullCounterClockwise()
|
||||||
{
|
{
|
||||||
auto raster = unew<RasterizerState>();
|
auto raster = unew<RasterizerState>();
|
||||||
raster->impl->dxDescription.FillMode = D3D11_FILL_SOLID;
|
raster->Implementation->Description.FillMode = D3D11_FILL_SOLID;
|
||||||
raster->impl->dxDescription.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
raster->Implementation->Description.CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK;
|
||||||
raster->impl->dxDescription.DepthClipEnable = true;
|
raster->Implementation->Description.DepthClipEnable = true;
|
||||||
return raster;
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
xna::CullMode RasterizerState::CullMode() const {
|
xna::CullMode RasterizerState::CullMode() const {
|
||||||
if (!impl)
|
if (!Implementation)
|
||||||
return xna::CullMode::None;
|
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) {
|
void RasterizerState::CullMode(xna::CullMode value) {
|
||||||
if (!impl)
|
if (!Implementation)
|
||||||
return;
|
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 {
|
xna::FillMode RasterizerState::FillMode() const {
|
||||||
if (!impl)
|
if (!Implementation)
|
||||||
return xna::FillMode::WireFrame;
|
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) {
|
void RasterizerState::FillMode(xna::FillMode value) {
|
||||||
if (!impl)
|
if (!Implementation)
|
||||||
return;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ namespace xna {
|
|||||||
blendState ? blendState->Implementation->BlendState.Get() : nullptr,
|
blendState ? blendState->Implementation->BlendState.Get() : nullptr,
|
||||||
samplerState ? samplerState->Implementation->SamplerState.Get() : nullptr,
|
samplerState ? samplerState->Implementation->SamplerState.Get() : nullptr,
|
||||||
depthStencil ? depthStencil->Implementation->DepthStencil.Get() : nullptr,
|
depthStencil ? depthStencil->Implementation->DepthStencil.Get() : nullptr,
|
||||||
rasterizerState ? rasterizerState->impl->dxRasterizerState.Get() : nullptr,
|
rasterizerState ? rasterizerState->Implementation->RasterizerState.Get() : nullptr,
|
||||||
effectFunc,
|
effectFunc,
|
||||||
_transformMatrix
|
_transformMatrix
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user