0026823: Configuration - use EGL on another platform without GLX
[occt.git] / src / OpenGl / OpenGl_Window.cxx
index 997e45b..73955bf 100644 (file)
@@ -26,7 +26,7 @@
 #include <TCollection_ExtendedString.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
 
-#if defined(HAVE_EGL) || defined(__ANDROID__)
+#if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
   #include <EGL/egl.h>
 #endif
 
@@ -36,7 +36,7 @@
 namespace
 {
 
-#if defined(HAVE_EGL) || defined(__ANDROID__)
+#if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
   //
 #elif defined(_WIN32)
 
@@ -118,9 +118,37 @@ namespace
     return DefWindowProcW (theWin, theMsg, theParamW, theParamL);
   }
 #else
-  static Bool WaitForNotify (Display* theDisp, XEvent* theEv, char* theArg)
+
+  // GLX_ARB_create_context
+#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
+  #define GLX_CONTEXT_DEBUG_BIT_ARB         0x00000001
+  #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
+  #define GLX_CONTEXT_MAJOR_VERSION_ARB     0x2091
+  #define GLX_CONTEXT_MINOR_VERSION_ARB     0x2092
+  #define GLX_CONTEXT_FLAGS_ARB             0x2094
+
+  // GLX_ARB_create_context_profile
+  #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB  0x00000001
+  #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
+  #define GLX_CONTEXT_PROFILE_MASK_ARB      0x9126
+#endif
+
+  //! Dummy XError handler which just skips errors
+  static int xErrorDummyHandler (Display*     /*theDisplay*/,
+                                 XErrorEvent* /*theErrorEvent*/)
   {
-    return (theEv->type == MapNotify) && (theEv->xmap.window == (Window )theArg);
+    return 0;
+  }
+
+  //! Auxiliary method to format list.
+  static void addMsgToList (TCollection_ExtendedString&       theList,
+                            const TCollection_ExtendedString& theMsg)
+  {
+    if (!theList.IsEmpty())
+    {
+      theList += ", ";
+    }
+    theList += theMsg;
   }
 #endif
 
@@ -131,24 +159,20 @@ namespace
 // purpose  :
 // =======================================================================
 OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
-                              const CALL_DEF_WINDOW&        theCWindow,
+                              const Handle(Aspect_Window)&  thePlatformWindow,
                               Aspect_RenderingContext       theGContext,
                               const Handle(OpenGl_Caps)&    theCaps,
                               const Handle(OpenGl_Context)& theShareCtx)
 : myGlContext (new OpenGl_Context (theCaps)),
   myOwnGContext (theGContext == 0),
-  myWidth   (theCWindow.dx),
-  myHeight  (theCWindow.dy),
+  myPlatformWindow (thePlatformWindow),
   mySwapInterval (theCaps->swapInterval)
 {
-  myBgColor.rgb[0] = theCWindow.Background.r;
-  myBgColor.rgb[1] = theCWindow.Background.g;
-  myBgColor.rgb[2] = theCWindow.Background.b;
-  myBgColor.rgb[3] = 1.0f;
+  myPlatformWindow->Size (myWidth, myHeight);
 
   Standard_Boolean isCoreProfile = Standard_False;
 
-#if defined(HAVE_EGL) || defined(__ANDROID__)
+#if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
   EGLDisplay anEglDisplay = (EGLDisplay )theDriver->getRawGlDisplay();
   EGLContext anEglContext = (EGLContext )theDriver->getRawGlContext();
   EGLConfig  anEglConfig  = (EGLConfig  )theDriver->getRawGlConfig();
@@ -164,7 +188,10 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
   if (theGContext == (EGLContext )EGL_NO_CONTEXT)
   {
     // create new surface
-    anEglSurf = eglCreateWindowSurface (anEglDisplay, anEglConfig, (EGLNativeWindowType )theCWindow.XWindow, NULL);
+    anEglSurf = eglCreateWindowSurface (anEglDisplay,
+                                        anEglConfig,
+                                        (EGLNativeWindowType )myPlatformWindow->NativeHandle(),
+                                        NULL);
     if (anEglSurf == EGL_NO_SURFACE)
     {
       Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL is unable to create surface for window!");
@@ -189,7 +216,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
   myGlContext->Init ((Aspect_Drawable )anEglSurf, (Aspect_Display )anEglDisplay, (Aspect_RenderingContext )anEglContext, isCoreProfile);
 #elif defined(_WIN32)
   (void )theDriver;
-  HWND  aWindow   = (HWND )theCWindow.XWindow;
+  HWND  aWindow   = (HWND )myPlatformWindow->NativeHandle();
   HDC   aWindowDC = GetDC (aWindow);
   HGLRC aGContext = (HGLRC )theGContext;
 
@@ -217,9 +244,9 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
     TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: "
                                      "ChoosePixelFormat is unable to find stereo supported pixel format. "
                                      "Choosing similar non stereo format.");
-    myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                              GL_DEBUG_TYPE_OTHER_ARB,
-                              0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
+    myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
+                              GL_DEBUG_TYPE_OTHER,
+                              0, GL_DEBUG_SEVERITY_HIGH, aMsg);
 
     aPixelFrmt.dwFlags &= ~PFD_STEREO;
     aPixelFrmtId = ChoosePixelFormat (aWindowDC, &aPixelFrmt);
@@ -384,7 +411,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
         && !theCaps->contextCompatible)
         {
           TCollection_ExtendedString aMsg("OpenGl_Window::CreateWindow: core profile creation failed.");
-          myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, aMsg);
+          myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
         }
       }
 
