1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Correções em GraphicsDevice::Initialize

This commit is contained in:
Danilo 2024-08-05 16:47:00 -03:00
parent c21871a951
commit 491626d654
3 changed files with 47 additions and 36 deletions

View File

@ -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<xna::SwapChain>(_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<HWND>(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<xna::SwapChain>(_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 {

View File

@ -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);
}
}

View File

@ -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<GraphicsDevice> const& device);
RenderTarget2D(sptr<GraphicsDevice> const& device);
static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device);
void Initialize();
void Apply();
public:
struct PlatformImplementation;
uptr<PlatformImplementation> impl2 = nullptr;