From af091f4fd4124a2a2019efe63d6c71ff9006fbf3 Mon Sep 17 00:00:00 2001 From: Danilo Date: Thu, 14 Nov 2024 15:25:11 -0300 Subject: [PATCH] Adiciona PlatformImplementation em GraphicsDevice --- includes/xna-dx/implementations.hpp | 59 ++++++------ includes/xna/graphics/device.hpp | 54 +++++------ sources/framework-dx/blendstate.cpp | 8 +- sources/framework-dx/depthstencilstate.cpp | 8 +- sources/framework-dx/device.cpp | 102 ++++++++++----------- sources/framework-dx/effect.cpp | 4 +- sources/framework-dx/gdevicemanager.cpp | 4 +- sources/framework-dx/rasterizerstate.cpp | 8 +- sources/framework-dx/rendertarget.cpp | 6 +- sources/framework-dx/samplerstate.cpp | 12 +-- sources/framework-dx/sprite.cpp | 8 +- sources/framework-dx/swapchain.cpp | 6 +- sources/framework-dx/texture.cpp | 36 ++++---- 13 files changed, 158 insertions(+), 157 deletions(-) diff --git a/includes/xna-dx/implementations.hpp b/includes/xna-dx/implementations.hpp index ce3706b..f482526 100644 --- a/includes/xna-dx/implementations.hpp +++ b/includes/xna-dx/implementations.hpp @@ -21,7 +21,34 @@ namespace xna { struct GraphicsAdapterImplementation { comptr Adapter; comptr Factory; - }; + }; + + struct GraphicsDeviceImplementation { + comptr Device; + comptr Context; + comptr Factory; + std::shared_ptr SwapChain; + std::shared_ptr RenderTarget2D; + intptr_t WindowHandle{ 0 }; + + D3D_FEATURE_LEVEL FeatureLevels[7] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + + D3D_FEATURE_LEVEL CurrentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 }; + + private: + friend class GraphicsDevice; + float backgroundColor[4] = { 0, 0, 0, 0 }; + UINT vSyncValue = 1; + }; struct SpriteFont::PlatformImplementation { uptr dxSpriteFont{ nullptr }; @@ -242,35 +269,7 @@ namespace xna { } uptr _dxAudioEngine = nullptr; - }; - - struct GraphicsDevice::PlatformImplementation { - comptr _device = nullptr; - comptr _context = nullptr; - comptr _factory = nullptr; - - sptr _swapChain = nullptr; - sptr _renderTarget2D = nullptr; - intptr_t windowHandle{ 0 }; - - D3D_FEATURE_LEVEL featureLevels[7] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1, - }; - - D3D_FEATURE_LEVEL currentFeatureLevel{ D3D_FEATURE_LEVEL_11_1 }; - - private: - friend class GraphicsDevice; - float _backgroundColor[4] = { 0, 0, 0, 0 }; - UINT vSyncValue = 1; - }; + }; struct Game::PlatformImplementation { private: diff --git a/includes/xna/graphics/device.hpp b/includes/xna/graphics/device.hpp index 54ed745..49d0de7 100644 --- a/includes/xna/graphics/device.hpp +++ b/includes/xna/graphics/device.hpp @@ -1,38 +1,44 @@ #ifndef XNA_GRAPHICS_DEVICE_HPP #define XNA_GRAPHICS_DEVICE_HPP -#include "../default.hpp" +#include "../platform.hpp" #include "presentparams.hpp" #include "viewport.hpp" +#include namespace xna { + struct GraphicsDeviceImplementation; + //Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. - class GraphicsDevice : public std::enable_shared_from_this { + class GraphicsDevice : public std::enable_shared_from_this, public PlatformImplementation { public: GraphicsDevice(); - GraphicsDevice(P_GraphicsAdapter const& adapter, GraphicsProfile const& graphicsProfile, P_PresentationParameters const& presentationParameters); + GraphicsDevice( + std::shared_ptr const& adapter, + GraphicsProfile const& graphicsProfile, + std::shared_ptr const& presentationParameters); //Gets the graphics adapter. - inline P_GraphicsAdapter Adapter() const { return adapter; } + inline std::shared_ptr Adapter() const { return adapter; } //Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque. - inline P_BlendState BlendState() const { return blendState; } + inline std::shared_ptr BlendState() const { return blendState; } //Gets or sets a system-defined instance of a blend state object initialized for alpha blending. The default value is BlendState.Opaque. - void BlendState(P_BlendState const& value); + void BlendState(std::shared_ptr const& value); //Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default. - inline P_DepthStencilState DepthStencilState() const { return depthStencilState; } + inline std::shared_ptr DepthStencilState() const { return depthStencilState; } //Gets or sets a system-defined instance of a depth-stencil state object. The default value is DepthStencilState.Default. - void DepthStencilState(P_DepthStencilState const& value); + void DepthStencilState(std::shared_ptr const& value); //Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise. - inline P_RasterizerState RasterizerState() const { return rasterizerState; } + inline std::shared_ptr RasterizerState() const { return rasterizerState; } //Gets or sets rasterizer state. The default value is RasterizerState.CullCounterClockwise. - void RasterizerState(P_RasterizerState const& value); + void RasterizerState(std::shared_ptr const& value); //Retrieves a collection of SamplerState objects for the current GraphicsDevice. - inline P_SamplerStateCollection SamplerStates() const { return samplerStateCollection; } + inline std::shared_ptr SamplerStates() const { return samplerStateCollection; } //Gets the graphics profile. constexpr GraphicsProfile Profile() const { return graphicsProfile; } //Gets the presentation parameters associated with this graphics device. - P_PresentationParameters PresentParameters() const { return presentationParameters; } + std::shared_ptr PresentParameters() const { return presentationParameters; } //Clears resource buffers. void Clear(Color const& color) const; //Clears resource buffers. @@ -40,30 +46,26 @@ namespace xna { //Presents the display with the contents of the next buffer in the sequence of back buffers owned by the GraphicsDevice. bool Present() const; //Resets the presentation parameters for the current GraphicsDevice. - void Reset(P_PresentationParameters const& presentationParameters, P_GraphicsAdapter const& graphicsAdapter); + void Reset(std::shared_ptr const& presentationParameters, std::shared_ptr const& graphicsAdapter); //Gets or sets a viewport identifying the portion of the render target to receive draw calls. constexpr xna::Viewport Viewport() const { return viewport; } //Gets or sets a viewport identifying the portion of the render target to receive draw calls. void Viewport(xna::Viewport const& viewport); //Sets a new render target for this GraphicsDevice. - void SetRenderTarget(P_RenderTarget2D const& renderTarget) { this->renderTarget = renderTarget; } + void SetRenderTarget(std::shared_ptr const& renderTarget) { this->renderTarget = renderTarget; } void Initialize(); private: - P_GraphicsAdapter adapter{ nullptr }; - P_BlendState blendState{ nullptr }; - P_DepthStencilState depthStencilState{ nullptr }; - P_RasterizerState rasterizerState{ nullptr }; - P_SamplerStateCollection samplerStateCollection{ nullptr }; - P_PresentationParameters presentationParameters{ nullptr }; - P_RenderTarget2D renderTarget{ nullptr }; + std::shared_ptr adapter{ nullptr }; + std::shared_ptr blendState{ nullptr }; + std::shared_ptr depthStencilState{ nullptr }; + std::shared_ptr rasterizerState{ nullptr }; + std::shared_ptr samplerStateCollection{ nullptr }; + std::shared_ptr presentationParameters{ nullptr }; + std::shared_ptr renderTarget{ nullptr }; GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef }; - xna::Viewport viewport{}; - - public: - struct PlatformImplementation; - uptr impl = nullptr; + xna::Viewport viewport{}; }; } diff --git a/sources/framework-dx/blendstate.cpp b/sources/framework-dx/blendstate.cpp index 794a675..d730505 100644 --- a/sources/framework-dx/blendstate.cpp +++ b/sources/framework-dx/blendstate.cpp @@ -97,7 +97,7 @@ namespace xna { bool BlendState::Initialize() { - if (!m_device || !m_device->impl->_device) { + if (!m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -105,7 +105,7 @@ namespace xna { Implementation->BlendState = nullptr; } - const auto hr = m_device->impl->_device->CreateBlendState( + const auto hr = m_device->Implementation->Device->CreateBlendState( &Implementation->Description, Implementation->BlendState.GetAddressOf()); @@ -117,7 +117,7 @@ namespace xna { } bool BlendState::Apply() { - if (!m_device || !m_device->impl->_context) { + if (!m_device || !m_device->Implementation->Context) { Exception::Throw(Exception::FAILED_TO_APPLY); } @@ -125,7 +125,7 @@ namespace xna { Initialize(); } - m_device->impl->_context->OMSetBlendState( + m_device->Implementation->Context->OMSetBlendState( Implementation->BlendState.Get(), Implementation->BlendFactor, Implementation->SampleMask); diff --git a/sources/framework-dx/depthstencilstate.cpp b/sources/framework-dx/depthstencilstate.cpp index 1f4a051..17c48c0 100644 --- a/sources/framework-dx/depthstencilstate.cpp +++ b/sources/framework-dx/depthstencilstate.cpp @@ -37,7 +37,7 @@ namespace xna { bool DepthStencilState::Initialize() { - if (!m_device || !m_device->impl->_device) { + if (!m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -45,7 +45,7 @@ namespace xna { Implementation->DepthStencil = nullptr; } - const auto hr = m_device->impl->_device->CreateDepthStencilState( + const auto hr = m_device->Implementation->Device->CreateDepthStencilState( &Implementation->Description, Implementation->DepthStencil.GetAddressOf()); @@ -58,7 +58,7 @@ namespace xna { bool DepthStencilState::Apply() { - if (!m_device || !m_device->impl->_context) { + if (!m_device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -66,7 +66,7 @@ namespace xna { Initialize(); } - m_device->impl->_context->OMSetDepthStencilState(Implementation->DepthStencil.Get(), 0); + m_device->Implementation->Context->OMSetDepthStencilState(Implementation->DepthStencil.Get(), 0); return true; } diff --git a/sources/framework-dx/device.cpp b/sources/framework-dx/device.cpp index 51ae38f..6f049e7 100644 --- a/sources/framework-dx/device.cpp +++ b/sources/framework-dx/device.cpp @@ -1,19 +1,19 @@ #include "xna-dx/framework.hpp" namespace xna { - static void reset(GraphicsDevice::PlatformImplementation& impl); - static void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter); + static void reset(GraphicsDeviceImplementation& impl); + static void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter); static void initAndApplyState(P_BlendState& blendState, P_RasterizerState& rasterizerState, P_DepthStencilState& depthStencilState, P_SamplerStateCollection& samplerStates, P_GraphicsDevice const& device); GraphicsDevice::GraphicsDevice() { - impl = unew(); + Implementation = unew(); adapter = GraphicsAdapter::DefaultAdapter(); } GraphicsDevice::GraphicsDevice(sptr const& adapter, GraphicsProfile const& graphicsProfile, sptr const& presentationParameters) : adapter(adapter), graphicsProfile(graphicsProfile), presentationParameters(presentationParameters) { - impl = unew(); + Implementation = unew(); blendState = xna::BlendState::Opaque(); depthStencilState = xna::DepthStencilState::Default(); @@ -22,11 +22,11 @@ namespace xna { } void GraphicsDevice::Initialize() { - reset(*impl); + reset(*Implementation); auto _this = shared_from_this(); - createDevice(*impl, *adapter); + createDevice(*Implementation, *adapter); // // Background @@ -35,22 +35,22 @@ namespace xna { const auto backColor = Colors::CornflowerBlue; const auto backColorV3 = backColor.ToVector3(); - impl->_backgroundColor[0] = backColorV3.X; - impl->_backgroundColor[1] = backColorV3.Y; - impl->_backgroundColor[2] = backColorV3.Z; - impl->_backgroundColor[3] = 1.0f; + Implementation->backgroundColor[0] = backColorV3.X; + Implementation->backgroundColor[1] = backColorV3.Y; + Implementation->backgroundColor[2] = backColorV3.Z; + Implementation->backgroundColor[3] = 1.0f; // // Window Association // - auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory); + auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&Implementation->Factory); if FAILED(hr) Exception::Throw(Exception::FAILED_TO_CREATE); auto hwnd = reinterpret_cast(presentationParameters->DeviceWindowHandle); - hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); + hr = Implementation->Factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); if (FAILED(hr)) Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION); @@ -65,7 +65,7 @@ namespace xna { 0.0F, 1.F); D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport); - impl->_context->RSSetViewports(1, &view); + Implementation->Context->RSSetViewports(1, &view); // // States @@ -84,18 +84,18 @@ namespace xna { case PresentInterval::Default: case PresentInterval::One: case PresentInterval::Two: - impl->vSyncValue = 1; + Implementation->vSyncValue = 1; break; case PresentInterval::Immediate: - impl->vSyncValue = 0; + Implementation->vSyncValue = 0; break; default: - impl->vSyncValue = 1; + Implementation->vSyncValue = 1; break; } - impl->_swapChain = snew(_this); - impl->_swapChain->Initialize(); + Implementation->SwapChain = snew(_this); + Implementation->SwapChain->Initialize(); // //Render Target @@ -103,44 +103,44 @@ namespace xna { if (renderTarget) { renderTarget->Initialize(); - impl->_renderTarget2D = renderTarget; + Implementation->RenderTarget2D = renderTarget; } else { - impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); + Implementation->RenderTarget2D = RenderTarget2D::FromBackBuffer(_this); } - const auto& renderView = impl->_renderTarget2D->impl2->_renderTargetView; - impl->_context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr); + const auto& renderView = Implementation->RenderTarget2D->impl2->_renderTargetView; + Implementation->Context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr); } bool GraphicsDevice::Present() const { - bool result = impl->_swapChain->Present(impl->vSyncValue != 0); + bool result = Implementation->SwapChain->Present(Implementation->vSyncValue != 0); - impl->_context->OMSetRenderTargets( + Implementation->Context->OMSetRenderTargets( 1, - impl->_renderTarget2D->impl2->_renderTargetView.GetAddressOf(), + Implementation->RenderTarget2D->impl2->_renderTargetView.GetAddressOf(), nullptr); return result; } void GraphicsDevice::Clear(Color const& color) const { - if (!impl) return; + if (!Implementation) return; const auto v4 = color.ToVector4(); - impl->_backgroundColor[0] = v4.X; - impl->_backgroundColor[1] = v4.Y; - impl->_backgroundColor[2] = v4.Z; - impl->_backgroundColor[3] = v4.W; + Implementation->backgroundColor[0] = v4.X; + Implementation->backgroundColor[1] = v4.Y; + Implementation->backgroundColor[2] = v4.Z; + Implementation->backgroundColor[3] = v4.W; - impl->_context->ClearRenderTargetView( - impl->_renderTarget2D->impl2->_renderTargetView.Get(), - impl->_backgroundColor); + Implementation->Context->ClearRenderTargetView( + Implementation->RenderTarget2D->impl2->_renderTargetView.Get(), + Implementation->backgroundColor); } void GraphicsDevice::Clear(ClearOptions options, Color const& color, float depth, Int stencil) const { - if (!impl) return; + if (!Implementation) return; switch (options) { @@ -162,7 +162,7 @@ namespace xna { viewport = value; const auto view = DxHelpers::ViewportToDx(viewport); - impl->_context->RSSetViewports(1, &view); + Implementation->Context->RSSetViewports(1, &view); } void GraphicsDevice::BlendState(sptr const& value) { @@ -181,7 +181,7 @@ namespace xna { } void GraphicsDevice::Reset(sptr const& parameters, sptr const& graphicsAdapter){ - impl = unew(); + Implementation = unew(); adapter = graphicsAdapter; presentationParameters = parameters; @@ -192,25 +192,25 @@ namespace xna { // INTERNAL // - void reset(GraphicsDevice::PlatformImplementation& impl) + void reset(GraphicsDeviceImplementation& impl) { - if (impl._device) { - impl._device->Release(); - impl._device = nullptr; + if (impl.Device) { + impl.Device->Release(); + impl.Device = nullptr; } - if (impl._context) { - impl._context->Release(); - impl._context = nullptr; + if (impl.Context) { + impl.Context->Release(); + impl.Context = nullptr; } - if (impl._factory) { - impl._factory->Release(); - impl._factory = nullptr; + if (impl.Factory) { + impl.Factory->Release(); + impl.Factory = nullptr; } } - void createDevice(GraphicsDevice::PlatformImplementation& impl, GraphicsAdapter& currentAdapter) { + void createDevice(GraphicsDeviceImplementation& impl, GraphicsAdapter& currentAdapter) { // // See ref // @@ -248,17 +248,17 @@ namespace xna { //UINT Flags, createDeviceFlags, //_In_reads_opt_( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels, - impl.featureLevels, + impl.FeatureLevels, //UINT FeatureLevels, 7, //UINT SDKVersion, D3D11_SDK_VERSION, //_COM_Outptr_opt_ ID3D11Device** ppDevice - impl._device.GetAddressOf(), + impl.Device.GetAddressOf(), //_Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel, - &impl.currentFeatureLevel, + &impl.CurrentFeatureLevel, //_COM_Outptr_opt_ ID3D11DeviceContext** ppImmediateContext - impl._context.GetAddressOf()); + impl.Context.GetAddressOf()); if FAILED(hr) Exception::Throw(Exception::FAILED_TO_CREATE); diff --git a/sources/framework-dx/effect.cpp b/sources/framework-dx/effect.cpp index 742e53e..c702c68 100644 --- a/sources/framework-dx/effect.cpp +++ b/sources/framework-dx/effect.cpp @@ -16,7 +16,7 @@ namespace xna { BasicEffect::BasicEffect(sptr const& device) : Effect(device) { impl = unew(); - uptr fxFactory = unew(device->impl->_device.Get()); + uptr fxFactory = unew(device->Implementation->Device.Get()); DxEffectFactory::EffectInfo info; info.name = L"basic"; info.alpha = 1.f; @@ -25,7 +25,7 @@ namespace xna { info.specularColor = DxHelpers::Vector3ToDx(specularColor); info.specularPower = specularPower; - Effect::impl->dxEffect = fxFactory->CreateEffect(info, device->impl->_context.Get()); + Effect::impl->dxEffect = fxFactory->CreateEffect(info, device->Implementation->Context.Get()); impl->dxBasicEffect = reinterpret_pointer_cast(Effect::impl->dxEffect); } diff --git a/sources/framework-dx/gdevicemanager.cpp b/sources/framework-dx/gdevicemanager.cpp index bd24b07..32573ce 100644 --- a/sources/framework-dx/gdevicemanager.cpp +++ b/sources/framework-dx/gdevicemanager.cpp @@ -25,10 +25,10 @@ namespace xna { } bool GraphicsDeviceManager::ToggleFullScreen() { - if (!game || !game->graphicsDevice || !game->graphicsDevice->impl->_swapChain) + if (!game || !game->graphicsDevice || !game->graphicsDevice->Implementation->SwapChain) return false; - auto& swap = game->graphicsDevice->impl->_swapChain; + auto& swap = game->graphicsDevice->Implementation->SwapChain; BOOL state = false; auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr); diff --git a/sources/framework-dx/rasterizerstate.cpp b/sources/framework-dx/rasterizerstate.cpp index 0823ad7..644d08b 100644 --- a/sources/framework-dx/rasterizerstate.cpp +++ b/sources/framework-dx/rasterizerstate.cpp @@ -17,7 +17,7 @@ namespace xna { bool RasterizerState::Initialize() { - if (!impl || !m_device || !m_device->impl->_device) { + if (!impl || !m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -25,7 +25,7 @@ namespace xna { impl->dxRasterizerState = nullptr; } - const auto hr = m_device->impl->_device->CreateRasterizerState( + const auto hr = m_device->Implementation->Device->CreateRasterizerState( &impl->dxDescription, impl->dxRasterizerState.GetAddressOf()); @@ -38,7 +38,7 @@ namespace xna { bool RasterizerState::Apply() { - if (!impl || !m_device || !m_device->impl->_context) { + if (!impl || !m_device || !m_device->Implementation->Context) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -46,7 +46,7 @@ namespace xna { Exception::Throw(Exception::INVALID_OPERATION); } - m_device->impl->_context->RSSetState(impl->dxRasterizerState.Get()); + m_device->Implementation->Context->RSSetState(impl->dxRasterizerState.Get()); return true; } diff --git a/sources/framework-dx/rendertarget.cpp b/sources/framework-dx/rendertarget.cpp index 2f50f40..b53aa65 100644 --- a/sources/framework-dx/rendertarget.cpp +++ b/sources/framework-dx/rendertarget.cpp @@ -10,7 +10,7 @@ namespace xna { } P_RenderTarget2D RenderTarget2D::FromBackBuffer(P_GraphicsDevice const& device) { - auto& swapChain = device->impl->_swapChain; + auto& swapChain = device->Implementation->SwapChain; auto rt = snew(device); auto& implementation = rt->impl; auto& implementation2 = rt->impl2; @@ -26,7 +26,7 @@ namespace xna { } void RenderTarget2D::Initialize() { - if (!impl || !m_device || !m_device->impl->_device) { + if (!impl || !m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -39,7 +39,7 @@ namespace xna { Texture2D::Initialize(); - auto& dxdevice = m_device->impl->_device; + auto& dxdevice = m_device->Implementation->Device; const auto hr = dxdevice->CreateRenderTargetView( impl->dxTexture2D.Get(), diff --git a/sources/framework-dx/samplerstate.cpp b/sources/framework-dx/samplerstate.cpp index 6f5ed96..d29158d 100644 --- a/sources/framework-dx/samplerstate.cpp +++ b/sources/framework-dx/samplerstate.cpp @@ -11,7 +11,7 @@ namespace xna { bool SamplerState::Initialize() { - if (!impl || !m_device || !m_device->impl->_device) { + if (!impl || !m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } @@ -19,7 +19,7 @@ namespace xna { impl->_samplerState = nullptr; } - const auto hr = m_device->impl->_device->CreateSamplerState( + const auto hr = m_device->Implementation->Device->CreateSamplerState( &impl->_description, impl->_samplerState.GetAddressOf()); @@ -32,7 +32,7 @@ namespace xna { bool SamplerState::Apply() { - if (!impl || !m_device || !m_device->impl->_context) { + if (!impl || !m_device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -40,7 +40,7 @@ namespace xna { Exception::Throw(Exception::INVALID_OPERATION); } - m_device->impl->_context->PSSetSamplers(0, 1, impl->_samplerState.GetAddressOf()); + m_device->Implementation->Context->PSSetSamplers(0, 1, impl->_samplerState.GetAddressOf()); return true; } @@ -49,7 +49,7 @@ namespace xna { if (samplers.empty()) return; - if (!device.impl || !device.impl->_device || !device.impl->_context) { + if (!device.Implementation || !device.Implementation->Device || !device.Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -65,7 +65,7 @@ namespace xna { states[i]->AddRef(); } - device.impl->_context->PSSetSamplers( + device.Implementation->Context->PSSetSamplers( 0, static_cast(states.size()), states.data()); diff --git a/sources/framework-dx/sprite.cpp b/sources/framework-dx/sprite.cpp index 3e31d56..5b6d4ad 100644 --- a/sources/framework-dx/sprite.cpp +++ b/sources/framework-dx/sprite.cpp @@ -110,12 +110,12 @@ namespace xna { SpriteBatch::SpriteBatch(sptr const& device) : GraphicsResource(device) { Exception::ThrowIfNull(device, nameof(device)); - Exception::ThrowIfNull(device->impl->_context.Get(), nameof(device->impl->_context)); + Exception::ThrowIfNull(device->Implementation->Context.Get(), nameof(device->Implementation->Context)); impl = unew(); impl->dxSpriteBatch = snew( //ID3D11DeviceContext* deviceContext - device->impl->_context.Get() + device->Implementation->Context.Get() ); Viewport(device->Viewport()); @@ -139,14 +139,14 @@ namespace xna { effect->impl->dxEffect->GetVertexShaderBytecode(&shaderByteCode, &byteCodeLength); - m_device->impl->_device->CreateInputLayout( + m_device->Implementation->Device->CreateInputLayout( DirectX::VertexPositionColorTexture::InputElements, DirectX::VertexPositionColorTexture::InputElementCount, shaderByteCode, byteCodeLength, impl->dxInputLayout.GetAddressOf()); } - auto& context = m_device->impl->_context; + auto& context = m_device->Implementation->Context; effectFunc = [=] { impl->dxEffectBuffer->Apply(context.Get()); diff --git a/sources/framework-dx/swapchain.cpp b/sources/framework-dx/swapchain.cpp index c7f6ac9..d4ffcfe 100644 --- a/sources/framework-dx/swapchain.cpp +++ b/sources/framework-dx/swapchain.cpp @@ -17,7 +17,7 @@ namespace xna { } static bool internalInit(GraphicsDevice& device, HWND windowHandle, comptr& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) { - if (!device.impl->_device || !windowHandle) + if (!device.Implementation->Device || !windowHandle) return false; if (swapChain) { @@ -33,7 +33,7 @@ namespace xna { return false; dxFactory2->CreateSwapChainForHwnd( - device.impl->_device.Get(), + device.Implementation->Device.Get(), windowHandle, &desc, &fdesc, @@ -44,7 +44,7 @@ namespace xna { } bool SwapChain::Initialize() { - if (!impl || !m_device || !m_device->impl->_device) { + if (!impl || !m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } diff --git a/sources/framework-dx/texture.cpp b/sources/framework-dx/texture.cpp index 8ae2d93..7990535 100644 --- a/sources/framework-dx/texture.cpp +++ b/sources/framework-dx/texture.cpp @@ -33,16 +33,16 @@ namespace xna { void Texture2D::Initialize() { - if (!m_device || !m_device->impl->_device) { + if (!m_device || !m_device->Implementation->Device) { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } - auto& deviceImpl = m_device->impl; + auto& deviceImpl = m_device->Implementation; HRESULT hr = 0; if (!impl->dxTexture2D) { - hr = deviceImpl->_device->CreateTexture2D( + hr = deviceImpl->Device->CreateTexture2D( &impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf()); @@ -63,7 +63,7 @@ namespace xna { //Only initializes if it is a ShaderResource if (impl->dxDescription.BindFlags & D3D11_BIND_SHADER_RESOURCE) { - hr = deviceImpl->_device->CreateShaderResourceView( + hr = deviceImpl->Device->CreateShaderResourceView( resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf()); @@ -81,7 +81,7 @@ namespace xna { void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { - if (!impl || !m_device || !m_device->impl->_device || !m_device->impl->_context) { + if (!impl || !m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -90,7 +90,7 @@ namespace xna { void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { - if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { + if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -111,7 +111,7 @@ namespace xna { void Texture2D::SetData(Int level, Rectangle* rect, std::vector const& data, size_t startIndex, size_t elementCount) { - if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { + if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -128,7 +128,7 @@ namespace xna { } if (!impl->dxTexture2D) { - auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.GetAddressOf()); + auto hr = m_device->Implementation->Device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.GetAddressOf()); if (FAILED(hr)) { Exception::Throw(Exception::FAILED_TO_CREATE); @@ -154,11 +154,11 @@ namespace xna { } constexpr int R8G8B8A8U_BYTE_SIZE = 4; - m_device->impl->_context->UpdateSubresource(resource.Get(), 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); + m_device->Implementation->Context->UpdateSubresource(resource.Get(), 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); impl->dxShaderDescription.Format = impl->dxDescription.Format; impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels; - hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf()); + hr = m_device->Implementation->Device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf()); if (FAILED(hr)) { Exception::Throw(Exception::FAILED_TO_CREATE); @@ -169,7 +169,7 @@ namespace xna { void Texture2D::SetData(std::vector const& data, size_t startIndex, size_t elementCount) { - if (!m_device || !m_device->impl->_device || !m_device->impl->_context) { + if (!m_device || !m_device->Implementation->Device || !m_device->Implementation->Context) { Exception::Throw(Exception::INVALID_OPERATION); } @@ -201,8 +201,8 @@ namespace xna { auto wstr = XnaHelper::ToWString(fileName); HRESULT result = DirectX::CreateWICTextureFromFile( - device.impl->_device.Get(), - device.impl->_context.Get(), + device.Implementation->Device.Get(), + device.Implementation->Context.Get(), wstr.c_str(), resource.GetAddressOf(), texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(), @@ -232,8 +232,8 @@ namespace xna { comptr resource = nullptr; auto hr = DirectX::CreateWICTextureFromMemory( - device.impl->_device.Get(), - device.impl->_context.Get(), + device.Implementation->Device.Get(), + device.Implementation->Context.Get(), data.data(), data.size(), resource.GetAddressOf(), @@ -260,7 +260,7 @@ namespace xna { HRESULT internalTexture2DSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) { if (!impl.dxTexture2D) { - auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf()); + auto hr = device.Implementation->Device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf()); if (FAILED(hr)) { Exception::Throw(Exception::FAILED_TO_CREATE); @@ -275,10 +275,10 @@ namespace xna { } constexpr int R8G8B8A8U_BYTE_SIZE = 4; - device.impl->_context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); + device.Implementation->Context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels; - hr = device.impl->_device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf()); + hr = device.Implementation->Device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf()); if (FAILED(hr)) { Exception::Throw(Exception::FAILED_TO_CREATE);