@@ -438,234 +465,131 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
 
   myGlContext->Init ((Aspect_Handle )aWindow, (Aspect_Handle )aWindowDC, (Aspect_RenderingContext )aGContext, isCoreProfile);
 #else
-  Window aParent = (Window )theCWindow.XWindow;
-  Window aWindow = 0;
-
+  Window     aWindow   = (Window )myPlatformWindow->NativeHandle();
   Display*   aDisp     = theDriver->GetDisplayConnection()->GetDisplay();
   GLXContext aGContext = (GLXContext )theGContext;
-
-  XWindowAttributes wattr;
-  XGetWindowAttributes (aDisp, aParent, &wattr);
-  const int scr = DefaultScreen (aDisp);
-
-  XVisualInfo* aVis = NULL;
+  GLXContext aSlaveCtx = !theShareCtx.IsNull() ? (GLXContext )theShareCtx->myGContext : NULL;
+
+  XWindowAttributes aWinAttribs;
+  XGetWindowAttributes (aDisp, aWindow, &aWinAttribs);
+  XVisualInfo aVisInfo;
+  aVisInfo.visualid = aWinAttribs.visual->visualid;
+  aVisInfo.screen   = DefaultScreen (aDisp);
+  int aNbItems;
+  XVisualInfo* aVis = XGetVisualInfo (aDisp, VisualIDMask | VisualScreenMask, &aVisInfo, &aNbItems);
+  int isGl = 0;
+  if (aVis == NULL)
   {
-    unsigned long aVisInfoMask = VisualIDMask | VisualScreenMask;
-    XVisualInfo aVisInfo;
-    aVisInfo.visualid = wattr.visual->visualid;
-    aVisInfo.screen   = scr;
-    int aNbItems;
-    aVis = XGetVisualInfo (aDisp, aVisInfoMask, &aVisInfo, &aNbItems);
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
+    return;
   }
-
-#if defined(__linux) || defined(Linux) || defined(__APPLE__)
-  if (aVis != NULL)
+  else if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0 || !isGl)
   {
-    // check Visual for OpenGl context's parameters compatibility
-    int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, isStereo = 0;
-    int aDepthSize = 0, aStencilSize = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0)
-      isGl = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_RGBA, &isRGBA) != 0)
-      isRGBA = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_DOUBLEBUFFER, &isDoubleBuffer) != 0)
-      isDoubleBuffer = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_STEREO, &isStereo) != 0)
-      isStereo = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize) != 0)
-      aDepthSize = 0;
-
-    if (glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize) != 0)
-      aStencilSize = 0;
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
+    return;
+  }
 
