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

Implementa mudanças no dispositivo gráfico

This commit is contained in:
Danilo 2024-04-01 11:29:32 -03:00
parent 17365b2af3
commit 399e8f8c24
11 changed files with 77 additions and 29 deletions

View File

@ -12,8 +12,8 @@ namespace xna {
constexpr Rectangle() = default;
constexpr Rectangle(const Int& Height, const Int& Width, const Int& X, const Int& Y)
: Height(Height), Width(Width), X(X), Y(Y) {}
constexpr Rectangle(const Int& X, const Int& Y, const Int& Width, const Int& Height):
X(X), Y(Y), Width(Width), Height(Height) {}
};
}

View File

@ -13,6 +13,8 @@ namespace xna {
virtual void PresentationParameters(xna::PresentationParameters const& value) = 0;
virtual xna::GraphicsProfile GraphicsProfile() const = 0;
virtual void GraphicsProfile(xna::GraphicsProfile value) = 0;
virtual PGameWindow Window() const = 0;
virtual void Window(PGameWindow const& window) = 0;
};
}

View File

@ -9,8 +9,7 @@
namespace xna {
GraphicsDevice::GraphicsDevice() {
_blendState = BlendState::NonPremultiplied();
_adapter = GraphicsAdapter::DefaultAdapter();
auto a = _adapter->DeviceId();
_adapter = GraphicsAdapter::DefaultAdapter();
}
GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) {
@ -32,9 +31,11 @@ namespace xna {
if (_context) {
_context->Release();
_context = nullptr;
}
}
gameWindow.Size(_presentParameters.BackBufferWidth, _presentParameters.BackBufferHeight);
const auto bounds = gameWindow.ClientBounds();
_viewport = xna::Viewport(0.0F, 0.0F,
static_cast<float>(bounds.Width),
static_cast<float>(bounds.Height),
@ -103,7 +104,7 @@ namespace xna {
bool GraphicsDevice::createDevice() {
#if _DEBUG
_createDeviceFlags |= D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
#endif
#endif
if FAILED(
D3D11CreateDevice(

View File

@ -13,18 +13,11 @@ namespace xna {
_gameWindow->Size(
GraphicsDeviceManager::DefaultBackBufferWidth,
GraphicsDeviceManager::DefaultBackBufferHeight, false);
_graphicsDevice = New<GraphicsDevice>();
}
int Game::Run() {
if (!_gameWindow->Create()) {
MessageBox(nullptr, "Falha na criação da janela", "Xna Game Engine", MB_OK);
return EXIT_FAILURE;
}
if (!_graphicsDevice->Initialize(*_gameWindow)) {
MessageBox(nullptr, "Falha na inicialização do dispositivo gráfico", "Xna Game Engine", MB_OK);
int Game::Run() {
if (_graphicsDevice == nullptr) {
MessageBox(nullptr, "O dispositivo gráfico não foi inicializar corretamente", "Xna Game Engine", MB_OK);
return EXIT_FAILURE;
}

View File

@ -26,8 +26,10 @@ namespace xna {
virtual void Initialize() override{}
virtual void Update(GameTime const& gameTime) override{}
protected:
public:
PGraphicsDevice _graphicsDevice{ nullptr };
protected:
PGameWindow _gameWindow{ nullptr };
GameClock _clock{};

View File

@ -3,6 +3,7 @@
#include "../game/gdeviceinfo.hpp"
#include "adapter-dx.hpp"
#include "window-dx.hpp"
namespace xna {
class GraphicsDeviceInformation : public IGraphicsDeviceInformation {
@ -15,26 +16,35 @@ namespace xna {
_adapter = value;
}
inline virtual xna::PresentationParameters PresentationParameters() const override{
constexpr virtual xna::PresentationParameters PresentationParameters() const override{
return _parameters;
};
inline virtual void PresentationParameters(xna::PresentationParameters const& value) override{
constexpr virtual void PresentationParameters(xna::PresentationParameters const& value) override{
_parameters = value;
};
inline virtual xna::GraphicsProfile GraphicsProfile() const override {
constexpr virtual xna::GraphicsProfile GraphicsProfile() const override {
return _profile;
};
inline virtual void GraphicsProfile(xna::GraphicsProfile value) override {
constexpr virtual void GraphicsProfile(xna::GraphicsProfile value) override {
_profile = value;
};
inline virtual PGameWindow Window() const override {
return _window;
}
inline virtual void Window(PGameWindow const& window) override {
_window = window;
}
private:
PGraphicsAdapter _adapter{ nullptr };
xna::GraphicsProfile _profile{xna::GraphicsProfile::Reach};
xna::PresentationParameters _parameters{};
PGameWindow _window{ nullptr };
};
}

View File

@ -5,19 +5,46 @@
#include "gdeviceinfo-dx.hpp"
namespace xna {
GraphicsDeviceManager::GraphicsDeviceManager(Game* game) : _game(game){
GraphicsDeviceInformation information;
const auto adp = GraphicsAdapter::DefaultAdapter();
information.Adapter(adp);
information.GraphicsProfile(xna::GraphicsProfile::HiDef);
PresentationParameters parameters;
parameters.BackBufferWidth = _backBufferWidth;
parameters.BackBufferHeight = _backBufferHeight;
information.PresentationParameters(parameters);
information.Window(game->Window());
CreateDevice(information);
}
void GraphicsDeviceManager::ApplyChanges() {
//_game->_graphicsDevice = _device;
}
void GraphicsDeviceManager::ToggleFullScreen() {
}
void GraphicsDeviceManager::CreateDevice(GraphicsDeviceInformation const& info) {
_device = New<GraphicsDevice>();
_device = New<GraphicsDevice>(info);
auto window = _game->Window();
window->Size(_backBufferWidth, _backBufferHeight);
_device->Initialize(*window);
if (!window->Create()) {
MessageBox(nullptr, "Falha na criação da janela", "Xna Game Engine", MB_OK);
return;
}
//_device->Initialize(*window);
if (!_device->Initialize(*window)) {
MessageBox(nullptr, "Falha na inicialização do dispositivo gráfico", "Xna Game Engine", MB_OK);
return;
}
_game->_graphicsDevice = _device;
}
void GraphicsDeviceManager::ChangeDevice() {

View File

@ -6,7 +6,7 @@
namespace xna {
class GraphicsDeviceManager : public IGraphicsDeviceManager {
public:
GraphicsDeviceManager(Game* game) : _game(game){}
GraphicsDeviceManager(Game* game);
virtual void ApplyChanges() override;
virtual void ToggleFullScreen() override;

View File

@ -39,7 +39,11 @@ namespace xna {
auto dxdevice = _device->_device;
if FAILED(dxFactory->CreateSwapChain(dxdevice, &_swapDescription, &_swapChain))
{
dxFactory->Release();
dxFactory = nullptr;
return false;
}
dxFactory->Release();
dxFactory = nullptr;

View File

@ -13,6 +13,11 @@ using namespace xna;
//}
class Game1 : public Game {
public:
Game1() {
manager = New<GraphicsDeviceManager>(this);
}
virtual void Update(GameTime const& gameTime) {
Game::Update(gameTime);
@ -23,13 +28,16 @@ class Game1 : public Game {
Game::Draw(gameTime);
}
private:
PGraphicsDeviceManager manager;
};
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB");
int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
/*FileStream stream("D:/VS_EXPBSLN_x64_enu.CAB");
auto pos = stream.Position();
auto len = stream.Length();
pos = stream.Position();
pos = stream.Position();*/
Game1 game;
game.Run();

View File

@ -11,5 +11,6 @@
#include "platform/device-dx.hpp"
#include "platform/game-dx.hpp"
#include "csharp/stream.hpp"
#include "platform/gdevicemanager-dx.hpp"
// TODO: Reference additional headers your program requires here.