summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/common/entry/entry_glfw.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/entry/entry_glfw.cpp125
1 files changed, 71 insertions, 54 deletions
diff --git a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
index 5e81dd9aece..4c699f23a5e 100644
--- a/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
+++ b/3rdparty/bgfx/examples/common/entry/entry_glfw.cpp
@@ -1,6 +1,6 @@
/*
- * 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"
@@ -15,6 +15,7 @@
#endif // GLFW_VERSION_MINOR < 2
#if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+# define GLFW_EXPOSE_NATIVE_WAYLAND
# define GLFW_EXPOSE_NATIVE_X11
# define GLFW_EXPOSE_NATIVE_GLX
#elif BX_PLATFORM_OSX
@@ -40,7 +41,14 @@ namespace entry
static void* glfwNativeWindowHandle(GLFWwindow* _window)
{
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
- return (void*)(uintptr_t)glfwGetX11Window(_window);
+ if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
+ {
+ return glfwGetWaylandWindow(_window);
+ }
+ else
+ {
+ return (void*)(uintptr_t)glfwGetX11Window(_window);
+ }
# elif BX_PLATFORM_OSX
return glfwGetCocoaWindow(_window);
# elif BX_PLATFORM_WINDOWS
@@ -48,23 +56,6 @@ namespace entry
# endif // BX_PLATFORM_
}
- static void glfwSetWindow(GLFWwindow* _window)
- {
- bgfx::PlatformData pd;
-# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
- pd.ndt = glfwGetX11Display();
-# elif BX_PLATFORM_OSX
- pd.ndt = NULL;
-# elif BX_PLATFORM_WINDOWS
- pd.ndt = NULL;
-# endif // BX_PLATFORM_WINDOWS
- pd.nwh = glfwNativeWindowHandle(_window);
- pd.context = NULL;
- pd.backBuffer = NULL;
- pd.backBufferDS = NULL;
- bgfx::setPlatformData(pd);
- }
-
static uint8_t translateKeyModifiers(int _glfw)
{
uint8_t modifiers = 0;
@@ -412,29 +403,28 @@ namespace entry
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
WindowHandle handle = { m_windowAlloc.alloc() };
- m_windows[0] = glfwCreateWindow(ENTRY_DEFAULT_WIDTH
+ m_window[0] = glfwCreateWindow(ENTRY_DEFAULT_WIDTH
, ENTRY_DEFAULT_HEIGHT
, "bgfx"
, NULL
, NULL
);
- if (!m_windows[0])
+ if (!m_window[0])
{
DBG("glfwCreateWindow failed!");
glfwTerminate();
return bx::kExitFailure;
}
- glfwSetKeyCallback(m_windows[0], keyCb);
- glfwSetCharCallback(m_windows[0], charCb);
- glfwSetScrollCallback(m_windows[0], scrollCb);
- glfwSetCursorPosCallback(m_windows[0], cursorPosCb);
- glfwSetMouseButtonCallback(m_windows[0], mouseButtonCb);
- glfwSetWindowSizeCallback(m_windows[0], windowSizeCb);
- glfwSetDropCallback(m_windows[0], dropFileCb);
+ glfwSetKeyCallback(m_window[0], keyCb);
+ glfwSetCharCallback(m_window[0], charCb);
+ glfwSetScrollCallback(m_window[0], scrollCb);
+ glfwSetCursorPosCallback(m_window[0], cursorPosCb);
+ glfwSetMouseButtonCallback(m_window[0], mouseButtonCb);
+ glfwSetWindowSizeCallback(m_window[0], windowSizeCb);
+ glfwSetDropCallback(m_window[0], dropFileCb);
- glfwSetWindow(m_windows[0]);
m_eventQueue.postSizeEvent(handle, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
for (uint32_t ii = 0; ii < ENTRY_CONFIG_MAX_GAMEPADS; ++ii)
@@ -451,10 +441,10 @@ namespace entry
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
- while (NULL != m_windows[0]
- && !glfwWindowShouldClose(m_windows[0]))
+ while (NULL != m_window[0]
+ && !glfwWindowShouldClose(m_window[0]))
{
- glfwWaitEvents();
+ glfwWaitEventsTimeout(0.016);
for (uint32_t ii = 0; ii < ENTRY_CONFIG_MAX_GAMEPADS; ++ii)
{
@@ -494,7 +484,7 @@ namespace entry
glfwSetWindowSizeCallback(window, windowSizeCb);
glfwSetDropCallback(window, dropFileCb);
- m_windows[msg->m_handle.idx] = window;
+ m_window[msg->m_handle.idx] = window;
m_eventQueue.postSizeEvent(msg->m_handle, msg->m_width, msg->m_height);
m_eventQueue.postWindowEvent(msg->m_handle, glfwNativeWindowHandle(window));
}
@@ -504,31 +494,31 @@ namespace entry
{
if (isValid(msg->m_handle) )
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
m_eventQueue.postWindowEvent(msg->m_handle);
glfwDestroyWindow(window);
- m_windows[msg->m_handle.idx] = NULL;
+ m_window[msg->m_handle.idx] = NULL;
}
}
break;
case GLFW_WINDOW_SET_TITLE:
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowTitle(window, msg->m_title.c_str());
}
break;
case GLFW_WINDOW_SET_POS:
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowPos(window, msg->m_x, msg->m_y);
}
break;
case GLFW_WINDOW_SET_SIZE:
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowSize(window, msg->m_width, msg->m_height);
}
break;
@@ -541,7 +531,7 @@ namespace entry
case GLFW_WINDOW_TOGGLE_FULL_SCREEN:
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
if (glfwGetWindowMonitor(window) )
{
glfwSetWindowMonitor(window
@@ -578,7 +568,7 @@ namespace entry
case GLFW_WINDOW_MOUSE_LOCK:
{
- GLFWwindow* window = m_windows[msg->m_handle.idx];
+ GLFWwindow* window = m_window[msg->m_handle.idx];
if (msg->m_value)
{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
@@ -598,7 +588,7 @@ namespace entry
m_eventQueue.postExitEvent();
m_thread.shutdown();
- glfwDestroyWindow(m_windows[0]);
+ glfwDestroyWindow(m_window[0]);
glfwTerminate();
return m_thread.getExitCode();
@@ -610,7 +600,7 @@ namespace entry
for (uint32_t ii = 0, num = m_windowAlloc.getNumHandles(); ii < num; ++ii)
{
uint16_t idx = m_windowAlloc.getHandleAt(ii);
- if (_window == m_windows[idx])
+ if (_window == m_window[idx])
{
WindowHandle handle = { idx };
return handle;
@@ -635,7 +625,7 @@ namespace entry
EventQueue m_eventQueue;
bx::Mutex m_lock;
- GLFWwindow* m_windows[ENTRY_CONFIG_MAX_WINDOWS];
+ GLFWwindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
GamepadGLFW m_gamepad[ENTRY_CONFIG_MAX_GAMEPADS];
@@ -758,13 +748,11 @@ namespace entry
const Event* poll()
{
- glfwPostEmptyEvent();
return s_ctx.m_eventQueue.poll();
}
const Event* poll(WindowHandle _handle)
{
- glfwPostEmptyEvent();
return s_ctx.m_eventQueue.poll(_handle);
}
@@ -784,7 +772,6 @@ namespace entry
msg->m_title = _title;
msg->m_handle.idx = s_ctx.m_windowAlloc.alloc();
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
return msg->m_handle;
}
@@ -793,7 +780,6 @@ namespace entry
Msg* msg = new Msg(GLFW_WINDOW_DESTROY);
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
}
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
@@ -803,7 +789,6 @@ namespace entry
msg->m_y = _y;
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
}
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
@@ -813,7 +798,6 @@ namespace entry
msg->m_height = _height;
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
}
void setWindowTitle(WindowHandle _handle, const char* _title)
@@ -822,7 +806,6 @@ namespace entry
msg->m_title = _title;
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
}
void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled)
@@ -835,7 +818,6 @@ namespace entry
Msg* msg = new Msg(GLFW_WINDOW_TOGGLE_FULL_SCREEN);
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
}
void setMouseLock(WindowHandle _handle, bool _lock)
@@ -844,7 +826,43 @@ namespace entry
msg->m_value = _lock;
msg->m_handle = _handle;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
+ }
+
+ void* getNativeWindowHandle(WindowHandle _handle)
+ {
+ return glfwNativeWindowHandle(s_ctx.m_window[_handle.idx]);
+ }
+
+ void* getNativeDisplayHandle()
+ {
+# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+ if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
+ {
+ return glfwGetWaylandDisplay();
+ }
+ else
+ {
+ return glfwGetX11Display();
+ }
+# else
+ return NULL;
+# endif // BX_PLATFORM_*
+ }
+
+ bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType(WindowHandle _handle)
+ {
+# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
+ if (glfwGetPlatform() == GLFW_PLATFORM_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)
@@ -858,7 +876,6 @@ namespace entry
Msg* msg = new Msg(GLFW_WINDOW_DESTROY);
msg->m_handle.idx = 0;
s_ctx.m_msgs.push(msg);
- glfwPostEmptyEvent();
return result;
}