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

Corrige Initialize em GraphicsDevice

This commit is contained in:
Danilo 2024-06-05 09:26:33 -03:00
parent 9a8e3e26b5
commit 4335323879
4 changed files with 29 additions and 11 deletions

View File

@ -2,7 +2,7 @@
#include "xna/game/gdevicemanager.hpp" #include "xna/game/gdevicemanager.hpp"
namespace xna { namespace xna {
void reset(GraphicsDevice::PlatformImplementation& impl) static void reset(GraphicsDevice::PlatformImplementation& impl)
{ {
if (impl._device) { if (impl._device) {
impl._device->Release(); impl._device->Release();
@ -24,7 +24,7 @@ namespace xna {
impl._renderTarget2D = nullptr; impl._renderTarget2D = nullptr;
} }
bool createDevice(GraphicsDevice::PlatformImplementation& impl) { static bool createDevice(GraphicsDevice::PlatformImplementation& impl) {
auto createDeviceFlags = 0; auto createDeviceFlags = 0;
#if _DEBUG #if _DEBUG
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG; createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
@ -75,6 +75,7 @@ namespace xna {
impl = unew<PlatformImplementation>(); impl = unew<PlatformImplementation>();
impl->_adapter = info.Adapter; impl->_adapter = info.Adapter;
impl->_gameWindow = info.Window;
impl->_presentationParameters = info.Parameters; impl->_presentationParameters = info.Parameters;
impl->_adapter->CurrentDisplayMode( impl->_adapter->CurrentDisplayMode(
impl->_presentationParameters->BackBufferFormat, impl->_presentationParameters->BackBufferFormat,
@ -86,7 +87,7 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
bool GraphicsDevice::Initialize(GameWindow& gameWindow) { bool GraphicsDevice::Initialize() {
if (!impl) if (!impl)
impl = uptr<PlatformImplementation>(); impl = uptr<PlatformImplementation>();
@ -101,14 +102,14 @@ namespace xna {
if (FAILED(hr)) if (FAILED(hr))
return false; return false;
const auto bounds = gameWindow.ClientBounds(); const auto bounds = impl->_gameWindow->ClientBounds();
impl->_viewport = xna::Viewport(0.0F, 0.0F, impl->_viewport = xna::Viewport(0.0F, 0.0F,
static_cast<float>(bounds.Width), static_cast<float>(bounds.Width),
static_cast<float>(bounds.Height), static_cast<float>(bounds.Height),
0.0F, 1.F); 0.0F, 1.F);
COLORREF color = gameWindow.impl->Color(); COLORREF color = impl->_gameWindow->impl->Color();
impl->_backgroundColor[0] = GetRValue(color) / 255.0f; impl->_backgroundColor[0] = GetRValue(color) / 255.0f;
impl->_backgroundColor[1] = GetGValue(color) / 255.0f; impl->_backgroundColor[1] = GetGValue(color) / 255.0f;
impl->_backgroundColor[2] = GetBValue(color) / 255.0f; impl->_backgroundColor[2] = GetBValue(color) / 255.0f;
@ -117,7 +118,7 @@ namespace xna {
impl->_swapChain = New<xna::SwapChain>(_this); impl->_swapChain = New<xna::SwapChain>(_this);
impl->_swapChain->Initialize(); impl->_swapChain->Initialize();
hr = impl->_factory->MakeWindowAssociation(gameWindow.impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER); hr = impl->_factory->MakeWindowAssociation(impl->_gameWindow->impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER);
if (FAILED(hr)) return false; if (FAILED(hr)) return false;
impl->_renderTarget2D = New<RenderTarget2D>(_this); impl->_renderTarget2D = New<RenderTarget2D>(_this);

View File

@ -83,12 +83,11 @@ namespace xna {
} }
bool initDevice(GraphicsDeviceInformation& info, Game& game, sptr<GraphicsDevice>& device) bool initDevice(GraphicsDeviceInformation& info, Game& game, sptr<GraphicsDevice>& device)
{ {
auto& window = info.Window;
device = New<GraphicsDevice>(info); device = New<GraphicsDevice>(info);
if (!device->Initialize(*window)) { if (!device->Initialize()) {
MessageBox(window->impl->WindowHandle(), "Falha na inicializaçăo do dispositivo gráfico", "XN65", MB_OK); MessageBox(info.Window->impl->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK);
device = nullptr; device = nullptr;
return false; return false;
} }

View File

@ -11,7 +11,7 @@ namespace xna {
~GraphicsDevice(); ~GraphicsDevice();
void Clear(); void Clear();
void Clear(Color const& color); void Clear(Color const& color);
bool Initialize(GameWindow& gameWindow); bool Initialize();
bool Present(); bool Present();
sptr<GraphicsAdapter> Adapter() const; sptr<GraphicsAdapter> Adapter() const;
void Adapter(sptr<GraphicsAdapter> const& adapter); void Adapter(sptr<GraphicsAdapter> const& adapter);

View File

@ -447,6 +447,23 @@ namespace xna {
}; };
struct GraphicsDevice::PlatformImplementation { struct GraphicsDevice::PlatformImplementation {
~PlatformImplementation() {
if (_device) {
_device->Release();
_device = nullptr;
}
if (_context) {
_context->Release();
_device = nullptr;
}
if (_factory) {
_factory->Release();
_factory = nullptr;
}
}
ID3D11Device* _device{ nullptr }; ID3D11Device* _device{ nullptr };
ID3D11DeviceContext* _context{ nullptr }; ID3D11DeviceContext* _context{ nullptr };
IDXGIFactory1* _factory = nullptr; IDXGIFactory1* _factory = nullptr;
@ -454,6 +471,7 @@ namespace xna {
sptr<GraphicsAdapter> _adapter{ nullptr }; sptr<GraphicsAdapter> _adapter{ nullptr };
sptr<RenderTarget2D> _renderTarget2D{ nullptr }; sptr<RenderTarget2D> _renderTarget2D{ nullptr };
sptr<BlendState> _blendState{ nullptr }; sptr<BlendState> _blendState{ nullptr };
sptr<GameWindow> _gameWindow = nullptr;
xna::Viewport _viewport{}; xna::Viewport _viewport{};
sptr<xna::PresentationParameters> _presentationParameters; sptr<xna::PresentationParameters> _presentationParameters;
D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 }; D3D_FEATURE_LEVEL _featureLevel{ D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0 };