mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
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.
This commit is contained in:
committed by
GitHub
parent
3f9fe0d34e
commit
e488a07f1b
@@ -15,13 +15,9 @@
|
||||
#endif // GLFW_VERSION_MINOR < 2
|
||||
|
||||
#if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
# include <wayland-egl.h>
|
||||
# define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
# else
|
||||
# define GLFW_EXPOSE_NATIVE_X11
|
||||
# define GLFW_EXPOSE_NATIVE_GLX
|
||||
# endif
|
||||
# define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
# define GLFW_EXPOSE_NATIVE_X11
|
||||
# define GLFW_EXPOSE_NATIVE_GLX
|
||||
#elif BX_PLATFORM_OSX
|
||||
# define GLFW_EXPOSE_NATIVE_COCOA
|
||||
# define GLFW_EXPOSE_NATIVE_NSGL
|
||||
@@ -45,12 +41,14 @@ namespace entry
|
||||
static void* glfwNativeWindowHandle(GLFWwindow* _window)
|
||||
{
|
||||
# if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window);
|
||||
return (void*)surface;
|
||||
# else
|
||||
return (void*)(uintptr_t)glfwGetX11Window(_window);
|
||||
# endif
|
||||
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
|
||||
@@ -58,23 +56,6 @@ namespace entry
|
||||
# endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
static void glfwDestroyWindowImpl(GLFWwindow *_window)
|
||||
{
|
||||
if(!_window)
|
||||
return;
|
||||
# if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
wl_egl_window *win_impl = (wl_egl_window*)glfwGetWindowUserPointer(_window);
|
||||
if(win_impl)
|
||||
{
|
||||
glfwSetWindowUserPointer(_window, nullptr);
|
||||
wl_egl_window_destroy(win_impl);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
glfwDestroyWindow(_window);
|
||||
}
|
||||
|
||||
static uint8_t translateKeyModifiers(int _glfw)
|
||||
{
|
||||
uint8_t modifiers = 0;
|
||||
@@ -515,7 +496,7 @@ namespace entry
|
||||
{
|
||||
GLFWwindow* window = m_window[msg->m_handle.idx];
|
||||
m_eventQueue.postWindowEvent(msg->m_handle);
|
||||
glfwDestroyWindowImpl(window);
|
||||
glfwDestroyWindow(window);
|
||||
m_window[msg->m_handle.idx] = NULL;
|
||||
}
|
||||
}
|
||||
@@ -607,7 +588,7 @@ namespace entry
|
||||
m_eventQueue.postExitEvent();
|
||||
m_thread.shutdown();
|
||||
|
||||
glfwDestroyWindowImpl(m_window[0]);
|
||||
glfwDestroyWindow(m_window[0]);
|
||||
glfwTerminate();
|
||||
|
||||
return m_thread.getExitCode();
|
||||
@@ -855,11 +836,14 @@ namespace entry
|
||||
void* getNativeDisplayHandle()
|
||||
{
|
||||
# if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
return glfwGetWaylandDisplay();
|
||||
# else
|
||||
return glfwGetX11Display();
|
||||
# endif // ENTRY_CONFIG_USE_WAYLAND
|
||||
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
|
||||
{
|
||||
return glfwGetWaylandDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
return glfwGetX11Display();
|
||||
}
|
||||
# else
|
||||
return NULL;
|
||||
# endif // BX_PLATFORM_*
|
||||
@@ -868,11 +852,14 @@ namespace entry
|
||||
bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType()
|
||||
{
|
||||
# if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
return bgfx::NativeWindowHandleType::Wayland;
|
||||
# else
|
||||
return bgfx::NativeWindowHandleType::Default;
|
||||
# endif // ENTRY_CONFIG_USE_WAYLAND
|
||||
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
|
||||
{
|
||||
return bgfx::NativeWindowHandleType::Wayland;
|
||||
}
|
||||
else
|
||||
{
|
||||
return bgfx::NativeWindowHandleType::Default;
|
||||
}
|
||||
# else
|
||||
return bgfx::NativeWindowHandleType::Default;
|
||||
# endif // BX_PLATFORM_*
|
||||
|
||||
@@ -25,10 +25,6 @@
|
||||
# define ENTRY_CONFIG_USE_GLFW 0
|
||||
#endif // ENTRY_CONFIG_USE_GLFW
|
||||
|
||||
#ifndef ENTRY_CONFIG_USE_WAYLAND
|
||||
# define ENTRY_CONFIG_USE_WAYLAND 0
|
||||
#endif // ENTRY_CONFIG_USE_WAYLAND
|
||||
|
||||
#if !defined(ENTRY_CONFIG_USE_NATIVE) \
|
||||
&& !ENTRY_CONFIG_USE_NOOP \
|
||||
&& !ENTRY_CONFIG_USE_SDL \
|
||||
|
||||
@@ -46,12 +46,14 @@ namespace entry
|
||||
}
|
||||
|
||||
# if BX_PLATFORM_LINUX
|
||||
# if ENTRY_CONFIG_USE_WAYLAND
|
||||
if (wmi.subsystem == SDL_SYSWM_WAYLAND)
|
||||
return (void*)wmi.info.wl.surface;
|
||||
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 || BX_PLATFORM_VISIONOS
|
||||
return wmi.info.cocoa.window;
|
||||
# elif BX_PLATFORM_WINDOWS
|
||||
@@ -61,13 +63,6 @@ namespace entry
|
||||
# endif // BX_PLATFORM_
|
||||
}
|
||||
|
||||
static void sdlDestroyWindow(SDL_Window* _window)
|
||||
{
|
||||
if(!_window)
|
||||
return;
|
||||
SDL_DestroyWindow(_window);
|
||||
}
|
||||
|
||||
static uint8_t translateKeyModifiers(uint16_t _sdl)
|
||||
{
|
||||
uint8_t modifiers = 0;
|
||||
@@ -779,7 +774,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;
|
||||
}
|
||||
}
|
||||
@@ -873,7 +868,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();
|
||||
@@ -1063,12 +1058,10 @@ namespace entry
|
||||
return NULL;
|
||||
}
|
||||
# if BX_PLATFORM_LINUX
|
||||
# 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_*
|
||||
@@ -1083,13 +1076,11 @@ namespace entry
|
||||
return bgfx::NativeWindowHandleType::Default;
|
||||
}
|
||||
# if BX_PLATFORM_LINUX
|
||||
# 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;
|
||||
}
|
||||
|
||||
@@ -851,14 +851,18 @@ namespace entry
|
||||
|
||||
if (utf16[0] >= 0xD800 && utf16[0] <= 0xDBFF) {
|
||||
m_surrogate = utf16[0];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int utf16_len;
|
||||
if (utf16[0] >= 0xDC00 && utf16[0] <= 0xDFFF) {
|
||||
utf16[1] = utf16[0];
|
||||
utf16[0] = m_surrogate;
|
||||
m_surrogate = 0;
|
||||
utf16_len = 2;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
utf16_len = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user