Use fullscreen desktop for vulkan

This commit is contained in:
Benau 2022-08-28 10:55:06 +08:00
parent e6f8dcfdb0
commit bba636263e
5 changed files with 79 additions and 19 deletions

View File

@ -358,6 +358,7 @@ namespace GE
{ return m_separate_rtt_texture; } { return m_separate_rtt_texture; }
void handleDeletedTextures(); void handleDeletedTextures();
void addRTTPolyCount(unsigned count) { m_rtt_polycount += count; } void addRTTPolyCount(unsigned count) { m_rtt_polycount += count; }
SDL_Window* getWindow() const { return m_window; }
private: private:
struct SwapChainSupportDetails struct SwapChainSupportDetails
{ {

View File

@ -58,7 +58,6 @@ extern "C" int Android_disablePadding();
namespace irr namespace irr
{ {
//! constructor //! constructor
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param) CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), : CIrrDeviceStub(param),
@ -93,7 +92,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
#ifndef MOBILE_STK #ifndef MOBILE_STK
// Prevent fullscreen minimizes when losing focus // Prevent fullscreen minimizes when losing focus
if (CreationParams.Fullscreen) if (CreationParams.Fullscreen &&
CreationParams.DriverType != video::EDT_VULKAN)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif #endif
@ -155,7 +155,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
} }
else else
return; return;
updateNativeScale(); updateNativeScale(&Width, &Height);
Width = (u32)((f32)Width * NativeScaleX); Width = (u32)((f32)Width * NativeScaleX);
Height = (u32)((f32)Height * NativeScaleY); Height = (u32)((f32)Height * NativeScaleY);
CreationParams.WindowSize.Width = Width; CreationParams.WindowSize.Width = Width;
@ -181,7 +181,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
} }
void CIrrDeviceSDL::updateNativeScale() void CIrrDeviceSDL::updateNativeScale(u32* saving_width, u32* saving_height)
{ {
int width, height = 0; int width, height = 0;
SDL_GetWindowSize(Window, &width, &height); SDL_GetWindowSize(Window, &width, &height);
@ -198,6 +198,10 @@ void CIrrDeviceSDL::updateNativeScale()
} }
NativeScaleX = (f32)real_width / (f32)width; NativeScaleX = (f32)real_width / (f32)width;
NativeScaleY = (f32)real_height / (f32)height; NativeScaleY = (f32)real_height / (f32)height;
if (saving_width)
*saving_width = width;
if (saving_height)
*saving_height = height;
} }
@ -328,6 +332,29 @@ bool versionCorrect(int major, int minor)
} }
// Used in OptionsScreenVideo for live fullscreen toggle for vulkan driver
extern "C" void update_fullscreen_desktop(int val)
{
GE::GEVulkanDriver* gevk = GE::getVKDriver();
if (!gevk)
return;
SDL_Window* window = gevk->getWindow();
int prev_width = 0;
int prev_height = 0;
SDL_GetWindowSize(window, &prev_width, &prev_height);
if (val != 0)
val = SDL_WINDOW_FULLSCREEN_DESKTOP;
SDL_SetWindowFullscreen(window, val);
if (val == 0)
{
SDL_SetWindowSize(window, prev_width * 0.8f, prev_height * 0.8f);
SDL_RaiseWindow(window);
}
}
// Used in OptionsScreenVideo for live updating vertical sync config // Used in OptionsScreenVideo for live updating vertical sync config
extern "C" void update_swap_interval(int swap_interval) extern "C" void update_swap_interval(int swap_interval)
{ {
@ -394,7 +421,17 @@ bool CIrrDeviceSDL::createWindow()
#endif #endif
if (CreationParams.Fullscreen) if (CreationParams.Fullscreen)
flags |= SDL_WINDOW_FULLSCREEN; {
#ifndef MOBILE_STK
if (CreationParams.DriverType == video::EDT_VULKAN)
{
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
CreationParams.Fullscreen = false;
}
else
#endif
flags |= SDL_WINDOW_FULLSCREEN;
}
if (CreationParams.DriverType == video::EDT_OPENGL || if (CreationParams.DriverType == video::EDT_OPENGL ||
CreationParams.DriverType == video::EDT_OGLES2) CreationParams.DriverType == video::EDT_OGLES2)
@ -651,7 +688,7 @@ void CIrrDeviceSDL::createDriver()
{ {
VideoDriver = video::createVulkanDriver(CreationParams, FileSystem, Window, this); VideoDriver = video::createVulkanDriver(CreationParams, FileSystem, Window, this);
// SDL_Vulkan_GetDrawableSize only works after driver is created // SDL_Vulkan_GetDrawableSize only works after driver is created
updateNativeScale(); updateNativeScale(&Width, &Height);
Width = (u32)((f32)Width * NativeScaleX); Width = (u32)((f32)Width * NativeScaleX);
Height = (u32)((f32)Height * NativeScaleY); Height = (u32)((f32)Height * NativeScaleY);
} }

View File

@ -28,7 +28,6 @@ class MoltenVK;
class CIrrDeviceSDL : public CIrrDeviceStub, video::IImagePresenter class CIrrDeviceSDL : public CIrrDeviceStub, video::IImagePresenter
{ {
public: public:
//! constructor //! constructor
CIrrDeviceSDL(const SIrrlichtCreationParameters& param); CIrrDeviceSDL(const SIrrlichtCreationParameters& param);
@ -330,7 +329,7 @@ class MoltenVK;
MoltenVK* m_moltenvk; MoltenVK* m_moltenvk;
#endif #endif
void createGUIAndVulkanScene(); void createGUIAndVulkanScene();
void updateNativeScale(); void updateNativeScale(u32* saving_width = NULL, u32* saving_height = NULL);
}; };
} // end namespace irr } // end namespace irr

View File

@ -608,8 +608,11 @@ void IrrDriver::initDevice()
{ {
Log::fatal("irr_driver", "Couldn't initialise irrlicht device. Quitting.\n"); Log::fatal("irr_driver", "Couldn't initialise irrlicht device. Quitting.\n");
} }
UserConfigParams::m_width = (unsigned)((float)UserConfigParams::m_real_width * m_device->getNativeScaleX()); m_actual_screen_size = m_device->getVideoDriver()->getCurrentRenderTargetSize();
UserConfigParams::m_height = (unsigned)((float)UserConfigParams::m_real_height * m_device->getNativeScaleY()); UserConfigParams::m_width = m_actual_screen_size.Width;
UserConfigParams::m_height = m_actual_screen_size.Height;
UserConfigParams::m_real_width = (unsigned)((float)UserConfigParams::m_width / m_device->getNativeScaleX());
UserConfigParams::m_real_height = (unsigned)((float)UserConfigParams::m_height / m_device->getNativeScaleY());
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
@ -693,8 +696,6 @@ void IrrDriver::initDevice()
m_scene_manager->addExternalMeshLoader(spml); m_scene_manager->addExternalMeshLoader(spml);
spml->drop(); spml->drop();
m_actual_screen_size = m_video_driver->getCurrentRenderTargetSize();
#ifdef ENABLE_RECORDER #ifdef ENABLE_RECORDER
ogrRegGeneralCallback(OGR_CBT_START_RECORDING, ogrRegGeneralCallback(OGR_CBT_START_RECORDING,
[] (void* user_data) [] (void* user_data)

View File

@ -47,7 +47,6 @@
#include <ge_vulkan_texture_descriptor.hpp> #include <ge_vulkan_texture_descriptor.hpp>
#endif #endif
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -317,6 +316,12 @@ void OptionsScreenVideo::init()
getWidget<LabelWidget>("rememberWinposText"); getWidget<LabelWidget>("rememberWinposText");
assert( rememberWinposText != NULL ); assert( rememberWinposText != NULL );
#endif #endif
bool is_vulkan = false;
#ifndef SERVER_ONLY
is_vulkan = GE::getDriver()->getDriverType() == video::EDT_VULKAN;
#endif
// --- get resolution list from irrlicht the first time // --- get resolution list from irrlicht the first time
if (!m_inited) if (!m_inited)
{ {
@ -360,11 +365,20 @@ void OptionsScreenVideo::init()
} }
} }
// Vulkan use fullscreen desktop so only show current screen size
if (is_vulkan)
{
found_config_res = false;
m_resolutions.clear();
found_1024_768 = true;
found_1280_720 = true;
}
if (!found_config_res) if (!found_config_res)
{ {
r.width = UserConfigParams::m_real_width; r.width = UserConfigParams::m_real_width;
r.height = UserConfigParams::m_real_height; r.height = UserConfigParams::m_real_height;
r.fullscreen = false; r.fullscreen = is_vulkan;
m_resolutions.push_back(r); m_resolutions.push_back(r);
if (r.width == 1024 && r.height == 768) if (r.width == 1024 && r.height == 768)
@ -457,8 +471,8 @@ void OptionsScreenVideo::init()
// disabled) // disabled)
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU; bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
res->setActive(!in_game); res->setActive(!in_game || is_vulkan);
full->setActive(!in_game); full->setActive(!in_game || is_vulkan);
applyBtn->setActive(!in_game); applyBtn->setActive(!in_game);
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
gfx->setActive(!in_game && CVS->isGLSL()); gfx->setActive(!in_game && CVS->isGLSL());
@ -466,7 +480,7 @@ void OptionsScreenVideo::init()
if (getWidget<SpinnerWidget>("scale_rtts")->isActivated()) if (getWidget<SpinnerWidget>("scale_rtts")->isActivated())
{ {
getWidget<SpinnerWidget>("scale_rtts")->setActive(!in_game || getWidget<SpinnerWidget>("scale_rtts")->setActive(!in_game ||
GE::getDriver()->getDriverType() == video::EDT_VULKAN); is_vulkan);
} }
#endif #endif
@ -719,6 +733,7 @@ void OptionsScreenVideo::updateBlurTooltip()
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
extern "C" void update_swap_interval(int swap_interval); extern "C" void update_swap_interval(int swap_interval);
extern "C" void update_fullscreen_desktop(int val);
void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name, void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
const int playerID) const int playerID)
@ -867,8 +882,15 @@ void OptionsScreenVideo::eventCallback(Widget* widget, const std::string& name,
CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos"); CheckBoxWidget* rememberWinpos = getWidget<CheckBoxWidget>("rememberWinpos");
rememberWinpos->setActive(!fullscreen->getState()); rememberWinpos->setActive(!fullscreen->getState());
#ifndef SERVER_ONLY
updateResolutionsList(); if (GE::getDriver()->getDriverType() == video::EDT_VULKAN)
{
UserConfigParams::m_fullscreen = fullscreen->getState();
update_fullscreen_desktop(UserConfigParams::m_fullscreen);
}
else
updateResolutionsList();
#endif
} }
} // eventCallback } // eventCallback