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

Implementa segunda sobrecarga GraphicsDeviceManager::AddDevices

This commit is contained in:
Danilo 2024-07-30 10:43:39 -03:00
parent 7dfd3b3fbd
commit 38e6779e12
6 changed files with 85 additions and 15 deletions

View File

@ -101,7 +101,7 @@ namespace xna {
impl->_adapter = info.Adapter;
impl->_gameWindow = info.Window;
impl->_presentationParameters = info.Parameters;
impl->_presentationParameters = info.PresentParameters;
}
bool GraphicsDevice::Initialize() {

View File

@ -13,8 +13,8 @@ namespace xna {
parameters->BackBufferWidth = backBufferWidth;
parameters->BackBufferHeight = backBufferHeight;
parameters->BackBufferFormat = SurfaceFormat::Color;
parameters->Fullscreen = false;
_information.Parameters = parameters;
parameters->IsFullscreen = false;
_information.PresentParameters = parameters;
if (game)
_information.Window = game->Window();
@ -72,7 +72,7 @@ namespace xna {
return false;
}
info.Parameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
info.PresentParameters->DeviceWindowHandle = reinterpret_cast<intptr_t>(window->impl->WindowHandle());
return true;
}
@ -95,8 +95,8 @@ namespace xna {
void GraphicsDeviceManager::CreateDevice() {
if (isDeviceDirty) {
_information.Parameters->BackBufferWidth = backBufferWidth;
_information.Parameters->BackBufferHeight = backBufferHeight;
_information.PresentParameters->BackBufferWidth = backBufferWidth;
_information.PresentParameters->BackBufferHeight = backBufferHeight;
}
auto result = initWindow(_information, *game, backBufferWidth, backBufferHeight);
@ -109,7 +109,7 @@ namespace xna {
void GraphicsDeviceManager::ChangeDevice() {
}
void GraphicsDeviceManager::AddDevice(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) {
void GraphicsDeviceManager::AddDevices(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) {
const auto handle = game->Window()->Handle();
std::vector<uptr<GraphicsAdapter>> adapters;
@ -122,9 +122,60 @@ namespace xna {
if (!IsWindowOnAdapter(handle, *adapter))
continue;
}
if (adapter->IsProfileSupported(graphicsProfile)) {
auto baseDeviceInfo = snew<GraphicsDeviceInformation>();
baseDeviceInfo->Adapter = std::move(adapter);
baseDeviceInfo->Profile = graphicsProfile;
baseDeviceInfo->PresentParameters = snew<PresentationParameters>();
baseDeviceInfo->PresentParameters->DeviceWindowHandle = handle;
baseDeviceInfo->PresentParameters->MultiSampleCount = 0;
baseDeviceInfo->PresentParameters->IsFullscreen = isFullScreen;
baseDeviceInfo->PresentParameters->PresentationInterval = synchronizeWithVerticalRetrace ? PresentInterval::One : PresentInterval::Immediate;
const auto& currentDisplayMode = baseDeviceInfo->Adapter->CurrentDisplayMode();
AddDevices(*baseDeviceInfo->Adapter, *currentDisplayMode, baseDeviceInfo, foundDevices);
if (isFullScreen) {
//TODO
}
}
}
}
void GraphicsDeviceManager::AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr<GraphicsDeviceInformation>& baseDeviceInfo, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices) {
auto deviceInformation = snew<GraphicsDeviceInformation>(*baseDeviceInfo);
if (isFullScreen)
{
deviceInformation->PresentParameters->BackBufferWidth = mode.Width();
deviceInformation->PresentParameters->BackBufferHeight = mode.Height();
}
else if (useResizedBackBuffer) {
deviceInformation->PresentParameters->BackBufferWidth = resizedBackBufferWidth;
deviceInformation->PresentParameters->BackBufferHeight = resizedBackBufferHeight;
}
else {
deviceInformation->PresentParameters->BackBufferWidth = backBufferWidth;
deviceInformation->PresentParameters->BackBufferHeight = backBufferHeight;
}
SurfaceFormat selectedFormat;
DepthFormat selectedDepthFormat;
int selectedMultiSampleCount;
adapter.QueryBackBufferFormat(deviceInformation->Profile, mode.Format(), depthStencilFormat, allowMultiSampling ? 16 : 0, selectedFormat, selectedDepthFormat, selectedMultiSampleCount);
deviceInformation->PresentParameters->BackBufferFormat = selectedFormat;
deviceInformation->PresentParameters->DepthStencilFormat = selectedDepthFormat;
deviceInformation->PresentParameters->MultiSampleCount = selectedMultiSampleCount;
if (std::find(foundDevices.begin(), foundDevices.end(), deviceInformation) != foundDevices.end())
return;
foundDevices.push_back(deviceInformation);
}
bool IsWindowOnAdapter(intptr_t windowHandle, GraphicsAdapter const& adapter) {
return GameWindow::ScreenFromAdapter(adapter) == GameWindow::ScreenFromHandle(windowHandle);
}

View File

@ -64,7 +64,7 @@ namespace xna {
impl->dxFullScreenDescription.RefreshRate.Denominator = 1;
impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
impl->dxFullScreenDescription.Windowed = !parameters->Fullscreen;
impl->dxFullScreenDescription.Windowed = !parameters->IsFullscreen;
HWND hwnd = reinterpret_cast<HWND>(parameters->DeviceWindowHandle);
return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription);

View File

@ -8,8 +8,8 @@ namespace xna {
public:
sptr<GraphicsAdapter> Adapter = nullptr;
xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach };
sptr<xna::PresentationParameters> Parameters = nullptr;
sptr<GameWindow> Window = nullptr;
sptr<xna::PresentationParameters> PresentParameters = nullptr;
sptr<GameWindow> Window = nullptr;
};
}

View File

@ -104,6 +104,15 @@ namespace xna {
isDeviceDirty = true;
}
constexpr bool PreferMultiSampling() const {
return allowMultiSampling;
}
constexpr void PreferMultiSampling(bool value) {
allowMultiSampling = value;
isDeviceDirty = true;
}
//Gets or sets the display orientations that are available if automatic rotation and scaling is enabled.
constexpr DisplayOrientation SupportedOrientations() const {
return supportedOrientations;
@ -134,7 +143,8 @@ namespace xna {
private:
void ChangeDevice(bool forceCreate){}
void AddDevice(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
void AddDevices(bool anySuitableDevice, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
void AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr<GraphicsDeviceInformation>& baseDeviceInfo, std::vector<sptr<GraphicsDeviceInformation>>& foundDevices);
protected:
void CreateDevice();
@ -153,11 +163,17 @@ namespace xna {
bool isFullScreen{ false };
Int backBufferWidth{ DefaultBackBufferWidth };
Int backBufferHeight{ DefaultBackBufferHeight };
GraphicsProfile graphicsProfile;
GraphicsProfile graphicsProfile{GraphicsProfile::HiDef};
DepthFormat depthStencilFormat{ DepthFormat::Depth24 };
SurfaceFormat backBufferFormat;
DisplayOrientation supportedOrientations;
SurfaceFormat backBufferFormat{SurfaceFormat::Color};
DisplayOrientation supportedOrientations{DisplayOrientation::Default};
bool synchronizeWithVerticalRetrace{ true };
bool useResizedBackBuffer{ false };
Int resizedBackBufferWidth{ 0 };
Int resizedBackBufferHeight{ 0 };
bool allowMultiSampling{ false };
std::vector<sptr<GraphicsDeviceInformation>> foundDevices;
};
}

View File

@ -12,7 +12,10 @@ namespace xna {
SurfaceFormat BackBufferFormat{ SurfaceFormat::Color };
SwapEffect PresentationSwapEffect{ SwapEffect::FlipDiscard };
intptr_t DeviceWindowHandle{ 0 };
bool Fullscreen{ false };
bool IsFullscreen{ false };
Int MultiSampleCount{ 0 };
PresentInterval PresentationInterval{ PresentInterval::Default };
DepthFormat DepthStencilFormat{ DepthFormat::None };
};
}