Better EGL context creation

This commit is contained in:
Deve 2017-04-22 21:51:49 +02:00
parent 035c33f960
commit 63517dd4be
4 changed files with 32 additions and 53 deletions

View File

@ -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. */

View File

@ -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;
}

View File

@ -20,6 +20,7 @@ extern bool GLContextDebugBit;
#include "IGUISpriteBank.h"
#include <sys/mman.h>
#include "CVideoModeList.h"
#include "CContextEGL.h"
#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#include <fcntl.h>
@ -462,6 +463,7 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param)
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);
}
EglContext = new ContextManagerEGL();
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;
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;
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->init(egl_params);
video::useCoreContext = !EglContext->isLegacyDevice();
}
bool CIrrDeviceWayland::createWindow()

View File

@ -14,12 +14,12 @@
#include <xkbcommon/xkbcommon.h>
#include <GL/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <vector>
#define KeySym s32
class ContextManagerEGL;
// Note : only supporting shell interface
namespace irr
@ -231,6 +231,8 @@ namespace irr
std::vector<core::dimension2du> Modes;
core::dimension2du CurrentModes;
ContextManagerEGL* EglContext;
public:
void signalEvent(const SEvent&);
void addMode(const core::dimension2du &mode) { Modes.push_back(mode); }
@ -252,9 +254,8 @@ namespace irr
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;