-    if (!isGl)
-    {
-      XFree (aVis);
-      aVis = NULL;
-      if (myOwnGContext)
-      {
-        TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
-        myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                                  GL_DEBUG_TYPE_OTHER_ARB,
-                                  0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
-      }
-    }
-    else
+  // create new context
+  GLXFBConfig anFBConfig = myPlatformWindow->NativeFBConfig();
+  const char* aGlxExts   = glXQueryExtensionsString (aDisp, aVisInfo.screen);
+  if (myOwnGContext
+   && anFBConfig != NULL
+   && OpenGl_Context::CheckExtension (aGlxExts, "GLX_ARB_create_context_profile"))
+  {
+    // Replace default XError handler to ignore errors.
+    // Warning - this is global for all threads!
+    typedef int (*xerrorhandler_t)(Display* , XErrorEvent* );
+    xerrorhandler_t anOldHandler = XSetErrorHandler(xErrorDummyHandler);
+
+    typedef GLXContext (*glXCreateContextAttribsARB_t)(Display* dpy, GLXFBConfig config,
+                                                       GLXContext share_context, Bool direct,
+                                                       const int* attrib_list);
+    glXCreateContextAttribsARB_t aCreateCtxProc = (glXCreateContextAttribsARB_t )glXGetProcAddress((const GLubyte* )"glXCreateContextAttribsARB");
+    if (!theCaps->contextCompatible)
     {
-      TCollection_ExtendedString aList;
-      if (aDepthSize < 1)
+      int aCoreCtxAttribs[] =
       {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "no depth buffer";
-      }
-      if (aStencilSize < 1)
-      {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "no stencil buffer";
-      }
-      if (isRGBA == 0)
-      {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "no RGBA color buffer";
-      }
-      if (isDoubleBuffer == 0)
-      {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "no Double Buffer";
-      }
-      if (theCaps->contextStereo && isStereo == 0)
-      {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "no Quad Buffer";
-      }
-      if (!theCaps->contextStereo && isStereo == 1)
+        GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+        GLX_CONTEXT_MINOR_VERSION_ARB, 2,
+        GLX_CONTEXT_PROFILE_MASK_ARB,  GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+        GLX_CONTEXT_FLAGS_ARB,         theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
+        0, 0
+      };
+
+      // try to create the core profile of highest OpenGL version supported by OCCT
+      for (int aLowVer4 = 5; aLowVer4 >= 0 && aGContext == NULL; --aLowVer4)
       {
-        if (!aList.IsEmpty()) aList += ", ";
-        aList += "extra Quad Buffer";
+        aCoreCtxAttribs[1] = 4;
+        aCoreCtxAttribs[3] = aLowVer4;
+        aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
       }
-      if (!aList.IsEmpty())
+      for (int aLowVer3 = 3; aLowVer3 >= 2 && aGContext == NULL; --aLowVer3)
       {
-        TCollection_ExtendedString aMsg = TCollection_ExtendedString ("OpenGl_Window::CreateWindow: window Visual is incomplete: ") + aList;
-        if (myOwnGContext)
-        {
-          XFree (aVis);
-          aVis = NULL;
-        }
-        myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                                  GL_DEBUG_TYPE_OTHER_ARB,
-                                  0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg);
+        aCoreCtxAttribs[1] = 3;
+        aCoreCtxAttribs[3] = aLowVer3;
+        aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
       }
-    }
-  }
-#endif
-
-  if (!myOwnGContext)
-  {
-    if (aVis == NULL)
-    {
-      Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
-      return;
+      isCoreProfile = aGContext != NULL;
     }
 
-    aWindow = aParent;
-  }
-  else
-  {
-    if (aVis == NULL)
+    if (aGContext == NULL)
     {
-      int anIter = 0;
-      int anAttribs[13];
-      anAttribs[anIter++] = GLX_RGBA;
-
-      anAttribs[anIter++] = GLX_DEPTH_SIZE;
-      anAttribs[anIter++] = 1;
-
-      anAttribs[anIter++] = GLX_STENCIL_SIZE;
-      anAttribs[anIter++] = 1;
-
-      anAttribs[anIter++] = GLX_RED_SIZE;
-      anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1;
-
-      anAttribs[anIter++] = GLX_GREEN_SIZE;
-      anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1;
-
-      anAttribs[anIter++] = GLX_BLUE_SIZE;
-      anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1;
-
-      anAttribs[anIter++] = GLX_DOUBLEBUFFER;
-
-      // warning: this flag may be set to None, so it need to be last in anAttribs
-      Standard_Integer aStereoFlagPos = anIter;
-      if (theCaps->contextStereo)
-        anAttribs[anIter++] = GLX_STEREO;
-
-      anAttribs[anIter++] = None;
-
-      aVis = glXChooseVisual (aDisp, scr, anAttribs);
-
-      // in case of failure try without stereo if any
-      if (aVis == NULL && theCaps->contextStereo)
+      int aCtxAttribs[] =
       {
-        TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: "
-                                         "glXChooseVisual is unable to find stereo supported pixel format. "
-                                         "Choosing similar non stereo format.");
-        myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                                  GL_DEBUG_TYPE_OTHER_ARB,
-                                  0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
-
-        anAttribs[aStereoFlagPos] = None;
-        aVis = glXChooseVisual (aDisp, scr, anAttribs);
-      }
+        GLX_CONTEXT_FLAGS_ARB, theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
+        0, 0
+      };
+      isCoreProfile = Standard_False;
+      aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCtxAttribs);
 
