2024-06-03 21:55:09 -03:00
|
|
|
|
#include "xna/game/gdevicemanager.hpp"
|
|
|
|
|
#include "xna/graphics/presentparams.hpp"
|
|
|
|
|
#include "xna/graphics/swapchain.hpp"
|
2024-07-07 16:06:05 -03:00
|
|
|
|
#include "xna/platform/dx.hpp"
|
2024-03-30 14:25:08 -03:00
|
|
|
|
|
|
|
|
|
namespace xna {
|
2024-05-24 14:42:12 -03:00
|
|
|
|
GraphicsDeviceManager::GraphicsDeviceManager(sptr<Game> const& game) : _game(game)
|
|
|
|
|
{
|
|
|
|
|
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
|
2024-05-24 12:31:24 -03:00
|
|
|
|
_information.Adapter = adp;
|
|
|
|
|
_information.Profile = xna::GraphicsProfile::HiDef;
|
|
|
|
|
|
|
|
|
|
auto parameters = snew<PresentationParameters>();
|
|
|
|
|
parameters->BackBufferWidth = _backBufferWidth;
|
|
|
|
|
parameters->BackBufferHeight = _backBufferHeight;
|
|
|
|
|
parameters->BackBufferFormat = SurfaceFormat::Color;
|
|
|
|
|
parameters->Fullscreen = false;
|
|
|
|
|
_information.Parameters = parameters;
|
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
|
if (_game)
|
|
|
|
|
_information.Window = _game->Window();
|
|
|
|
|
}
|
2024-04-01 11:29:32 -03:00
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
bool GraphicsDeviceManager::Initialize() {
|
|
|
|
|
if (!_game)
|
|
|
|
|
return false;
|
2024-04-16 16:13:36 -03:00
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
return CreateDevice();
|
2024-04-01 11:29:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-30 14:25:08 -03:00
|
|
|
|
void GraphicsDeviceManager::ApplyChanges() {
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
bool GraphicsDeviceManager::ToggleFullScreen() {
|
2024-05-24 22:26:10 -03:00
|
|
|
|
if (!_game || !_game->graphicsDevice || !_game->graphicsDevice->impl->_swapChain)
|
2024-04-26 10:13:00 -03:00
|
|
|
|
return false;
|
2024-04-22 16:14:55 -03:00
|
|
|
|
|
2024-05-24 22:26:10 -03:00
|
|
|
|
auto& swap = _game->graphicsDevice->impl->_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
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
_isFullScreen = !state;
|
2024-04-26 10:37:49 -03:00
|
|
|
|
|
|
|
|
|
return true;
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
void GraphicsDeviceManager::PreferredBackBufferWidth(Int value) {
|
|
|
|
|
_backBufferWidth = value;
|
|
|
|
|
_isDeviceDirty = true;
|
|
|
|
|
}
|
2024-03-30 14:25:08 -03:00
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
void GraphicsDeviceManager::PreferredBackBufferHeight(Int value) {
|
|
|
|
|
_backBufferHeight = value;
|
|
|
|
|
_isDeviceDirty = true;
|
|
|
|
|
}
|
2024-05-24 14:42:12 -03:00
|
|
|
|
|
|
|
|
|
bool initWindow(GraphicsDeviceInformation& info, Game& game, int backWidth, int backHeight)
|
2024-04-26 10:13:00 -03:00
|
|
|
|
{
|
2024-05-24 14:42:12 -03:00
|
|
|
|
auto window = info.Window;
|
2024-04-26 10:13:00 -03:00
|
|
|
|
|
|
|
|
|
if (!window) {
|
2024-05-24 14:42:12 -03:00
|
|
|
|
window = game.Window();
|
|
|
|
|
info.Window = window;
|
2024-04-26 10:13:00 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
|
window->impl->Size(backWidth, backHeight);
|
2024-04-26 10:13:00 -03:00
|
|
|
|
|
2024-05-24 12:31:24 -03:00
|
|
|
|
if (!window->impl->Create()) {
|
2024-04-26 10:13:00 -03:00
|
|
|
|
MessageBox(nullptr, "Falha na cria<69><61>o da janela", "XN65", MB_OK);
|
|
|
|
|
return false;
|
2024-04-01 11:29:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
|
info.Parameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
|
2024-04-26 10:13:00 -03:00
|
|
|
|
|
|
|
|
|
return true;
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
|
bool initDevice(GraphicsDeviceInformation& info, Game& game, sptr<GraphicsDevice>& device)
|
2024-06-05 09:26:33 -03:00
|
|
|
|
{
|
2024-06-22 11:52:21 -03:00
|
|
|
|
device = snew<GraphicsDevice>(info);
|
2024-04-26 10:13:00 -03:00
|
|
|
|
|
2024-06-05 09:26:33 -03:00
|
|
|
|
if (!device->Initialize()) {
|
|
|
|
|
MessageBox(info.Window->impl->WindowHandle(), "Falha na inicializa<7A><61>o do dispositivo gr<67>fico", "XN65", MB_OK);
|
2024-05-24 14:42:12 -03:00
|
|
|
|
device = nullptr;
|
2024-04-26 10:13:00 -03:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:42:12 -03:00
|
|
|
|
game.graphicsDevice = device;
|
2024-04-26 10:37:49 -03:00
|
|
|
|
|
|
|
|
|
return true;
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|
2024-05-24 14:42:12 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GraphicsDeviceManager::CreateDevice() {
|
|
|
|
|
if (_isDeviceDirty) {
|
|
|
|
|
_information.Parameters->BackBufferWidth = _backBufferWidth;
|
|
|
|
|
_information.Parameters->BackBufferHeight = _backBufferHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto result = initWindow(_information, *_game, _backBufferWidth, _backBufferHeight);
|
|
|
|
|
|
|
|
|
|
if (!result) return false;
|
|
|
|
|
|
|
|
|
|
return initDevice(_information, *_game, _device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphicsDeviceManager::ChangeDevice() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|