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

Corrige GraphicsDeviceManager

This commit is contained in:
Danilo 2024-05-24 14:42:12 -03:00
parent d2a8b1d397
commit 2aa02112cf
9 changed files with 85 additions and 119 deletions

View File

@ -2,8 +2,8 @@
#include "graphics/displaymode.hpp"
#include "platform-dx/dxheaders.hpp"
#include "platform-dx/dxhelpers.hpp"
#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp"
#include "game/gdevicemanager.hpp"
namespace xna {
static size_t getDisplayModesCount(IDXGIAdapter* adapter);

View File

@ -3,9 +3,9 @@
#include "graphics/blendstate.hpp"
#include "graphics/rendertarget.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp"
#include "game/gdeviceinfo.hpp"
#include "game/gdevicemanager.hpp"
namespace xna {
GraphicsDevice::GraphicsDevice() {

View File

@ -2,8 +2,8 @@
#include "game/time.hpp"
#include "platform-dx/audioengine-dx.hpp"
#include "platform-dx/game-dx.hpp"
#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/implementations.hpp"
#include "game/gdevicemanager.hpp"
namespace xna {
Game::Game() {

View File

@ -1,13 +1,14 @@
#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/game-dx.hpp"
#include "game/gdevicemanager.hpp"
#include "graphics/presentparams.hpp"
#include "graphics/swapchain.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/game-dx.hpp"
#include "platform-dx/implementations.hpp"
namespace xna {
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
GraphicsDeviceManager::GraphicsDeviceManager(sptr<Game> const& game) : _game(game)
{
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
_information.Adapter = adp;
_information.Profile = xna::GraphicsProfile::HiDef;
@ -18,9 +19,9 @@ namespace xna {
parameters->Fullscreen = false;
_information.Parameters = parameters;
if(_game)
_information.Window =_game->Window();
}
if (_game)
_information.Window = _game->Window();
}
bool GraphicsDeviceManager::Initialize() {
if (!_game)
@ -61,6 +62,44 @@ namespace xna {
_backBufferHeight = value;
_isDeviceDirty = true;
}
bool initWindow(GraphicsDeviceInformation& info, Game& game, int backWidth, int backHeight)
{
auto window = info.Window;
if (!window) {
window = game.Window();
info.Window = window;
}
window->impl->Size(backWidth, backHeight);
if (!window->impl->Create()) {
MessageBox(nullptr, "Falha na criação da janela", "XN65", MB_OK);
return false;
}
info.Parameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
return true;
}
bool initDevice(GraphicsDeviceInformation& info, Game& game, sptr<GraphicsDevice>& device)
{
auto& window = info.Window;
device = New<GraphicsDevice>(info);
if (!device->Initialize(*window)) {
MessageBox(window->impl->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK);
device = nullptr;
return false;
}
game.graphicsDevice = device;
return true;
}
bool GraphicsDeviceManager::CreateDevice() {
if (_isDeviceDirty) {
@ -68,50 +107,15 @@ namespace xna {
_information.Parameters->BackBufferHeight = _backBufferHeight;
}
auto result = initWindow();
auto result = initWindow(_information, *_game, _backBufferWidth, _backBufferHeight);
if (!result) return false;
return initDevice();
return initDevice(_information, *_game, _device);
}
void GraphicsDeviceManager::ChangeDevice() {
}
bool GraphicsDeviceManager::initWindow()
{
auto window = _information.Window;
if (!window) {
window = _game->Window();
_information.Window = window;
}
window->impl->Size(_backBufferWidth, _backBufferHeight);
if (!window->impl->Create()) {
MessageBox(nullptr, "Falha na criação da janela", "XN65", MB_OK);
return false;
}
_information.Parameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
return true;
}
bool GraphicsDeviceManager::initDevice()
{
auto window = _information.Window;
_device = New<GraphicsDevice>(_information);
if (!_device->Initialize(*window)) {
MessageBox(window->impl->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK);
_device = nullptr;
return false;
}
_game->graphicsDevice = _device;
return true;
}
}

View File

@ -10,13 +10,12 @@ namespace xna {
class Game1 : public Game {
public:
Game1() : Game() {
auto _game = reinterpret_cast<Game*>(this);
graphics = New<GraphicsDeviceManager>(_game);
Content()->RootDirectory("Content");
}
void Initialize() override {
auto game = reinterpret_cast<Game*>(this);
graphics = New<GraphicsDeviceManager>(game->shared_from_this());
graphics->Initialize();
std::any device = graphicsDevice;
@ -64,7 +63,7 @@ namespace xna {
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
xna::Platform::Init();
auto game = xna::Game1();
const auto result = game.Run();
auto game = snew<Game1>();
const auto result = game->Run();
return result;
}

View File

@ -2,21 +2,37 @@
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
#include "../default.hpp"
#include "gdeviceinfo.hpp"
namespace xna {
class IGraphicsDeviceManager {
class GraphicsDeviceManager {
public:
virtual ~IGraphicsDeviceManager(){}
virtual void ApplyChanges() = 0;
virtual bool Initialize() = 0;
virtual bool ToggleFullScreen() = 0;
virtual Int PreferredBackBufferWidth() const = 0;
virtual Int PreferredBackBufferHeight() const = 0;
virtual void PreferredBackBufferWidth(Int value) = 0;
virtual void PreferredBackBufferHeight(Int value) = 0;
GraphicsDeviceManager(sptr<Game> const& game);
~GraphicsDeviceManager() {}
void ApplyChanges();
bool Initialize();
bool ToggleFullScreen();
Int PreferredBackBufferWidth() const;
Int PreferredBackBufferHeight() const;
void PreferredBackBufferWidth(Int value);
void PreferredBackBufferHeight(Int value);
public:
static constexpr int DefaultBackBufferWidth = 800;
static constexpr int DefaultBackBufferHeight = 600;
protected:
virtual bool CreateDevice() = 0;
virtual void ChangeDevice() = 0;
bool CreateDevice();
void ChangeDevice();
private:
sptr<Game> _game = nullptr;
Int _backBufferWidth{ DefaultBackBufferWidth };
Int _backBufferHeight{ DefaultBackBufferHeight };
bool _isDeviceDirty{ false };
sptr<GraphicsDevice> _device = nullptr;
bool _isFullScreen{ false };
GraphicsDeviceInformation _information{};
};
}

View File

@ -8,7 +8,7 @@
#include "dxheaders.hpp"
namespace xna {
class Game : public IGame {
class Game : public IGame, public std::enable_shared_from_this<Game> {
public:
Game();

View File

@ -1,52 +0,0 @@
#ifndef XNA_PLATFORM_GDEVICEMANAGER_DX_HPP
#define XNA_PLATFORM_GDEVICEMANAGER_DX_HPP
#include "../game/gdevicemanager.hpp"
#include "game/gdeviceinfo.hpp"
namespace xna {
class GraphicsDeviceManager : public IGraphicsDeviceManager {
public:
GraphicsDeviceManager(Game*& game);
virtual ~GraphicsDeviceManager() override{}
virtual void ApplyChanges() override;
virtual bool Initialize() override;
virtual bool ToggleFullScreen() override;
virtual constexpr Int PreferredBackBufferWidth() const {
return _backBufferWidth;
}
virtual constexpr Int PreferredBackBufferHeight() const {
return _backBufferHeight;
}
virtual void PreferredBackBufferWidth(Int value);
virtual void PreferredBackBufferHeight(Int value);
protected:
virtual bool CreateDevice() override;
virtual void ChangeDevice() override;
public:
static constexpr int DefaultBackBufferWidth = 800;//800;
static constexpr int DefaultBackBufferHeight = 600;// 480;
private:
Game* _game;
Int _backBufferWidth{ DefaultBackBufferWidth };
Int _backBufferHeight{ DefaultBackBufferHeight };
bool _isDeviceDirty{ false };
sptr<GraphicsDevice> _device = nullptr;
bool _isFullScreen{ false };
GraphicsDeviceInformation _information{};
bool initWindow();
bool initDevice();
};
}
#endif

View File

@ -4,7 +4,6 @@
#include "dx/StepTimer.hpp"
#include "dxheaders.hpp"
#include "game-dx.hpp"
#include "gdevicemanager-dx.hpp"
#include "init-dx.hpp"
#include "soundeffect-dx.hpp"
#include "implementations.hpp"