mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em ApplyChanges em GraphicsDeviceManager
This commit is contained in:
parent
60193f3a75
commit
6663aeb756
@ -39,9 +39,11 @@ namespace xna {
|
|||||||
|
|
||||||
adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter);
|
adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter);
|
||||||
|
|
||||||
setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color,
|
if (adp->supportedDisplayModes && adp->supportedDisplayModes->Count() > 0) {
|
||||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color,
|
||||||
GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode);
|
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||||
|
GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode);
|
||||||
|
}
|
||||||
|
|
||||||
return adp;
|
return adp;
|
||||||
}
|
}
|
||||||
@ -75,12 +77,14 @@ namespace xna {
|
|||||||
|
|
||||||
setOutputVars(pAdapter, adp->deviceName, adp->monitorHandle);
|
setOutputVars(pAdapter, adp->deviceName, adp->monitorHandle);
|
||||||
|
|
||||||
setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color,
|
|
||||||
GraphicsDeviceManager::DefaultBackBufferWidth,
|
|
||||||
GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode);
|
|
||||||
|
|
||||||
adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter);
|
adp->supportedDisplayModes = getSupportedDisplayModes(pAdapter);
|
||||||
|
|
||||||
|
if (adp->supportedDisplayModes && adp->supportedDisplayModes->Count() > 0) {
|
||||||
|
setCurrentDisplayMode(*adp->supportedDisplayModes, SurfaceFormat::Color,
|
||||||
|
GraphicsDeviceManager::DefaultBackBufferWidth,
|
||||||
|
GraphicsDeviceManager::DefaultBackBufferHeight, adp->currentDisplayMode);
|
||||||
|
}
|
||||||
|
|
||||||
adapters.push_back(std::move(adp));
|
adapters.push_back(std::move(adp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ namespace xna {
|
|||||||
GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters) {
|
GraphicsDevice::GraphicsDevice(sptr<GraphicsAdapter> const& adapter, GraphicsProfile const& graphicsProfile, sptr<PresentationParameters> const& presentationParameters) {
|
||||||
impl = unew<PlatformImplementation>();
|
impl = unew<PlatformImplementation>();
|
||||||
impl->_adapter = adapter;
|
impl->_adapter = adapter;
|
||||||
impl->_presentationParameters = presentationParameters;
|
impl->_presentationParameters = presentationParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDevice::Initialize() {
|
bool GraphicsDevice::Initialize() {
|
||||||
|
@ -64,7 +64,12 @@ namespace xna {
|
|||||||
|
|
||||||
int Game::Run() {
|
int Game::Run() {
|
||||||
try {
|
try {
|
||||||
Initialize();
|
if (!_gameWindow->impl->Create()) {
|
||||||
|
Exception::Throw(Exception::FAILED_TO_CREATE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Initialize();
|
||||||
|
|
||||||
if (graphicsDevice == nullptr) {
|
if (graphicsDevice == nullptr) {
|
||||||
MessageBox(nullptr, "O dispositivo gráfico não foi inicializado corretamente", "XN65", MB_OK);
|
MessageBox(nullptr, "O dispositivo gráfico não foi inicializado corretamente", "XN65", MB_OK);
|
||||||
|
@ -14,10 +14,8 @@ namespace xna {
|
|||||||
parameters->BackBufferHeight = backBufferHeight;
|
parameters->BackBufferHeight = backBufferHeight;
|
||||||
parameters->BackBufferFormat = SurfaceFormat::Color;
|
parameters->BackBufferFormat = SurfaceFormat::Color;
|
||||||
parameters->IsFullscreen = false;
|
parameters->IsFullscreen = false;
|
||||||
_information.PresentParameters = parameters;
|
_information.PresentParameters = parameters;
|
||||||
|
_information.Window = game->Window();
|
||||||
if (game)
|
|
||||||
_information.Window = game->Window();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDeviceManager::Initialize() {
|
bool GraphicsDeviceManager::Initialize() {
|
||||||
@ -92,14 +90,13 @@ namespace xna {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicsDeviceManager::CreateDevice() {
|
void GraphicsDeviceManager::CreateDevice() {
|
||||||
if (isDeviceDirty) {
|
if (isDeviceDirty) {
|
||||||
_information.PresentParameters->BackBufferWidth = backBufferWidth;
|
_information.PresentParameters->BackBufferWidth = backBufferWidth;
|
||||||
_information.PresentParameters->BackBufferHeight = backBufferHeight;
|
_information.PresentParameters->BackBufferHeight = backBufferHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = initWindow(_information, *game, backBufferWidth, backBufferHeight);
|
//auto result = initWindow(_information, *game, backBufferWidth, backBufferHeight);
|
||||||
|
|
||||||
//if (!result) return false;
|
//if (!result) return false;
|
||||||
|
|
||||||
@ -135,29 +132,30 @@ namespace xna {
|
|||||||
device->Reset(deviceInformation->PresentParameters, deviceInformation->Adapter);
|
device->Reset(deviceInformation->PresentParameters, deviceInformation->Adapter);
|
||||||
//GraphicsDeviceManager.ConfigureTouchInput(deviceInformation.PresentationParameters);
|
//GraphicsDeviceManager.ConfigureTouchInput(deviceInformation.PresentationParameters);
|
||||||
flag2 = false;
|
flag2 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag2)
|
|
||||||
CreateDevice(*bestDevice);
|
|
||||||
|
|
||||||
auto presentationParameters = device->PresentParameters();
|
|
||||||
|
|
||||||
screenDeviceName = device->Adapter()->DeviceName();
|
|
||||||
|
|
||||||
isReallyFullScreen = presentationParameters.IsFullscreen;
|
|
||||||
|
|
||||||
if (presentationParameters.BackBufferWidth != 0)
|
|
||||||
clientWidth = presentationParameters.BackBufferWidth;
|
|
||||||
|
|
||||||
if (presentationParameters.BackBufferHeight != 0)
|
|
||||||
clientHeight = presentationParameters.BackBufferHeight;
|
|
||||||
|
|
||||||
isDeviceDirty = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flag2)
|
||||||
|
CreateDevice(*bestDevice);
|
||||||
|
|
||||||
|
auto presentationParameters = device->PresentParameters();
|
||||||
|
|
||||||
|
screenDeviceName = device->Adapter()->DeviceName();
|
||||||
|
|
||||||
|
isReallyFullScreen = presentationParameters.IsFullscreen;
|
||||||
|
|
||||||
|
if (presentationParameters.BackBufferWidth != 0)
|
||||||
|
clientWidth = presentationParameters.BackBufferWidth;
|
||||||
|
|
||||||
|
if (presentationParameters.BackBufferHeight != 0)
|
||||||
|
clientHeight = presentationParameters.BackBufferHeight;
|
||||||
|
|
||||||
|
isDeviceDirty = false;
|
||||||
|
|
||||||
//if (flag1) game->Window()->EndScreenDeviceChange(screenDeviceName, clientWidth, clientHeight);
|
//if (flag1) game->Window()->EndScreenDeviceChange(screenDeviceName, clientWidth, clientHeight);
|
||||||
|
|
||||||
currentWindowOrientation = game->Window()->CurrentOrientation();
|
currentWindowOrientation = game->Window()->CurrentOrientation();
|
||||||
|
game->graphicsDevice = this->device;
|
||||||
inDeviceTransition = false;
|
inDeviceTransition = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +169,7 @@ namespace xna {
|
|||||||
ValidateGraphicsDeviceInformation(newInfo);
|
ValidateGraphicsDeviceInformation(newInfo);
|
||||||
|
|
||||||
device = snew<GraphicsDevice>(newInfo.Adapter, newInfo.Profile, newInfo.PresentParameters);
|
device = snew<GraphicsDevice>(newInfo.Adapter, newInfo.Profile, newInfo.PresentParameters);
|
||||||
|
device->Initialize();
|
||||||
|
|
||||||
//device.DeviceResetting += new EventHandler<EventArgs>(this.HandleDeviceResetting);
|
//device.DeviceResetting += new EventHandler<EventArgs>(this.HandleDeviceResetting);
|
||||||
//device.DeviceReset += new EventHandler<EventArgs>(this.HandleDeviceReset);
|
//device.DeviceReset += new EventHandler<EventArgs>(this.HandleDeviceReset);
|
||||||
@ -187,7 +186,7 @@ namespace xna {
|
|||||||
std::vector<uptr<GraphicsAdapter>> adapters;
|
std::vector<uptr<GraphicsAdapter>> adapters;
|
||||||
GraphicsAdapter::Adapters(adapters);
|
GraphicsAdapter::Adapters(adapters);
|
||||||
|
|
||||||
for (size_t i = 0; adapters.size(); ++i) {
|
for (size_t i = 0; i < adapters.size(); ++i) {
|
||||||
auto& adapter = adapters[i];
|
auto& adapter = adapters[i];
|
||||||
|
|
||||||
if (!anySuitableDevice) {
|
if (!anySuitableDevice) {
|
||||||
@ -433,6 +432,9 @@ namespace xna {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter) {
|
bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter) {
|
||||||
return GameWindow::ScreenFromAdapter(adapter) == GameWindow::ScreenFromHandle(windowHandle);
|
const auto fromAdapter = GameWindow::ScreenFromAdapter(adapter);
|
||||||
|
const auto fromHandle = GameWindow::ScreenFromHandle(windowHandle);
|
||||||
|
|
||||||
|
return (fromAdapter && fromHandle) && (*fromAdapter == *fromHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -85,7 +85,8 @@ namespace xna {
|
|||||||
winRect.bottom - winRect.top,
|
winRect.bottom - winRect.top,
|
||||||
TRUE);
|
TRUE);
|
||||||
|
|
||||||
return _windowHandle ? true : false;
|
if (!_windowHandle)
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +94,9 @@ namespace xna {
|
|||||||
// GameWindow
|
// GameWindow
|
||||||
//
|
//
|
||||||
|
|
||||||
gameWindow->handle = reinterpret_cast<intptr_t>(_windowHandle);
|
const auto handle = reinterpret_cast<intptr_t>(_windowHandle);
|
||||||
|
|
||||||
|
gameWindow->handle = handle;
|
||||||
gameWindow->title = _windowTitle;
|
gameWindow->title = _windowTitle;
|
||||||
gameWindow->clientBounds = { _windowPosX, _windowPosY, _windowWidth, _windowHeight };
|
gameWindow->clientBounds = { _windowPosX, _windowPosY, _windowWidth, _windowHeight };
|
||||||
gameWindow->currentOrientation = DisplayOrientation::Default;
|
gameWindow->currentOrientation = DisplayOrientation::Default;
|
||||||
@ -200,15 +203,14 @@ namespace xna {
|
|||||||
|
|
||||||
if (screen->DeviceName() == adapter.DeviceName())
|
if (screen->DeviceName() == adapter.DeviceName())
|
||||||
return std::move(screen);
|
return std::move(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
Exception::Throw("Invalid screen adapter.");
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uptr<Screen> GameWindow::ScreenFromHandle(intptr_t windowHandle) {
|
uptr<Screen> GameWindow::ScreenFromHandle(intptr_t windowHandle) {
|
||||||
auto hMonitor = reinterpret_cast<HMONITOR>(windowHandle);
|
const auto handle = reinterpret_cast<HWND>(windowHandle);
|
||||||
|
auto hMonitor = MonitorFromWindow(handle, MONITOR_DEFAULTTOPRIMARY);
|
||||||
|
|
||||||
if (!hMonitor)
|
if (!hMonitor)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -41,7 +41,7 @@ namespace xna {
|
|||||||
bool IsWindowMinimized() const;
|
bool IsWindowMinimized() const;
|
||||||
|
|
||||||
inline static constexpr Int DefaultClientWidth = 800;
|
inline static constexpr Int DefaultClientWidth = 800;
|
||||||
inline static constexpr Int DefaultClientHeight = 600;
|
inline static constexpr Int DefaultClientHeight = 480;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String title;
|
String title;
|
||||||
@ -53,6 +53,7 @@ namespace xna {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
friend struct PlatformImplementation;
|
||||||
uptr<PlatformImplementation> impl = nullptr;
|
uptr<PlatformImplementation> impl = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,7 @@ namespace xna {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class GameWindow;
|
friend class GameWindow;
|
||||||
GameWindow*& gameWindow;
|
GameWindow* gameWindow = nullptr;
|
||||||
|
|
||||||
HINSTANCE _hInstance{ nullptr };
|
HINSTANCE _hInstance{ nullptr };
|
||||||
HWND _windowHandle{ nullptr };
|
HWND _windowHandle{ nullptr };
|
||||||
|
@ -17,7 +17,8 @@ namespace xna {
|
|||||||
void Initialize() override {
|
void Initialize() override {
|
||||||
auto game = reinterpret_cast<Game*>(this);
|
auto game = reinterpret_cast<Game*>(this);
|
||||||
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
graphics = snew<GraphicsDeviceManager>(game->shared_from_this());
|
||||||
graphics->Initialize();
|
//graphics->Initialize();
|
||||||
|
graphics->ApplyChanges();
|
||||||
|
|
||||||
std::any device = graphicsDevice;
|
std::any device = graphicsDevice;
|
||||||
services->AddService(*typeof<GraphicsDevice>(), device);
|
services->AddService(*typeof<GraphicsDevice>(), device);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user