diff --git a/includes/xna-dx/implementations.hpp b/includes/xna-dx/implementations.hpp index 2f0491b..4440962 100644 --- a/includes/xna-dx/implementations.hpp +++ b/includes/xna-dx/implementations.hpp @@ -54,6 +54,11 @@ namespace xna { UINT vSyncValue = 1; }; + struct RasterizerStateImplementation { + comptr RasterizerState; + D3D11_RASTERIZER_DESC Description{}; + }; + struct SamplerStateImplementation { comptr SamplerState; D3D11_SAMPLER_DESC Description; @@ -107,11 +112,6 @@ namespace xna { } uptr _dxMouse = nullptr; - }; - - struct RasterizerState::PlatformImplementation { - comptr dxRasterizerState = nullptr; - D3D11_RASTERIZER_DESC dxDescription{}; }; struct SwapChain::PlatformImplementation { diff --git a/includes/xna/enumerations.hpp b/includes/xna/enumerations.hpp index e03dea3..06d1ff9 100644 --- a/includes/xna/enumerations.hpp +++ b/includes/xna/enumerations.hpp @@ -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, diff --git a/includes/xna/graphics/rasterizerstate.hpp b/includes/xna/graphics/rasterizerstate.hpp index a04f55e..cc5eebd 100644 --- a/includes/xna/graphics/rasterizerstate.hpp +++ b/includes/xna/graphics/rasterizerstate.hpp @@ -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 { public: RasterizerState(); - RasterizerState(sptr const& device); + RasterizerState(std::shared_ptr 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 CullNone(); + static std::unique_ptr CullNone(); //A built-in state object with settings for culling primitives with clockwise winding order. - static uptr CullClockwise(); + static std::unique_ptr CullClockwise(); //A built-in state object with settings for culling primitives with counter-clockwise winding order. - static uptr CullCounterClockwise(); + static std::unique_ptr CullCounterClockwise(); bool Initialize(); - bool Apply(); - - public: - struct PlatformImplementation; - uptr impl = nullptr; - }; - - using PRasterizerState = sptr; + bool Apply(); + }; } #endif \ No newline at end of file diff --git a/sources/framework-dx/rasterizerstate.cpp b/sources/framework-dx/rasterizerstate.cpp index 77f7d64..26a05b8 100644 --- a/sources/framework-dx/rasterizerstate.cpp +++ b/sources/framework-dx/rasterizerstate.cpp @@ -6,28 +6,28 @@ namespace xna { RasterizerState::RasterizerState() : RasterizerState(nullptr){} RasterizerState::RasterizerState(sptr const& device) : GraphicsResource(device) { - impl = unew(); - 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(); + 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(impl->dxDescription.DepthBias); + return static_cast(Implementation->Description.DepthBias); } void RasterizerState::DepthBias(float value) { - impl->dxDescription.DepthBias = static_cast(value); + Implementation->Description.DepthBias = static_cast(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::CullNone() { auto raster = unew(); - 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::CullClockwise() { auto raster = unew(); - 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::CullCounterClockwise() { auto raster = unew(); - 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(static_cast(impl->dxDescription.CullMode) - 1); + return static_cast(static_cast(Implementation->Description.CullMode) - 1); } void RasterizerState::CullMode(xna::CullMode value) { - if (!impl) + if (!Implementation) return; - impl->dxDescription.CullMode = static_cast(static_cast(value) + 1); + Implementation->Description.CullMode = static_cast(static_cast(value) + 1); } xna::FillMode RasterizerState::FillMode() const { - if (!impl) + if (!Implementation) return xna::FillMode::WireFrame; - return static_cast(static_cast(impl->dxDescription.FillMode) - 2); + return static_cast(static_cast(Implementation->Description.FillMode) - 2); } void RasterizerState::FillMode(xna::FillMode value) { - if (!impl) + if (!Implementation) return; - impl->dxDescription.FillMode = static_cast(static_cast(value) + 2); + Implementation->Description.FillMode = static_cast(static_cast(value) + 2); } } diff --git a/sources/framework-dx/sprite.cpp b/sources/framework-dx/sprite.cpp index 9744c56..9ec1aa3 100644 --- a/sources/framework-dx/sprite.cpp +++ b/sources/framework-dx/sprite.cpp @@ -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 );