From 9aceb23df6f7a85f01c22823d00e0d2102546cb7 Mon Sep 17 00:00:00 2001 From: kgv Date: Sat, 25 May 2019 18:59:17 +0300 Subject: [PATCH] 0030745: Visualization, TKOpenGl - fix initialization of GLES3 context OpenGl_GraphicDriver::InitContext() now tries to initialize GLES3 context (EGL_CONTEXT_CLIENT_VERSION) and then fallback to GLES2. --- src/OpenGl/OpenGl_GraphicDriver.cxx | 48 ++++++++++++++++++++--------- src/Xw/Xw_Window.cxx | 32 ++++++++++++++----- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/OpenGl/OpenGl_GraphicDriver.cxx b/src/OpenGl/OpenGl_GraphicDriver.cxx index 03f02a636e..833c4c5e10 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver.cxx @@ -50,6 +50,9 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver) #if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__) #include + #ifndef EGL_OPENGL_ES3_BIT + #define EGL_OPENGL_ES3_BIT 0x00000040 + #endif #endif namespace @@ -78,17 +81,30 @@ namespace EGLConfig aCfg = NULL; EGLint aNbConfigs = 0; - if (eglChooseConfig (theDisplay, aConfigAttribs, &aCfg, 1, &aNbConfigs) == EGL_TRUE - || aCfg != NULL) + for (Standard_Integer aGlesVer = 3; aGlesVer >= 2; --aGlesVer) { - return aCfg; - } + #if defined(GL_ES_VERSION_2_0) + aConfigAttribs[6 * 2 + 1] = aGlesVer == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT; + #else + if (aGlesVer == 2) + { + break; + } + #endif - eglGetError(); - aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer - if (eglChooseConfig (theDisplay, aConfigAttribs, &aCfg, 1, &aNbConfigs) != EGL_TRUE - || aCfg == NULL) - { + if (eglChooseConfig (theDisplay, aConfigAttribs, &aCfg, 1, &aNbConfigs) == EGL_TRUE + && aCfg != NULL) + { + return aCfg; + } + eglGetError(); + + aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer + if (eglChooseConfig (theDisplay, aConfigAttribs, &aCfg, 1, &aNbConfigs) == EGL_TRUE + && aCfg != NULL) + { + return aCfg; + } eglGetError(); } return aCfg; @@ -280,16 +296,18 @@ Standard_Boolean OpenGl_GraphicDriver::InitContext() } #if defined(GL_ES_VERSION_2_0) - EGLint anEglCtxAttribs[] = - { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; + EGLint anEglCtxAttribs3[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE, EGL_NONE }; + EGLint anEglCtxAttribs2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; if (eglBindAPI (EGL_OPENGL_ES_API) != EGL_TRUE) { ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL ES client!", Message_Fail); return Standard_False; } + myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs3); + if ((EGLContext )myEglContext == EGL_NO_CONTEXT) + { + myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs2); + } #else EGLint* anEglCtxAttribs = NULL; if (eglBindAPI (EGL_OPENGL_API) != EGL_TRUE) @@ -297,9 +315,9 @@ Standard_Boolean OpenGl_GraphicDriver::InitContext() ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL client!", Message_Fail); return Standard_False; } + myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs); #endif - myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs); if ((EGLContext )myEglContext == EGL_NO_CONTEXT) { ::Message::DefaultMessenger()->Send ("Error: EGL is unable to create OpenGL context!", Message_Fail); diff --git a/src/Xw/Xw_Window.cxx b/src/Xw/Xw_Window.cxx index 264c61b42d..b811c5e1e3 100644 --- a/src/Xw/Xw_Window.cxx +++ b/src/Xw/Xw_Window.cxx @@ -24,6 +24,9 @@ #if defined(HAVE_EGL) || defined(HAVE_GLES2) #include + #ifndef EGL_OPENGL_ES3_BIT + #define EGL_OPENGL_ES3_BIT 0x00000040 + #endif #else #include @@ -120,16 +123,31 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, EGLint aNbConfigs = 0; void* anEglConfig = NULL; - if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE - || anEglConfig == NULL) + for (Standard_Integer aGlesVer = 3; aGlesVer >= 2; --aGlesVer) { - eglGetError(); - aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer - if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE - || anEglConfig == NULL) + #if defined(GL_ES_VERSION_2_0) + aConfigAttribs[6 * 2 + 1] = aGlesVer == 3 ? EGL_OPENGL_ES3_BIT : EGL_OPENGL_ES2_BIT; + #else + if (aGlesVer == 2) { - anEglConfig = NULL; + break; } + #endif + + if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) == EGL_TRUE + && anEglConfig != NULL) + { + break; + } + eglGetError(); + + aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer + if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) == EGL_TRUE + && anEglConfig != NULL) + { + break; + } + eglGetError(); } if (anEglConfig != NULL