diff --git a/framework/forward.hpp b/framework/forward.hpp index 17686b9..93bdb91 100644 --- a/framework/forward.hpp +++ b/framework/forward.hpp @@ -6,135 +6,67 @@ namespace xna { //Audio class SoundEffect; - using PSoundEffect = std::shared_ptr; struct SoundEffectInstance; - using PSoundEffectInstance = std::shared_ptr; class AudioEngine; - using PAudioEngine = std::shared_ptr; struct WaveFormat; - using PWaveFormat = std::shared_ptr; //CShap struct TimeSpan; - using PTimeSpan = std::shared_ptr; class Stream; - using PStream = std::shared_ptr; class FileStream; - using PFileStream = std::shared_ptr; class MemoryStream; - using PMemoryStream = std::shared_ptr; //Framework class BoundingBox; - using PBoundingBox = std::shared_ptr; class BoundingFrustum; - using PBoundingFrustum = std::shared_ptr; class BoundinSphere; - using PBoundinSphere = std::shared_ptr; struct Color; - using PColor = std::shared_ptr; class Curve; - using PCurve = std::shared_ptr; class CurveContinuity; - using PCurveContinuity = std::shared_ptr; class CurveKey; - using PCurveKey = std::shared_ptr; class CurveKeyCollection; - using PCurveKeyCollection = std::shared_ptr; struct Matrix; - using PMatrix = std::shared_ptr; class Plane; - using PPlane = std::shared_ptr; struct Point; - using PPoint = std::shared_ptr; struct Quaternion; - using PQuaternion = std::shared_ptr; class Ray; - using PRay = std::shared_ptr; struct Rectangle; - using PRectangle = std::shared_ptr; struct Vector2; - using PVector2 = std::shared_ptr; struct Vector3; - using PVector3 = std::shared_ptr; struct Vector4; - using PVector4 = std::shared_ptr; - //Game - class DrawableGameComponent; - using PDrawableGameComponent = std::shared_ptr; + //Game class Game; - using PGame = std::shared_ptr; - class GameComponent; - using PGameComponent = std::shared_ptr; - class GameComponentCollection; - using PGameComponentCollection = std::shared_ptr; class GameClock; - using PGameClock = std::shared_ptr; class GameTime; - using PGameTime = std::shared_ptr; class GameWindow; - using PGameWindow = std::shared_ptr; class GraphicsDeviceInformation; - using PGraphicsDeviceInformation = std::shared_ptr; class GraphicsDeviceManager; - using PGraphicsDeviceManager = std::shared_ptr; - class IDrawable; - using PIDrawable = std::shared_ptr; - class IGameComponent; - using PIGameComponent = std::shared_ptr; - class IUpdatable; - using PIUpdatable = std::shared_ptr; //Graphics class BlendState; - using PBlendState = std::shared_ptr; class ConstantBuffer; - using PConstantBuffer = std::shared_ptr; class DataBuffer; - using PDataBuffer = std::shared_ptr; class DepthStencilState; - using PDepthStencilState = std::shared_ptr; class DisplayMode; - using PDisplayMode = std::shared_ptr; - using UDisplayMode = std::unique_ptr; class DisplayModeCollection; - using PDisplayModeCollection = std::shared_ptr; - using UDisplayModeCollection = std::unique_ptr; class GraphicsAdapter; - using PGraphicsAdapter = std::shared_ptr; - using UGraphicsAdapter = std::unique_ptr; class GraphicsDevice; - using PGraphicsDevice = std::shared_ptr; class GraphicsDeviceInformation; - using PGraphicsDeviceInformation = std::shared_ptr; class PresentationParameters; - using PPresentationParameters = std::shared_ptr< PresentationParameters>; class RenderTarget2D; - using PRenderTarget2D = std::shared_ptr; class SwapChain; - using PSwapChain = std::shared_ptr; class Texture; - using PTexture = std::shared_ptr; class Texture2D; - using PTexture2D = std::shared_ptr; class RasterizerState; - using PRasterizerState = std::shared_ptr; class SamplerState; - using PSamplerState = std::shared_ptr; class Shader; - using PShader = std::shared_ptr; class SpriteBatch; - using PSpriteBatch = std::shared_ptr; class SpriteFont; - using PSpriteFont = std::shared_ptr; struct VertexPositionColor; - using PVertexPositionColor = std::shared_ptr; class VertexShader; - using pVertexShader = std::shared_ptr; struct Viewport; - using PViewport = std::shared_ptr; //Input struct GamePadTriggers; diff --git a/framework/game/game.hpp b/framework/game/game.hpp index 0aa121a..6f0a0bc 100644 --- a/framework/game/game.hpp +++ b/framework/game/game.hpp @@ -14,8 +14,8 @@ namespace xna { virtual void Exit() = 0; virtual int Run() = 0; - virtual PGameWindow Window() = 0; - virtual PGraphicsDevice GetGraphicsDevice() = 0; + virtual sptr Window() = 0; + virtual sptr GetGraphicsDevice() = 0; protected: virtual void Draw(GameTime const& gameTime) = 0; diff --git a/framework/game/gdeviceinfo.hpp b/framework/game/gdeviceinfo.hpp index a01baaf..bb8661f 100644 --- a/framework/game/gdeviceinfo.hpp +++ b/framework/game/gdeviceinfo.hpp @@ -8,14 +8,14 @@ namespace xna { class IGraphicsDeviceInformation { public: virtual ~IGraphicsDeviceInformation(){} - virtual PGraphicsAdapter Adapter() const = 0; - virtual void Adapter(PGraphicsAdapter const& value) = 0; + virtual sptr Adapter() const = 0; + virtual void Adapter(sptr const& value) = 0; virtual xna::PresentationParameters PresentationParameters() const = 0; virtual void PresentationParameters(xna::PresentationParameters const& value) = 0; virtual xna::GraphicsProfile GraphicsProfile() const = 0; virtual void GraphicsProfile(xna::GraphicsProfile value) = 0; - virtual PGameWindow Window() const = 0; - virtual void Window(PGameWindow const& window) = 0; + virtual sptr Window() const = 0; + virtual void Window(sptr const& window) = 0; }; } diff --git a/framework/graphics/adapter.hpp b/framework/graphics/adapter.hpp index 929fad3..d74c575 100644 --- a/framework/graphics/adapter.hpp +++ b/framework/graphics/adapter.hpp @@ -16,14 +16,14 @@ namespace xna { virtual Uint Revision() const = 0; virtual Uint SubSystemId() const = 0; virtual Uint VendorId() const = 0; - virtual UDisplayModeCollection SupportedDisplayModes() const = 0; - virtual UDisplayModeCollection SupportedDisplayModes(SurfaceFormat surfaceFormat) const = 0; - virtual PDisplayMode CurrentDisplayMode() = 0; + virtual uptr SupportedDisplayModes() const = 0; + virtual uptr SupportedDisplayModes(SurfaceFormat surfaceFormat) const = 0; + virtual sptr CurrentDisplayMode() = 0; virtual void CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height) = 0; - static UGraphicsAdapter DefaultAdapter(); - static void Adapters(std::vector& adapters); - static void Adapters(std::vector& adapters); + static uptr DefaultAdapter(); + static void Adapters(std::vector>& adapters); + static void Adapters(std::vector>& adapters); }; } diff --git a/framework/graphics/device.hpp b/framework/graphics/device.hpp index 0ab1229..8b4750b 100644 --- a/framework/graphics/device.hpp +++ b/framework/graphics/device.hpp @@ -19,8 +19,8 @@ namespace xna { virtual void Clear(Color const& color) = 0; virtual bool Initialize(GameWindow& gameWindow) = 0; virtual bool Present() = 0; - virtual PGraphicsAdapter Adapter() const = 0; - virtual void Adapter(PGraphicsAdapter const& adapter) = 0; + virtual sptr Adapter() const = 0; + virtual void Adapter(sptr const& adapter) = 0; virtual xna::Viewport Viewport() const = 0; virtual void Viewport(xna::Viewport const& viewport) = 0; virtual void UseVSync(bool use) = 0; diff --git a/framework/graphics/samplerstate.hpp b/framework/graphics/samplerstate.hpp index 38875da..444d932 100644 --- a/framework/graphics/samplerstate.hpp +++ b/framework/graphics/samplerstate.hpp @@ -7,7 +7,8 @@ namespace xna { class ISamplerState { public: virtual ~ISamplerState(){} - virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) = 0; + 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; @@ -25,14 +26,7 @@ namespace xna { virtual float MipLODBias() const = 0; virtual float MinLOD() const = 0; virtual float MaxLOD() const = 0; - virtual Uint MaxAnisotropy() const = 0; - - static PSamplerState PoinWrap(); - static PSamplerState PointClamp(); - static PSamplerState LinearWrap(); - static PSamplerState LinearClamp(); - static PSamplerState AnisotropicWrap(); - static PSamplerState AnisotropicClamp(); + virtual Uint MaxAnisotropy() const = 0; }; } diff --git a/framework/platform/adapter-dx.cpp b/framework/platform/adapter-dx.cpp index 148461e..e909b28 100644 --- a/framework/platform/adapter-dx.cpp +++ b/framework/platform/adapter-dx.cpp @@ -3,9 +3,9 @@ namespace xna { static size_t getDisplayModesCount(IDXGIAdapter* adapter); - static UDisplayModeCollection createDisplayModeCollection(std::vector const& source); + static uptr createDisplayModeCollection(std::vector const& source); - UGraphicsAdapter IGraphicsAdapter::DefaultAdapter() { + uptr IGraphicsAdapter::DefaultAdapter() { IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) @@ -28,7 +28,7 @@ namespace xna { return nullptr; } - void IGraphicsAdapter::Adapters(std::vector& adapters){ + void IGraphicsAdapter::Adapters(std::vector>& adapters){ IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) @@ -50,7 +50,7 @@ namespace xna { pFactory = nullptr; } - void IGraphicsAdapter::Adapters(std::vector& adapters) { + void IGraphicsAdapter::Adapters(std::vector>& adapters) { IDXGIFactory1* pFactory = nullptr; if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) @@ -154,7 +154,7 @@ namespace xna { return static_cast(desc.VendorId); } - UDisplayModeCollection GraphicsAdapter::SupportedDisplayModes() const { + uptr GraphicsAdapter::SupportedDisplayModes() const { if (!dxadapter) return nullptr; const auto totalDisplay = getDisplayModesCount(dxadapter); @@ -193,7 +193,7 @@ namespace xna { return createDisplayModeCollection(buffer); } - UDisplayModeCollection GraphicsAdapter::SupportedDisplayModes(SurfaceFormat surfaceFormat) const + uptr GraphicsAdapter::SupportedDisplayModes(SurfaceFormat surfaceFormat) const { if (!dxadapter) return nullptr; @@ -222,7 +222,7 @@ namespace xna { return uNew(); } - PDisplayMode GraphicsAdapter::CurrentDisplayMode() { + sptr GraphicsAdapter::CurrentDisplayMode() { if (!_currentDisplayMode) { CurrentDisplayMode(SurfaceFormat::Color, GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight); } @@ -278,11 +278,11 @@ namespace xna { return numModes; } - static UDisplayModeCollection createDisplayModeCollection(std::vector const& source) { + static uptr createDisplayModeCollection(std::vector const& source) { auto collection = uNew(); DisplayMode currentDisplayMode; - std::vector displayList; - PDisplayMode pDisplay = nullptr; + std::vector> displayList; + sptr pDisplay = nullptr; for (size_t i = 0; i < source.size(); ++i) { auto& modedesc = source[i]; diff --git a/framework/platform/adapter-dx.hpp b/framework/platform/adapter-dx.hpp index 9ed8eec..0e32cbc 100644 --- a/framework/platform/adapter-dx.hpp +++ b/framework/platform/adapter-dx.hpp @@ -5,7 +5,6 @@ #include "displaymode-dx.hpp" #include "dxheaders.hpp" - namespace xna { class GraphicsAdapter : public IGraphicsAdapter { public: @@ -27,9 +26,9 @@ namespace xna { virtual Uint Revision() const override; virtual Uint SubSystemId() const override; virtual Uint VendorId() const override; - virtual UDisplayModeCollection SupportedDisplayModes() const override; - virtual UDisplayModeCollection SupportedDisplayModes(SurfaceFormat surfaceFormat) const override; - virtual PDisplayMode CurrentDisplayMode() override; + virtual uptr SupportedDisplayModes() const override; + virtual uptr SupportedDisplayModes(SurfaceFormat surfaceFormat) const override; + virtual sptr CurrentDisplayMode() override; virtual void CurrentDisplayMode(SurfaceFormat surfaceFormat, Uint width, Uint height) override; virtual constexpr bool IsDefaultAdapter() const { return _index == 0; } bool GetOutput(UINT slot, IDXGIOutput*& output); @@ -38,7 +37,7 @@ namespace xna { IDXGIAdapter1* dxadapter{ nullptr }; private: Uint _index{ 0 }; - PDisplayMode _currentDisplayMode = nullptr; + sptr _currentDisplayMode = nullptr; public: static constexpr DXGI_FORMAT ConvertSurfaceToDXGIFORMAT(SurfaceFormat format) diff --git a/framework/platform/device-dx.hpp b/framework/platform/device-dx.hpp index 76eb63e..07e013a 100644 --- a/framework/platform/device-dx.hpp +++ b/framework/platform/device-dx.hpp @@ -41,11 +41,11 @@ namespace xna { virtual bool Initialize(GameWindow& gameWindow) override; virtual bool Present() override; - virtual PGraphicsAdapter Adapter() const override { + virtual sptr Adapter() const override { return _adapter; } - virtual void Adapter(PGraphicsAdapter const& adapter) override { + virtual void Adapter(sptr const& adapter) override { _adapter = adapter; } @@ -75,10 +75,10 @@ namespace xna { ID3D11Device* _device{ nullptr }; ID3D11DeviceContext* _context{ nullptr }; IDXGIFactory1* _factory = nullptr; - PSwapChain _swapChain{ nullptr }; - PGraphicsAdapter _adapter{ nullptr }; - PRenderTarget2D _renderTarget2D{ nullptr }; - PBlendState _blendState{ nullptr }; + sptr _swapChain{ nullptr }; + sptr _adapter{ nullptr }; + sptr _renderTarget2D{ nullptr }; + sptr _blendState{ nullptr }; xna::Viewport _viewport{}; xna::PresentationParameters _presentationParameters; diff --git a/framework/platform/displaymode-dx.cpp b/framework/platform/displaymode-dx.cpp index 8187bfc..bd39f86 100644 --- a/framework/platform/displaymode-dx.cpp +++ b/framework/platform/displaymode-dx.cpp @@ -14,12 +14,12 @@ namespace xna { return counter; } - std::vector DisplayModeCollection::Query(SurfaceFormat format) const + std::vector> DisplayModeCollection::Query(SurfaceFormat format) const { const auto count = SurfaceCount(format); size_t index = 0; - std::vector modes(count); + std::vector> modes(count); for (size_t i = 0; i < _displayModes.size(); ++i) { if (_displayModes[i]->Format() == format) { @@ -34,9 +34,9 @@ namespace xna { return modes; } - PDisplayMode DisplayModeCollection::Query(SurfaceFormat format, Uint width, Uint height) const + sptr DisplayModeCollection::Query(SurfaceFormat format, Uint width, Uint height) const { - PDisplayMode matched = nullptr; + sptr matched = nullptr; for (size_t i = 0; i < _displayModes.size(); ++i) { const auto& mode = _displayModes[i]; diff --git a/framework/platform/displaymode-dx.hpp b/framework/platform/displaymode-dx.hpp index 300263a..72890f7 100644 --- a/framework/platform/displaymode-dx.hpp +++ b/framework/platform/displaymode-dx.hpp @@ -85,16 +85,16 @@ namespace xna { DisplayModeCollection(size_t count) : _displayModes(count) {} - DisplayModeCollection(std::vector const& displayModes) : + DisplayModeCollection(std::vector> const& displayModes) : _displayModes(displayModes) {} virtual size_t SurfaceCount(SurfaceFormat format) const override; - std::vector Query(SurfaceFormat format) const; - PDisplayMode Query(SurfaceFormat format, Uint width, Uint height) const; + std::vector> Query(SurfaceFormat format) const; + sptr Query(SurfaceFormat format, Uint width, Uint height) const; public: - std::vector _displayModes; + std::vector> _displayModes; }; } diff --git a/framework/platform/game-dx.hpp b/framework/platform/game-dx.hpp index a22ef34..ba18972 100644 --- a/framework/platform/game-dx.hpp +++ b/framework/platform/game-dx.hpp @@ -18,11 +18,11 @@ namespace xna { virtual int Run() override; - virtual PGameWindow Window() override { + virtual sptr Window() override { return _gameWindow; } - virtual PGraphicsDevice GetGraphicsDevice() override { + virtual sptr GetGraphicsDevice() override { return _graphicsDevice; } @@ -36,11 +36,11 @@ namespace xna { virtual void Update(GameTime const& gameTime) override; public: - PGraphicsDevice _graphicsDevice{ nullptr }; + sptr _graphicsDevice{ nullptr }; protected: - PGameWindow _gameWindow{ nullptr }; - PAudioEngine _audioEngine = nullptr; + sptr _gameWindow{ nullptr }; + sptr _audioEngine = nullptr; GameTime _currentGameTime{}; DX::StepTimer _stepTimer; diff --git a/framework/platform/gdeviceinfo-dx.hpp b/framework/platform/gdeviceinfo-dx.hpp index d174fbf..d302031 100644 --- a/framework/platform/gdeviceinfo-dx.hpp +++ b/framework/platform/gdeviceinfo-dx.hpp @@ -11,11 +11,11 @@ namespace xna { public: virtual ~GraphicsDeviceInformation() override {} - inline virtual PGraphicsAdapter Adapter() const override { + inline virtual sptr Adapter() const override { return _adapter; }; - inline virtual void Adapter(PGraphicsAdapter const& value) override { + inline virtual void Adapter(sptr const& value) override { _adapter = value; } @@ -35,19 +35,19 @@ namespace xna { _profile = value; }; - inline virtual PGameWindow Window() const override { + inline virtual sptr Window() const override { return _window; } - inline virtual void Window(PGameWindow const& window) override { + inline virtual void Window(sptr const& window) override { _window = window; } public: - PGraphicsAdapter _adapter{ nullptr }; + sptr _adapter{ nullptr }; xna::GraphicsProfile _profile{xna::GraphicsProfile::Reach}; xna::PresentationParameters _parameters{}; - PGameWindow _window{ nullptr }; + sptr _window{ nullptr }; }; } diff --git a/framework/platform/gdevicemanager-dx.hpp b/framework/platform/gdevicemanager-dx.hpp index a961132..d6d7e07 100644 --- a/framework/platform/gdevicemanager-dx.hpp +++ b/framework/platform/gdevicemanager-dx.hpp @@ -39,7 +39,7 @@ namespace xna { Int _backBufferWidth{ DefaultBackBufferWidth }; Int _backBufferHeight{ DefaultBackBufferHeight }; bool _isDeviceDirty{ false }; - PGraphicsDevice _device = nullptr; + sptr _device = nullptr; bool _isFullScreen{ false }; GraphicsDeviceInformation _information{}; diff --git a/framework/platform/samplerstate-dx.cpp b/framework/platform/samplerstate-dx.cpp index b223000..c5c91d7 100644 --- a/framework/platform/samplerstate-dx.cpp +++ b/framework/platform/samplerstate-dx.cpp @@ -2,64 +2,80 @@ #include "device-dx.hpp" namespace xna { - PSamplerState ISamplerState::PoinWrap() { - auto state = New(); - 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; - } - - PSamplerState ISamplerState::PointClamp() { - auto state = New(); - 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; - } - - PSamplerState ISamplerState::LinearWrap() { - auto state = New(); - 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; - } - - PSamplerState ISamplerState::LinearClamp() { - auto state = New(); - 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; - } - - PSamplerState ISamplerState::AnisotropicWrap() { - auto state = New(); - 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; - } - - PSamplerState ISamplerState::AnisotropicClamp() { - auto state = New(); - 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; - } - - bool SamplerState::Initialize(GraphicsDevice& device, xna_error_ptr_arg) + bool SamplerState::Apply(xna_error_ptr_arg) { - if (!device._device) { - xna_error_apply(err, XnaErrorCode::ARGUMENT_IS_NULL); + 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; + } + + 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; + } + + 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; + } + + bool SamplerState::Initialize(xna_error_ptr_arg) + { + if (!m_device || !m_device->_device) { + xna_error_apply(err, XnaErrorCode::INVALID_OPERATION); return false; } @@ -68,7 +84,7 @@ namespace xna { _samplerState = nullptr; } - const auto hr = device._device->CreateSamplerState(&_description, &_samplerState); + const auto hr = m_device->_device->CreateSamplerState(&_description, &_samplerState); if (FAILED(hr)) { xna_error_apply(err, XnaErrorCode::FAILED_OPERATION); diff --git a/framework/platform/samplerstate-dx.hpp b/framework/platform/samplerstate-dx.hpp index 8f34e22..9e93f38 100644 --- a/framework/platform/samplerstate-dx.hpp +++ b/framework/platform/samplerstate-dx.hpp @@ -2,13 +2,14 @@ #define XNA_PLATFORM_SAMPLERSTATE_DX_HPP #include "../graphics/samplerstate.hpp" +#include "../graphics/gresource.hpp" #include "dxheaders.hpp" namespace xna { - class SamplerState : public ISamplerState { + class SamplerState : public ISamplerState, public GraphicsResource { public: - SamplerState() { - _description.MaxAnisotropy = 4; + SamplerState(GraphicsDevice* device) : GraphicsResource(device) { + _description.MaxAnisotropy = 4; } virtual ~SamplerState() override { @@ -18,7 +19,8 @@ namespace xna { } } - virtual bool Initialize(GraphicsDevice& device, xna_error_nullarg) override; + virtual bool Initialize(xna_error_nullarg) override; + virtual bool Apply(xna_error_nullarg) override; virtual constexpr void Filter(TextureFilter value) override { switch (value) @@ -50,7 +52,7 @@ namespace xna { case xna::TextureFilter::MinPointMagLinearMipPoint: _description.Filter = D3D11_FILTER::D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; break; - default: + default: break; } } @@ -68,7 +70,7 @@ namespace xna { } virtual constexpr void Comparison(ComparisonFunction value) override { - _description.ComparisonFunc = static_cast(static_cast(value) + 1); + _description.ComparisonFunc = static_cast(static_cast(value) + 1); } virtual constexpr void MipLODBias(float value) override { @@ -91,26 +93,26 @@ namespace xna { switch (_description.Filter) { case D3D11_FILTER::D3D11_FILTER_MIN_MAG_MIP_LINEAR: - return xna::TextureFilter::Linear; + return xna::TextureFilter::Linear; case D3D11_FILTER_MIN_MAG_MIP_POINT: return xna::TextureFilter::Point; - case D3D11_FILTER_ANISOTROPIC: + 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: + 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: + 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: + 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; - } + return xna::TextureFilter::Linear; + } } virtual constexpr TextureAddressMode AddressU() const override { @@ -118,7 +120,7 @@ namespace xna { ConvertAddressMode(_description.AddressU, mode); return mode; } - + virtual constexpr TextureAddressMode AddressV() const override { TextureAddressMode mode; ConvertAddressMode(_description.AddressV, mode); @@ -132,17 +134,17 @@ namespace xna { } virtual ComparisonFunction Comparison() const override { - return static_cast(_description.ComparisonFunc - 1); + 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; } @@ -151,18 +153,28 @@ namespace xna { 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); + target = static_cast(static_cast(value) + 1); } static constexpr void ConvertAddressMode(D3D11_TEXTURE_ADDRESS_MODE value, TextureAddressMode& target) { - target = static_cast(value - 1); + target = static_cast(value - 1); } + + private: + SamplerState() : GraphicsResource(nullptr) {} }; } diff --git a/framework/platform/texture-dx.cpp b/framework/platform/texture-dx.cpp index 5c54814..63757e1 100644 --- a/framework/platform/texture-dx.cpp +++ b/framework/platform/texture-dx.cpp @@ -7,7 +7,7 @@ namespace xna { Texture2D::Texture2D() { } - PTexture2D Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) + sptr Texture2D::FromStream(GraphicsDevice& device, String const& fileName, xna_error_ptr_arg) { auto texture2d = New(); ID3D11Resource* resource = nullptr; diff --git a/framework/platform/texture-dx.hpp b/framework/platform/texture-dx.hpp index 7270b9a..dbd5b16 100644 --- a/framework/platform/texture-dx.hpp +++ b/framework/platform/texture-dx.hpp @@ -31,7 +31,7 @@ namespace xna { return _description.Height; } - static PTexture2D FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg); + static sptr FromStream(GraphicsDevice& device, String const& fileName, xna_error_nullarg); public: ID3D11Texture2D* _texture2D{nullptr}; diff --git a/framework/xna.cpp b/framework/xna.cpp index f46add4..c7824ca 100644 --- a/framework/xna.cpp +++ b/framework/xna.cpp @@ -48,9 +48,9 @@ namespace xna { } private: - PGraphicsDeviceManager graphics = nullptr; - PSpriteBatch spriteBatch = nullptr; - PTexture2D texture = nullptr; //200x200 + sptr graphics = nullptr; + sptr spriteBatch = nullptr; + sptr texture = nullptr; //200x200 Vector2 position{}; std::vector points; MouseState currentState{};