-      if (aVis == NULL)
+      if (aGContext != NULL
+      && !theCaps->contextCompatible)
       {
-        Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXChooseVisual failed.");
-        return;
+        TCollection_ExtendedString aMsg("OpenGl_Window::CreateWindow: core profile creation failed.");
+        myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
       }
-      else
-      {
-        TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: child window has been created with better Visual.");
-        myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB,
-                                  GL_DEBUG_TYPE_OTHER_ARB,
-                                  0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg);
-      }
-    }
-
-    if (!theShareCtx.IsNull())
-    {
-      // ctx est une copie du previous
-      aGContext = glXCreateContext (aDisp, aVis, (GLXContext )theShareCtx->myGContext, GL_TRUE);
-    }
-    else
-    {
-      aGContext = glXCreateContext (aDisp, aVis, NULL, GL_TRUE);
     }
+    XSetErrorHandler(anOldHandler);
+  }
 
-    if (!aGContext)
+  if (myOwnGContext
+   && aGContext == NULL)
+  {
+    aGContext = glXCreateContext (aDisp, aVis, aSlaveCtx, GL_TRUE);
+    if (aGContext == NULL)
     {
       Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXCreateContext failed.");
       return;
     }
+  }
 
-    Colormap cmap = XCreateColormap (aDisp, aParent, aVis->visual, AllocNone);
-
-    XColor color;
-    color.red   = (unsigned short) (myBgColor.rgb[0] * 0xFFFF);
-    color.green = (unsigned short) (myBgColor.rgb[1] * 0xFFFF);
-    color.blue  = (unsigned short) (myBgColor.rgb[2] * 0xFFFF);
-    color.flags = DoRed | DoGreen | DoBlue;
-    XAllocColor (aDisp, cmap, &color);
-
-    XSetWindowAttributes cwa;
-    cwa.colormap         = cmap;
-    cwa.event_mask       = StructureNotifyMask;
-    cwa.border_pixel     = color.pixel;
-    cwa.background_pixel = color.pixel;
-
-    if (aVis->visualid == wattr.visual->visualid)
-    {
-      aWindow = aParent;
-    }
-    else
-    {
-      unsigned long mask = CWBackPixel | CWColormap | CWBorderPixel | CWEventMask;
-      aWindow = XCreateWindow (aDisp, aParent, 0, 0, myWidth, myHeight, 0/*bw*/, aVis->depth, InputOutput, aVis->visual, mask, &cwa);
-    }
-
-    XSetWindowBackground (aDisp, aWindow, cwa.background_pixel);
-    XClearWindow (aDisp, aWindow);
-
-    if (aWindow != aParent)
-    {
-      XEvent anEvent;
-      XMapWindow (aDisp, aWindow);
-      XIfEvent (aDisp, &anEvent, WaitForNotify, (char* )aWindow);
-    }
+  // check Visual for OpenGl context's parameters compatibility
+  TCollection_ExtendedString aList;
+  int isDoubleBuffer = 0, isRGBA = 0, isStereo = 0;
+  int aDepthSize = 0, aStencilSize = 0;
+  glXGetConfig (aDisp, aVis, GLX_RGBA,         &isRGBA);
+  glXGetConfig (aDisp, aVis, GLX_DOUBLEBUFFER, &isDoubleBuffer);
+  glXGetConfig (aDisp, aVis, GLX_STEREO,       &isStereo);
+  glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE,   &aDepthSize);
+  glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize);
+  if (aDepthSize < 1)      addMsgToList (aList, "no depth buffer");
+  if (aStencilSize < 1)    addMsgToList (aList, "no stencil buffer");
+  if (isRGBA == 0)         addMsgToList (aList, "no RGBA color buffer");
+  if (isDoubleBuffer == 0) addMsgToList (aList, "no Double Buffer");
+  if (theCaps->contextStereo && isStereo == 0)
+  {
+    addMsgToList (aList, "no Quad Buffer");
+  }
+  else if (!theCaps->contextStereo && isStereo == 1)
+  {
+    addMsgToList (aList, "extra Quad Buffer");
+  }
+  if (!aList.IsEmpty())
+  {
+    TCollection_ExtendedString aMsg = TCollection_ExtendedString ("OpenGl_Window::CreateWindow: window Visual is incomplete: ") + aList;
+    myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION,
+                              GL_DEBUG_TYPE_OTHER,
+                              0, GL_DEBUG_SEVERITY_MEDIUM, aMsg);
   }
 
   myGlContext->Init ((Aspect_Drawable )aWindow, (Aspect_Display )aDisp, (Aspect_RenderingContext )aGContext, isCoreProfile);
