Implement high dpi support in sdl2 properly
This commit is contained in:
parent
ea69c36cb3
commit
e991e06640
@ -26,6 +26,8 @@
|
|||||||
#include "ge_vulkan_scene_manager.hpp"
|
#include "ge_vulkan_scene_manager.hpp"
|
||||||
#include "MoltenVK.h"
|
#include "MoltenVK.h"
|
||||||
|
|
||||||
|
#include <SDL_vulkan.h>
|
||||||
|
|
||||||
extern bool GLContextDebugBit;
|
extern bool GLContextDebugBit;
|
||||||
|
|
||||||
namespace irr
|
namespace irr
|
||||||
@ -57,9 +59,6 @@ extern "C" int Android_disablePadding();
|
|||||||
namespace irr
|
namespace irr
|
||||||
{
|
{
|
||||||
|
|
||||||
float g_native_scale_x = 1.0f;
|
|
||||||
float g_native_scale_y = 1.0f;
|
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
||||||
: CIrrDeviceStub(param),
|
: CIrrDeviceStub(param),
|
||||||
@ -69,7 +68,8 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||||||
TopPadding(0), BottomPadding(0), LeftPadding(0), RightPadding(0),
|
TopPadding(0), BottomPadding(0), LeftPadding(0), RightPadding(0),
|
||||||
InitialOrientation(0), WindowHasFocus(false), WindowMinimized(false),
|
InitialOrientation(0), WindowHasFocus(false), WindowMinimized(false),
|
||||||
Resizable(false), AccelerometerIndex(-1), AccelerometerInstance(-1),
|
Resizable(false), AccelerometerIndex(-1), AccelerometerInstance(-1),
|
||||||
GyroscopeIndex(-1), GyroscopeInstance(-1)
|
GyroscopeIndex(-1), GyroscopeInstance(-1), NativeScaleX(1.0f),
|
||||||
|
NativeScaleY(1.0f)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
setDebugName("CIrrDeviceSDL");
|
setDebugName("CIrrDeviceSDL");
|
||||||
@ -155,33 +155,12 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
updateNativeScale();
|
||||||
|
Width = (u32)((f32)Width * NativeScaleX);
|
||||||
|
Height = (u32)((f32)Height * NativeScaleY);
|
||||||
|
CreationParams.WindowSize.Width = Width;
|
||||||
|
CreationParams.WindowSize.Height = Height;
|
||||||
}
|
}
|
||||||
#if !defined(ANDROID) && !defined(__SWITCH__)
|
|
||||||
else if (!GUIEngine::isNoGraphics())
|
|
||||||
{
|
|
||||||
// Get highdpi native scale using renderer so it will work with any
|
|
||||||
// backend later (opengl or vulkan)
|
|
||||||
// Android doesn't use high dpi
|
|
||||||
SDL_Window* window = NULL;
|
|
||||||
SDL_Renderer* renderer = NULL;
|
|
||||||
if (SDL_CreateWindowAndRenderer(640, 480,
|
|
||||||
SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN,
|
|
||||||
&window, &renderer) == 0)
|
|
||||||
{
|
|
||||||
int w, h, rw, rh;
|
|
||||||
w = h = rw = rh = 0;
|
|
||||||
SDL_GetWindowSize(window, &w, &h);
|
|
||||||
SDL_GetRendererOutputSize(renderer, &rw, &rh);
|
|
||||||
if (w != 0 && h != 0 && rw != 0 && rh != 0)
|
|
||||||
{
|
|
||||||
g_native_scale_x = (float)rw / (float)w;
|
|
||||||
g_native_scale_y = (float)rh / (float)h;
|
|
||||||
}
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// create cursor control
|
// create cursor control
|
||||||
CursorControl = new CCursorControl(this);
|
CursorControl = new CCursorControl(this);
|
||||||
@ -202,6 +181,26 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CIrrDeviceSDL::updateNativeScale()
|
||||||
|
{
|
||||||
|
int width, height = 0;
|
||||||
|
SDL_GetWindowSize(Window, &width, &height);
|
||||||
|
int real_width = width;
|
||||||
|
int real_height = height;
|
||||||
|
if (CreationParams.DriverType == video::EDT_OPENGL ||
|
||||||
|
CreationParams.DriverType == video::EDT_OGLES2)
|
||||||
|
{
|
||||||
|
SDL_GL_GetDrawableSize(Window, &real_width, &real_height);
|
||||||
|
}
|
||||||
|
else if (CreationParams.DriverType == video::EDT_VULKAN)
|
||||||
|
{
|
||||||
|
SDL_Vulkan_GetDrawableSize(Window, &real_width, &real_height);
|
||||||
|
}
|
||||||
|
NativeScaleX = (f32)real_width / (f32)width;
|
||||||
|
NativeScaleY = (f32)real_height / (f32)height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! destructor
|
//! destructor
|
||||||
CIrrDeviceSDL::~CIrrDeviceSDL()
|
CIrrDeviceSDL::~CIrrDeviceSDL()
|
||||||
{
|
{
|
||||||
@ -386,7 +385,14 @@ bool CIrrDeviceSDL::createWindow()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI;
|
u32 flags = SDL_WINDOW_SHOWN;
|
||||||
|
#if !defined(ANDROID) && !defined(__SWITCH__)
|
||||||
|
if (CreationParams.DriverType == video::EDT_OPENGL ||
|
||||||
|
CreationParams.DriverType == video::EDT_OGLES2 ||
|
||||||
|
CreationParams.DriverType == video::EDT_VULKAN)
|
||||||
|
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (CreationParams.Fullscreen)
|
if (CreationParams.Fullscreen)
|
||||||
flags |= SDL_WINDOW_FULLSCREEN;
|
flags |= SDL_WINDOW_FULLSCREEN;
|
||||||
|
|
||||||
@ -427,10 +433,10 @@ bool CIrrDeviceSDL::createWindow()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (!Window)
|
if (!Window)
|
||||||
{
|
{
|
||||||
os::Printer::log( "Could not initialize display!" );
|
os::Printer::log( "Could not initialize display!" );
|
||||||
@ -477,10 +483,10 @@ start:
|
|||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (Window)
|
if (Window)
|
||||||
{
|
{
|
||||||
Context = SDL_GL_CreateContext(Window);
|
Context = SDL_GL_CreateContext(Window);
|
||||||
@ -503,10 +509,10 @@ start:
|
|||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (Window)
|
if (Window)
|
||||||
{
|
{
|
||||||
Context = SDL_GL_CreateContext(Window);
|
Context = SDL_GL_CreateContext(Window);
|
||||||
@ -528,10 +534,10 @@ start:
|
|||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (Window)
|
if (Window)
|
||||||
{
|
{
|
||||||
Context = SDL_GL_CreateContext(Window);
|
Context = SDL_GL_CreateContext(Window);
|
||||||
@ -553,10 +559,10 @@ start:
|
|||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (Window)
|
if (Window)
|
||||||
{
|
{
|
||||||
Context = SDL_GL_CreateContext(Window);
|
Context = SDL_GL_CreateContext(Window);
|
||||||
@ -590,10 +596,10 @@ legacy:
|
|||||||
else
|
else
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
|
||||||
Window = SDL_CreateWindow("",
|
Window = SDL_CreateWindow("",
|
||||||
(float)CreationParams.WindowPosition.X / g_native_scale_x,
|
(float)CreationParams.WindowPosition.X,
|
||||||
(float)CreationParams.WindowPosition.Y / g_native_scale_y,
|
(float)CreationParams.WindowPosition.Y,
|
||||||
(float)CreationParams.WindowSize.Width / g_native_scale_x,
|
(float)CreationParams.WindowSize.Width,
|
||||||
(float)CreationParams.WindowSize.Height / g_native_scale_y, flags);
|
(float)CreationParams.WindowSize.Height, flags);
|
||||||
if (Window)
|
if (Window)
|
||||||
{
|
{
|
||||||
Context = SDL_GL_CreateContext(Window);
|
Context = SDL_GL_CreateContext(Window);
|
||||||
@ -644,6 +650,10 @@ void CIrrDeviceSDL::createDriver()
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
VideoDriver = video::createVulkanDriver(CreationParams, FileSystem, Window, this);
|
VideoDriver = video::createVulkanDriver(CreationParams, FileSystem, Window, this);
|
||||||
|
// SDL_Vulkan_GetDrawableSize only works after driver is created
|
||||||
|
updateNativeScale();
|
||||||
|
Width = (u32)((f32)Width * NativeScaleX);
|
||||||
|
Height = (u32)((f32)Height * NativeScaleY);
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
@ -782,8 +792,8 @@ bool CIrrDeviceSDL::run()
|
|||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
||||||
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
||||||
MouseX = irrevent.MouseInput.X = SDL_event.motion.x * g_native_scale_x;
|
MouseX = irrevent.MouseInput.X = SDL_event.motion.x * NativeScaleX;
|
||||||
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y * g_native_scale_y;
|
MouseY = irrevent.MouseInput.Y = SDL_event.motion.y * NativeScaleY;
|
||||||
irrevent.MouseInput.ButtonStates = MouseButtonStates;
|
irrevent.MouseInput.ButtonStates = MouseButtonStates;
|
||||||
|
|
||||||
postEventFromUser(irrevent);
|
postEventFromUser(irrevent);
|
||||||
@ -793,8 +803,8 @@ bool CIrrDeviceSDL::run()
|
|||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
|
||||||
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
|
||||||
irrevent.MouseInput.X = SDL_event.button.x * g_native_scale_x;
|
irrevent.MouseInput.X = SDL_event.button.x * NativeScaleX;
|
||||||
irrevent.MouseInput.Y = SDL_event.button.y * g_native_scale_y;
|
irrevent.MouseInput.Y = SDL_event.button.y * NativeScaleY;
|
||||||
|
|
||||||
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
|
||||||
|
|
||||||
@ -900,16 +910,19 @@ bool CIrrDeviceSDL::run()
|
|||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
{
|
{
|
||||||
u32 new_width = SDL_event.window.data1 * g_native_scale_x;
|
if (SDL_event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
|
||||||
u32 new_height = SDL_event.window.data2 * g_native_scale_y;
|
|
||||||
if (SDL_event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
|
||||||
((new_width != Width) || (new_height != Height)))
|
|
||||||
{
|
{
|
||||||
Width = new_width;
|
updateNativeScale();
|
||||||
Height = new_height;
|
u32 new_width = SDL_event.window.data1 * NativeScaleX;
|
||||||
if (VideoDriver)
|
u32 new_height = SDL_event.window.data2 * NativeScaleY;
|
||||||
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
|
if (new_width != Width || new_height != Height)
|
||||||
reset_network_body();
|
{
|
||||||
|
Width = new_width;
|
||||||
|
Height = new_height;
|
||||||
|
if (VideoDriver)
|
||||||
|
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
|
||||||
|
reset_network_body();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (SDL_event.window.event == SDL_WINDOWEVENT_MINIMIZED)
|
else if (SDL_event.window.event == SDL_WINDOWEVENT_MINIMIZED)
|
||||||
{
|
{
|
||||||
@ -1050,20 +1063,20 @@ video::IVideoModeList* CIrrDeviceSDL::getVideoModeList()
|
|||||||
if (SDL_GetDesktopDisplayMode(0, &mode) == 0)
|
if (SDL_GetDesktopDisplayMode(0, &mode) == 0)
|
||||||
{
|
{
|
||||||
VideoModeList.setDesktop(SDL_BITSPERPIXEL(mode.format),
|
VideoModeList.setDesktop(SDL_BITSPERPIXEL(mode.format),
|
||||||
core::dimension2d<u32>(mode.w * g_native_scale_x, mode.h * g_native_scale_y));
|
core::dimension2d<u32>(mode.w, mode.h));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOBILE_STK
|
#ifdef MOBILE_STK
|
||||||
// SDL2 will return w,h and h,w for mobile STK, as we only use landscape
|
// SDL2 will return w,h and h,w for mobile STK, as we only use landscape
|
||||||
// so we just use desktop resolution for now
|
// so we just use desktop resolution for now
|
||||||
VideoModeList.addMode(core::dimension2d<u32>(mode.w * g_native_scale_x, mode.h * g_native_scale_y),
|
VideoModeList.addMode(core::dimension2d<u32>(mode.w, mode.h),
|
||||||
SDL_BITSPERPIXEL(mode.format));
|
SDL_BITSPERPIXEL(mode.format));
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < mode_count; i++)
|
for (int i = 0; i < mode_count; i++)
|
||||||
{
|
{
|
||||||
if (SDL_GetDisplayMode(0, i, &mode) == 0)
|
if (SDL_GetDisplayMode(0, i, &mode) == 0)
|
||||||
{
|
{
|
||||||
VideoModeList.addMode(core::dimension2d<u32>(mode.w * g_native_scale_x, mode.h * g_native_scale_y),
|
VideoModeList.addMode(core::dimension2d<u32>(mode.w, mode.h),
|
||||||
SDL_BITSPERPIXEL(mode.format));
|
SDL_BITSPERPIXEL(mode.format));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1498,7 +1511,7 @@ extern "C" int Android_getMovedHeight();
|
|||||||
s32 CIrrDeviceSDL::getMovedHeight() const
|
s32 CIrrDeviceSDL::getMovedHeight() const
|
||||||
{
|
{
|
||||||
#if defined(IOS_STK)
|
#if defined(IOS_STK)
|
||||||
return SDL_GetMovedHeightByScreenKeyboard() * g_native_scale_y;
|
return SDL_GetMovedHeightByScreenKeyboard() * NativeScaleY;
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
return Android_getMovedHeight();
|
return Android_getMovedHeight();
|
||||||
#else
|
#else
|
||||||
@ -1511,7 +1524,7 @@ extern "C" int Android_getKeyboardHeight();
|
|||||||
u32 CIrrDeviceSDL::getOnScreenKeyboardHeight() const
|
u32 CIrrDeviceSDL::getOnScreenKeyboardHeight() const
|
||||||
{
|
{
|
||||||
#if defined(IOS_STK)
|
#if defined(IOS_STK)
|
||||||
return SDL_GetScreenKeyboardHeight() * g_native_scale_y;
|
return SDL_GetScreenKeyboardHeight() * NativeScaleY;
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
return Android_getKeyboardHeight();
|
return Android_getKeyboardHeight();
|
||||||
#else
|
#else
|
||||||
@ -1522,13 +1535,13 @@ u32 CIrrDeviceSDL::getOnScreenKeyboardHeight() const
|
|||||||
|
|
||||||
f32 CIrrDeviceSDL::getNativeScaleX() const
|
f32 CIrrDeviceSDL::getNativeScaleX() const
|
||||||
{
|
{
|
||||||
return g_native_scale_x;
|
return NativeScaleX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
f32 CIrrDeviceSDL::getNativeScaleY() const
|
f32 CIrrDeviceSDL::getNativeScaleY() const
|
||||||
{
|
{
|
||||||
return g_native_scale_y;
|
return NativeScaleY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,6 +303,8 @@ class MoltenVK;
|
|||||||
s32 GyroscopeIndex;
|
s32 GyroscopeIndex;
|
||||||
s32 GyroscopeInstance;
|
s32 GyroscopeInstance;
|
||||||
|
|
||||||
|
f32 NativeScaleX, NativeScaleY;
|
||||||
|
|
||||||
struct SKeyMap
|
struct SKeyMap
|
||||||
{
|
{
|
||||||
SKeyMap() {}
|
SKeyMap() {}
|
||||||
@ -328,6 +330,7 @@ class MoltenVK;
|
|||||||
MoltenVK* m_moltenvk;
|
MoltenVK* m_moltenvk;
|
||||||
#endif
|
#endif
|
||||||
void createGUIAndVulkanScene();
|
void createGUIAndVulkanScene();
|
||||||
|
void updateNativeScale();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
@ -611,21 +611,27 @@ namespace UserConfigParams
|
|||||||
PARAM_PREFIX GroupUserConfigParam m_video_group
|
PARAM_PREFIX GroupUserConfigParam m_video_group
|
||||||
PARAM_DEFAULT( GroupUserConfigParam("Video", "Video Settings") );
|
PARAM_DEFAULT( GroupUserConfigParam("Video", "Video Settings") );
|
||||||
|
|
||||||
|
PARAM_PREFIX IntUserConfigParam m_real_width
|
||||||
|
PARAM_DEFAULT( IntUserConfigParam(1024, "real_width", &m_video_group,
|
||||||
|
"Screen/window real width in pixels before high dpi is applied") );
|
||||||
|
PARAM_PREFIX IntUserConfigParam m_real_height
|
||||||
|
PARAM_DEFAULT( IntUserConfigParam(768, "real_height", &m_video_group,
|
||||||
|
"Screen/window real height in pixels before high dpi is applied") );
|
||||||
PARAM_PREFIX IntUserConfigParam m_width
|
PARAM_PREFIX IntUserConfigParam m_width
|
||||||
PARAM_DEFAULT( IntUserConfigParam(1024, "width", &m_video_group,
|
PARAM_DEFAULT( IntUserConfigParam(1024, "width", &m_video_group,
|
||||||
"Screen/window width in pixels") );
|
"Screen/window width in pixels, this value should not be edited") );
|
||||||
PARAM_PREFIX IntUserConfigParam m_height
|
PARAM_PREFIX IntUserConfigParam m_height
|
||||||
PARAM_DEFAULT( IntUserConfigParam(768, "height", &m_video_group,
|
PARAM_DEFAULT( IntUserConfigParam(768, "height", &m_video_group,
|
||||||
"Screen/window height in pixels") );
|
"Screen/window height in pixels, this value should not be edited") );
|
||||||
PARAM_PREFIX BoolUserConfigParam m_fullscreen
|
PARAM_PREFIX BoolUserConfigParam m_fullscreen
|
||||||
PARAM_DEFAULT( BoolUserConfigParam(false, "fullscreen",
|
PARAM_DEFAULT( BoolUserConfigParam(false, "fullscreen",
|
||||||
&m_video_group) );
|
&m_video_group) );
|
||||||
PARAM_PREFIX IntUserConfigParam m_prev_width
|
PARAM_PREFIX IntUserConfigParam m_prev_real_width
|
||||||
PARAM_DEFAULT( IntUserConfigParam(1024, "prev_width",
|
PARAM_DEFAULT( IntUserConfigParam(1024, "prev_real_width",
|
||||||
&m_video_group, "Previous screen/window width") );
|
&m_video_group, "Previous real screen/window width") );
|
||||||
PARAM_PREFIX IntUserConfigParam m_prev_height
|
PARAM_PREFIX IntUserConfigParam m_prev_real_height
|
||||||
PARAM_DEFAULT( IntUserConfigParam(768, "prev_height",
|
PARAM_DEFAULT( IntUserConfigParam(768, "prev_real_height",
|
||||||
&m_video_group,"Previous screen/window height") );
|
&m_video_group,"Previous real screen/window height") );
|
||||||
PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen
|
PARAM_PREFIX BoolUserConfigParam m_prev_fullscreen
|
||||||
PARAM_DEFAULT( BoolUserConfigParam(false, "prev_fullscreen",
|
PARAM_DEFAULT( BoolUserConfigParam(false, "prev_fullscreen",
|
||||||
&m_video_group) );
|
&m_video_group) );
|
||||||
|
@ -453,13 +453,13 @@ void IrrDriver::initDevice()
|
|||||||
{
|
{
|
||||||
Log::warn("irr_driver", "Unknown desktop resolution.");
|
Log::warn("irr_driver", "Unknown desktop resolution.");
|
||||||
}
|
}
|
||||||
else if (UserConfigParams::m_width > (int)ssize.Width ||
|
else if (UserConfigParams::m_real_width > (int)ssize.Width ||
|
||||||
UserConfigParams::m_height > (int)ssize.Height)
|
UserConfigParams::m_real_height > (int)ssize.Height)
|
||||||
{
|
{
|
||||||
Log::warn("irr_driver", "The window size specified in "
|
Log::warn("irr_driver", "The window size specified in "
|
||||||
"user config is larger than your screen!");
|
"user config is larger than your screen!");
|
||||||
UserConfigParams::m_width = (int)ssize.Width;
|
UserConfigParams::m_real_width = (int)ssize.Width;
|
||||||
UserConfigParams::m_height = (int)ssize.Height;
|
UserConfigParams::m_real_height = (int)ssize.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UserConfigParams::m_fullscreen)
|
if (UserConfigParams::m_fullscreen)
|
||||||
@ -467,12 +467,12 @@ void IrrDriver::initDevice()
|
|||||||
if (modes->getVideoModeCount() > 0)
|
if (modes->getVideoModeCount() > 0)
|
||||||
{
|
{
|
||||||
core::dimension2d<u32> res = core::dimension2du(
|
core::dimension2d<u32> res = core::dimension2du(
|
||||||
UserConfigParams::m_width,
|
UserConfigParams::m_real_width,
|
||||||
UserConfigParams::m_height);
|
UserConfigParams::m_real_height);
|
||||||
res = modes->getVideoModeResolution(res, res);
|
res = modes->getVideoModeResolution(res, res);
|
||||||
|
|
||||||
UserConfigParams::m_width = res.Width;
|
UserConfigParams::m_real_width = res.Width;
|
||||||
UserConfigParams::m_height = res.Height;
|
UserConfigParams::m_real_height = res.Height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -482,12 +482,12 @@ void IrrDriver::initDevice()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UserConfigParams::m_width < 1 || UserConfigParams::m_height < 1)
|
if (UserConfigParams::m_real_width < 1 || UserConfigParams::m_real_height < 1)
|
||||||
{
|
{
|
||||||
Log::warn("irr_driver", "Invalid window size. "
|
Log::warn("irr_driver", "Invalid window size. "
|
||||||
"Try to use the default one.");
|
"Try to use the default one.");
|
||||||
UserConfigParams::m_width = MIN_SUPPORTED_WIDTH;
|
UserConfigParams::m_real_width = MIN_SUPPORTED_WIDTH;
|
||||||
UserConfigParams::m_height = MIN_SUPPORTED_HEIGHT;
|
UserConfigParams::m_real_height = MIN_SUPPORTED_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_device->closeDevice();
|
m_device->closeDevice();
|
||||||
@ -528,8 +528,8 @@ void IrrDriver::initDevice()
|
|||||||
params.SwapInterval = UserConfigParams::m_swap_interval;
|
params.SwapInterval = UserConfigParams::m_swap_interval;
|
||||||
params.FileSystem = file_manager->getFileSystem();
|
params.FileSystem = file_manager->getFileSystem();
|
||||||
params.WindowSize =
|
params.WindowSize =
|
||||||
core::dimension2du(UserConfigParams::m_width,
|
core::dimension2du(UserConfigParams::m_real_width,
|
||||||
UserConfigParams::m_height);
|
UserConfigParams::m_real_height);
|
||||||
params.HandleSRGB = false;
|
params.HandleSRGB = false;
|
||||||
params.ShadersPath = (file_manager->getShadersDir() +
|
params.ShadersPath = (file_manager->getShadersDir() +
|
||||||
"irrlicht/").c_str();
|
"irrlicht/").c_str();
|
||||||
@ -575,11 +575,11 @@ void IrrDriver::initDevice()
|
|||||||
// size is the problem
|
// size is the problem
|
||||||
if(!m_device)
|
if(!m_device)
|
||||||
{
|
{
|
||||||
UserConfigParams::m_width = MIN_SUPPORTED_WIDTH;
|
UserConfigParams::m_real_width = MIN_SUPPORTED_WIDTH;
|
||||||
UserConfigParams::m_height = MIN_SUPPORTED_HEIGHT;
|
UserConfigParams::m_real_height = MIN_SUPPORTED_HEIGHT;
|
||||||
m_device = createDevice(driver_created,
|
m_device = createDevice(driver_created,
|
||||||
core::dimension2du(UserConfigParams::m_width,
|
core::dimension2du(UserConfigParams::m_real_width,
|
||||||
UserConfigParams::m_height ),
|
UserConfigParams::m_real_height ),
|
||||||
32, //bits per pixel
|
32, //bits per pixel
|
||||||
UserConfigParams::m_fullscreen,
|
UserConfigParams::m_fullscreen,
|
||||||
false, // stencil buffers
|
false, // stencil buffers
|
||||||
@ -600,6 +600,9 @@ 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());
|
||||||
|
UserConfigParams::m_height = (unsigned)((float)UserConfigParams::m_real_height * m_device->getNativeScaleY());
|
||||||
|
|
||||||
#ifndef SERVER_ONLY
|
#ifndef SERVER_ONLY
|
||||||
|
|
||||||
GE::setVideoDriver(m_device->getVideoDriver());
|
GE::setVideoDriver(m_device->getVideoDriver());
|
||||||
@ -958,12 +961,12 @@ void IrrDriver::changeResolution(const int w, const int h,
|
|||||||
const bool fullscreen)
|
const bool fullscreen)
|
||||||
{
|
{
|
||||||
// update user config values
|
// update user config values
|
||||||
UserConfigParams::m_prev_width = UserConfigParams::m_width;
|
UserConfigParams::m_prev_real_width = UserConfigParams::m_real_width;
|
||||||
UserConfigParams::m_prev_height = UserConfigParams::m_height;
|
UserConfigParams::m_prev_real_height = UserConfigParams::m_real_height;
|
||||||
UserConfigParams::m_prev_fullscreen = UserConfigParams::m_fullscreen;
|
UserConfigParams::m_prev_fullscreen = UserConfigParams::m_fullscreen;
|
||||||
|
|
||||||
UserConfigParams::m_width = w;
|
UserConfigParams::m_real_width = w;
|
||||||
UserConfigParams::m_height = h;
|
UserConfigParams::m_real_height = h;
|
||||||
UserConfigParams::m_fullscreen = fullscreen;
|
UserConfigParams::m_fullscreen = fullscreen;
|
||||||
|
|
||||||
// Setting this flag will trigger a call to applyResolutionSetting()
|
// Setting this flag will trigger a call to applyResolutionSetting()
|
||||||
@ -987,10 +990,9 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
|
|||||||
if (recreate_device)
|
if (recreate_device)
|
||||||
{
|
{
|
||||||
m_video_driver->beginScene(true, true, video::SColor(255,100,101,140));
|
m_video_driver->beginScene(true, true, video::SColor(255,100,101,140));
|
||||||
GL32_draw2DRectangle( video::SColor(255, 0, 0, 0),
|
GL32_draw2DRectangle( video::SColor(255, 0, 0, 0), core::rect<s32>(0, 0,
|
||||||
core::rect<s32>(0, 0,
|
s32(m_device->getNativeScaleX() * (float)UserConfigParams::m_prev_real_width),
|
||||||
UserConfigParams::m_prev_width,
|
s32(m_device->getNativeScaleY() * (float)UserConfigParams::m_prev_real_height)) );
|
||||||
UserConfigParams::m_prev_height) );
|
|
||||||
m_video_driver->endScene();
|
m_video_driver->endScene();
|
||||||
}
|
}
|
||||||
track_manager->removeAllCachedData();
|
track_manager->removeAllCachedData();
|
||||||
@ -1119,8 +1121,8 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
|
|||||||
|
|
||||||
void IrrDriver::cancelResChange()
|
void IrrDriver::cancelResChange()
|
||||||
{
|
{
|
||||||
UserConfigParams::m_width = UserConfigParams::m_prev_width;
|
UserConfigParams::m_real_width = UserConfigParams::m_prev_real_width;
|
||||||
UserConfigParams::m_height = UserConfigParams::m_prev_height;
|
UserConfigParams::m_real_height = UserConfigParams::m_prev_real_height;
|
||||||
UserConfigParams::m_fullscreen = UserConfigParams::m_prev_fullscreen;
|
UserConfigParams::m_fullscreen = UserConfigParams::m_prev_fullscreen;
|
||||||
|
|
||||||
// This will trigger calling applyResolutionSettings in update(). This is
|
// This will trigger calling applyResolutionSettings in update(). This is
|
||||||
@ -2025,6 +2027,8 @@ void IrrDriver::handleWindowResize()
|
|||||||
m_actual_screen_size = m_video_driver->getCurrentRenderTargetSize();
|
m_actual_screen_size = m_video_driver->getCurrentRenderTargetSize();
|
||||||
UserConfigParams::m_width = m_actual_screen_size.Width;
|
UserConfigParams::m_width = m_actual_screen_size.Width;
|
||||||
UserConfigParams::m_height = m_actual_screen_size.Height;
|
UserConfigParams::m_height = m_actual_screen_size.Height;
|
||||||
|
UserConfigParams::m_real_width = (unsigned)((float)m_actual_screen_size.Width / m_device->getNativeScaleX());
|
||||||
|
UserConfigParams::m_real_height = (unsigned)((float)m_actual_screen_size.Height / m_device->getNativeScaleY());
|
||||||
resizeWindow();
|
resizeWindow();
|
||||||
}
|
}
|
||||||
// In case reset by opening options in game
|
// In case reset by opening options in game
|
||||||
|
12
src/main.cpp
12
src/main.cpp
@ -867,13 +867,13 @@ int handleCmdLinePreliminary()
|
|||||||
UserConfigParams::m_blacklist_res.end(),res) ==
|
UserConfigParams::m_blacklist_res.end(),res) ==
|
||||||
UserConfigParams::m_blacklist_res.end())
|
UserConfigParams::m_blacklist_res.end())
|
||||||
{
|
{
|
||||||
UserConfigParams::m_prev_width =
|
UserConfigParams::m_prev_real_width =
|
||||||
UserConfigParams::m_width = width;
|
UserConfigParams::m_real_width = width;
|
||||||
UserConfigParams::m_prev_height =
|
UserConfigParams::m_prev_real_height =
|
||||||
UserConfigParams::m_height = height;
|
UserConfigParams::m_real_height = height;
|
||||||
Log::verbose("main", "You choose to use %dx%d.",
|
Log::verbose("main", "You choose to use %dx%d.",
|
||||||
(int)UserConfigParams::m_width,
|
(int)UserConfigParams::m_real_width,
|
||||||
(int)UserConfigParams::m_height );
|
(int)UserConfigParams::m_real_height );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Log::warn("main", "Resolution %s has been blacklisted, so "
|
Log::warn("main", "Resolution %s has been blacklisted, so "
|
||||||
|
@ -326,8 +326,8 @@ void OptionsScreenVideo::init()
|
|||||||
r.fullscreen = true;
|
r.fullscreen = true;
|
||||||
m_resolutions.push_back(r);
|
m_resolutions.push_back(r);
|
||||||
|
|
||||||
if (r.width == UserConfigParams::m_width &&
|
if (r.width == UserConfigParams::m_real_width &&
|
||||||
r.height == UserConfigParams::m_height)
|
r.height == UserConfigParams::m_real_height)
|
||||||
{
|
{
|
||||||
found_config_res = true;
|
found_config_res = true;
|
||||||
}
|
}
|
||||||
@ -344,8 +344,8 @@ void OptionsScreenVideo::init()
|
|||||||
|
|
||||||
if (!found_config_res)
|
if (!found_config_res)
|
||||||
{
|
{
|
||||||
r.width = UserConfigParams::m_width;
|
r.width = UserConfigParams::m_real_width;
|
||||||
r.height = UserConfigParams::m_height;
|
r.height = UserConfigParams::m_real_height;
|
||||||
r.fullscreen = false;
|
r.fullscreen = false;
|
||||||
m_resolutions.push_back(r);
|
m_resolutions.push_back(r);
|
||||||
|
|
||||||
@ -418,8 +418,8 @@ void OptionsScreenVideo::init()
|
|||||||
|
|
||||||
// ---- select current resolution every time
|
// ---- select current resolution every time
|
||||||
char searching_for[32];
|
char searching_for[32];
|
||||||
snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_width,
|
snprintf(searching_for, 32, "%ix%i", (int)UserConfigParams::m_real_width,
|
||||||
(int)UserConfigParams::m_height);
|
(int)UserConfigParams::m_real_height);
|
||||||
|
|
||||||
|
|
||||||
if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER,
|
if (!res->setSelection(searching_for, PLAYER_ID_GAME_MASTER,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user