Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support Wayland under EGL and Vulkan. #3358

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions examples/common/entry/entry_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,8 @@ namespace entry
{
# if BX_PLATFORM_LINUX
# if ENTRY_CONFIG_USE_WAYLAND
wl_egl_window *win_impl = (wl_egl_window*)glfwGetWindowUserPointer(_window);
if(!win_impl)
{
int width, height;
glfwGetWindowSize(_window, &width, &height);
struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window);
if(!surface)
return nullptr;
win_impl = wl_egl_window_create(surface, width, height);
glfwSetWindowUserPointer(_window, (void*)(uintptr_t)win_impl);
}
return (void*)(uintptr_t)win_impl;
struct wl_surface* surface = (struct wl_surface*)glfwGetWaylandWindow(_window);
return (void*)surface;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code there was added by @BlockoS, and it looks like he had some reason why it was more complex than just glfwGetWaylandWindow.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see below you moved that code in EGL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the main reason it should be in EGL is to link it up with the resizing events that need to get forwarded to wl_egl_window_resize.

# else
return (void*)(uintptr_t)glfwGetX11Window(_window);
# endif
Expand Down
15 changes: 1 addition & 14 deletions examples/common/entry/entry_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,7 @@ namespace entry
# if BX_PLATFORM_LINUX
# 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;
}
return (void*)wmi.info.wl.surface;
else
# endif // ENTRY_CONFIG_USE_WAYLAND
return (void*)wmi.info.x11.window;
Expand Down
2 changes: 2 additions & 0 deletions examples/common/example-glue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
}
}
}
#else
ImGui::Text("Renderer: %s", bgfx::getRendererName(bgfx::getRendererType()));
#endif // 0

const bgfx::Stats* stats = bgfx::getStats();
Expand Down
21 changes: 21 additions & 0 deletions src/glcontext_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
# define EGL_CHECK(_call) _call
#endif // BGFX_CONFIG_DEBUG

#if defined(WL_EGL_PLATFORM)
# include <wayland-egl.h>
#endif

namespace bgfx { namespace gl
{
#ifndef EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
Expand Down Expand Up @@ -329,6 +333,14 @@ EGL_IMPORT
vc_dispmanx_update_submit_sync(dispmanUpdate);
# endif // BX_PLATFORM_ANDROID

# if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
if (g_platformData.type == NativeWindowHandleType::Wayland) {
// A wl_surface needs to be first wrapped in a wl_egl_window
// before it can be used to create the EGLSurface.
m_egl_window = wl_egl_window_create((wl_surface*)nwh, _width, _height);
nwh = m_egl_window;
}
# endif
if (headless)
{
EGLint pbAttribs[] =
Expand Down Expand Up @@ -430,6 +442,11 @@ EGL_IMPORT
EGL_CHECK(eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) );
EGL_CHECK(eglDestroyContext(m_display, m_context) );
EGL_CHECK(eglDestroySurface(m_display, m_surface) );
# if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
if (m_egl_window) {
wl_egl_window_destroy(m_egl_window);
}
# endif
EGL_CHECK(eglTerminate(m_display) );
m_context = NULL;
}
Expand Down Expand Up @@ -461,6 +478,10 @@ EGL_IMPORT
}
# elif BX_PLATFORM_EMSCRIPTEN
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(HTML5_TARGET_CANVAS_SELECTOR, _width, _height) );
# elif BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
if (NULL != m_egl_window) {
wl_egl_window_resize(m_egl_window, _width, _height, 0, 0);
}
# else
BX_UNUSED(_width, _height);
# endif // BX_PLATFORM_*
Expand Down
7 changes: 7 additions & 0 deletions src/glcontext_egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>


// EGL pulls X11 crap...
#if defined(None)
# undef None
Expand All @@ -35,6 +36,9 @@ namespace bgfx { namespace gl
, m_context(NULL)
, m_display(NULL)
, m_surface(NULL)
#if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
, m_egl_window(NULL)
#endif
, m_msaaContext(false)
{
}
Expand Down Expand Up @@ -62,6 +66,9 @@ namespace bgfx { namespace gl
EGLContext m_context;
EGLDisplay m_display;
EGLSurface m_surface;
#if BX_PLATFORM_LINUX && defined(WL_EGL_PLATFORM)
struct wl_egl_window *m_egl_window;
#endif
// true when MSAA is handled by the context instead of using MSAA FBO
bool m_msaaContext;
};
Expand Down
2 changes: 1 addition & 1 deletion src/renderer_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6940,7 +6940,7 @@ VK_DESTROY
sci.pNext = NULL;
sci.flags = 0;
sci.display = (wl_display*)g_platformData.ndt;
sci.surface = (wl_surface*)((wl_egl_window*)m_nwh)->surface;
sci.surface = (wl_surface*)m_nwh;
result = vkCreateWaylandSurfaceKHR(instance, &sci, allocatorCb, &m_surface);
}
else
Expand Down
Loading