diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 3d525b7..018dca0 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -101,13 +101,19 @@ namespace xna { //Render Target // - impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); + if (renderTarget) { + renderTarget->Initialize(); + impl->_renderTarget2D = renderTarget; + } + else { + impl->_renderTarget2D = RenderTarget2D::FromBackBuffer(_this); + } + const auto& renderView = impl->_renderTarget2D->impl2->_renderTargetView; impl->_context->OMSetRenderTargets(1, renderView.GetAddressOf(), nullptr); } bool GraphicsDevice::Present() const { - const auto currentPresenInterval = presentationParameters->PresentationInterval; bool result = impl->_swapChain->Present(impl->vSyncValue != 0); impl->_context->OMSetRenderTargets( diff --git a/framework/platform-dx/rendertarget.cpp b/framework/platform-dx/rendertarget.cpp index 3c0aafa..08a83ca 100644 --- a/framework/platform-dx/rendertarget.cpp +++ b/framework/platform-dx/rendertarget.cpp @@ -30,6 +30,9 @@ namespace xna { Exception::Throw(Exception::UNABLE_TO_INITIALIZE); } + if (impl2->_renderTargetView) + return; + impl->dxDescription.Width = width; impl->dxDescription.Height = height; impl->dxDescription.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET; diff --git a/inc/xna/graphics/device.hpp b/inc/xna/graphics/device.hpp index 08f259e..0cb6f4c 100644 --- a/inc/xna/graphics/device.hpp +++ b/inc/xna/graphics/device.hpp @@ -45,7 +45,9 @@ namespace xna { 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 Initialize(); private: @@ -55,6 +57,7 @@ namespace xna { P_RasterizerState rasterizerState{ nullptr }; P_SamplerStateCollection samplerStateCollection{ nullptr }; P_PresentationParameters presentationParameters{ nullptr }; + P_RenderTarget2D renderTarget{ nullptr }; GraphicsProfile graphicsProfile{ GraphicsProfile::HiDef }; xna::Viewport viewport{};