@@ -691,7 +615,7 @@ OpenGl_Window::~OpenGl_Window()
   // release "GL" context if it is owned by window
   // Mesa implementation can fail to destroy GL context if it set for current thread.
   // It should be safer to unset thread GL context before its destruction.
-#if defined(HAVE_EGL) || defined(__ANDROID__)
+#if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
   if ((EGLSurface )myGlContext->myWindow != EGL_NO_SURFACE)
   {
     eglDestroySurface ((EGLDisplay )myGlContext->myDisplay,
@@ -751,22 +675,26 @@ Standard_Boolean OpenGl_Window::Activate()
 // function : Resize
 // purpose  : call_subr_resize
 // =======================================================================
-void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
+void OpenGl_Window::Resize()
 {
-#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__)
+#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__) && !defined(__QNX__)
   Display* aDisp = (Display* )myGlContext->myDisplay;
   if (aDisp == NULL)
     return;
 #endif
 
+  Standard_Integer aWidth  = 0;
+  Standard_Integer aHeight = 0;
+  myPlatformWindow->Size (aWidth, aHeight);
+
   // If the size is not changed - do nothing
-  if ((myWidth == theCWindow.dx) && (myHeight == theCWindow.dy))
+  if ((myWidth == aWidth) && (myHeight == aHeight))
     return;
 
-  myWidth  = theCWindow.dx;
-  myHeight = theCWindow.dy;
+  myWidth  = aWidth;
+  myHeight = aHeight;
 
-#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__)
+#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__) && !defined(__QNX__)
   XResizeWindow (aDisp, myGlContext->myWindow, (unsigned int )myWidth, (unsigned int )myHeight);
   XSync (aDisp, False);
 #endif
@@ -774,60 +702,6 @@ void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
   Init();
 }
 
-#endif // !__APPLE__
-
-// =======================================================================
-// function : ReadDepths
-// purpose  : TelReadDepths
-// =======================================================================
-void OpenGl_Window::ReadDepths (const Standard_Integer theX,     const Standard_Integer theY,
-                                const Standard_Integer theWidth, const Standard_Integer theHeight,
-                                float* theDepths)
-{
-  if (theDepths == NULL || !Activate())
-    return;
-
-  OpenGl_Mat4 aProjectMat;
-  Graphic3d_TransformUtils::Ortho2D (aProjectMat,
-    0.f, static_cast<GLfloat> (myWidth), 0.f, static_cast<GLfloat> (myHeight));
-
-  myGlContext->WorldViewState.Push();
-  myGlContext->ProjectionState.Push();
-
-  myGlContext->WorldViewState.SetIdentity();
-  myGlContext->ProjectionState.SetCurrent (aProjectMat);
-
-  myGlContext->ApplyProjectionMatrix();
-  myGlContext->ApplyWorldViewMatrix();
-
-#if !defined(GL_ES_VERSION_2_0)
-  glRasterPos2i (theX, theY);
-  DisableFeatures();
-  glReadPixels (theX, theY, theWidth, theHeight, GL_DEPTH_COMPONENT, GL_FLOAT, theDepths);
-  EnableFeatures();
-#endif
-
-  myGlContext->WorldViewState.Pop();
-  myGlContext->ProjectionState.Pop();
-
-  myGlContext->ApplyProjectionMatrix();
-}
-
-// =======================================================================
-// function : SetBackgroundColor
-// purpose  : call_subr_set_background
-// =======================================================================
-void OpenGl_Window::SetBackgroundColor (const Standard_ShortReal theR,
-                                        const Standard_ShortReal theG,
-                                        const Standard_ShortReal theB)
-{
-  myBgColor.rgb[0] = theR;
-  myBgColor.rgb[1] = theG;
-  myBgColor.rgb[2] = theB;
-}
-
-#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
-
 // =======================================================================
 // function : Init
 // purpose  :
@@ -837,7 +711,7 @@ void OpenGl_Window::Init()
   if (!Activate())
     return;
 
-#if defined(HAVE_EGL) || defined(__ANDROID__)
+#if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
   eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_WIDTH,  &myWidth);
   eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_HEIGHT, &myHeight);
 #elif defined(_WIN32)
