GLContext: Wayland support

This commit is contained in:
Connor McLaughlin
2020-07-07 21:40:55 +10:00
parent eab70546c8
commit 4ce5f7e802
5 changed files with 91 additions and 2 deletions

View File

@ -149,7 +149,7 @@ if(USE_EGL)
endif()
endif()
if(SUPPORTS_X11)
if(USE_X11)
target_sources(common PRIVATE
gl/context_glx.cpp
gl/context_glx.h
@ -157,6 +157,15 @@ if(SUPPORTS_X11)
target_compile_definitions(common PRIVATE "-DUSE_GLX=1")
endif()
if(USE_WAYLAND)
target_sources(common PRIVATE
gl/context_egl_wayland.cpp
gl/context_egl_wayland.h
)
target_compile_definitions(common PRIVATE "-DUSE_WAYLAND=1")
target_link_libraries(common PRIVATE Wayland::Egl)
endif()
if(APPLE)
target_sources(common PRIVATE
gl/context_agl.mm

View File

@ -18,6 +18,8 @@ Log_SetChannel(GL::Context);
#ifdef USE_EGL
#if defined(USE_X11)
#include "context_egl_x11.h"
#elif defined(USE_WAYLAND)
#include "context_egl_wayland.h"
#elif defined(ANDROID)
#include "context_egl_android.h"
#else
@ -78,7 +80,9 @@ std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version
#ifdef USE_EGL
context = ContextEGLAndroid::Create(wi, versions_to_try, num_versions_to_try);
#endif
#elif defined(USE_X11)
#endif
#if defined(USE_X11)
if (wi.type == WindowInfo::Type::X11)
{
#ifdef USE_EGL
@ -93,6 +97,11 @@ std::unique_ptr<GL::Context> Context::Create(const WindowInfo& wi, const Version
}
#endif
#if defined(USE_WAYLAND)
if (wi.type == WindowInfo::Type::Wayland)
context = ContextEGLWayland::Create(wi, versions_to_try, num_versions_to_try);
#endif
if (!context)
return nullptr;

View File

@ -0,0 +1,40 @@
#include "context_egl_wayland.h"
#include "../log.h"
#include <wayland-egl.h>
Log_SetChannel(GL::ContextEGLWayland);
namespace GL {
ContextEGLWayland::ContextEGLWayland(const WindowInfo& wi) : ContextEGL(wi) {}
ContextEGLWayland::~ContextEGLWayland() = default;
std::unique_ptr<Context> ContextEGLWayland::Create(const WindowInfo& wi, const Version* versions_to_try,
size_t num_versions_to_try)
{
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
if (!context->Initialize(versions_to_try, num_versions_to_try))
return nullptr;
return context;
}
std::unique_ptr<Context> ContextEGLWayland::CreateSharedContext(const WindowInfo& wi)
{
std::unique_ptr<ContextEGLWayland> context = std::make_unique<ContextEGLWayland>(wi);
context->m_display = m_display;
if (!context->CreateContextAndSurface(m_version, m_context, false))
return nullptr;
return context;
}
EGLNativeWindowType ContextEGLWayland::GetNativeWindow(EGLConfig config)
{
wl_egl_window* window =
wl_egl_window_create(static_cast<wl_surface*>(m_wi.window_handle), m_wi.surface_width, m_wi.surface_height);
if (!window)
return {};
return reinterpret_cast<EGLNativeWindowType>(window);
}
} // namespace GL

View File

@ -0,0 +1,21 @@
#pragma once
#include "context_egl.h"
namespace GL {
class ContextEGLWayland final : public ContextEGL
{
public:
ContextEGLWayland(const WindowInfo& wi);
~ContextEGLWayland() override;
static std::unique_ptr<Context> Create(const WindowInfo& wi, const Version* versions_to_try,
size_t num_versions_to_try);
std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
protected:
EGLNativeWindowType GetNativeWindow(EGLConfig config) override;
};
} // namespace GL