summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/glcontext_egl.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/glcontext_egl.cpp')
-rw-r--r--3rdparty/bgfx/src/glcontext_egl.cpp102
1 files changed, 96 insertions, 6 deletions
diff --git a/3rdparty/bgfx/src/glcontext_egl.cpp b/3rdparty/bgfx/src/glcontext_egl.cpp
index 54e0230b778..85de92e1df5 100644
--- a/3rdparty/bgfx/src/glcontext_egl.cpp
+++ b/3rdparty/bgfx/src/glcontext_egl.cpp
@@ -111,6 +111,43 @@ EGL_IMPORT
}
#endif // BGFX_USE_GL_DYNAMIC_LIB
+
+#if BX_PLATFORM_LINUX
+# define WL_EGL_IMPORT \
+ WL_EGL_FUNC(struct wl_egl_window *, wl_egl_window_create, (struct wl_surface *, int, int) ) \
+ WL_EGL_FUNC(void, wl_egl_window_destroy, (struct wl_egl_window *)) \
+ WL_EGL_FUNC(void, wl_egl_window_resize, (struct wl_egl_window *, int, int, int, int)) \
+ WL_EGL_FUNC(void, wl_egl_window_get_attached_size, (struct wl_egl_window *, int *, int *) ) \
+
+# define WL_EGL_FUNC(rt, fname, params) \
+ typedef rt(*PFNWLEGL_##fname) params; \
+ PFNWLEGL_##fname BGFX_WAYLAND_##fname;
+
+WL_EGL_IMPORT
+# undef WL_EGL_FUNC
+
+ void* waylandEglOpen()
+ {
+ void* handle = bx::dlopen("libwayland-egl.so.1");
+ BGFX_FATAL(handle != NULL, Fatal::UnableToInitialize, "Could not dlopen() libwayland-egl.so.1");
+
+# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = (PFNWLEGL_##fname) bx::dlsym(handle, #fname);
+ WL_EGL_IMPORT
+# undef WL_EGL_FUNC
+
+ return handle;
+ }
+
+ void waylandEglClose(void* _handle)
+ {
+ bx::dlclose(_handle);
+
+# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = NULL;
+ WL_EGL_IMPORT
+# undef WL_EGL_FUNC
+ }
+#endif // BX_PLATFORM_LINUX
+
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
# include "glimports.h"
@@ -118,18 +155,32 @@ EGL_IMPORT
struct SwapChainGL
{
- SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh)
+ SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh, int _width, int _height)
: m_nwh(_nwh)
, m_display(_display)
+# if BX_PLATFORM_LINUX
+ , m_eglWindow(NULL)
+# endif
{
EGLSurface defaultSurface = eglGetCurrentSurface(EGL_DRAW);
+ BX_UNUSED(_width, _height);
+
if (EGLNativeWindowType(0) == _nwh)
{
m_surface = eglCreatePbufferSurface(m_display, _config, NULL);
}
else
{
+# if BX_PLATFORM_LINUX
+ 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_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)_nwh, _width, _height);
+ _nwh = (EGLNativeWindowType) m_eglWindow;
+ }
+# endif
m_surface = eglCreateWindowSurface(m_display, _config, _nwh, NULL);
}
@@ -157,6 +208,12 @@ EGL_IMPORT
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(m_display, m_context);
eglDestroySurface(m_display, m_surface);
+# if BX_PLATFORM_LINUX
+ if (m_eglWindow)
+ {
+ BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow);
+ }
+# endif
eglMakeCurrent(m_display, defaultSurface, defaultSurface, defaultContext);
}
@@ -174,6 +231,9 @@ EGL_IMPORT
EGLContext m_context;
EGLDisplay m_display;
EGLSurface m_surface;
+# if BX_PLATFORM_LINUX
+ wl_egl_window *m_eglWindow;
+# endif
};
# if BX_PLATFORM_RPI
@@ -188,7 +248,7 @@ EGL_IMPORT
bcm_host_init();
# endif // BX_PLATFORM_RPI
- m_eglLibrary = eglOpen();
+ m_eglDll = eglOpen();
if (NULL == g_platformData.context)
{
@@ -207,7 +267,7 @@ EGL_IMPORT
}
# endif // BX_PLATFORM_WINDOWS
- m_display = eglGetDisplay(NULL == ndt ? EGL_DEFAULT_DISPLAY : ndt);
+ m_display = eglGetDisplay(NULL == ndt ? EGL_DEFAULT_DISPLAY : ndt);
BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);
EGLint major = 0;
@@ -316,6 +376,12 @@ EGL_IMPORT
vc_dispmanx_update_submit_sync(dispmanUpdate);
# endif // BX_PLATFORM_ANDROID
+# if BX_PLATFORM_LINUX
+ if (g_platformData.type == NativeWindowHandleType::Wayland)
+ {
+ m_waylandEglDll = waylandEglOpen();
+ }
+# endif
if (headless)
{
EGLint pbAttribs[] =
@@ -330,6 +396,15 @@ EGL_IMPORT
}
else
{
+# if BX_PLATFORM_LINUX
+ 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_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)nwh, _width, _height);
+ nwh = (EGLNativeWindowType) m_eglWindow;
+ }
+# endif
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
}
@@ -412,16 +487,26 @@ EGL_IMPORT
void GlContext::destroy()
{
+ BX_TRACE("GLContext::destroy()");
if (NULL != m_display)
{
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(m_display, m_context);
eglDestroySurface(m_display, m_surface);
+# if BX_PLATFORM_LINUX
+ if (m_eglWindow)
+ {
+ BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow);
+ waylandEglClose(m_waylandEglDll);
+ m_waylandEglDll = NULL;
+ }
+# endif
eglTerminate(m_display);
m_context = NULL;
}
- eglClose(m_eglLibrary);
+ eglClose(m_eglDll);
+ m_eglDll = NULL;
# if BX_PLATFORM_RPI
bcm_host_deinit();
@@ -447,6 +532,11 @@ EGL_IMPORT
}
# elif BX_PLATFORM_EMSCRIPTEN
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(HTML5_TARGET_CANVAS_SELECTOR, _width, _height) );
+# elif BX_PLATFORM_LINUX
+ if (NULL != m_eglWindow)
+ {
+ BGFX_WAYLAND_wl_egl_window_resize(m_eglWindow, _width, _height, 0, 0);
+ }
# else
BX_UNUSED(_width, _height);
# endif // BX_PLATFORM_*
@@ -470,9 +560,9 @@ EGL_IMPORT
;
}
- SwapChainGL* GlContext::createSwapChain(void* _nwh)
+ SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height)
{
- return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh);
+ return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh, _width, _height);
}
void GlContext::destroySwapChain(SwapChainGL* _swapChain)