summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
diff options
context:
space:
mode:
author Julian Sikorski <belegdol+github@gmail.com>2025-01-02 13:50:37 +0100
committer GitHub <noreply@github.com>2025-01-02 13:50:37 +0100
commitba6f5853e9382a959af8ff81980c0f06a6ffe80e (patch)
tree82f1b4963be587f0aa8766a03557c58996b4ca38 /3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
parent6a403fc29993062aa451f5557cc88abc2fe7b2e7 (diff)
Cherry-pick wayland improvements from upstream bgfx (#13070)
* Properly support Wayland under EGL and Vulkan. (#3358) * Dynamically load libwayland-egl.so.1 when dealing with Wayland to remove dependencies at program startup. (#3359) * Cleanup. * Support both X11 and Wayland in the same build. (#3360) * Support both X11 and Wayland in the same build. - Works for both Vulkan and OpenGL. - Remove --with-wayland from genie options. - Vulkan loads all three extensions for surface creation instead of only one. - Add width and height parameter to GlContext::createSwapChain(), which is needed for EGL to create a SwapChain with the given window size. - Dirty-fix the example-22-windows to recreate the FrameBuffer by first destroying and then recreating to make sure the window is released of its swapchain. - Fix dbgText glitch in example-22-windows. - Remove old X11-related dependencies for GLFW3. * Formatting. * Adapt to latest bgfx wayland code * Cleanup. * Fix Vulkan swapchain invalidation issue. (#3379) * Fix Vulkan swapchain invalidation issue. * Always clamp render pass to frame buffer size. * Fix formatting. * Hopefully fix macOS build * Hopefully fix macOS build, attempt 2 --------- Co-authored-by: Martijn Courteaux <courteauxmartijn@gmail.com> Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_sdl.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_sdl.cpp92
1 files changed, 26 insertions, 66 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
index 5a862c0ca05..bbcdb069257 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
@@ -8,9 +8,6 @@
#if ENTRY_CONFIG_USE_SDL
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
-# if ENTRY_CONFIG_USE_WAYLAND
-# include <wayland-egl.h>
-# endif
#elif BX_PLATFORM_WINDOWS
# define SDL_MAIN_HANDLED
#endif
@@ -49,25 +46,14 @@ namespace entry
}
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
-# if ENTRY_CONFIG_USE_WAYLAND
- if (wmi.subsystem == SDL_SYSWM_WAYLAND)
- {
- wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(_window, "wl_egl_window");
- if(!win_impl)
- {
- int width, height;
- SDL_GetWindowSize(_window, &width, &height);
- struct wl_surface* surface = wmi.info.wl.surface;
- if(!surface)
- return nullptr;
- win_impl = wl_egl_window_create(surface, width, height);
- SDL_SetWindowData(_window, "wl_egl_window", win_impl);
- }
- return (void*)(uintptr_t)win_impl;
- }
- else
-# endif // ENTRY_CONFIG_USE_WAYLAND
- return (void*)wmi.info.x11.window;
+ if (wmi.subsystem == SDL_SYSWM_WAYLAND)
+ {
+ return (void*)wmi.info.wl.surface;
+ }
+ else
+ {
+ return (void*)wmi.info.x11.window;
+ }
# elif BX_PLATFORM_OSX || BX_PLATFORM_IOS
return wmi.info.cocoa.window;
# elif BX_PLATFORM_WINDOWS
@@ -77,23 +63,6 @@ namespace entry
# endif // BX_PLATFORM_
}
- static void sdlDestroyWindow(SDL_Window* _window)
- {
- if(!_window)
- return;
-# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
-# if ENTRY_CONFIG_USE_WAYLAND
- wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(_window, "wl_egl_window");
- if(win_impl)
- {
- SDL_SetWindowData(_window, "wl_egl_window", nullptr);
- wl_egl_window_destroy(win_impl);
- }
-# endif
-# endif
- SDL_DestroyWindow(_window);
- }
-
static uint8_t translateKeyModifiers(uint16_t _sdl)
{
uint8_t modifiers = 0;
@@ -493,7 +462,7 @@ namespace entry
// Force window resolution...
WindowHandle defaultWindow = { 0 };
- setWindowSize(defaultWindow, m_width, m_height, true);
+ entry::setWindowSize(defaultWindow, m_width, m_height);
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
@@ -671,7 +640,15 @@ namespace entry
case SDL_WINDOWEVENT_SIZE_CHANGED:
{
WindowHandle handle = findHandle(wev.windowID);
- setWindowSize(handle, wev.data1, wev.data2);
+ uint32_t width = wev.data1;
+ uint32_t height = wev.data2;
+ if (width != m_width
+ || height != m_height)
+ {
+ m_width = width;
+ m_height = height;
+ m_eventQueue.postSizeEvent(handle, m_width, m_height);
+ }
}
break;
@@ -865,7 +842,7 @@ namespace entry
if (isValid(handle) )
{
m_eventQueue.postWindowEvent(handle);
- sdlDestroyWindow(m_window[handle.idx]);
+ SDL_DestroyWindow(m_window[handle.idx]);
m_window[handle.idx] = NULL;
}
}
@@ -916,7 +893,7 @@ namespace entry
Msg* msg = (Msg*)uev.data2;
if (isValid(handle) )
{
- setWindowSize(handle, msg->m_width, msg->m_height);
+ SDL_SetWindowSize(m_window[handle.idx], msg->m_width, msg->m_height);
}
delete msg;
}
@@ -959,7 +936,7 @@ namespace entry
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
m_thread.shutdown();
- sdlDestroyWindow(m_window[0]);
+ SDL_DestroyWindow(m_window[0]);
SDL_Quit();
return m_thread.getExitCode();
@@ -988,20 +965,6 @@ namespace entry
return invalid;
}
- void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height, bool _force = false)
- {
- if (_width != m_width
- || _height != m_height
- || _force)
- {
- m_width = _width;
- m_height = _height;
-
- SDL_SetWindowSize(m_window[_handle.idx], m_width, m_height);
- m_eventQueue.postSizeEvent(_handle, m_width, m_height);
- }
- }
-
GamepadHandle findGamepad(SDL_JoystickID _jid)
{
for (uint32_t ii = 0, num = m_gamepadAlloc.getNumHandles(); ii < num; ++ii)
@@ -1102,6 +1065,7 @@ namespace entry
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
{
+ // Function to set the window size programmatically from the examples/tools.
Msg* msg = new Msg;
msg->m_width = _width;
msg->m_height = _height;
@@ -1149,12 +1113,10 @@ namespace entry
return NULL;
}
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
-# if ENTRY_CONFIG_USE_WAYLAND
- if (wmi.subsystem == SDL_SYSWM_WAYLAND)
- return wmi.info.wl.display;
- else
-# endif // ENTRY_CONFIG_USE_WAYLAND
- return wmi.info.x11.display;
+ if (wmi.subsystem == SDL_SYSWM_WAYLAND)
+ return wmi.info.wl.display;
+ else
+ return wmi.info.x11.display;
# else
return NULL;
# endif // BX_PLATFORM_*
@@ -1169,11 +1131,9 @@ namespace entry
return bgfx::NativeWindowHandleType::Default;
}
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
-# if ENTRY_CONFIG_USE_WAYLAND
if (wmi.subsystem == SDL_SYSWM_WAYLAND)
return bgfx::NativeWindowHandleType::Wayland;
else
-# endif // ENTRY_CONFIG_USE_WAYLAND
return bgfx::NativeWindowHandleType::Default;
# else
return bgfx::NativeWindowHandleType::Default;