@@ -866,87 +740,17 @@ void OpenGl_Window::Init()
 #endif
 }
 
-#endif // !__APPLE__
-
-// =======================================================================
-// function : EnableFeatures
-// purpose  :
-// =======================================================================
-void OpenGl_Window::EnableFeatures() const
-{
-  //
-}
-
 // =======================================================================
-// function : DisableFeatures
+// function : SetSwapInterval
 // purpose  :
 // =======================================================================
-void OpenGl_Window::DisableFeatures() const
+void OpenGl_Window::SetSwapInterval()
 {
-#if !defined(GL_ES_VERSION_2_0)
-  glPixelTransferi (GL_MAP_COLOR, GL_FALSE);
-#endif
-
-  /*
-  * Disable stuff that's likely to slow down glDrawPixels.
-  * (Omit as much of this as possible, when you know in advance
-  * that the OpenGL state will already be set correctly.)
-  */
-  glDisable(GL_DITHER);
-  glDisable(GL_BLEND);
-  glDisable(GL_DEPTH_TEST);
-  glDisable(GL_TEXTURE_2D);
-  glDisable(GL_STENCIL_TEST);
-
-#if !defined(GL_ES_VERSION_2_0)
-  glDisable(GL_LIGHTING);
-  glDisable(GL_ALPHA_TEST);
-  glDisable(GL_FOG);
-  glDisable(GL_LOGIC_OP);
-  glDisable(GL_TEXTURE_1D);
-
-  glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
-  glPixelTransferi(GL_RED_SCALE, 1);
-  glPixelTransferi(GL_RED_BIAS, 0);
-  glPixelTransferi(GL_GREEN_SCALE, 1);
-  glPixelTransferi(GL_GREEN_BIAS, 0);
-  glPixelTransferi(GL_BLUE_SCALE, 1);
-  glPixelTransferi(GL_BLUE_BIAS, 0);
-  glPixelTransferi(GL_ALPHA_SCALE, 1);
-  glPixelTransferi(GL_ALPHA_BIAS, 0);
-
-  /*
-  * Disable extensions that could slow down glDrawPixels.
-  * (Actually, you should check for the presence of the proper
-  * extension before making these calls.  I've omitted that
-  * code for simplicity.)
-  */
-
-  if ((myGlContext->myGlVerMajor >= 1) && (myGlContext->myGlVerMinor >= 2))
+  if (mySwapInterval != myGlContext->caps->swapInterval)
   {
-#ifdef GL_EXT_convolution
-    if (myGlContext->CheckExtension ("GL_CONVOLUTION_1D_EXT"))
-      glDisable(GL_CONVOLUTION_1D_EXT);
-
-    if (myGlContext->CheckExtension ("GL_CONVOLUTION_2D_EXT"))
-      glDisable(GL_CONVOLUTION_2D_EXT);
-
-    if (myGlContext->CheckExtension ("GL_SEPARABLE_2D_EXT"))
-      glDisable(GL_SEPARABLE_2D_EXT);
-#endif
-
-#ifdef GL_EXT_histogram
-    if (myGlContext->CheckExtension ("GL_SEPARABLE_2D_EXT"))
-      glDisable(GL_HISTOGRAM_EXT);
-
-    if (myGlContext->CheckExtension ("GL_MINMAX_EXT"))
-      glDisable(GL_MINMAX_EXT);
-#endif
-
-#ifdef GL_EXT_texture3D
-    if (myGlContext->CheckExtension ("GL_TEXTURE_3D_EXT"))
-      glDisable(GL_TEXTURE_3D_EXT);
-#endif
+    mySwapInterval = myGlContext->caps->swapInterval;
+    myGlContext->SetSwapInterval (mySwapInterval);
   }
-#endif
 }
+
+#endif // !__APPLE__