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

118 lines
2.9 KiB
C++
Raw Normal View History

#include "platform-dx/gdevicemanager-dx.hpp"
#include "platform-dx/device-dx.hpp"
#include "platform-dx/game-dx.hpp"
#include "platform-dx/window-dx.hpp"
#include "platform-dx/gdeviceinfo-dx.hpp"
2024-05-22 09:55:25 -03:00
#include "graphics/presentparams.hpp"
2024-05-22 20:05:52 -03:00
#include "graphics/swapchain.hpp"
#include "platform-dx/implementations.hpp"
namespace xna {
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
_information.Adapter(adp);
_information.GraphicsProfile(xna::GraphicsProfile::HiDef);
PresentationParameters parameters;
2024-05-22 09:55:25 -03:00
parameters.BackBufferWidth = _backBufferWidth;
parameters.BackBufferHeight = _backBufferHeight;
parameters.BackBufferFormat = SurfaceFormat::Color;
parameters.Fullscreen = false;
_information.PresentationParameters(parameters);
if(_game) _information.Window(_game->Window());
}
bool GraphicsDeviceManager::Initialize() {
if (!_game)
return false;
return CreateDevice();
}
void GraphicsDeviceManager::ApplyChanges() {
}
bool GraphicsDeviceManager::ToggleFullScreen() {
2024-05-06 14:54:13 -03:00
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->_swapChain)
return false;
2024-04-22 16:14:55 -03:00
2024-05-06 14:54:13 -03:00
auto& swap = _game->graphicsDevice->_swapChain;
2024-04-22 16:14:55 -03:00
BOOL state = false;
2024-05-22 20:05:52 -03:00
auto hr = swap->impl->dxSwapChain->GetFullscreenState(&state, nullptr);
2024-04-23 16:11:17 -03:00
2024-04-26 10:37:49 -03:00
if (FAILED(hr)) return false;
2024-04-23 16:11:17 -03:00
2024-05-22 20:05:52 -03:00
hr = swap->impl->dxSwapChain->SetFullscreenState(!state, nullptr);
2024-04-23 16:11:17 -03:00
2024-04-26 10:37:49 -03:00
if (FAILED(hr)) return false;
2024-04-23 16:11:17 -03:00
_isFullScreen = !state;
2024-04-26 10:37:49 -03:00
return true;
}
void GraphicsDeviceManager::PreferredBackBufferWidth(Int value) {
_backBufferWidth = value;
_isDeviceDirty = true;
}
void GraphicsDeviceManager::PreferredBackBufferHeight(Int value) {
_backBufferHeight = value;
_isDeviceDirty = true;
}
bool GraphicsDeviceManager::CreateDevice() {
if (_isDeviceDirty) {
2024-05-22 09:55:25 -03:00
_information._parameters.BackBufferWidth = _backBufferWidth;
_information._parameters.BackBufferHeight = _backBufferHeight;
}
2024-04-26 10:37:49 -03:00
auto result = initWindow();
if (!result) return false;
2024-04-22 16:14:55 -03:00
2024-04-26 10:37:49 -03:00
return initDevice();
}
void GraphicsDeviceManager::ChangeDevice() {
}
bool GraphicsDeviceManager::initWindow()
{
auto window = _information.Window();
if (!window) {
window = _game->Window();
_information.Window(window);
}
window->Size(_backBufferWidth, _backBufferHeight);
if (!window->Create()) {
MessageBox(nullptr, "Falha na cria<69><61>o da janela", "XN65", MB_OK);
return false;
}
2024-05-22 09:55:25 -03:00
_information._parameters.DeviceWindowHandle = reinterpret_cast<intptr_t>(window->WindowHandle());
return true;
}
bool GraphicsDeviceManager::initDevice()
{
auto window = _information.Window();
_device = New<GraphicsDevice>(_information);
if (!_device->Initialize(*window)) {
MessageBox(window->WindowHandle(), "Falha na inicializa<7A><61>o do dispositivo gr<67>fico", "XN65", MB_OK);
_device = nullptr;
return false;
}
2024-05-06 14:54:13 -03:00
_game->graphicsDevice = _device;
2024-04-26 10:37:49 -03:00
return true;
}
}