From 491626d654aaf73012ab6b106ba164098d1e9038 Mon Sep 17 00:00:00 2001 From: Danilo Date: Mon, 5 Aug 2024 16:47:00 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20em=20GraphicsDevice::Init?= =?UTF-8?q?ialize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/device.cpp | 64 ++++++++++++++++++-------- framework/platform-dx/rendertarget.cpp | 14 ------ inc/xna/graphics/rendertarget.hpp | 5 +- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index ffff87b..3d525b7 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -22,46 +22,61 @@ namespace xna { } void GraphicsDevice::Initialize() { - auto _this = shared_from_this(); - - reset(*impl); - createDevice(*impl, *adapter); - - auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory); + reset(*impl); - if FAILED(hr) - Exception::Throw(Exception::FAILED_TO_CREATE); - - viewport = xna::Viewport(0.0F, 0.0F, - presentationParameters->BackBufferWidth, - presentationParameters->BackBufferHeight, - 0.0F, 1.F); + auto _this = shared_from_this(); + + createDevice(*impl, *adapter); + // + // Background + // + 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; + impl->_backgroundColor[3] = 1.0f; - impl->_swapChain = snew(_this); - impl->_swapChain->Initialize(); + // + // Window Association + // + + auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_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); if (FAILED(hr)) Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION); - - impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); - impl->_renderTarget2D->Apply(); + + // + // Viewport + // + + viewport = xna::Viewport(0.0F, 0.0F, + presentationParameters->BackBufferWidth, + presentationParameters->BackBufferHeight, + 0.0F, 1.F); D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport); impl->_context->RSSetViewports(1, &view); + // + // States + // + initAndApplyState(blendState, rasterizerState, depthStencilState, samplerStateCollection, _this); + // + // Presentation + // + const auto currentPresenInterval = presentationParameters->PresentationInterval; switch (currentPresenInterval) @@ -78,6 +93,17 @@ namespace xna { impl->vSyncValue = 1; break; } + + impl->_swapChain = snew(_this); + impl->_swapChain->Initialize(); + + // + //Render Target + // + + impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); + const auto& renderView = impl->_renderTarget2D->impl2->_renderTargetView; + impl->_context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr); } bool GraphicsDevice::Present() const { diff --git a/framework/platform-dx/rendertarget.cpp b/framework/platform-dx/rendertarget.cpp index 6bc26cb..3c0aafa 100644 --- a/framework/platform-dx/rendertarget.cpp +++ b/framework/platform-dx/rendertarget.cpp @@ -49,18 +49,4 @@ namespace xna { impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc); } - - void RenderTarget2D::Apply() { - if (!m_device || !m_device->impl->_context) { - Exception::Throw(Exception::FAILED_TO_APPLY); - } - - if (!impl2->_renderTargetView) - { - Initialize(); - } - - auto& context = m_device->impl->_context; - context->OMSetRenderTargets(1, impl2->_renderTargetView.GetAddressOf(), nullptr); - } } \ No newline at end of file diff --git a/inc/xna/graphics/rendertarget.hpp b/inc/xna/graphics/rendertarget.hpp index ee91904..168fd6c 100644 --- a/inc/xna/graphics/rendertarget.hpp +++ b/inc/xna/graphics/rendertarget.hpp @@ -5,16 +5,15 @@ #include "texture.hpp" namespace xna { + //Contains a 2D texture that can be used as a render target. class RenderTarget2D : public Texture2D { public: RenderTarget2D(); - RenderTarget2D(sptr const& device); - + RenderTarget2D(sptr const& device); static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device); void Initialize(); - void Apply(); public: struct PlatformImplementation; uptr impl2 = nullptr;