2024-03-30 14:25:08 -03:00
|
|
|
|
#include "gdevicemanager-dx.hpp"
|
|
|
|
|
#include "device-dx.hpp"
|
|
|
|
|
#include "game-dx.hpp"
|
|
|
|
|
#include "window-dx.hpp"
|
|
|
|
|
#include "gdeviceinfo-dx.hpp"
|
2024-04-22 16:14:55 -03:00
|
|
|
|
#include "adapter-dx.hpp"
|
2024-04-26 10:13:00 -03:00
|
|
|
|
#include "presentparameters-dx.hpp"
|
2024-03-30 14:25:08 -03:00
|
|
|
|
|
|
|
|
|
namespace xna {
|
2024-04-16 16:13:36 -03:00
|
|
|
|
GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) {
|
2024-04-26 10:13:00 -03:00
|
|
|
|
sptr<GraphicsAdapter> adp = GraphicsAdapter::DefaultAdapter();
|
|
|
|
|
_information.Adapter(adp);
|
|
|
|
|
_information.GraphicsProfile(xna::GraphicsProfile::HiDef);
|
2024-04-16 16:13:36 -03:00
|
|
|
|
|
2024-04-01 11:29:32 -03:00
|
|
|
|
PresentationParameters parameters;
|
2024-04-26 10:13:00 -03:00
|
|
|
|
parameters.backBufferWidth = _backBufferWidth;
|
|
|
|
|
parameters.backBufferHeight = _backBufferHeight;
|
|
|
|
|
parameters.backBufferFormat = SurfaceFormat::Color;
|
|
|
|
|
parameters.fullscreen = false;
|
|
|
|
|
_information.PresentationParameters(parameters);
|
2024-04-01 11:29:32 -03:00
|
|
|
|
|
2024-04-26 10:13:00 -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-04-22 16:14:55 -03:00
|
|
|
|
if (!_game || !_game->_graphicsDevice || !_game->_graphicsDevice->_swapChain)
|
2024-04-26 10:13:00 -03:00
|
|
|
|
return false;
|
2024-04-22 16:14:55 -03:00
|
|
|
|
|
|
|
|
|
auto& swap = _game->_graphicsDevice->_swapChain;
|
|
|
|
|
|
|
|
|
|
BOOL state = false;
|
2024-04-23 16:11:17 -03:00
|
|
|
|
auto hr = swap->dxSwapChain->GetFullscreenState(&state, nullptr);
|
|
|
|
|
|
2024-04-26 10:37:49 -03:00
|
|
|
|
if (FAILED(hr)) return false;
|
2024-04-23 16:11:17 -03:00
|
|
|
|
|
|
|
|
|
hr = swap->dxSwapChain->SetFullscreenState(!state, nullptr);
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GraphicsDeviceManager::CreateDevice() {
|
|
|
|
|
if (_isDeviceDirty) {
|
|
|
|
|
_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();
|
2024-04-26 10:13:00 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GraphicsDeviceManager::ChangeDevice() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GraphicsDeviceManager::initWindow()
|
|
|
|
|
{
|
|
|
|
|
auto window = _information.Window();
|
|
|
|
|
|
|
|
|
|
if (!window) {
|
|
|
|
|
window = _game->Window();
|
|
|
|
|
_information.Window(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window->Size(_backBufferWidth, _backBufferHeight);
|
|
|
|
|
|
2024-04-01 11:29:32 -03:00
|
|
|
|
if (!window->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-04-26 10:13:00 -03:00
|
|
|
|
_information._parameters.windowHandle = window->WindowHandle();
|
|
|
|
|
|
|
|
|
|
return true;
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 10:13:00 -03:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_game->_graphicsDevice = _device;
|
2024-04-26 10:37:49 -03:00
|
|
|
|
|
|
|
|
|
return true;
|
2024-03-30 14:25:08 -03:00
|
|
|
|
}
|
|
|
|
|
}
|