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.cpp140
1 files changed, 76 insertions, 64 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
index d582b034e5e..bbcdb069257 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_sdl.cpp
@@ -1,15 +1,16 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ * Copyright 2011-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "entry_p.h"
#if ENTRY_CONFIG_USE_SDL
-#if BX_PLATFORM_WINDOWS
+#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+#elif BX_PLATFORM_WINDOWS
# define SDL_MAIN_HANDLED
-#endif // BX_PLATFORM_WINDOWS
+#endif
#include <bx/os.h>
@@ -34,35 +35,32 @@ BX_PRAGMA_DIAGNOSTIC_POP()
namespace entry
{
- inline bool sdlSetWindow(SDL_Window* _window)
+ ///
+ static void* sdlNativeWindowHandle(SDL_Window* _window)
{
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo(_window, &wmi) )
{
- return false;
+ return NULL;
}
- bgfx::PlatformData pd;
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
- pd.ndt = wmi.info.x11.display;
- pd.nwh = (void*)(uintptr_t)wmi.info.x11.window;
-# elif BX_PLATFORM_OSX
- pd.ndt = NULL;
- pd.nwh = wmi.info.cocoa.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
- pd.ndt = NULL;
- pd.nwh = wmi.info.win.window;
-# elif BX_PLATFORM_STEAMLINK
- pd.ndt = wmi.info.vivante.display;
- pd.nwh = wmi.info.vivante.window;
+ return wmi.info.win.window;
+# elif BX_PLATFORM_ANDROID
+ return wmi.info.android.window;
# endif // BX_PLATFORM_
- pd.context = NULL;
- pd.backBuffer = NULL;
- pd.backBufferDS = NULL;
- bgfx::setPlatformData(pd);
-
- return true;
}
static uint8_t translateKeyModifiers(uint16_t _sdl)
@@ -102,7 +100,7 @@ namespace entry
static void initTranslateKey(uint16_t _sdl, Key::Enum _key)
{
- BX_CHECK(_sdl < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _sdl);
+ BX_ASSERT(_sdl < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _sdl);
s_translateKey[_sdl&0xff] = (uint8_t)_key;
}
@@ -252,27 +250,6 @@ namespace entry
static int32_t threadFunc(bx::Thread* _thread, void* _userData);
};
- ///
- static void* sdlNativeWindowHandle(SDL_Window* _window)
- {
- SDL_SysWMinfo wmi;
- SDL_VERSION(&wmi.version);
- if (!SDL_GetWindowWMInfo(_window, &wmi) )
- {
- return NULL;
- }
-
-# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
- return (void*)wmi.info.x11.window;
-# elif BX_PLATFORM_OSX
- return wmi.info.cocoa.window;
-# elif BX_PLATFORM_WINDOWS
- return wmi.info.win.window;
-# elif BX_PLATFORM_STEAMLINK
- return wmi.info.vivante.window;
-# endif // BX_PLATFORM_
- }
-
struct Msg
{
Msg()
@@ -479,14 +456,13 @@ namespace entry
s_userEventStart = SDL_RegisterEvents(7);
- sdlSetWindow(m_window[0]);
bgfx::renderFrame();
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
// 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);
@@ -502,7 +478,7 @@ namespace entry
bx::AllocatorI* allocator = getAllocator();
uint32_t size = (uint32_t)bx::getSize(reader);
void* data = BX_ALLOC(allocator, size + 1);
- bx::read(reader, data, size);
+ bx::read(reader, data, size, bx::ErrorAssert{});
bx::close(reader);
((char*)data)[size] = '\0';
@@ -664,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;
@@ -909,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;
}
@@ -981,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)
@@ -1095,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;
@@ -1128,6 +1099,47 @@ namespace entry
sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);
}
+ void* getNativeWindowHandle(WindowHandle _handle)
+ {
+ return sdlNativeWindowHandle(s_ctx.m_window[_handle.idx]);
+ }
+
+ void* getNativeDisplayHandle()
+ {
+ SDL_SysWMinfo wmi;
+ SDL_VERSION(&wmi.version);
+ if (!SDL_GetWindowWMInfo(s_ctx.m_window[0], &wmi) )
+ {
+ return NULL;
+ }
+# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+ if (wmi.subsystem == SDL_SYSWM_WAYLAND)
+ return wmi.info.wl.display;
+ else
+ return wmi.info.x11.display;
+# else
+ return NULL;
+# endif // BX_PLATFORM_*
+ }
+
+ bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType(WindowHandle _handle)
+ {
+ SDL_SysWMinfo wmi;
+ SDL_VERSION(&wmi.version);
+ if (!SDL_GetWindowWMInfo(s_ctx.m_window[_handle.idx], &wmi) )
+ {
+ return bgfx::NativeWindowHandleType::Default;
+ }
+# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+ if (wmi.subsystem == SDL_SYSWM_WAYLAND)
+ return bgfx::NativeWindowHandleType::Wayland;
+ else
+ return bgfx::NativeWindowHandleType::Default;
+# else
+ return bgfx::NativeWindowHandleType::Default;
+# endif // BX_PLATFORM_*
+ }
+
int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
BX_UNUSED(_thread);