From 3961a9a3b728cf21af5c06fc1ad634d78a180f05 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 5 Apr 2017 20:28:38 +0200 Subject: [PATCH 1/6] Move EGL context to separate class. It will allow to use it for OpenGL + Wayland. --- lib/irrlicht/CMakeLists.txt | 2 + lib/irrlicht/include/IrrCompileConfig.h | 4 + lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 394 ++++++++++++++++++ lib/irrlicht/source/Irrlicht/CContextEGL.h | 76 ++++ .../source/Irrlicht/COGLES2Driver.cpp | 388 +---------------- lib/irrlicht/source/Irrlicht/COGLES2Driver.h | 30 +- .../Irrlicht/COGLES2ExtensionHandler.cpp | 11 +- .../source/Irrlicht/COGLES2ExtensionHandler.h | 5 - 8 files changed, 502 insertions(+), 408 deletions(-) create mode 100644 lib/irrlicht/source/Irrlicht/CContextEGL.cpp create mode 100644 lib/irrlicht/source/Irrlicht/CContextEGL.h diff --git a/lib/irrlicht/CMakeLists.txt b/lib/irrlicht/CMakeLists.txt index ac3e0d49c..8fe03e683 100644 --- a/lib/irrlicht/CMakeLists.txt +++ b/lib/irrlicht/CMakeLists.txt @@ -67,6 +67,7 @@ source/Irrlicht/CAttributes.cpp source/Irrlicht/CBillboardSceneNode.cpp source/Irrlicht/CBoneSceneNode.cpp source/Irrlicht/CCameraSceneNode.cpp +source/Irrlicht/CContextEGL.cpp source/Irrlicht/CColorConverter.cpp source/Irrlicht/CCubeSceneNode.cpp source/Irrlicht/CDefaultGUIElementFactory.cpp @@ -199,6 +200,7 @@ source/Irrlicht/CBillboardSceneNode.h source/Irrlicht/CBlit.h source/Irrlicht/CBoneSceneNode.h source/Irrlicht/CCameraSceneNode.h +source/Irrlicht/CContextEGL.h source/Irrlicht/CColorConverter.h source/Irrlicht/CCubeSceneNode.h source/Irrlicht/CDefaultGUIElementFactory.h diff --git a/lib/irrlicht/include/IrrCompileConfig.h b/lib/irrlicht/include/IrrCompileConfig.h index 1c5c02985..30fc5695e 100644 --- a/lib/irrlicht/include/IrrCompileConfig.h +++ b/lib/irrlicht/include/IrrCompileConfig.h @@ -117,6 +117,10 @@ #define _IRR_COMPILE_ANDROID_ASSET_READER_ #endif +#if defined(_IRR_COMPILE_WITH_OGLES2_) && !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) +#define _IRR_COMPILE_WITH_EGL_ +#endif + #if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_) #ifndef _IRR_SOLARIS_PLATFORM_ #define _IRR_LINUX_PLATFORM_ diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp new file mode 100644 index 000000000..37c7110e0 --- /dev/null +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -0,0 +1,394 @@ +// Copyright (C) 2013 Patryk Nadrowski +// Copyright (C) 2016-2017 Dawid Gan +// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt +// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0 +// driver implemented by Amundis. +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#include "CContextEGL.h" +#include "os.h" +#include "fast_atof.h" + +#if defined(_IRR_COMPILE_WITH_EGL_) + +namespace irr +{ +namespace video +{ + +ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, + const SExposedVideoData& data) +{ + EglDisplay = EGL_NO_DISPLAY; + IsCoreContext = true; + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + HDc = 0; +#endif + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; + HDc = GetDC((HWND)EglWindow); + EglDisplay = eglGetDisplay((NativeDisplayType)HDc); +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window; + EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display); +#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + EglWindow = ((struct android_app *)(params.PrivateData))->window; + EglDisplay = EGL_NO_DISPLAY; +#endif + + if (EglDisplay == EGL_NO_DISPLAY) + { + os::Printer::log("Getting OpenGL-ES2 display."); + EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); + } + if (EglDisplay == EGL_NO_DISPLAY) + { + os::Printer::log("Could not get OpenGL-ES2 display."); + } + + EGLint majorVersion, minorVersion; + if (!eglInitialize(EglDisplay, &majorVersion, &minorVersion)) + { + os::Printer::log("Could not initialize OpenGL-ES2 display."); + } + else + { + char text[64]; + sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion); + os::Printer::log(text); + } + + EGLint attribs[] = + { +#if defined( _IRR_COMPILE_WITH_ANDROID_DEVICE_ ) + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_DEPTH_SIZE, 16, + EGL_NONE +#else + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 5, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, params.WithAlphaChannel ? 1 : 0, + EGL_BUFFER_SIZE, params.Bits, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + //EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, + EGL_DEPTH_SIZE, params.ZBufferBits, + EGL_STENCIL_SIZE, params.Stencilbuffer, + EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1 : 0, + EGL_SAMPLES, params.AntiAlias, +#ifdef EGL_VERSION_1_3 + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, +#endif + EGL_NONE, 0 +#endif + }; + + EGLint num_configs; + u32 steps=5; + while (!eglChooseConfig(EglDisplay, attribs, &EglConfig, 1, &num_configs) || !num_configs) + { + switch (steps) + { + case 5: // samples + if (attribs[19]>2) + { + --attribs[19]; + } + else + { + attribs[17]=0; + attribs[19]=0; + --steps; + } + break; + case 4: // alpha + if (attribs[7]) + { + attribs[7]=0; + if (params.AntiAlias) + { + attribs[17]=1; + attribs[19]=params.AntiAlias; + steps=5; + } + } + else + --steps; + break; + case 3: // stencil + if (attribs[15]) + { + attribs[15]=0; + if (params.AntiAlias) + { + attribs[17]=1; + attribs[19]=params.AntiAlias; + steps=5; + } + } + else + --steps; + break; + case 2: // depth size + if (attribs[13]>16) + { + attribs[13]-=8; + } + else + --steps; + break; + case 1: // buffer size + if (attribs[9]>16) + { + attribs[9]-=8; + } + else + --steps; + break; + default: + os::Printer::log("Could not get config for OpenGL-ES2 display."); + return; + } + } + if (params.AntiAlias && !attribs[17]) + os::Printer::log("No multisampling."); + if (params.WithAlphaChannel && !attribs[7]) + os::Printer::log("No alpha."); + if (params.Stencilbuffer && !attribs[15]) + os::Printer::log("No stencil buffer."); + if (params.ZBufferBits > attribs[13]) + os::Printer::log("No full depth buffer."); + if (params.Bits > attribs[9]) + os::Printer::log("No full color buffer."); + #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is + * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). + * As soon as we picked a EGLConfig, we can safely reconfigure the + * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ + EGLint format; + eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format); + + ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); + #endif + os::Printer::log(" Creating EglSurface with nativeWindow..."); + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL); + if (EGL_NO_SURFACE == EglSurface) + { + os::Printer::log("FAILED\n"); + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); + os::Printer::log("Creating EglSurface without nativeWindows..."); + } + else + os::Printer::log("SUCCESS\n"); + if (EGL_NO_SURFACE == EglSurface) + { + os::Printer::log("FAILED\n"); + os::Printer::log("Could not create surface for OpenGL-ES2 display."); + } + else + os::Printer::log("SUCCESS\n"); + +#ifdef EGL_VERSION_1_2 + if (minorVersion>1) + eglBindAPI(EGL_OPENGL_ES_API); +#endif + os::Printer::log("Creating EglContext..."); + EglContext = EGL_NO_CONTEXT; + + if (!params.ForceLegacyDevice) + { + os::Printer::log("Trying to create Context for OpenGL-ES3."); + + EGLint contextAttrib[] = + { + #ifdef EGL_VERSION_1_3 + EGL_CONTEXT_CLIENT_VERSION, 3, + #endif + EGL_NONE, 0 + }; + + EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); + } + + if (EGL_NO_CONTEXT == EglContext) + { + os::Printer::log("Trying to create Context for OpenGL-ES2."); + IsCoreContext = false; + + EGLint contextAttrib[] = + { + #ifdef EGL_VERSION_1_3 + EGL_CONTEXT_CLIENT_VERSION, 2, + #endif + EGL_NONE, 0 + }; + + EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); + if (EGL_NO_CONTEXT == EglContext) + { + os::Printer::log("FAILED\n"); + os::Printer::log("Could not create Context for OpenGL-ES2 display."); + } + } + + eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); + if (testEGLError()) + { + os::Printer::log("Could not make Context current for OpenGL-ES2 display."); + } + +//~ #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + //~ int backingWidth; + //~ int backingHeight; + //~ eglQuerySurface(EglDisplay, EglSurface, EGL_WIDTH, &backingWidth); + //~ eglQuerySurface(EglDisplay, EglSurface, EGL_HEIGHT, &backingHeight); + //~ core::dimension2d WindowSize(backingWidth, backingHeight); + //~ CNullDriver::ScreenSize = WindowSize; +//~ #endif + + + // set vsync + if (params.Vsync) + eglSwapInterval(EglDisplay, 1); + + + + const f32 egl_ver = core::fast_atof(reinterpret_cast(eglQueryString(EglDisplay, EGL_VERSION))); + EGLVersion = static_cast(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f)); + core::stringc eglExtensions = eglQueryString(EglDisplay, EGL_EXTENSIONS); + os::Printer::log(eglExtensions.c_str()); + + os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS)); +} + + +ContextEGL::~ContextEGL() +{ + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + if (EglContext != EGL_NO_CONTEXT) + { + eglDestroyContext(EglDisplay, EglContext); + EglContext = EGL_NO_CONTEXT; + } + + if (EglSurface != EGL_NO_SURFACE) + { + eglDestroySurface(EglDisplay, EglSurface); + EglSurface = EGL_NO_SURFACE; + } + + if (EglDisplay != EGL_NO_DISPLAY) + { + eglTerminate(EglDisplay); + EglDisplay = EGL_NO_DISPLAY; + } + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + if (HDc) + ReleaseDC((HWND)EglWindow, HDc); +#endif +} + + +bool ContextEGL::swapBuffers() +{ + eglSwapBuffers(EglDisplay, EglSurface); + EGLint g = eglGetError(); + + return g == EGL_SUCCESS; +} + + +void ContextEGL::reloadEGLSurface(void* window) +{ + os::Printer::log("Reload EGL surface."); + + #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + EglWindow = (ANativeWindow*)window; + #endif + + if (!EglWindow) + os::Printer::log("Invalid Egl window."); + + eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglDestroySurface(EglDisplay, EglSurface); + + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0); + + if (EGL_NO_SURFACE == EglSurface) + os::Printer::log("Could not create EGL surface."); + + eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); +} + + +bool ContextEGL::testEGLError() +{ +#if defined(_DEBUG) + EGLint g = eglGetError(); + switch (g) + { + case EGL_SUCCESS: + return false; + case EGL_NOT_INITIALIZED : + os::Printer::log("Not Initialized", ELL_ERROR); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Bad Access", ELL_ERROR); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Bad Alloc", ELL_ERROR); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Bad Attribute", ELL_ERROR); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Bad Context", ELL_ERROR); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Bad Config", ELL_ERROR); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Bad Current Surface", ELL_ERROR); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Bad Display", ELL_ERROR); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Bad Surface", ELL_ERROR); + break; + case EGL_BAD_MATCH: + os::Printer::log("Bad Match", ELL_ERROR); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Bad Parameter", ELL_ERROR); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Bad Native Pixmap", ELL_ERROR); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Bad Native Window", ELL_ERROR); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Context Lost", ELL_ERROR); + break; + }; + return true; +#else + return false; +#endif +} + +} + +} + +#endif diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.h b/lib/irrlicht/source/Irrlicht/CContextEGL.h new file mode 100644 index 000000000..794a66ef0 --- /dev/null +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.h @@ -0,0 +1,76 @@ +// Copyright (C) 2013 Patryk Nadrowski +// Copyright (C) 2016-2017 Dawid Gan +// Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt +// OpenGL ES driver implemented by Christian Stehno and first OpenGL ES 2.0 +// driver implemented by Amundis. +// This file is part of the "Irrlicht Engine". +// For conditions of distribution and use, see copyright notice in Irrlicht.h + +#ifndef __C_CONTEXT_EGL_H_INCLUDED__ +#define __C_CONTEXT_EGL_H_INCLUDED__ + +#include "IrrCompileConfig.h" + +#if defined(_IRR_COMPILE_WITH_EGL_) + +#include "SIrrCreationParameters.h" +#include "SExposedVideoData.h" + +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) +#include +#else +#include +#include +#endif + +#if defined(_IRR_WINDOWS_API_) +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#endif + +#ifdef _MSC_VER +#pragma comment(lib, "libEGL.lib") +#endif + + +namespace irr +{ +namespace video +{ + +class ContextEGL +{ +private: + NativeWindowType EglWindow; + void* EglDisplay; + void* EglSurface; + void* EglContext; + EGLConfig EglConfig; + u16 EGLVersion; + +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + HDC HDc; +#endif + + bool IsCoreContext; + + bool testEGLError(); + +public: + ContextEGL(const SIrrlichtCreationParameters& params, + const SExposedVideoData& data); + ~ContextEGL(); + + void reloadEGLSurface(void* window); + bool swapBuffers(); + bool isCoreContext() {return IsCoreContext;} +}; + +} +} + +#endif + +#endif diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp index a39445e7f..68d3c1cf6 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp @@ -17,6 +17,7 @@ #include "COGLES2NormalMapRenderer.h" #include "COGLES2ParallaxMapRenderer.h" #include "COGLES2Renderer2D.h" +#include "CContextEGL.h" #include "CImage.h" #include "os.h" @@ -24,7 +25,6 @@ #include #include #else -#include #include #endif @@ -45,11 +45,8 @@ namespace video BridgeCalls(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(params.AntiAlias), RenderTargetTexture(0), CurrentRendertargetSize(0, 0), ColorFormat(ECF_R8G8B8) -#ifdef EGL_VERSION_1_0 - , EglDisplay(EGL_NO_DISPLAY) -#endif -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - , HDc(0) +#if defined(_IRR_COMPILE_WITH_EGL_) + , EglContext(0) #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) , ViewFramebuffer(0) , ViewRenderbuffer(0) @@ -61,248 +58,22 @@ namespace video setDebugName("COGLES2Driver"); #endif ExposedData = data; -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; - HDc = GetDC((HWND)EglWindow); - EglDisplay = eglGetDisplay((NativeDisplayType)HDc); -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - EglWindow = (NativeWindowType)ExposedData.OpenGLLinux.X11Window; - EglDisplay = eglGetDisplay((NativeDisplayType)ExposedData.OpenGLLinux.X11Display); -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) - Device = device; -#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - EglWindow = ((struct android_app *)(params.PrivateData))->window; - EglDisplay = EGL_NO_DISPLAY; -#endif -#ifdef EGL_VERSION_1_0 - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Getting OpenGL-ES2 display."); - EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); - } - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Could not get OpenGL-ES2 display."); - } - EGLint majorVersion, minorVersion; - if (!eglInitialize(EglDisplay, &majorVersion, &minorVersion)) - { - os::Printer::log("Could not initialize OpenGL-ES2 display."); - } - else - { - char text[64]; - sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion); - os::Printer::log(text); - } - - EGLint attribs[] = - { -#if defined( _IRR_COMPILE_WITH_ANDROID_DEVICE_ ) - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_BLUE_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_RED_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_NONE -#else - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 5, - EGL_BLUE_SIZE, 5, - EGL_ALPHA_SIZE, params.WithAlphaChannel ? 1 : 0, - EGL_BUFFER_SIZE, params.Bits, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - //EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, - EGL_DEPTH_SIZE, params.ZBufferBits, - EGL_STENCIL_SIZE, params.Stencilbuffer, - EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1 : 0, - EGL_SAMPLES, params.AntiAlias, -#ifdef EGL_VERSION_1_3 - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, -#endif - EGL_NONE, 0 -#endif - }; - - EGLint num_configs; - u32 steps=5; - while (!eglChooseConfig(EglDisplay, attribs, &EglConfig, 1, &num_configs) || !num_configs) - { - switch (steps) - { - case 5: // samples - if (attribs[19]>2) - { - --attribs[19]; - } - else - { - attribs[17]=0; - attribs[19]=0; - --steps; - } - break; - case 4: // alpha - if (attribs[7]) - { - attribs[7]=0; - if (params.AntiAlias) - { - attribs[17]=1; - attribs[19]=params.AntiAlias; - steps=5; - } - } - else - --steps; - break; - case 3: // stencil - if (attribs[15]) - { - attribs[15]=0; - if (params.AntiAlias) - { - attribs[17]=1; - attribs[19]=params.AntiAlias; - steps=5; - } - } - else - --steps; - break; - case 2: // depth size - if (attribs[13]>16) - { - attribs[13]-=8; - } - else - --steps; - break; - case 1: // buffer size - if (attribs[9]>16) - { - attribs[9]-=8; - } - else - --steps; - break; - default: - os::Printer::log("Could not get config for OpenGL-ES2 display."); - return; - } - } - if (params.AntiAlias && !attribs[17]) - os::Printer::log("No multisampling."); - if (params.WithAlphaChannel && !attribs[7]) - os::Printer::log("No alpha."); - if (params.Stencilbuffer && !attribs[15]) - os::Printer::log("No stencil buffer."); - if (params.ZBufferBits > attribs[13]) - os::Printer::log("No full depth buffer."); - if (params.Bits > attribs[9]) - os::Printer::log("No full color buffer."); - #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is - * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). - * As soon as we picked a EGLConfig, we can safely reconfigure the - * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ - EGLint format; - eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format); - - ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); - #endif - os::Printer::log(" Creating EglSurface with nativeWindow..."); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL); - if (EGL_NO_SURFACE == EglSurface) - { - os::Printer::log("FAILED\n"); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); - os::Printer::log("Creating EglSurface without nativeWindows..."); - } - else - os::Printer::log("SUCCESS\n"); - if (EGL_NO_SURFACE == EglSurface) - { - os::Printer::log("FAILED\n"); - os::Printer::log("Could not create surface for OpenGL-ES2 display."); - } - else - os::Printer::log("SUCCESS\n"); - -#ifdef EGL_VERSION_1_2 - if (minorVersion>1) - eglBindAPI(EGL_OPENGL_ES_API); -#endif - os::Printer::log("Creating EglContext..."); - EglContext = EGL_NO_CONTEXT; - - if (!Params.ForceLegacyDevice) - { - os::Printer::log("Trying to create Context for OpenGL-ES3."); - - EGLint contextAttrib[] = - { - #ifdef EGL_VERSION_1_3 - EGL_CONTEXT_CLIENT_VERSION, 3, - #endif - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - } - - if (EGL_NO_CONTEXT == EglContext) - { - os::Printer::log("Trying to create Context for OpenGL-ES2."); - useCoreContext = false; - - EGLint contextAttrib[] = - { - #ifdef EGL_VERSION_1_3 - EGL_CONTEXT_CLIENT_VERSION, 2, - #endif - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - if (EGL_NO_CONTEXT == EglContext) - { - os::Printer::log("FAILED\n"); - os::Printer::log("Could not create Context for OpenGL-ES2 display."); - } - } - - eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); - if (testEGLError()) - { - os::Printer::log("Could not make Context current for OpenGL-ES2 display."); - } +#if defined(_IRR_COMPILE_WITH_EGL_) + EglContext = new ContextEGL(params, data); + useCoreContext = EglContext->isCoreContext(); genericDriverInit(params.WindowSize, params.Stencilbuffer); -#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ - int backingWidth; - int backingHeight; - eglQuerySurface(EglDisplay, EglSurface, EGL_WIDTH, &backingWidth); - eglQuerySurface(EglDisplay, EglSurface, EGL_HEIGHT, &backingHeight); - core::dimension2d WindowSize(backingWidth, backingHeight); - CNullDriver::ScreenSize = WindowSize; -#endif +#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) + Device = device; - - // set vsync - if (params.Vsync) - eglSwapInterval(EglDisplay, 1); -#elif defined(GL_ES_VERSION_2_0) glGenFramebuffers(1, &ViewFramebuffer); glGenRenderbuffers(1, &ViewRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer); -#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) ExposedData.OGLESIPhone.AppDelegate = Device; Device->displayInitialize(&ExposedData.OGLESIPhone.Context, &ExposedData.OGLESIPhone.View); -#endif GLint backingWidth; GLint backingHeight; @@ -342,32 +113,11 @@ namespace video if (BridgeCalls) delete BridgeCalls; -#if defined(EGL_VERSION_1_0) - eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +#if defined(_IRR_COMPILE_WITH_EGL_) + delete EglContext; - if (EglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(EglDisplay, EglContext); - EglContext = EGL_NO_CONTEXT; - } - if (EglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(EglDisplay, EglSurface); - EglSurface = EGL_NO_SURFACE; - } - - if (EglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(EglDisplay); - EglDisplay = EGL_NO_DISPLAY; - } - -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - if (HDc) - ReleaseDC((HWND)EglWindow, HDc); -#endif -#elif defined(GL_ES_VERSION_2_0) +#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) if (0 != ViewFramebuffer) { glDeleteFramebuffers(1,&ViewFramebuffer); @@ -390,41 +140,12 @@ namespace video // METHODS // ----------------------------------------------------------------------- - void COGLES2Driver::reloadEGLSurface(void* window) - { - os::Printer::log("Reload EGL surface."); - - #ifdef EGL_VERSION_1_0 - #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - EglWindow = (ANativeWindow*)window; - #endif - - if (!EglWindow) - os::Printer::log("Invalid Egl window."); - - eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - eglDestroySurface(EglDisplay, EglSurface); - - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0); - - if (EGL_NO_SURFACE == EglSurface) - os::Printer::log("Could not create EGL surface."); - - eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); - #endif - } - bool COGLES2Driver::genericDriverInit(const core::dimension2d& screenSize, bool stencilBuffer) { Name = glGetString(GL_VERSION); printVersion(); -#if defined(EGL_VERSION_1_0) - os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS)); -#endif - // print renderer information vendorName = glGetString(GL_VENDOR); os::Printer::log(vendorName.c_str(), ELL_INFORMATION); @@ -433,11 +154,7 @@ namespace video for (i = 0; i < MATERIAL_MAX_TEXTURES; ++i) CurrentTexture[i] = 0; // load extensions - initExtensions(this, -#if defined(EGL_VERSION_1_0) - EglDisplay, -#endif - stencilBuffer); + initExtensions(this, stencilBuffer); if (!BridgeCalls) BridgeCalls = new COGLES2CallBridge(this); @@ -713,26 +430,20 @@ namespace video { CNullDriver::endScene(); -#if defined(EGL_VERSION_1_0) - eglSwapBuffers(EglDisplay, EglSurface); - EGLint g = eglGetError(); - if (EGL_SUCCESS != g) +#if defined(_IRR_COMPILE_WITH_EGL_) + + bool res = EglContext->swapBuffers(); + + if (!res) { - if (EGL_CONTEXT_LOST == g) - { - // o-oh, ogl-es has lost contexts... - os::Printer::log("Context lost, please restart your app."); - } - else - os::Printer::log("Could not swap buffers for OpenGL-ES2 driver."); + os::Printer::log("Could not swap buffers for OpenGL-ES2 driver."); return false; } -#elif defined(GL_ES_VERSION_2_0) + +#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) glFlush(); glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer); -#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) Device->displayEnd(); -#endif #endif return true; @@ -1896,65 +1607,6 @@ namespace video #endif } - //! prints error if an error happened. - bool COGLES2Driver::testEGLError() - { -#if defined(EGL_VERSION_1_0) && defined(_DEBUG) - EGLint g = eglGetError(); - switch (g) - { - case EGL_SUCCESS: - return false; - case EGL_NOT_INITIALIZED : - os::Printer::log("Not Initialized", ELL_ERROR); - break; - case EGL_BAD_ACCESS: - os::Printer::log("Bad Access", ELL_ERROR); - break; - case EGL_BAD_ALLOC: - os::Printer::log("Bad Alloc", ELL_ERROR); - break; - case EGL_BAD_ATTRIBUTE: - os::Printer::log("Bad Attribute", ELL_ERROR); - break; - case EGL_BAD_CONTEXT: - os::Printer::log("Bad Context", ELL_ERROR); - break; - case EGL_BAD_CONFIG: - os::Printer::log("Bad Config", ELL_ERROR); - break; - case EGL_BAD_CURRENT_SURFACE: - os::Printer::log("Bad Current Surface", ELL_ERROR); - break; - case EGL_BAD_DISPLAY: - os::Printer::log("Bad Display", ELL_ERROR); - break; - case EGL_BAD_SURFACE: - os::Printer::log("Bad Surface", ELL_ERROR); - break; - case EGL_BAD_MATCH: - os::Printer::log("Bad Match", ELL_ERROR); - break; - case EGL_BAD_PARAMETER: - os::Printer::log("Bad Parameter", ELL_ERROR); - break; - case EGL_BAD_NATIVE_PIXMAP: - os::Printer::log("Bad Native Pixmap", ELL_ERROR); - break; - case EGL_BAD_NATIVE_WINDOW: - os::Printer::log("Bad Native Window", ELL_ERROR); - break; - case EGL_CONTEXT_LOST: - os::Printer::log("Context Lost", ELL_ERROR); - break; - }; - return true; -#else - return false; -#endif - } - - void COGLES2Driver::setRenderStates3DMode() { if (useCoreContext) diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h index c6cdb9aa3..65163376d 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h @@ -10,13 +10,7 @@ #include "IrrCompileConfig.h" -#if defined(_IRR_WINDOWS_API_) -// include windows headers for HWND -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) +#if defined(_IRR_COMPILE_WITH_OSX_DEVICE_) #include "MacOSX/CIrrDeviceMacOSX.h" #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) #include "iOS/CIrrDeviceiOS.h" @@ -30,11 +24,8 @@ #include #include #elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) -#include #include #include "android_native_app_glue.h" -#else -#include #endif #include "CNullDriver.h" @@ -43,7 +34,6 @@ #include "fast_atof.h" #ifdef _MSC_VER -#pragma comment(lib, "libEGL.lib") #pragma comment(lib, "libGLESv2.lib") #endif #include "COGLES2ExtensionHandler.h" @@ -58,6 +48,7 @@ namespace video class COGLES2Renderer2D; class COGLES2NormalMapRenderer; class COGLES2ParallaxMapRenderer; + class ContextEGL; class COGLES2Driver : public CNullDriver, public IMaterialRendererServices, public COGLES2ExtensionHandler { @@ -340,9 +331,6 @@ namespace video //! checks if an OpenGL error has happend and prints it bool testGLError(); - //! checks if an OGLES1 error has happend and prints it - bool testEGLError(); - //! Set/unset a clipping plane. virtual bool setClipPlane(u32 index, const core::plane3df& plane, bool enable = false); @@ -382,8 +370,6 @@ namespace video //! Get bridge calls. COGLES2CallBridge* getBridgeCalls() const; - void reloadEGLSurface(void* window); - private: // Bridge calls. COGLES2CallBridge* BridgeCalls; @@ -466,21 +452,15 @@ namespace video SColorf AmbientLight; COGLES2Renderer2D* MaterialRenderer2D; - -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - HDC HDc; + +#if defined(_IRR_COMPILE_WITH_EGL_) + ContextEGL* EglContext; #endif #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) CIrrDeviceIPhone* Device; GLuint ViewFramebuffer; GLuint ViewRenderbuffer; GLuint ViewDepthRenderbuffer; -#else - NativeWindowType EglWindow; - void* EglDisplay; - void* EglSurface; - void* EglContext; - EGLConfig EglConfig; #endif SIrrlichtCreationParameters Params; diff --git a/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.cpp b/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.cpp index 82bec11ea..4ec8eff19 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.cpp @@ -158,7 +158,7 @@ namespace video }; COGLES2ExtensionHandler::COGLES2ExtensionHandler() : - EGLVersion(0), Version(0), MaxTextureUnits(0), MaxSupportedTextures(0), + Version(0), MaxTextureUnits(0), MaxSupportedTextures(0), MaxAnisotropy(1), MaxIndices(0xffff), MaxTextureSize(1), MaxTextureLODBias(0.f), StencilBuffer(false) @@ -176,17 +176,8 @@ namespace video void COGLES2ExtensionHandler::initExtensions(COGLES2Driver* driver, -#ifdef EGL_VERSION_1_0 - EGLDisplay display, -#endif bool withStencil) { -#ifdef EGL_VERSION_1_0 - const f32 egl_ver = core::fast_atof(reinterpret_cast(eglQueryString(display, EGL_VERSION))); - EGLVersion = static_cast(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f)); - core::stringc eglExtensions = eglQueryString(display, EGL_EXTENSIONS); - os::Printer::log(eglExtensions.c_str()); -#endif const core::stringc stringVer(glGetString(GL_VERSION)); const f32 ogl_ver = core::fast_atof(stringVer.c_str() + 10); Version = static_cast(core::floor32(ogl_ver) * 100 + core::round32(core::fract(ogl_ver) * 10.0f)); diff --git a/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.h b/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.h index 056196d8e..58ae56c63 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.h +++ b/lib/irrlicht/source/Irrlicht/COGLES2ExtensionHandler.h @@ -14,7 +14,6 @@ #include #include #else -#include #include // seems to be missing... typedef char GLchar; @@ -232,13 +231,9 @@ namespace video void dump() const; void initExtensions(COGLES2Driver* driver, -#ifdef EGL_VERSION_1_0 - EGLDisplay display, -#endif bool withStencil); protected: - u16 EGLVersion; u16 Version; u8 MaxTextureUnits; u8 MaxSupportedTextures; From 635ea89cd0c99485715d1a1295fa69e6139d97eb Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 5 Apr 2017 20:43:04 +0200 Subject: [PATCH 2/6] Some corrections with egl attribs --- lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 205 ++++++++++--------- 1 file changed, 108 insertions(+), 97 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp index 37c7110e0..a208c998b 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -60,112 +60,123 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion); os::Printer::log(text); } + + EGLint EglOpenGLBIT = 0; - EGLint attribs[] = - { -#if defined( _IRR_COMPILE_WITH_ANDROID_DEVICE_ ) - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_BLUE_SIZE, 8, - EGL_GREEN_SIZE, 8, + // We need proper OpenGL BIT. + switch (params.DriverType) + { + case EDT_OGLES2: + EglOpenGLBIT = EGL_OPENGL_ES2_BIT; + break; + default: + break; + } + + EGLint Attribs[] = + { EGL_RED_SIZE, 8, - EGL_DEPTH_SIZE, 16, - EGL_NONE -#else - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 5, - EGL_BLUE_SIZE, 5, - EGL_ALPHA_SIZE, params.WithAlphaChannel ? 1 : 0, - EGL_BUFFER_SIZE, params.Bits, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - //EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, - EGL_DEPTH_SIZE, params.ZBufferBits, - EGL_STENCIL_SIZE, params.Stencilbuffer, - EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1 : 0, - EGL_SAMPLES, params.AntiAlias, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, params.WithAlphaChannel ? 1:0, + EGL_BUFFER_SIZE, params.Bits, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_DEPTH_SIZE, params.ZBufferBits, + EGL_STENCIL_SIZE, params.Stencilbuffer, + EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0, + EGL_SAMPLES, params.AntiAlias, #ifdef EGL_VERSION_1_3 - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_RENDERABLE_TYPE, EglOpenGLBIT, #endif - EGL_NONE, 0 -#endif - }; + EGL_NONE, 0 + }; - EGLint num_configs; - u32 steps=5; - while (!eglChooseConfig(EglDisplay, attribs, &EglConfig, 1, &num_configs) || !num_configs) + EglConfig = 0; + EGLint NumConfigs = 0; + u32 Steps = 5; + + // Choose the best EGL config. + while (!eglChooseConfig(EglDisplay, Attribs, &EglConfig, 1, &NumConfigs) || !NumConfigs) + { + switch (Steps) { - switch (steps) + case 5: // samples + if (Attribs[19] > 2) + --Attribs[19]; + else { - case 5: // samples - if (attribs[19]>2) - { - --attribs[19]; - } - else - { - attribs[17]=0; - attribs[19]=0; - --steps; - } - break; - case 4: // alpha - if (attribs[7]) - { - attribs[7]=0; - if (params.AntiAlias) - { - attribs[17]=1; - attribs[19]=params.AntiAlias; - steps=5; - } - } - else - --steps; - break; - case 3: // stencil - if (attribs[15]) - { - attribs[15]=0; - if (params.AntiAlias) - { - attribs[17]=1; - attribs[19]=params.AntiAlias; - steps=5; - } - } - else - --steps; - break; - case 2: // depth size - if (attribs[13]>16) - { - attribs[13]-=8; - } - else - --steps; - break; - case 1: // buffer size - if (attribs[9]>16) - { - attribs[9]-=8; - } - else - --steps; - break; - default: - os::Printer::log("Could not get config for OpenGL-ES2 display."); - return; + Attribs[17] = 0; + Attribs[19] = 0; + --Steps; } + break; + case 4: // alpha + if (Attribs[7]) + { + Attribs[7] = 0; + + if (params.AntiAlias) + { + Attribs[17] = 1; + Attribs[19] = params.AntiAlias; + Steps = 5; + } + } + else + --Steps; + break; + case 3: // stencil + if (Attribs[15]) + { + Attribs[15] = 0; + + if (params.AntiAlias) + { + Attribs[17] = 1; + Attribs[19] = params.AntiAlias; + Steps = 5; + } + } + else + --Steps; + break; + case 2: // depth size + if (Attribs[13] > 16) + { + Attribs[13] -= 8; + } + else + --Steps; + break; + case 1: // buffer size + if (Attribs[9] > 16) + { + Attribs[9] -= 8; + } + else + --Steps; + break; + default: + os::Printer::log("Could not get config for EGL display."); + return; } - if (params.AntiAlias && !attribs[17]) - os::Printer::log("No multisampling."); - if (params.WithAlphaChannel && !attribs[7]) - os::Printer::log("No alpha."); - if (params.Stencilbuffer && !attribs[15]) - os::Printer::log("No stencil buffer."); - if (params.ZBufferBits > attribs[13]) - os::Printer::log("No full depth buffer."); - if (params.Bits > attribs[9]) - os::Printer::log("No full color buffer."); + } + + if (params.AntiAlias && !Attribs[17]) + os::Printer::log("No multisampling."); + + if (params.WithAlphaChannel && !Attribs[7]) + os::Printer::log("No alpha."); + + if (params.Stencilbuffer && !Attribs[15]) + os::Printer::log("No stencil buffer."); + + if (params.ZBufferBits > Attribs[13]) + os::Printer::log("No full depth buffer."); + + if (params.Bits > Attribs[9]) + os::Printer::log("No full color buffer."); + #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). From 1d39030f516e2f19936494431b1ca4f22836b973 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 5 Apr 2017 21:41:25 +0200 Subject: [PATCH 3/6] Assume that EGL version is always greater than 1.3 because otherwise we won't be able to create GLES 2.0/3.0 context. --- lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 220 ++++++++----------- lib/irrlicht/source/Irrlicht/CContextEGL.h | 3 +- 2 files changed, 98 insertions(+), 125 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp index a208c998b..e6aa9017e 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -21,6 +21,12 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, const SExposedVideoData& data) { EglDisplay = EGL_NO_DISPLAY; + EglSurface = EGL_NO_SURFACE; + EglContext = EGL_NO_CONTEXT; + EglConfig = 0; + EglWindow = 0; + EGLVersionMajor = 1; + EGLVersionMinor = 0; IsCoreContext = true; #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) @@ -28,38 +34,38 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, #endif #if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; - HDc = GetDC((HWND)EglWindow); - EglDisplay = eglGetDisplay((NativeDisplayType)HDc); + EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; + HDc = GetDC((HWND)EglWindow); + EglDisplay = eglGetDisplay((NativeDisplayType)HDc); #elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window; - EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display); + EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window; + EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display); #elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - EglWindow = ((struct android_app *)(params.PrivateData))->window; - EglDisplay = EGL_NO_DISPLAY; + EglWindow = ((struct android_app *)(params.PrivateData))->window; + EglDisplay = EGL_NO_DISPLAY; #endif - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Getting OpenGL-ES2 display."); - EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); - } - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Could not get OpenGL-ES2 display."); - } + if (EglDisplay == EGL_NO_DISPLAY) + { + os::Printer::log("Getting EGL display."); + EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); + } + + if (EglDisplay == EGL_NO_DISPLAY) + { + os::Printer::log("Could not get EGL display."); + } - EGLint majorVersion, minorVersion; - if (!eglInitialize(EglDisplay, &majorVersion, &minorVersion)) - { - os::Printer::log("Could not initialize OpenGL-ES2 display."); - } - else - { - char text[64]; - sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", majorVersion, minorVersion); - os::Printer::log(text); - } + if (!eglInitialize(EglDisplay, &EGLVersionMajor, &EGLVersionMinor)) + { + os::Printer::log("Could not initialize EGL display."); + } + else + { + char text[64]; + sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", EGLVersionMajor, EGLVersionMinor); + os::Printer::log(text); + } EGLint EglOpenGLBIT = 0; @@ -85,9 +91,7 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, EGL_STENCIL_SIZE, params.Stencilbuffer, EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0, EGL_SAMPLES, params.AntiAlias, -#ifdef EGL_VERSION_1_3 EGL_RENDERABLE_TYPE, EglOpenGLBIT, -#endif EGL_NONE, 0 }; @@ -177,105 +181,73 @@ ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, if (params.Bits > Attribs[9]) os::Printer::log("No full color buffer."); - #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is - * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). - * As soon as we picked a EGLConfig, we can safely reconfigure the - * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ - EGLint format; - eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format); + #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is + * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). + * As soon as we picked a EGLConfig, we can safely reconfigure the + * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ + EGLint format; + eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format); + + ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); + #endif + + os::Printer::log(" Creating EglSurface with nativeWindow..."); + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL); + + if (EGL_NO_SURFACE == EglSurface) + { + os::Printer::log("FAILED"); + os::Printer::log("Creating EglSurface without nativeWindows..."); + EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); + } + + if (EGL_NO_SURFACE == EglSurface) + { + os::Printer::log("FAILED"); + os::Printer::log("Could not create surface for EGL display."); + } - ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); - #endif - os::Printer::log(" Creating EglSurface with nativeWindow..."); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL); - if (EGL_NO_SURFACE == EglSurface) + eglBindAPI(EGL_OPENGL_ES_API); + + os::Printer::log("Creating EglContext..."); + + if (!params.ForceLegacyDevice) + { + os::Printer::log("Trying to create Context for OpenGL ES3."); + EGLint contextAttrib[] = { - os::Printer::log("FAILED\n"); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); - os::Printer::log("Creating EglSurface without nativeWindows..."); - } - else - os::Printer::log("SUCCESS\n"); - if (EGL_NO_SURFACE == EglSurface) + EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_NONE, 0 + }; + + EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); + } + + if (EGL_NO_CONTEXT == EglContext) + { + os::Printer::log("Trying to create Context for OpenGL ES2."); + EGLint contextAttrib[] = { - os::Printer::log("FAILED\n"); - os::Printer::log("Could not create surface for OpenGL-ES2 display."); - } - else - os::Printer::log("SUCCESS\n"); + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE, 0 + }; + + EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); + IsCoreContext = false; + } -#ifdef EGL_VERSION_1_2 - if (minorVersion>1) - eglBindAPI(EGL_OPENGL_ES_API); -#endif - os::Printer::log("Creating EglContext..."); - EglContext = EGL_NO_CONTEXT; + eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); + if (testEGLError()) + { + os::Printer::log("Could not make Context current for EGL display."); + } - if (!params.ForceLegacyDevice) - { - os::Printer::log("Trying to create Context for OpenGL-ES3."); - - EGLint contextAttrib[] = - { - #ifdef EGL_VERSION_1_3 - EGL_CONTEXT_CLIENT_VERSION, 3, - #endif - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - } - - if (EGL_NO_CONTEXT == EglContext) - { - os::Printer::log("Trying to create Context for OpenGL-ES2."); - IsCoreContext = false; - - EGLint contextAttrib[] = - { - #ifdef EGL_VERSION_1_3 - EGL_CONTEXT_CLIENT_VERSION, 2, - #endif - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - if (EGL_NO_CONTEXT == EglContext) - { - os::Printer::log("FAILED\n"); - os::Printer::log("Could not create Context for OpenGL-ES2 display."); - } - } - - eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); - if (testEGLError()) - { - os::Printer::log("Could not make Context current for OpenGL-ES2 display."); - } - -//~ #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ - //~ int backingWidth; - //~ int backingHeight; - //~ eglQuerySurface(EglDisplay, EglSurface, EGL_WIDTH, &backingWidth); - //~ eglQuerySurface(EglDisplay, EglSurface, EGL_HEIGHT, &backingHeight); - //~ core::dimension2d WindowSize(backingWidth, backingHeight); - //~ CNullDriver::ScreenSize = WindowSize; -//~ #endif - - - // set vsync - if (params.Vsync) - eglSwapInterval(EglDisplay, 1); - - - - const f32 egl_ver = core::fast_atof(reinterpret_cast(eglQueryString(EglDisplay, EGL_VERSION))); - EGLVersion = static_cast(core::floor32(egl_ver)*100+core::round32(core::fract(egl_ver)*10.0f)); - core::stringc eglExtensions = eglQueryString(EglDisplay, EGL_EXTENSIONS); - os::Printer::log(eglExtensions.c_str()); - - os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS)); + // set vsync + if (params.Vsync) + eglSwapInterval(EglDisplay, 1); + + os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS)); } @@ -326,7 +298,7 @@ void ContextEGL::reloadEGLSurface(void* window) #endif if (!EglWindow) - os::Printer::log("Invalid Egl window."); + os::Printer::log("Invalid EGL window."); eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.h b/lib/irrlicht/source/Irrlicht/CContextEGL.h index 794a66ef0..a7cbe1b42 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.h +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.h @@ -48,7 +48,8 @@ private: void* EglSurface; void* EglContext; EGLConfig EglConfig; - u16 EGLVersion; + int EGLVersionMajor; + int EGLVersionMinor; #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ HDC HDc; From 240041f5204fbb90f244d7c83a9acfe13015a32d Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 5 Apr 2017 21:46:37 +0200 Subject: [PATCH 4/6] Fixed android compilation --- lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 4 ++++ lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp | 3 ++- lib/irrlicht/source/Irrlicht/COGLES2Driver.h | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp index e6aa9017e..05fbfb93b 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -10,6 +10,10 @@ #include "os.h" #include "fast_atof.h" +#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) +#include "android_native_app_glue.h" +#endif + #if defined(_IRR_COMPILE_WITH_EGL_) namespace irr diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index 3e491ff4b..95db25696 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -10,6 +10,7 @@ #include #include "os.h" +#include "CContextEGL.h" #include "CFileSystem.h" #include "COGLES2Driver.h" @@ -306,7 +307,7 @@ void CIrrDeviceAndroid::handleAndroidCommand(android_app* app, int32_t cmd) device->CreationParams.DriverType == video::EDT_OGLES2) { video::COGLES2Driver* driver = (video::COGLES2Driver*)(device->VideoDriver); - driver->reloadEGLSurface(app->window); + driver->getEGLContext()->reloadEGLSurface(app->window); } } diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h index 65163376d..328b13189 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h @@ -369,6 +369,10 @@ namespace video //! Get bridge calls. COGLES2CallBridge* getBridgeCalls() const; + +#if defined(_IRR_COMPILE_WITH_EGL_) + ContextEGL* getEGLContext() {return EglContext;} +#endif private: // Bridge calls. From 9fc3578b5109c40e89d85920724553bc0dd5dee4 Mon Sep 17 00:00:00 2001 From: Deve Date: Thu, 20 Apr 2017 23:20:21 +0200 Subject: [PATCH 5/6] Rewrite whole EGL manager. Now it allows to create OpenGL context, so we can use it for Wayland. --- lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 874 +++++++++++------- lib/irrlicht/source/Irrlicht/CContextEGL.h | 114 +-- .../source/Irrlicht/COGLES2Driver.cpp | 40 +- lib/irrlicht/source/Irrlicht/COGLES2Driver.h | 10 +- 4 files changed, 636 insertions(+), 402 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp index 05fbfb93b..ac7fe8a6f 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -6,376 +6,566 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h -#include "CContextEGL.h" -#include "os.h" -#include "fast_atof.h" - -#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) -#include "android_native_app_glue.h" -#endif +#include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_EGL_) -namespace irr -{ -namespace video -{ - -ContextEGL::ContextEGL(const SIrrlichtCreationParameters& params, - const SExposedVideoData& data) -{ - EglDisplay = EGL_NO_DISPLAY; - EglSurface = EGL_NO_SURFACE; - EglContext = EGL_NO_CONTEXT; - EglConfig = 0; - EglWindow = 0; - EGLVersionMajor = 1; - EGLVersionMinor = 0; - IsCoreContext = true; - -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - HDc = 0; -#endif - -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - EglWindow = (NativeWindowType)data.OpenGLWin32.HWnd; - HDc = GetDC((HWND)EglWindow); - EglDisplay = eglGetDisplay((NativeDisplayType)HDc); -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - EglWindow = (NativeWindowType)data.OpenGLLinux.X11Window; - EglDisplay = eglGetDisplay((NativeDisplayType)data.OpenGLLinux.X11Display); -#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - EglWindow = ((struct android_app *)(params.PrivateData))->window; - EglDisplay = EGL_NO_DISPLAY; +#include +#include +#include +#include + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ +#include #endif - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Getting EGL display."); - EglDisplay = eglGetDisplay((NativeDisplayType) EGL_DEFAULT_DISPLAY); - } - - if (EglDisplay == EGL_NO_DISPLAY) - { - os::Printer::log("Could not get EGL display."); - } +#include "CContextEGL.h" +#include "os.h" - if (!eglInitialize(EglDisplay, &EGLVersionMajor, &EGLVersionMinor)) - { - os::Printer::log("Could not initialize EGL display."); - } - else - { - char text[64]; - sprintf(text, "EglDisplay initialized. Egl version %d.%d\n", EGLVersionMajor, EGLVersionMinor); - os::Printer::log(text); - } - - EGLint EglOpenGLBIT = 0; +using namespace irr; - // We need proper OpenGL BIT. - switch (params.DriverType) - { - case EDT_OGLES2: - EglOpenGLBIT = EGL_OPENGL_ES2_BIT; - break; - default: - break; - } - - EGLint Attribs[] = - { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, params.WithAlphaChannel ? 1:0, - EGL_BUFFER_SIZE, params.Bits, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_DEPTH_SIZE, params.ZBufferBits, - EGL_STENCIL_SIZE, params.Stencilbuffer, - EGL_SAMPLE_BUFFERS, params.AntiAlias ? 1:0, - EGL_SAMPLES, params.AntiAlias, - EGL_RENDERABLE_TYPE, EglOpenGLBIT, - EGL_NONE, 0 - }; - - EglConfig = 0; - EGLint NumConfigs = 0; - u32 Steps = 5; - - // Choose the best EGL config. - while (!eglChooseConfig(EglDisplay, Attribs, &EglConfig, 1, &NumConfigs) || !NumConfigs) - { - switch (Steps) - { - case 5: // samples - if (Attribs[19] > 2) - --Attribs[19]; - else - { - Attribs[17] = 0; - Attribs[19] = 0; - --Steps; - } - break; - case 4: // alpha - if (Attribs[7]) - { - Attribs[7] = 0; - - if (params.AntiAlias) - { - Attribs[17] = 1; - Attribs[19] = params.AntiAlias; - Steps = 5; - } - } - else - --Steps; - break; - case 3: // stencil - if (Attribs[15]) - { - Attribs[15] = 0; - - if (params.AntiAlias) - { - Attribs[17] = 1; - Attribs[19] = params.AntiAlias; - Steps = 5; - } - } - else - --Steps; - break; - case 2: // depth size - if (Attribs[13] > 16) - { - Attribs[13] -= 8; - } - else - --Steps; - break; - case 1: // buffer size - if (Attribs[9] > 16) - { - Attribs[9] -= 8; - } - else - --Steps; - break; - default: - os::Printer::log("Could not get config for EGL display."); - return; - } - } - - if (params.AntiAlias && !Attribs[17]) - os::Printer::log("No multisampling."); - - if (params.WithAlphaChannel && !Attribs[7]) - os::Printer::log("No alpha."); - - if (params.Stencilbuffer && !Attribs[15]) - os::Printer::log("No stencil buffer."); - - if (params.ZBufferBits > Attribs[13]) - os::Printer::log("No full depth buffer."); - - if (params.Bits > Attribs[9]) - os::Printer::log("No full color buffer."); - - #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is - * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). - * As soon as we picked a EGLConfig, we can safely reconfigure the - * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ - EGLint format; - eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &format); - - ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, format); - #endif - - os::Printer::log(" Creating EglSurface with nativeWindow..."); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, NULL); - - if (EGL_NO_SURFACE == EglSurface) - { - os::Printer::log("FAILED"); - os::Printer::log("Creating EglSurface without nativeWindows..."); - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, NULL); - } - - if (EGL_NO_SURFACE == EglSurface) - { - os::Printer::log("FAILED"); - os::Printer::log("Could not create surface for EGL display."); - } - - eglBindAPI(EGL_OPENGL_ES_API); - - os::Printer::log("Creating EglContext..."); - - if (!params.ForceLegacyDevice) - { - os::Printer::log("Trying to create Context for OpenGL ES3."); - EGLint contextAttrib[] = - { - EGL_CONTEXT_CLIENT_VERSION, 3, - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - } - - if (EGL_NO_CONTEXT == EglContext) - { - os::Printer::log("Trying to create Context for OpenGL ES2."); - EGLint contextAttrib[] = - { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE, 0 - }; - - EglContext = eglCreateContext(EglDisplay, EglConfig, EGL_NO_CONTEXT, contextAttrib); - IsCoreContext = false; - } - - eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); - if (testEGLError()) - { - os::Printer::log("Could not make Context current for EGL display."); - } - - // set vsync - if (params.Vsync) - eglSwapInterval(EglDisplay, 1); - - os::Printer::log(eglQueryString(EglDisplay, EGL_CLIENT_APIS)); +ContextManagerEGL::ContextManagerEGL() +{ + m_egl_window = 0; + m_egl_display = EGL_NO_DISPLAY; + m_egl_surface = EGL_NO_SURFACE; + m_egl_context = EGL_NO_CONTEXT; + m_egl_config = 0; + m_egl_version = 0; + m_is_legacy_device = false; + m_initialized = false; + + memset(&m_creation_params, 0, sizeof(ContextEGLParams)); } -ContextEGL::~ContextEGL() +ContextManagerEGL::~ContextManagerEGL() { - eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + close(); +} - if (EglContext != EGL_NO_CONTEXT) - { - eglDestroyContext(EglDisplay, EglContext); - EglContext = EGL_NO_CONTEXT; - } - if (EglSurface != EGL_NO_SURFACE) - { - eglDestroySurface(EglDisplay, EglSurface); - EglSurface = EGL_NO_SURFACE; - } +bool ContextManagerEGL::init(const ContextEGLParams& params) +{ + if (m_initialized) + return false; - if (EglDisplay != EGL_NO_DISPLAY) - { - eglTerminate(EglDisplay); - EglDisplay = EGL_NO_DISPLAY; - } + m_creation_params = params; + m_egl_window = m_creation_params.window; -#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) - if (HDc) - ReleaseDC((HWND)EglWindow, HDc); + bool success = initDisplay(); + + if (!success) + { + os::Printer::log("Error: Could not initialize EGL display.\n"); + close(); + return false; + } + + bool has_minimum_requirements = false; + + if (m_creation_params.opengl_api == CEGL_API_OPENGL) + { + if (hasEGLExtension("EGL_KHR_create_context") || m_egl_version >= 150) + { + has_minimum_requirements = true; + eglBindAPI(EGL_OPENGL_API); + } + } + else if (m_creation_params.opengl_api == CEGL_API_OPENGL_ES) + { + if (m_egl_version >= 130) + { + has_minimum_requirements = true; + eglBindAPI(EGL_OPENGL_ES_API); + } + } + + if (!has_minimum_requirements) + { + os::Printer::log("Error: EGL version is too old.\n"); + close(); + return false; + } + + success = chooseConfig(); + + if (!success) + { + os::Printer::log("Error: Couldn't get EGL config.\n"); + close(); + return false; + } + + success = createSurface(); + + if (!success) + { + os::Printer::log("Error: Couldn't create EGL surface.\n"); + close(); + return false; + } + + success = createContext(); + + if (!success) + { + os::Printer::log("Error: Couldn't create OpenGL context.\n"); + close(); + return false; + } + + success = eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, + m_egl_context); + + if (!success) + { + checkEGLError(); + os::Printer::log("Error: Couldn't make context current for EGL display.\n"); + close(); + return false; + } + + eglSwapInterval(m_egl_display, m_creation_params.vsync_enabled ? 1 : 0); + + m_initialized = true; + return true; +} + + +bool ContextManagerEGL::initDisplay() +{ + NativeDisplayType display = (NativeDisplayType)(m_creation_params.display); + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + display = EGL_DEFAULT_DISPLAY; #endif -} + if (display != EGL_DEFAULT_DISPLAY) + { + m_egl_display = eglGetDisplay(display); + } -bool ContextEGL::swapBuffers() -{ - eglSwapBuffers(EglDisplay, EglSurface); - EGLint g = eglGetError(); - - return g == EGL_SUCCESS; -} + if (m_egl_display == EGL_NO_DISPLAY) + { + m_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + } + if (m_egl_display == EGL_NO_DISPLAY) + { + return false; + } -void ContextEGL::reloadEGLSurface(void* window) -{ - os::Printer::log("Reload EGL surface."); + int egl_version_major = 0; + int egl_version_minor = 0; - #if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) - EglWindow = (ANativeWindow*)window; - #endif + bool success = eglInitialize(m_egl_display, &egl_version_major, + &egl_version_minor); - if (!EglWindow) - os::Printer::log("Invalid EGL window."); - - eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - eglDestroySurface(EglDisplay, EglSurface); - - EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0); - - if (EGL_NO_SURFACE == EglSurface) - os::Printer::log("Could not create EGL surface."); - - eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext); -} - - -bool ContextEGL::testEGLError() -{ -#if defined(_DEBUG) - EGLint g = eglGetError(); - switch (g) + if (success) { - case EGL_SUCCESS: - return false; - case EGL_NOT_INITIALIZED : - os::Printer::log("Not Initialized", ELL_ERROR); - break; - case EGL_BAD_ACCESS: - os::Printer::log("Bad Access", ELL_ERROR); - break; - case EGL_BAD_ALLOC: - os::Printer::log("Bad Alloc", ELL_ERROR); - break; - case EGL_BAD_ATTRIBUTE: - os::Printer::log("Bad Attribute", ELL_ERROR); - break; - case EGL_BAD_CONTEXT: - os::Printer::log("Bad Context", ELL_ERROR); - break; - case EGL_BAD_CONFIG: - os::Printer::log("Bad Config", ELL_ERROR); - break; - case EGL_BAD_CURRENT_SURFACE: - os::Printer::log("Bad Current Surface", ELL_ERROR); - break; - case EGL_BAD_DISPLAY: - os::Printer::log("Bad Display", ELL_ERROR); - break; - case EGL_BAD_SURFACE: - os::Printer::log("Bad Surface", ELL_ERROR); - break; - case EGL_BAD_MATCH: - os::Printer::log("Bad Match", ELL_ERROR); - break; - case EGL_BAD_PARAMETER: - os::Printer::log("Bad Parameter", ELL_ERROR); - break; - case EGL_BAD_NATIVE_PIXMAP: - os::Printer::log("Bad Native Pixmap", ELL_ERROR); - break; - case EGL_BAD_NATIVE_WINDOW: - os::Printer::log("Bad Native Window", ELL_ERROR); - break; - case EGL_CONTEXT_LOST: - os::Printer::log("Context Lost", ELL_ERROR); - break; - }; - return true; -#else - return false; + m_egl_version = 100 * egl_version_major + 10 * egl_version_minor; + } + + return success; +} + + +bool ContextManagerEGL::chooseConfig() +{ + std::vector config_attribs; + config_attribs.push_back(EGL_RED_SIZE); + config_attribs.push_back(8); + config_attribs.push_back(EGL_GREEN_SIZE); + config_attribs.push_back(8); + config_attribs.push_back(EGL_BLUE_SIZE); + config_attribs.push_back(8); + config_attribs.push_back(EGL_ALPHA_SIZE); + config_attribs.push_back(m_creation_params.with_alpha_channel ? 8 : 0); + // config_attribs.push_back(EGL_BUFFER_SIZE); + // config_attribs.push_back(24); + config_attribs.push_back(EGL_DEPTH_SIZE); + config_attribs.push_back(16); + // config_attribs.push_back(EGL_STENCIL_SIZE); + // config_attribs.push_back(stencil_buffer); + // config_attribs.push_back(EGL_SAMPLE_BUFFERS); + // config_attribs.push_back(antialias ? 1 : 0); + // config_attribs.push_back(EGL_SAMPLES); + // config_attribs.push_back(antialias); + + if (m_creation_params.opengl_api == CEGL_API_OPENGL) + { + config_attribs.push_back(EGL_RENDERABLE_TYPE); + config_attribs.push_back(EGL_OPENGL_BIT); + } + else if (m_creation_params.opengl_api == CEGL_API_OPENGL_ES) + { + config_attribs.push_back(EGL_RENDERABLE_TYPE); + config_attribs.push_back(EGL_OPENGL_ES2_BIT); + } + + if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW) + { + config_attribs.push_back(EGL_SURFACE_TYPE); + config_attribs.push_back(EGL_WINDOW_BIT); + } + else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER) + { + config_attribs.push_back(EGL_SURFACE_TYPE); + config_attribs.push_back(EGL_PBUFFER_BIT); + } + + config_attribs.push_back(EGL_NONE); + config_attribs.push_back(0); + + EGLint num_configs = 0; + + bool success = eglChooseConfig(m_egl_display, &config_attribs[0], + &m_egl_config, 1, &num_configs); + + if (!success || num_configs == 0) + { + return false; + } + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + EGLint format = 0; + eglGetConfigAttrib(m_egl_display, m_egl_config, EGL_NATIVE_VISUAL_ID, + &format); + ANativeWindow_setBuffersGeometry(m_egl_window, 0, 0, format); #endif + + return true; } + +bool ContextManagerEGL::createSurface() +{ + if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW) + { + if (m_egl_surface == EGL_NO_SURFACE) + { + m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config, + m_egl_window, NULL); + } + + if (m_egl_surface == EGL_NO_SURFACE) + { + m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config, + 0, NULL); + } + } + else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER) + { + if (m_egl_surface == EGL_NO_SURFACE) + { + std::vector pbuffer_attribs; + pbuffer_attribs.push_back(EGL_WIDTH); + pbuffer_attribs.push_back(m_creation_params.pbuffer_width); + pbuffer_attribs.push_back(EGL_HEIGHT); + pbuffer_attribs.push_back(m_creation_params.pbuffer_height); + pbuffer_attribs.push_back(EGL_NONE); + pbuffer_attribs.push_back(0); + + m_egl_surface = eglCreatePbufferSurface(m_egl_display, + m_egl_config, + &pbuffer_attribs[0]); + } + + if (m_egl_surface == EGL_NO_SURFACE) + { + std::vector pbuffer_attribs; + pbuffer_attribs.push_back(EGL_WIDTH); + pbuffer_attribs.push_back(m_creation_params.pbuffer_width); + pbuffer_attribs.push_back(EGL_HEIGHT); + pbuffer_attribs.push_back(m_creation_params.pbuffer_height); + pbuffer_attribs.push_back(EGL_LARGEST_PBUFFER); + pbuffer_attribs.push_back(EGL_TRUE); + pbuffer_attribs.push_back(EGL_NONE); + pbuffer_attribs.push_back(0); + + m_egl_surface = eglCreatePbufferSurface(m_egl_display, + m_egl_config, + &pbuffer_attribs[0]); + } + } + + return m_egl_surface != EGL_NO_SURFACE; } + +bool ContextManagerEGL::createContext() +{ + m_is_legacy_device = false; + + if (m_creation_params.opengl_api == CEGL_API_OPENGL_ES) + { + if (!m_creation_params.force_legacy_device) + { + if (m_egl_context == EGL_NO_CONTEXT) + { + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_CLIENT_VERSION); + context_attribs.push_back(3); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + } + + if (m_egl_context == EGL_NO_CONTEXT) + { + m_is_legacy_device = true; + + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_CLIENT_VERSION); + context_attribs.push_back(2); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + } + else if (m_creation_params.opengl_api == CEGL_API_OPENGL) + { + if (!m_creation_params.force_legacy_device) + { + if (m_egl_context == EGL_NO_CONTEXT) + { + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(4); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(3); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + + if (m_egl_context == EGL_NO_CONTEXT) + { + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(3); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(3); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + + if (m_egl_context == EGL_NO_CONTEXT) + { + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(3); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(1); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + } + + if (m_egl_context == EGL_NO_CONTEXT) + { + m_is_legacy_device = true; + + std::vector context_attribs; + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(2); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(1); + context_attribs.push_back(EGL_NONE); + context_attribs.push_back(0); + + m_egl_context = eglCreateContext(m_egl_display, + m_egl_config, + EGL_NO_CONTEXT, + &context_attribs[0]); + } + } + + return m_egl_context != EGL_NO_CONTEXT; +} + + +void ContextManagerEGL::close() +{ + eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + + if (m_egl_context != EGL_NO_CONTEXT) + { + eglDestroyContext(m_egl_display, m_egl_context); + m_egl_context = EGL_NO_CONTEXT; + } + + if (m_egl_surface != EGL_NO_SURFACE) + { + eglDestroySurface(m_egl_display, m_egl_surface); + m_egl_surface = EGL_NO_SURFACE; + } + + if (m_egl_display != EGL_NO_DISPLAY) + { + eglTerminate(m_egl_display); + m_egl_display = EGL_NO_DISPLAY; + } +} + + +bool ContextManagerEGL::swapBuffers() +{ + bool success = eglSwapBuffers(m_egl_display, m_egl_surface); + +#ifdef DEBUG + if (!success) + { + eglGetError(); + } +#endif + + return success; +} + + +void ContextManagerEGL::reloadEGLSurface(void* window) +{ +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + m_egl_window = (ANativeWindow*)window; + + if (!m_egl_window) + { + os::Printer::log("Error: Invalid EGL window.\n"); + } +#endif + + eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + + eglDestroySurface(m_egl_display, m_egl_surface); + m_egl_surface = EGL_NO_SURFACE; + + bool success = createSurface(); + + if (!success) + { + os::Printer::log("Error: Could not create EGL surface."); + } + + success = eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, + m_egl_context); + + if (!success) + { + checkEGLError(); + os::Printer::log("Error: Couldn't make context current for EGL display.\n"); + } +} + + +bool ContextManagerEGL::getSurfaceDimensions(int* width, int* height) +{ + if (!eglQuerySurface(m_egl_display, m_egl_surface, EGL_WIDTH, width)) + return false; + + if (!eglQuerySurface(m_egl_display, m_egl_surface, EGL_HEIGHT, height)) + return false; + + return true; +} + + +bool ContextManagerEGL::hasEGLExtension(const char* extension) +{ + const char* extensions = eglQueryString(m_egl_display, EGL_EXTENSIONS); + + if (extensions && strstr(extensions, extension) != NULL) + { + return true; + } + + return false; +} + + +bool ContextManagerEGL::checkEGLError() +{ + bool result = true; + + switch (eglGetError()) + { + case EGL_SUCCESS: + result = false; + break; + case EGL_NOT_INITIALIZED: + os::Printer::log("Error: EGL_NOT_INITIALIZED\n"); + break; + case EGL_BAD_ACCESS: + os::Printer::log("Error: EGL_BAD_ACCESS\n"); + break; + case EGL_BAD_ALLOC: + os::Printer::log("Error: EGL_BAD_ALLOC\n"); + break; + case EGL_BAD_ATTRIBUTE: + os::Printer::log("Error: EGL_BAD_ATTRIBUTE\n"); + break; + case EGL_BAD_CONTEXT: + os::Printer::log("Error: EGL_BAD_CONTEXT\n"); + break; + case EGL_BAD_CONFIG: + os::Printer::log("Error: EGL_BAD_CONFIG\n"); + break; + case EGL_BAD_CURRENT_SURFACE: + os::Printer::log("Error: EGL_BAD_CURRENT_SURFACE\n"); + break; + case EGL_BAD_DISPLAY: + os::Printer::log("Error: EGL_BAD_DISPLAY\n"); + break; + case EGL_BAD_SURFACE: + os::Printer::log("Error: EGL_BAD_SURFACE\n"); + break; + case EGL_BAD_MATCH: + os::Printer::log("Error: EGL_BAD_MATCH\n"); + break; + case EGL_BAD_PARAMETER: + os::Printer::log("Error: EGL_BAD_PARAMETER\n"); + break; + case EGL_BAD_NATIVE_PIXMAP: + os::Printer::log("Error: EGL_BAD_NATIVE_PIXMAP\n"); + break; + case EGL_BAD_NATIVE_WINDOW: + os::Printer::log("Error: EGL_BAD_NATIVE_WINDOW\n"); + break; + case EGL_CONTEXT_LOST: + os::Printer::log("Error: EGL_CONTEXT_LOST\n"); + break; + default: + os::Printer::log("Error: Unknown EGL error.\n"); + break; + }; + + return result; } #endif diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.h b/lib/irrlicht/source/Irrlicht/CContextEGL.h index a7cbe1b42..beae64d47 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.h +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.h @@ -6,71 +6,75 @@ // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in Irrlicht.h -#ifndef __C_CONTEXT_EGL_H_INCLUDED__ -#define __C_CONTEXT_EGL_H_INCLUDED__ +#ifndef CONTEXT_EGL_HPP +#define CONTEXT_EGL_HPP #include "IrrCompileConfig.h" #if defined(_IRR_COMPILE_WITH_EGL_) -#include "SIrrCreationParameters.h" -#include "SExposedVideoData.h" - -#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) #include -#else -#include -#include -#endif +#include -#if defined(_IRR_WINDOWS_API_) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#endif - -#ifdef _MSC_VER -#pragma comment(lib, "libEGL.lib") -#endif - - -namespace irr +enum ContextEGLOpenGLAPI { -namespace video -{ - -class ContextEGL -{ -private: - NativeWindowType EglWindow; - void* EglDisplay; - void* EglSurface; - void* EglContext; - EGLConfig EglConfig; - int EGLVersionMajor; - int EGLVersionMinor; - -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ - HDC HDc; -#endif - - bool IsCoreContext; - - bool testEGLError(); - -public: - ContextEGL(const SIrrlichtCreationParameters& params, - const SExposedVideoData& data); - ~ContextEGL(); - - void reloadEGLSurface(void* window); - bool swapBuffers(); - bool isCoreContext() {return IsCoreContext;} + CEGL_API_OPENGL, + CEGL_API_OPENGL_ES }; -} -} +enum ContextEGLSurfaceType +{ + CEGL_SURFACE_WINDOW, + CEGL_SURFACE_PBUFFER +}; + +struct ContextEGLParams +{ + ContextEGLOpenGLAPI opengl_api; + ContextEGLSurfaceType surface_type; + EGLNativeWindowType window; + EGLNativeDisplayType display; + bool force_legacy_device; + bool with_alpha_channel; + bool vsync_enabled; + int pbuffer_width; + int pbuffer_height; +}; + + +class ContextManagerEGL +{ +private: + NativeWindowType m_egl_window; + EGLDisplay m_egl_display; + EGLSurface m_egl_surface; + EGLContext m_egl_context; + EGLConfig m_egl_config; + + ContextEGLParams m_creation_params; + bool m_is_legacy_device; + bool m_initialized; + int m_egl_version; + + bool initDisplay(); + bool chooseConfig(); + bool createSurface(); + bool createContext(); + bool hasEGLExtension(const char* extension); + bool checkEGLError(); + +public: + ContextManagerEGL(); + ~ContextManagerEGL(); + + bool init(const ContextEGLParams& params); + void close(); + + void reloadEGLSurface(void* window); + bool swapBuffers(); + bool isLegacyDevice() {return m_is_legacy_device;} + bool getSurfaceDimensions(int* width, int* height); +}; #endif diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp index 68d3c1cf6..16991fd95 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.cpp @@ -51,6 +51,9 @@ namespace video , ViewFramebuffer(0) , ViewRenderbuffer(0) , ViewDepthRenderbuffer(0) +#endif +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + , HDc(0) #endif , Params(params) { @@ -60,10 +63,38 @@ namespace video ExposedData = data; #if defined(_IRR_COMPILE_WITH_EGL_) - EglContext = new ContextEGL(params, data); - useCoreContext = EglContext->isCoreContext(); + EglContext = new ContextManagerEGL(); + + ContextEGLParams egl_params; + egl_params.opengl_api = CEGL_API_OPENGL_ES; + egl_params.surface_type = CEGL_SURFACE_WINDOW; + egl_params.force_legacy_device = Params.ForceLegacyDevice; + egl_params.with_alpha_channel = Params.WithAlphaChannel; + egl_params.vsync_enabled = Params.Vsync; + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + egl_params.window = (EGLNativeWindowType)(data.OpenGLWin32.HWnd); + HDc = GetDC(data.OpenGLWin32.HWnd); + egl_params.display = (NativeDisplayType)(HDc); +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) + egl_params.window = data.OpenGLLinux.X11Window; + egl_params.display = (EGLNativeDisplayType)(data.OpenGLLinux.X11Display); +#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) + egl_params.window = ((struct android_app *)(params.PrivateData))->window; + egl_params.display = NULL; +#endif + + EglContext->init(egl_params); + useCoreContext = !EglContext->isLegacyDevice(); genericDriverInit(params.WindowSize, params.Stencilbuffer); + +#ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ + int width = 0; + int height = 0; + EglContext->getSurfaceDimensions(&width, &height); + CNullDriver::ScreenSize = core::dimension2d(width, height); +#endif #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) Device = device; @@ -115,6 +146,11 @@ namespace video #if defined(_IRR_COMPILE_WITH_EGL_) delete EglContext; + +#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) + if (HDc) + ReleaseDC((ExposedData.OpenGLWin32.HWnd, HDc); +#endif #elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) diff --git a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h index 328b13189..007dc2dbc 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2Driver.h +++ b/lib/irrlicht/source/Irrlicht/COGLES2Driver.h @@ -38,6 +38,8 @@ #endif #include "COGLES2ExtensionHandler.h" +class ContextManagerEGL; + namespace irr { namespace video @@ -48,7 +50,6 @@ namespace video class COGLES2Renderer2D; class COGLES2NormalMapRenderer; class COGLES2ParallaxMapRenderer; - class ContextEGL; class COGLES2Driver : public CNullDriver, public IMaterialRendererServices, public COGLES2ExtensionHandler { @@ -371,7 +372,7 @@ namespace video COGLES2CallBridge* getBridgeCalls() const; #if defined(_IRR_COMPILE_WITH_EGL_) - ContextEGL* getEGLContext() {return EglContext;} + ContextManagerEGL* getEGLContext() {return EglContext;} #endif private: @@ -458,7 +459,7 @@ namespace video COGLES2Renderer2D* MaterialRenderer2D; #if defined(_IRR_COMPILE_WITH_EGL_) - ContextEGL* EglContext; + ContextManagerEGL* EglContext; #endif #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_) CIrrDeviceIPhone* Device; @@ -466,6 +467,9 @@ namespace video GLuint ViewRenderbuffer; GLuint ViewDepthRenderbuffer; #endif +#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ + HDC HDc; +#endif SIrrlichtCreationParameters Params; }; From f4e803220bf98a1d15e2898c61a8f9bf5b584f77 Mon Sep 17 00:00:00 2001 From: deve Date: Fri, 21 Apr 2017 08:51:54 +0200 Subject: [PATCH 6/6] Some minor fixes --- lib/irrlicht/source/Irrlicht/CContextEGL.cpp | 106 +++++++++---------- lib/irrlicht/source/Irrlicht/CContextEGL.h | 10 +- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp index ac7fe8a6f..fd68b92e3 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.cpp +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.cpp @@ -34,7 +34,7 @@ ContextManagerEGL::ContextManagerEGL() m_egl_version = 0; m_is_legacy_device = false; m_initialized = false; - + memset(&m_creation_params, 0, sizeof(ContextEGLParams)); } @@ -135,7 +135,7 @@ bool ContextManagerEGL::init(const ContextEGLParams& params) bool ContextManagerEGL::initDisplay() { - NativeDisplayType display = (NativeDisplayType)(m_creation_params.display); + EGLNativeDisplayType display = m_creation_params.display; #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ display = EGL_DEFAULT_DISPLAY; @@ -162,10 +162,10 @@ bool ContextManagerEGL::initDisplay() bool success = eglInitialize(m_egl_display, &egl_version_major, &egl_version_minor); - if (success) - { - m_egl_version = 100 * egl_version_major + 10 * egl_version_minor; - } + if (success) + { + m_egl_version = 100 * egl_version_major + 10 * egl_version_minor; + } return success; } @@ -195,25 +195,25 @@ bool ContextManagerEGL::chooseConfig() if (m_creation_params.opengl_api == CEGL_API_OPENGL) { - config_attribs.push_back(EGL_RENDERABLE_TYPE); - config_attribs.push_back(EGL_OPENGL_BIT); - } + config_attribs.push_back(EGL_RENDERABLE_TYPE); + config_attribs.push_back(EGL_OPENGL_BIT); + } else if (m_creation_params.opengl_api == CEGL_API_OPENGL_ES) { - config_attribs.push_back(EGL_RENDERABLE_TYPE); - config_attribs.push_back(EGL_OPENGL_ES2_BIT); - } + config_attribs.push_back(EGL_RENDERABLE_TYPE); + config_attribs.push_back(EGL_OPENGL_ES2_BIT); + } - if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW) - { - config_attribs.push_back(EGL_SURFACE_TYPE); - config_attribs.push_back(EGL_WINDOW_BIT); - } - else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER) - { - config_attribs.push_back(EGL_SURFACE_TYPE); - config_attribs.push_back(EGL_PBUFFER_BIT); - } + if (m_creation_params.surface_type == CEGL_SURFACE_WINDOW) + { + config_attribs.push_back(EGL_SURFACE_TYPE); + config_attribs.push_back(EGL_WINDOW_BIT); + } + else if (m_creation_params.surface_type == CEGL_SURFACE_PBUFFER) + { + config_attribs.push_back(EGL_SURFACE_TYPE); + config_attribs.push_back(EGL_PBUFFER_BIT); + } config_attribs.push_back(EGL_NONE); config_attribs.push_back(0); @@ -259,26 +259,26 @@ bool ContextManagerEGL::createSurface() { if (m_egl_surface == EGL_NO_SURFACE) { - std::vector pbuffer_attribs; - pbuffer_attribs.push_back(EGL_WIDTH); - pbuffer_attribs.push_back(m_creation_params.pbuffer_width); - pbuffer_attribs.push_back(EGL_HEIGHT); - pbuffer_attribs.push_back(m_creation_params.pbuffer_height); - pbuffer_attribs.push_back(EGL_NONE); - pbuffer_attribs.push_back(0); + std::vector pbuffer_attribs; + pbuffer_attribs.push_back(EGL_WIDTH); + pbuffer_attribs.push_back(m_creation_params.pbuffer_width); + pbuffer_attribs.push_back(EGL_HEIGHT); + pbuffer_attribs.push_back(m_creation_params.pbuffer_height); + pbuffer_attribs.push_back(EGL_NONE); + pbuffer_attribs.push_back(0); - m_egl_surface = eglCreatePbufferSurface(m_egl_display, - m_egl_config, - &pbuffer_attribs[0]); + m_egl_surface = eglCreatePbufferSurface(m_egl_display, + m_egl_config, + &pbuffer_attribs[0]); } if (m_egl_surface == EGL_NO_SURFACE) { std::vector pbuffer_attribs; - pbuffer_attribs.push_back(EGL_WIDTH); - pbuffer_attribs.push_back(m_creation_params.pbuffer_width); - pbuffer_attribs.push_back(EGL_HEIGHT); - pbuffer_attribs.push_back(m_creation_params.pbuffer_height); + pbuffer_attribs.push_back(EGL_WIDTH); + pbuffer_attribs.push_back(m_creation_params.pbuffer_width); + pbuffer_attribs.push_back(EGL_HEIGHT); + pbuffer_attribs.push_back(m_creation_params.pbuffer_height); pbuffer_attribs.push_back(EGL_LARGEST_PBUFFER); pbuffer_attribs.push_back(EGL_TRUE); pbuffer_attribs.push_back(EGL_NONE); @@ -340,9 +340,9 @@ bool ContextManagerEGL::createContext() if (m_egl_context == EGL_NO_CONTEXT) { std::vector context_attribs; - context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION); context_attribs.push_back(4); - context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION); context_attribs.push_back(3); context_attribs.push_back(EGL_NONE); context_attribs.push_back(0); @@ -356,9 +356,9 @@ bool ContextManagerEGL::createContext() if (m_egl_context == EGL_NO_CONTEXT) { std::vector context_attribs; - context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION); context_attribs.push_back(3); - context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION); context_attribs.push_back(3); context_attribs.push_back(EGL_NONE); context_attribs.push_back(0); @@ -372,9 +372,9 @@ bool ContextManagerEGL::createContext() if (m_egl_context == EGL_NO_CONTEXT) { std::vector context_attribs; - context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION); context_attribs.push_back(3); - context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION); context_attribs.push_back(1); context_attribs.push_back(EGL_NONE); context_attribs.push_back(0); @@ -391,9 +391,9 @@ bool ContextManagerEGL::createContext() m_is_legacy_device = true; std::vector context_attribs; - context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MAJOR_VERSION); context_attribs.push_back(2); - context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); + context_attribs.push_back(EGL_CONTEXT_MINOR_VERSION); context_attribs.push_back(1); context_attribs.push_back(EGL_NONE); context_attribs.push_back(0); @@ -439,13 +439,13 @@ bool ContextManagerEGL::swapBuffers() bool success = eglSwapBuffers(m_egl_display, m_egl_surface); #ifdef DEBUG - if (!success) - { - eglGetError(); - } + if (!success) + { + eglGetError(); + } #endif - return success; + return success; } @@ -461,11 +461,11 @@ void ContextManagerEGL::reloadEGLSurface(void* window) #endif eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT); + EGL_NO_CONTEXT); eglDestroySurface(m_egl_display, m_egl_surface); - m_egl_surface = EGL_NO_SURFACE; - + m_egl_surface = EGL_NO_SURFACE; + bool success = createSurface(); if (!success) @@ -474,7 +474,7 @@ void ContextManagerEGL::reloadEGLSurface(void* window) } success = eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, - m_egl_context); + m_egl_context); if (!success) { diff --git a/lib/irrlicht/source/Irrlicht/CContextEGL.h b/lib/irrlicht/source/Irrlicht/CContextEGL.h index beae64d47..5029df497 100644 --- a/lib/irrlicht/source/Irrlicht/CContextEGL.h +++ b/lib/irrlicht/source/Irrlicht/CContextEGL.h @@ -14,7 +14,13 @@ #if defined(_IRR_COMPILE_WITH_EGL_) #include -#include + +#ifndef EGL_CONTEXT_MAJOR_VERSION +#define EGL_CONTEXT_MAJOR_VERSION 0x3098 +#endif +#ifndef EGL_CONTEXT_MINOR_VERSION +#define EGL_CONTEXT_MINOR_VERSION 0x30FB +#endif enum ContextEGLOpenGLAPI { @@ -45,7 +51,7 @@ struct ContextEGLParams class ContextManagerEGL { private: - NativeWindowType m_egl_window; + EGLNativeWindowType m_egl_window; EGLDisplay m_egl_display; EGLSurface m_egl_surface; EGLContext m_egl_context;