From a29d9d2790a8f5a775e3de271e1319455613b2fd Mon Sep 17 00:00:00 2001 From: Danilo Date: Wed, 22 May 2024 11:55:13 -0300 Subject: [PATCH] Corrige SamplerState --- framework/platform/rasterizerstate-dx.cpp | 13 +- framework/platform/samplerstate-dx.cpp | 288 ++++++++++++++++------ framework/platform/sprite-dx.cpp | 4 +- inc/graphics/samplerstate.hpp | 58 +++-- inc/platform-dx/dxhelpers.hpp | 8 + inc/platform-dx/implementations.hpp | 13 + inc/platform-dx/samplerstate-dx.hpp | 181 -------------- inc/platform-dx/xna-dx.hpp | 1 - inc/types.hpp | 10 + 9 files changed, 298 insertions(+), 278 deletions(-) delete mode 100644 inc/platform-dx/samplerstate-dx.hpp diff --git a/framework/platform/rasterizerstate-dx.cpp b/framework/platform/rasterizerstate-dx.cpp index 8267dde..43ef107 100644 --- a/framework/platform/rasterizerstate-dx.cpp +++ b/framework/platform/rasterizerstate-dx.cpp @@ -4,9 +4,13 @@ namespace xna { - RasterizerState::RasterizerState() : GraphicsResource(nullptr){} + RasterizerState::RasterizerState() : GraphicsResource(nullptr){ + impl = unew(); + } - RasterizerState::RasterizerState(sptr const& device) : GraphicsResource(device) {} + RasterizerState::RasterizerState(sptr const& device) : GraphicsResource(device) { + impl = unew(); + } RasterizerState::~RasterizerState() { impl = nullptr; @@ -19,6 +23,11 @@ namespace xna { return false; } + if (impl->dxRasterizerState) { + impl->dxRasterizerState->Release(); + impl->dxRasterizerState = nullptr; + } + const auto hr = m_device->_device->CreateRasterizerState( &impl->dxDescription, &impl->dxRasterizerState); diff --git a/framework/platform/samplerstate-dx.cpp b/framework/platform/samplerstate-dx.cpp index 1a73cfe..8562704 100644 --- a/framework/platform/samplerstate-dx.cpp +++ b/framework/platform/samplerstate-dx.cpp @@ -1,90 +1,37 @@ -#include "platform-dx/samplerstate-dx.hpp" +#include "graphics/samplerstate.hpp" #include "platform-dx/device-dx.hpp" +#include "graphics/samplerstate.hpp" +#include "platform-dx/implementations.hpp" +#include "platform-dx/dxhelpers.hpp" namespace xna { - bool SamplerState::Apply(xna_error_ptr_arg) - { - if (!m_device || !m_device->_context) { - xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); - return false; - } - - if (!_samplerState) { - xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); - return false; - } - - m_device->_context->PSSetSamplers(0, 1, &_samplerState); - - return true; - } - uptr SamplerState::PoinWrap() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; - return state; + SamplerState::SamplerState() : GraphicsResource(nullptr) { + impl = unew(); } - uptr SamplerState::PointClamp() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - return state; + SamplerState::SamplerState(sptr const& device) : GraphicsResource(device) { + impl = unew(); } - uptr SamplerState::LinearWrap() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; - return state; - } - - uptr SamplerState::LinearClamp() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - return state; - } - - uptr SamplerState::AnisotropicWrap() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_ANISOTROPIC; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; - return state; - } - - uptr SamplerState::AnisotropicClamp() { - auto state = std::unique_ptr(new SamplerState()); - state->_description.Filter = D3D11_FILTER_ANISOTROPIC; - state->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - state->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - return state; + SamplerState::~SamplerState() { + impl = nullptr; } bool SamplerState::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; } - if (_samplerState) { - _samplerState->Release(); - _samplerState = nullptr; + if (impl->_samplerState) { + impl->_samplerState->Release(); + impl->_samplerState = nullptr; } - const auto hr = m_device->_device->CreateSamplerState(&_description, &_samplerState); + const auto hr = m_device->_device->CreateSamplerState( + &impl->_description, + &impl->_samplerState); if (FAILED(hr)) { xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); @@ -93,4 +40,205 @@ namespace xna { return true; } + + bool SamplerState::Apply(xna_error_ptr_arg) + { + if (!impl || !m_device || !m_device->_context) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); + return false; + } + + if (!impl->_samplerState) { + xna_error_apply(err, XnaErrorCode::UNINTIALIZED_RESOURCE); + return false; + } + + m_device->_context->PSSetSamplers(0, 1, &impl->_samplerState); + + return true; + } + uptr SamplerState::PoinWrap() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + return state; + } + + uptr SamplerState::PointClamp() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + return state; + } + + uptr SamplerState::LinearWrap() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + return state; + } + + uptr SamplerState::LinearClamp() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + return state; + } + + uptr SamplerState::AnisotropicWrap() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_ANISOTROPIC; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + return state; + } + + uptr SamplerState::AnisotropicClamp() { + auto state = unew(); + state->impl->_description.Filter = D3D11_FILTER_ANISOTROPIC; + state->impl->_description.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + state->impl->_description.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + return state; + } + + void SamplerState::Filter(TextureFilter value) { + switch (value) + { + case xna::TextureFilter::Linear: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR; + break; + case xna::TextureFilter::Point: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_POINT; + break; + case xna::TextureFilter::Anisotropic: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC; + break; + case xna::TextureFilter::LinearMipPoint: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; + break; + case xna::TextureFilter::PointMipLinear: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; + break; + case xna::TextureFilter::MinLinearMagPointMipLinear: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; + break; + case xna::TextureFilter::MinLinearMagPointMipPoint: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; + break; + case xna::TextureFilter::MinPointMagLinearMipLinear: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; + break; + case xna::TextureFilter::MinPointMagLinearMipPoint: + impl->_description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; + break; + default: + break; + } + } + + void SamplerState::AddressU(TextureAddressMode value) { + DxHelpers::ConvertAddressMode(value, impl->_description.AddressU); + } + + void SamplerState::AddressV(TextureAddressMode value) { + DxHelpers::ConvertAddressMode(value, impl->_description.AddressV); + } + + void SamplerState::AddressW(TextureAddressMode value) { + DxHelpers::ConvertAddressMode(value, impl->_description.AddressW); + } + + void SamplerState::Comparison(ComparisonFunction value) { + impl->_description.ComparisonFunc = static_cast(static_cast(value) + 1); + } + + void SamplerState::MipLODBias(float value) { + impl->_description.MipLODBias = value; + } + + void SamplerState::MinLOD(float value) { + impl->_description.MinLOD = value; + } + + void SamplerState::MaxLOD(float value) { + impl->_description.MaxLOD = value; + } + + void SamplerState::MaxAnisotropy(Uint value) { + impl->_description.MaxAnisotropy = static_cast(value); + } + + TextureFilter SamplerState::Filter() const { + switch (impl->_description.Filter) + { + case D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR: + return xna::TextureFilter::Linear; + case D3D11_FILTER_MIN_MAG_MIP_POINT: + return xna::TextureFilter::Point; + case D3D11_FILTER_ANISOTROPIC: + return xna::TextureFilter::Anisotropic; + case D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT: + return xna::TextureFilter::LinearMipPoint; + case D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR: + return xna::TextureFilter::PointMipLinear; + case D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR: + return xna::TextureFilter::MinLinearMagPointMipLinear; + case D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT: + return xna::TextureFilter::MinLinearMagPointMipPoint; + case D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR: + return xna::TextureFilter::MinPointMagLinearMipLinear; + case D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT: + return xna::TextureFilter::MinPointMagLinearMipPoint; + default: + return xna::TextureFilter::Linear; + } + } + + TextureAddressMode SamplerState::AddressU() const { + TextureAddressMode mode; + DxHelpers::ConvertAddressMode(impl->_description.AddressU, mode); + return mode; + } + + TextureAddressMode SamplerState::AddressV() const { + TextureAddressMode mode; + DxHelpers::ConvertAddressMode(impl->_description.AddressV, mode); + return mode; + } + + TextureAddressMode SamplerState::AddressW() const { + TextureAddressMode mode; + DxHelpers::ConvertAddressMode(impl->_description.AddressW, mode); + return mode; + } + + ComparisonFunction SamplerState::Comparison() const { + return static_cast(impl->_description.ComparisonFunc - 1); + } + + float SamplerState::MipLODBias() const { + return impl->_description.MipLODBias; + } + + float SamplerState::MinLOD() const { + return impl->_description.MinLOD; + } + + float SamplerState::MaxLOD() const { + return impl->_description.MaxLOD; + } + + Uint SamplerState::MaxAnisotropy() const { + return impl->_description.MaxAnisotropy; + } } \ No newline at end of file diff --git a/framework/platform/sprite-dx.cpp b/framework/platform/sprite-dx.cpp index ea158d1..d61badd 100644 --- a/framework/platform/sprite-dx.cpp +++ b/framework/platform/sprite-dx.cpp @@ -1,6 +1,6 @@ #include "platform-dx/device-dx.hpp" #include "graphics/rasterizerstate.hpp" -#include "platform-dx/samplerstate-dx.hpp" +#include "graphics/samplerstate.hpp" #include "platform-dx/texture-dx.hpp" #include "common/color.hpp" #include "common/numerics.hpp" @@ -79,7 +79,7 @@ namespace xna { implementation->_dxspriteBatch->Begin( sort, blendState ? blendState->impl->dxBlendState : nullptr, - samplerState ? samplerState->_samplerState : nullptr, + samplerState ? samplerState->impl->_samplerState : nullptr, depthStencil ? depthStencil->impl->dxDepthStencil : nullptr, rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr, nullptr, diff --git a/inc/graphics/samplerstate.hpp b/inc/graphics/samplerstate.hpp index 444d932..bc5ce77 100644 --- a/inc/graphics/samplerstate.hpp +++ b/inc/graphics/samplerstate.hpp @@ -2,31 +2,45 @@ #define XNA_GRAPHICS_SAMPLERSTATE_HPP #include "../default.hpp" +#include "gresource.hpp" namespace xna { - class ISamplerState { + class SamplerState : GraphicsResource { public: - virtual ~ISamplerState(){} - virtual bool Initialize(xna_error_nullarg) = 0; - virtual bool Apply(xna_error_nullarg) = 0; - virtual void Filter(TextureFilter value) = 0; - virtual void AddressU(TextureAddressMode value) = 0; - virtual void AddressV(TextureAddressMode value) = 0; - virtual void AddressW(TextureAddressMode value) = 0; - virtual void Comparison(ComparisonFunction value) = 0; - virtual void MipLODBias(float value) = 0; - virtual void MinLOD(float value) = 0; - virtual void MaxLOD(float value) = 0; - virtual void MaxAnisotropy(Uint value) = 0; - virtual TextureFilter Filter() const = 0; - virtual TextureAddressMode AddressU() const = 0; - virtual TextureAddressMode AddressV() const = 0; - virtual TextureAddressMode AddressW() const = 0; - virtual ComparisonFunction Comparison() const = 0; - virtual float MipLODBias() const = 0; - virtual float MinLOD() const = 0; - virtual float MaxLOD() const = 0; - virtual Uint MaxAnisotropy() const = 0; + SamplerState(); + SamplerState(sptr const& device); + ~SamplerState(); + bool Initialize(xna_error_nullarg); + bool Apply(xna_error_nullarg); + void Filter(TextureFilter value); + void AddressU(TextureAddressMode value); + void AddressV(TextureAddressMode value); + void AddressW(TextureAddressMode value); + void Comparison(ComparisonFunction value); + void MipLODBias(float value); + void MinLOD(float value); + void MaxLOD(float value); + void MaxAnisotropy(Uint value); + TextureFilter Filter() const; + TextureAddressMode AddressU() const; + TextureAddressMode AddressV() const; + TextureAddressMode AddressW() const; + ComparisonFunction Comparison() const; + float MipLODBias() const; + float MinLOD() const; + float MaxLOD() const; + Uint MaxAnisotropy() const; + + static uptr PoinWrap(); + static uptr PointClamp(); + static uptr LinearWrap(); + static uptr LinearClamp(); + static uptr AnisotropicWrap(); + static uptr AnisotropicClamp(); + + public: + struct PlatformImplementation; + uptr impl = nullptr; }; } diff --git a/inc/platform-dx/dxhelpers.hpp b/inc/platform-dx/dxhelpers.hpp index 0bc73d4..c4bd6c2 100644 --- a/inc/platform-dx/dxhelpers.hpp +++ b/inc/platform-dx/dxhelpers.hpp @@ -161,5 +161,13 @@ namespace xna { return D3D11_COLOR_WRITE_ENABLE_ALL; } } + + static constexpr void ConvertAddressMode(TextureAddressMode value, D3D11_TEXTURE_ADDRESS_MODE& target) { + target = static_cast(static_cast(value) + 1); + } + + static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) { + target = static_cast(value - 1); + } }; } \ No newline at end of file diff --git a/inc/platform-dx/implementations.hpp b/inc/platform-dx/implementations.hpp index 5fed4f6..0d4d79f 100644 --- a/inc/platform-dx/implementations.hpp +++ b/inc/platform-dx/implementations.hpp @@ -6,6 +6,7 @@ #include "graphics/device.hpp" #include "graphics/displaymode.hpp" #include "graphics/sprite.hpp" +#include "graphics/samplerstate.hpp" #include "input/gamepad.hpp" #include "input/keyboard.hpp" #include "input/mouse.hpp" @@ -214,4 +215,16 @@ namespace xna { ID3D11RasterizerState* dxRasterizerState = nullptr; D3D11_RASTERIZER_DESC dxDescription{}; }; + + struct SamplerState::PlatformImplementation { + ~PlatformImplementation() { + if (_samplerState) { + _samplerState->Release(); + _samplerState = nullptr; + } + } + + ID3D11SamplerState* _samplerState = nullptr; + D3D11_SAMPLER_DESC _description{}; + }; } \ No newline at end of file diff --git a/inc/platform-dx/samplerstate-dx.hpp b/inc/platform-dx/samplerstate-dx.hpp deleted file mode 100644 index 2b2dfe7..0000000 --- a/inc/platform-dx/samplerstate-dx.hpp +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef XNA_PLATFORM_SAMPLERSTATE_DX_HPP -#define XNA_PLATFORM_SAMPLERSTATE_DX_HPP - -#include "../graphics/samplerstate.hpp" -#include "../graphics/gresource.hpp" -#include "dxheaders.hpp" - -namespace xna { - class SamplerState : public ISamplerState, public GraphicsResource { - public: - SamplerState(sptr const& device) : GraphicsResource(device) { - _description.MaxAnisotropy = 4; - } - - virtual ~SamplerState() override { - if (_samplerState) { - _samplerState->Release(); - _samplerState = nullptr; - } - } - - virtual bool Initialize(xna_error_nullarg) override; - virtual bool Apply(xna_error_nullarg) override; - - virtual constexpr void Filter(TextureFilter value) override { - switch (value) - { - case xna::TextureFilter::Linear: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR; - break; - case xna::TextureFilter::Point: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_POINT; - break; - case xna::TextureFilter::Anisotropic: - _description.Filter = D3D11_FILTER::D3D11_FILTER_ANISOTROPIC; - break; - case xna::TextureFilter::LinearMipPoint: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - break; - case xna::TextureFilter::PointMipLinear: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; - break; - case xna::TextureFilter::MinLinearMagPointMipLinear: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; - break; - case xna::TextureFilter::MinLinearMagPointMipPoint: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; - break; - case xna::TextureFilter::MinPointMagLinearMipLinear: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; - break; - case xna::TextureFilter::MinPointMagLinearMipPoint: - _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; - break; - default: - break; - } - } - - virtual constexpr void AddressU(TextureAddressMode value) override { - ConvertAddressMode(value, _description.AddressU); - } - - virtual constexpr void AddressV(TextureAddressMode value) override { - ConvertAddressMode(value, _description.AddressV); - } - - virtual constexpr void AddressW(TextureAddressMode value) override { - ConvertAddressMode(value, _description.AddressW); - } - - virtual constexpr void Comparison(ComparisonFunction value) override { - _description.ComparisonFunc = static_cast(static_cast(value) + 1); - } - - virtual constexpr void MipLODBias(float value) override { - _description.MipLODBias = value; - } - - virtual constexpr void MinLOD(float value) override { - _description.MinLOD = value; - } - - virtual constexpr void MaxLOD(float value) override { - _description.MaxLOD = value; - } - - virtual void MaxAnisotropy(Uint value) override { - _description.MaxAnisotropy = static_cast(value); - } - - virtual constexpr TextureFilter Filter() const override { - switch (_description.Filter) - { - case D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR: - return xna::TextureFilter::Linear; - case D3D11_FILTER_MIN_MAG_MIP_POINT: - return xna::TextureFilter::Point; - case D3D11_FILTER_ANISOTROPIC: - return xna::TextureFilter::Anisotropic; - case D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT: - return xna::TextureFilter::LinearMipPoint; - case D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR: - return xna::TextureFilter::PointMipLinear; - case D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR: - return xna::TextureFilter::MinLinearMagPointMipLinear; - case D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT: - return xna::TextureFilter::MinLinearMagPointMipPoint; - case D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR: - return xna::TextureFilter::MinPointMagLinearMipLinear; - case D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT: - return xna::TextureFilter::MinPointMagLinearMipPoint; - default: - return xna::TextureFilter::Linear; - } - } - - virtual constexpr TextureAddressMode AddressU() const override { - TextureAddressMode mode; - ConvertAddressMode(_description.AddressU, mode); - return mode; - } - - virtual constexpr TextureAddressMode AddressV() const override { - TextureAddressMode mode; - ConvertAddressMode(_description.AddressV, mode); - return mode; - } - - virtual constexpr TextureAddressMode AddressW() const override { - TextureAddressMode mode; - ConvertAddressMode(_description.AddressW, mode); - return mode; - } - - virtual ComparisonFunction Comparison() const override { - return static_cast(_description.ComparisonFunc - 1); - } - - virtual constexpr float MipLODBias() const override { - return _description.MipLODBias; - } - - virtual constexpr float MinLOD() const override { - return _description.MinLOD; - } - - virtual constexpr float MaxLOD() const override { - return _description.MaxLOD; - } - - virtual constexpr Uint MaxAnisotropy() const override { - return _description.MaxAnisotropy; - } - - static uptr PoinWrap(); - static uptr PointClamp(); - static uptr LinearWrap(); - static uptr LinearClamp(); - static uptr AnisotropicWrap(); - static uptr AnisotropicClamp(); - - public: - ID3D11SamplerState* _samplerState = nullptr; - D3D11_SAMPLER_DESC _description{}; - - public: - static constexpr void ConvertAddressMode(TextureAddressMode value, D3D11_TEXTURE_ADDRESS_MODE& target) { - target = static_cast(static_cast(value) + 1); - } - - static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) { - target = static_cast(value - 1); - } - - private: - SamplerState() : GraphicsResource(nullptr) {} - }; -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/xna-dx.hpp b/inc/platform-dx/xna-dx.hpp index aee68dd..2cf941f 100644 --- a/inc/platform-dx/xna-dx.hpp +++ b/inc/platform-dx/xna-dx.hpp @@ -8,7 +8,6 @@ #include "gdevicemanager-dx.hpp" #include "init-dx.hpp" #include "rendertarget-dx.hpp" -#include "samplerstate-dx.hpp" #include "shader-dx.hpp" #include "soundeffect-dx.hpp" #include "swapchain-dx.hpp" diff --git a/inc/types.hpp b/inc/types.hpp index 8593dbd..70e067b 100644 --- a/inc/types.hpp +++ b/inc/types.hpp @@ -61,6 +61,16 @@ namespace xna { return std::make_unique<_Ty>(std::forward<_Types>(_Args)...); } + template + inline std::shared_ptr<_Ty> snew(_Types&&... _Args) { + return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); + } + + template + inline std::unique_ptr<_Ty> unew(_Types&&... _Args) { + return std::make_unique<_Ty>(std::forward<_Types>(_Args)...); + } + //See ref: https://en.cppreference.com/w/cpp/error/assert #define assertm(exp, msg) assert(((void)msg, exp)) }