1212#include < OpenGl_View.hxx>
1313#include < OpenGl_Window.hxx>
1414
15+ #if defined(HAVE_WAYLAND) || defined(HAVE_GLES2)
16+ #include < EGL/egl.h>
17+ #endif
18+
1519// Exporting this symbol from .exe with value=1 will direct to NVIDIA GPU on Optimus systems
1620// __declspec(dllexport) DWORD NvOptimusEnablement = 1;
1721// Exporting this symbol from .exe with value=1 will direct to faster GPU on AMD PowerXpress systems
@@ -96,6 +100,25 @@ bool OcctGlTools::InitializeGlWindow(const Handle(V3d_View)& theView,
96100 {
97101 aWindow = new OcctNeutralWindow ();
98102 aWindow->SetVirtual (true );
103+
104+ #if defined(HAVE_WAYLAND) || defined(HAVE_GLES2)
105+ // wrap EGL surface
106+ EGLContext anEglCtx = eglGetCurrentContext ();
107+ EGLContext anEglDisplay = eglGetCurrentDisplay ();
108+ EGLContext anEglSurf = eglGetCurrentSurface (EGL_DRAW);
109+
110+ EGLint anEglCfgId = 0 , aNbConfigs = 0 ;
111+ eglQuerySurface (anEglDisplay, anEglSurf, EGL_CONFIG_ID, &anEglCfgId);
112+ const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, anEglCfgId, EGL_NONE };
113+ void * anEglCfg = nullptr ;
114+ eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglCfg, 1 , &aNbConfigs);
115+
116+ if (!aDriver->InitEglContext (anEglDisplay, anEglCtx, anEglCfg))
117+ {
118+ Message::SendFail () << " Error: OpenGl_GraphicDriver cannot initialize EGL context" ;
119+ return false ;
120+ }
121+ #endif
99122 }
100123 aWindow->SetNativeHandle (aNativeWin);
101124 aWindow->SetSize (theSize.x (), theSize.y ());
@@ -118,20 +141,21 @@ bool OcctGlTools::InitializeGlWindow(const Handle(V3d_View)& theView,
118141// ================================================================
119142bool OcctGlTools::InitializeGlFbo (const Handle (V3d_View)& theView)
120143{
121- Handle (OpenGl_Context) aGlCtx = OcctGlTools::GetGlContext (theView);
122- Handle (OpenGl_FrameBuffer ) aDefaultFbo = aGlCtx->DefaultFrameBuffer ();
144+ Handle (OpenGl_Context) aGlCtx = OcctGlTools::GetGlContext (theView);
145+ Handle (OcctQtFrameBuffer ) aDefaultFbo = Handle (OcctQtFrameBuffer):: DownCast ( aGlCtx->DefaultFrameBuffer () );
123146 if (aDefaultFbo.IsNull ())
124- {
125147 aDefaultFbo = new OcctQtFrameBuffer ();
126- aGlCtx->SetDefaultFrameBuffer (aDefaultFbo);
127- }
148+
128149 if (!aDefaultFbo->InitWrapper (aGlCtx))
129150 {
130151 aDefaultFbo.Nullify ();
131152 Message::DefaultMessenger ()->Send (" Default FBO wrapper creation failed" , Message_Fail);
132153 return false ;
133154 }
134155
156+ // workaround some bugs (legacy code in OpenGl_Window::init() for surface-less EGL context)
157+ aGlCtx->SetDefaultFrameBuffer (Handle (OpenGl_FrameBuffer)());
158+
135159 Graphic3d_Vec2i aViewSizeOld;
136160 const Graphic3d_Vec2i aViewSizeNew = aDefaultFbo->GetVPSize ();
137161 Handle (OcctNeutralWindow) aWindow = Handle (OcctNeutralWindow)::DownCast (theView->Window ());
@@ -150,6 +174,7 @@ bool OcctGlTools::InitializeGlFbo(const Handle(V3d_View)& theView)
150174 }
151175#endif
152176 }
177+ aGlCtx->SetDefaultFrameBuffer (aDefaultFbo);
153178 return true ;
154179}
155180
@@ -173,11 +198,13 @@ void OcctGlTools::ResetGlStateBeforeOcct(const Handle(V3d_View)& theView)
173198 // Disable also texture bindings left by Qt.
174199 aGlCtx->core11fwd ->glBindTexture (GL_TEXTURE_2D, 0 );
175200 aGlCtx->core11fwd ->glDisable (GL_BLEND);
201+ #ifndef HAVE_GLES2
176202 if (aGlCtx->core11ffp != nullptr )
177203 {
178204 aGlCtx->core11fwd ->glDisable (GL_ALPHA_TEST);
179205 aGlCtx->core11fwd ->glDisable (GL_TEXTURE_2D);
180206 }
207+ #endif
181208}
182209
183210// ================================================================
0 commit comments