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:
parent
c21871a951
commit
491626d654
@ -22,46 +22,61 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDevice::Initialize() {
|
void GraphicsDevice::Initialize() {
|
||||||
auto _this = shared_from_this();
|
reset(*impl);
|
||||||
|
|
||||||
reset(*impl);
|
|
||||||
createDevice(*impl, *adapter);
|
|
||||||
|
|
||||||
auto hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&impl->_factory);
|
|
||||||
|
|
||||||
if FAILED(hr)
|
auto _this = shared_from_this();
|
||||||
Exception::Throw(Exception::FAILED_TO_CREATE);
|
|
||||||
|
createDevice(*impl, *adapter);
|
||||||
viewport = xna::Viewport(0.0F, 0.0F,
|
|
||||||
presentationParameters->BackBufferWidth,
|
|
||||||
presentationParameters->BackBufferHeight,
|
|
||||||
0.0F, 1.F);
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Background
|
||||||
|
//
|
||||||
|
|
||||||
const auto backColor = Colors::CornflowerBlue;
|
const auto backColor = Colors::CornflowerBlue;
|
||||||
const auto backColorV3 = backColor.ToVector3();
|
const auto backColorV3 = backColor.ToVector3();
|
||||||
|
|
||||||
impl->_backgroundColor[0] = backColorV3.X;
|
impl->_backgroundColor[0] = backColorV3.X;
|
||||||
impl->_backgroundColor[1] = backColorV3.Y;
|
impl->_backgroundColor[1] = backColorV3.Y;
|
||||||
impl->_backgroundColor[2] = backColorV3.Z;
|
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);
|
auto hwnd = reinterpret_cast<HWND>(presentationParameters->DeviceWindowHandle);
|
||||||
hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
hr = impl->_factory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
||||||
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
Exception::Throw(Exception::FAILED_TO_MAKE_WINDOW_ASSOCIATION);
|
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);
|
D3D11_VIEWPORT view = DxHelpers::ViewportToDx(viewport);
|
||||||
impl->_context->RSSetViewports(1, &view);
|
impl->_context->RSSetViewports(1, &view);
|
||||||
|
|
||||||
|
//
|
||||||
|
// States
|
||||||
|
//
|
||||||
|
|
||||||
initAndApplyState(blendState, rasterizerState, depthStencilState, samplerStateCollection, _this);
|
initAndApplyState(blendState, rasterizerState, depthStencilState, samplerStateCollection, _this);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Presentation
|
||||||
|
//
|
||||||
|
|
||||||
const auto currentPresenInterval = presentationParameters->PresentationInterval;
|
const auto currentPresenInterval = presentationParameters->PresentationInterval;
|
||||||
|
|
||||||
switch (currentPresenInterval)
|
switch (currentPresenInterval)
|
||||||
@ -78,6 +93,17 @@ namespace xna {
|
|||||||
impl->vSyncValue = 1;
|
impl->vSyncValue = 1;
|
||||||
break;
|
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 {
|
bool GraphicsDevice::Present() const {
|
||||||
|
@ -49,18 +49,4 @@ namespace xna {
|
|||||||
|
|
||||||
impl2->_renderTargetView->GetDesc(&impl2->_renderTargetDesc);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,16 +5,15 @@
|
|||||||
#include "texture.hpp"
|
#include "texture.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
|
//Contains a 2D texture that can be used as a render target.
|
||||||
class RenderTarget2D : public Texture2D {
|
class RenderTarget2D : public Texture2D {
|
||||||
public:
|
public:
|
||||||
RenderTarget2D();
|
RenderTarget2D();
|
||||||
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
RenderTarget2D(sptr<GraphicsDevice> const& device);
|
||||||
|
|
||||||
|
|
||||||
static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device);
|
static P_RenderTarget2D FromBackBuffer(P_GraphicsDevice const& device);
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Apply();
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl2 = nullptr;
|
uptr<PlatformImplementation> impl2 = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user