summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
diff options
context:
space:
mode:
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;