mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Corrige GraphicsDeviceManager
This commit is contained in:
parent
d2a8b1d397
commit
2aa02112cf
@ -2,8 +2,8 @@
|
|||||||
#include "graphics/displaymode.hpp"
|
#include "graphics/displaymode.hpp"
|
||||||
#include "platform-dx/dxheaders.hpp"
|
#include "platform-dx/dxheaders.hpp"
|
||||||
#include "platform-dx/dxhelpers.hpp"
|
#include "platform-dx/dxhelpers.hpp"
|
||||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
|
#include "game/gdevicemanager.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
static size_t getDisplayModesCount(IDXGIAdapter* adapter);
|
static size_t getDisplayModesCount(IDXGIAdapter* adapter);
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
#include "graphics/blendstate.hpp"
|
#include "graphics/blendstate.hpp"
|
||||||
#include "graphics/rendertarget.hpp"
|
#include "graphics/rendertarget.hpp"
|
||||||
#include "platform-dx/device-dx.hpp"
|
#include "platform-dx/device-dx.hpp"
|
||||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
#include "game/gdeviceinfo.hpp"
|
#include "game/gdeviceinfo.hpp"
|
||||||
|
#include "game/gdevicemanager.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
GraphicsDevice::GraphicsDevice() {
|
GraphicsDevice::GraphicsDevice() {
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#include "game/time.hpp"
|
#include "game/time.hpp"
|
||||||
#include "platform-dx/audioengine-dx.hpp"
|
#include "platform-dx/audioengine-dx.hpp"
|
||||||
#include "platform-dx/game-dx.hpp"
|
#include "platform-dx/game-dx.hpp"
|
||||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
|
#include "game/gdevicemanager.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
Game::Game() {
|
Game::Game() {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#include "platform-dx/gdevicemanager-dx.hpp"
|
#include "game/gdevicemanager.hpp"
|
||||||
#include "platform-dx/device-dx.hpp"
|
|
||||||
#include "platform-dx/game-dx.hpp"
|
|
||||||
#include "graphics/presentparams.hpp"
|
#include "graphics/presentparams.hpp"
|
||||||
#include "graphics/swapchain.hpp"
|
#include "graphics/swapchain.hpp"
|
||||||
|
#include "platform-dx/device-dx.hpp"
|
||||||
|
#include "platform-dx/game-dx.hpp"
|
||||||
#include "platform-dx/implementations.hpp"
|
#include "platform-dx/implementations.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
|
GraphicsDeviceManager::GraphicsDeviceManager(sptr<Game> const& game) : _game(game)
|
||||||
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
|
{
|
||||||
|
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
|
||||||
_information.Adapter = adp;
|
_information.Adapter = adp;
|
||||||
_information.Profile = xna::GraphicsProfile::HiDef;
|
_information.Profile = xna::GraphicsProfile::HiDef;
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ namespace xna {
|
|||||||
parameters->Fullscreen = false;
|
parameters->Fullscreen = false;
|
||||||
_information.Parameters = parameters;
|
_information.Parameters = parameters;
|
||||||
|
|
||||||
if(_game)
|
if (_game)
|
||||||
_information.Window =_game->Window();
|
_information.Window = _game->Window();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDeviceManager::Initialize() {
|
bool GraphicsDeviceManager::Initialize() {
|
||||||
if (!_game)
|
if (!_game)
|
||||||
@ -61,6 +62,44 @@ namespace xna {
|
|||||||
_backBufferHeight = value;
|
_backBufferHeight = value;
|
||||||
_isDeviceDirty = true;
|
_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() {
|
bool GraphicsDeviceManager::CreateDevice() {
|
||||||
if (_isDeviceDirty) {
|
if (_isDeviceDirty) {
|
||||||
@ -68,50 +107,15 @@ namespace xna {
|
|||||||
_information.Parameters->BackBufferHeight = _backBufferHeight;
|
_information.Parameters->BackBufferHeight = _backBufferHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = initWindow();
|
auto result = initWindow(_information, *_game, _backBufferWidth, _backBufferHeight);
|
||||||
|
|
||||||
if (!result) return false;
|
if (!result) return false;
|
||||||
|
|
||||||
return initDevice();
|
return initDevice(_information, *_game, _device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDeviceManager::ChangeDevice() {
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -10,13 +10,12 @@ namespace xna {
|
|||||||
class Game1 : public Game {
|
class Game1 : public Game {
|
||||||
public:
|
public:
|
||||||
Game1() : Game() {
|
Game1() : Game() {
|
||||||
auto _game = reinterpret_cast<Game*>(this);
|
|
||||||
graphics = New<GraphicsDeviceManager>(_game);
|
|
||||||
|
|
||||||
Content()->RootDirectory("Content");
|
Content()->RootDirectory("Content");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize() override {
|
void Initialize() override {
|
||||||
|
auto game = reinterpret_cast<Game*>(this);
|
||||||
|
graphics = New<GraphicsDeviceManager>(game->shared_from_this());
|
||||||
graphics->Initialize();
|
graphics->Initialize();
|
||||||
|
|
||||||
std::any device = graphicsDevice;
|
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) {
|
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
|
||||||
xna::Platform::Init();
|
xna::Platform::Init();
|
||||||
|
|
||||||
auto game = xna::Game1();
|
auto game = snew<Game1>();
|
||||||
const auto result = game.Run();
|
const auto result = game->Run();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,37 @@
|
|||||||
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
|
#define XNA_GAME_GRAPHICSDEVICEMANAGER_HPP
|
||||||
|
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
#include "gdeviceinfo.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class IGraphicsDeviceManager {
|
class GraphicsDeviceManager {
|
||||||
public:
|
public:
|
||||||
virtual ~IGraphicsDeviceManager(){}
|
GraphicsDeviceManager(sptr<Game> const& game);
|
||||||
virtual void ApplyChanges() = 0;
|
~GraphicsDeviceManager() {}
|
||||||
virtual bool Initialize() = 0;
|
void ApplyChanges();
|
||||||
virtual bool ToggleFullScreen() = 0;
|
bool Initialize();
|
||||||
virtual Int PreferredBackBufferWidth() const = 0;
|
bool ToggleFullScreen();
|
||||||
virtual Int PreferredBackBufferHeight() const = 0;
|
Int PreferredBackBufferWidth() const;
|
||||||
virtual void PreferredBackBufferWidth(Int value) = 0;
|
Int PreferredBackBufferHeight() const;
|
||||||
virtual void PreferredBackBufferHeight(Int value) = 0;
|
void PreferredBackBufferWidth(Int value);
|
||||||
|
void PreferredBackBufferHeight(Int value);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr int DefaultBackBufferWidth = 800;
|
||||||
|
static constexpr int DefaultBackBufferHeight = 600;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool CreateDevice() = 0;
|
bool CreateDevice();
|
||||||
virtual void ChangeDevice() = 0;
|
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{};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "dxheaders.hpp"
|
#include "dxheaders.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
class Game : public IGame {
|
class Game : public IGame, public std::enable_shared_from_this<Game> {
|
||||||
public:
|
public:
|
||||||
Game();
|
Game();
|
||||||
|
|
||||||
|
@ -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
|
|
@ -4,7 +4,6 @@
|
|||||||
#include "dx/StepTimer.hpp"
|
#include "dx/StepTimer.hpp"
|
||||||
#include "dxheaders.hpp"
|
#include "dxheaders.hpp"
|
||||||
#include "game-dx.hpp"
|
#include "game-dx.hpp"
|
||||||
#include "gdevicemanager-dx.hpp"
|
|
||||||
#include "init-dx.hpp"
|
#include "init-dx.hpp"
|
||||||
#include "soundeffect-dx.hpp"
|
#include "soundeffect-dx.hpp"
|
||||||
#include "implementations.hpp"
|
#include "implementations.hpp"
|
Loading…
x
Reference in New Issue
Block a user