diff --git a/lib/irrlicht/include/IrrCompileConfig.h b/lib/irrlicht/include/IrrCompileConfig.h index 6e03f7014..5a2b409b4 100644 --- a/lib/irrlicht/include/IrrCompileConfig.h +++ b/lib/irrlicht/include/IrrCompileConfig.h @@ -213,6 +213,10 @@ define out. */ #define _IRR_COMPILE_WITH_WAYLAND +#ifdef _IRR_COMPILE_WITH_WAYLAND +#define _IRR_COMPILE_WITH_EGL_ +#endif + //! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers. /** On some systems there is no support for the dynamic extension of OpenGL via function pointers such that this has to be undef'ed. */ diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp index 74ba076f6..9655a49ad 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp @@ -28,6 +28,7 @@ extern bool GLContextDebugBit; #ifdef _IRR_COMPILE_WITH_WAYLAND #include "cirrdevicewayland.h" +#include "CContextEGL.h" #endif namespace irr @@ -981,7 +982,7 @@ bool COpenGLDriver::endScene() if (DeviceType == EIDT_WAYLAND) { wl_display_dispatch_pending(wl_device->display); - eglSwapBuffers(wl_device->egl_display, wl_device->egl_surface); + wl_device->getEGLContext()->swapBuffers(); return true; } diff --git a/lib/irrlicht/source/Irrlicht/cirrdevicewayland.cpp b/lib/irrlicht/source/Irrlicht/cirrdevicewayland.cpp index cf131d3b1..6dff26432 100644 --- a/lib/irrlicht/source/Irrlicht/cirrdevicewayland.cpp +++ b/lib/irrlicht/source/Irrlicht/cirrdevicewayland.cpp @@ -20,6 +20,7 @@ extern bool GLContextDebugBit; #include "IGUISpriteBank.h" #include #include "CVideoModeList.h" +#include "CContextEGL.h" #if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ #include @@ -461,7 +462,8 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) #ifdef _DEBUG setDebugName("CIrrDeviceLinux"); #endif - + + EglContext = NULL; // print version, distribution etc. // thx to LynxLuna for pointing me to the uname function @@ -530,7 +532,9 @@ CIrrDeviceWayland::~CIrrDeviceWayland() wl_registry_destroy(registry); wl_display_disconnect(display); xkb_context_unref(xkbctx); -//TODO : surfaces, egl + + delete EglContext; + #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) { @@ -565,50 +569,19 @@ void CIrrDeviceWayland::initEGL() { egl_window = wl_egl_window_create(surface, Width, Height); - egl_display = eglGetDisplay(display); - if (egl_display == EGL_NO_DISPLAY) - { - os::Printer::log("eglGetDisplay() error", "", ELL_ERROR); - } - if(!eglInitialize(egl_display, NULL, NULL)) - { - os::Printer::log("eglInitialize() error", "", ELL_ERROR); - } - - int confsize; - int attrib[] = {EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_RED_SIZE, 4, - EGL_GREEN_SIZE, 4, - EGL_BLUE_SIZE, 4, - EGL_DEPTH_SIZE, 24, - EGL_NONE}; - EGLConfig eglconf; - - if (!eglChooseConfig(egl_display, attrib, &eglconf, 1, &confsize)) - { - os::Printer::log("eglChooseConfig() error", "", ELL_ERROR); - } - egl_surface = eglCreateWindowSurface(egl_display, eglconf, egl_window, 0); - if (egl_surface == EGL_NO_SURFACE) - { - os::Printer::log("eglCreateWindowSurface() error", "", ELL_ERROR); - } - if (!eglBindAPI(EGL_OPENGL_API)) - { - os::Printer::log("eglBindAPI() error", "", ELL_ERROR); - } - int glattrib[] = {EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_CONTEXT_MINOR_VERSION_KHR, 3, EGL_NONE}; - egl_context = eglCreateContext(egl_display, eglconf, EGL_NO_CONTEXT, glattrib); - if (egl_context == EGL_NO_CONTEXT) - { - os::Printer::log("eglCreateContext() error", "", ELL_ERROR); - } - if (!eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context)) - { - os::Printer::log("eglMakeCurrent() error", "", ELL_ERROR); - } - video::useCoreContext = true; - eglSwapInterval(egl_display, CreationParams.Vsync ? 1 : 0); + EglContext = new ContextManagerEGL(); + + ContextEGLParams egl_params; + egl_params.opengl_api = CEGL_API_OPENGL; + egl_params.surface_type = CEGL_SURFACE_WINDOW; + egl_params.force_legacy_device = CreationParams.ForceLegacyDevice; + egl_params.with_alpha_channel = CreationParams.WithAlphaChannel; + egl_params.vsync_enabled = CreationParams.Vsync; + egl_params.window = egl_window; + egl_params.display = display; + + EglContext->init(egl_params); + video::useCoreContext = !EglContext->isLegacyDevice(); } bool CIrrDeviceWayland::createWindow() diff --git a/lib/irrlicht/source/Irrlicht/cirrdevicewayland.h b/lib/irrlicht/source/Irrlicht/cirrdevicewayland.h index 5f5976414..929d170c5 100644 --- a/lib/irrlicht/source/Irrlicht/cirrdevicewayland.h +++ b/lib/irrlicht/source/Irrlicht/cirrdevicewayland.h @@ -14,12 +14,12 @@ #include #include -#include -#include #include #define KeySym s32 +class ContextManagerEGL; + // Note : only supporting shell interface namespace irr @@ -231,6 +231,8 @@ namespace irr std::vector Modes; core::dimension2du CurrentModes; + ContextManagerEGL* EglContext; + public: void signalEvent(const SEvent&); void addMode(const core::dimension2du &mode) { Modes.push_back(mode); } @@ -251,10 +253,9 @@ namespace irr wl_surface *surface; wl_shell_surface *shell_surface; wl_egl_window *egl_window; - - EGLSurface egl_surface; - EGLDisplay egl_display; - EGLContext egl_context; + + ContextManagerEGL* getEGLContext() {return EglContext;} + private: // XVisualInfo* visual; mutable core::stringc Clipboard;