0025147: Visualization, TKOpenGl - support EGL as alternative to GLX
authorkgv <kgv@opencascade.com>
Thu, 2 Oct 2014 09:43:33 +0000 (13:43 +0400)
committerbugmaster <bugmaster@opencascade.com>
Thu, 2 Oct 2014 10:29:17 +0000 (14:29 +0400)
Aspect_Window - add interface methods NativeHandle() and NativeParentHandle().
OpenGl_Window - pass OpenGl_GraphicDriver instance to the constructor.
OpenGl_Caps - add option to disable buffers swap at the end of frame redraw.

15 files changed:
src/Aspect/Aspect_Window.cdl
src/Cocoa/Cocoa_Window.hxx
src/OpenGl/OpenGl_Caps.cxx
src/OpenGl/OpenGl_Caps.hxx
src/OpenGl/OpenGl_GraphicDriver.cxx [changed mode: 0755->0644]
src/OpenGl/OpenGl_GraphicDriver.hxx
src/OpenGl/OpenGl_GraphicDriver_7.cxx
src/OpenGl/OpenGl_Window.cxx
src/OpenGl/OpenGl_Window.hxx
src/OpenGl/OpenGl_Workspace.cxx
src/OpenGl/OpenGl_Workspace.hxx [changed mode: 0755->0644]
src/Visual3d/Visual3d_View.cxx
src/WNT/WNT_Window.cdl
src/WNT/WNT_Window.lxx
src/Xw/Xw_Window.hxx

index 0522b6c..69ecfb7 100644 (file)
@@ -20,6 +20,7 @@ inherits
 
 uses
         Background         from Aspect,
+        Drawable           from Aspect,
         GradientBackground from Aspect,
         TypeOfResize       from Aspect,
         FillMethod         from Aspect,
@@ -160,6 +161,12 @@ is
         ---Purpose: Returns The Window SIZE in PIXEL
         ---Category: Inquire methods
 
+        NativeHandle ( me ) returns Drawable from Aspect is deferred;
+        ---Purpose: Returns native Window handle (HWND on Windows, Window with Xlib, and so on)
+
+        NativeParentHandle ( me ) returns Drawable from Aspect is deferred;
+        ---Purpose: Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on)
+
 fields
         MyBackground : Background from Aspect is protected;
         MyGradientBackground   : GradientBackground from Aspect is protected;
index 0545406..e01a0eb 100644 (file)
@@ -101,6 +101,18 @@ public:
   //! Setup new NSView.
   Standard_EXPORT void SetHView (NSView* theView);
 
+  //! @return native Window handle
+  virtual Aspect_Drawable NativeHandle() const
+  {
+    return (Aspect_Drawable )HView();
+  }
+
+  //! @return parent of native Window handle
+  virtual Aspect_Drawable NativeParentHandle() const
+  {
+    return 0;
+  }
+
 protected:
 
   NSWindow*        myHWindow;
index a848bd6..baff8d1 100755 (executable)
@@ -26,6 +26,7 @@ OpenGl_Caps::OpenGl_Caps()
 : vboDisable        (Standard_False),
   pntSpritesDisable (Standard_False),
   keepArrayData     (Standard_False),
+  buffersNoSwap     (Standard_False),
   contextStereo     (Standard_False),
 #ifdef DEB
   contextDebug      (Standard_True),
@@ -47,6 +48,7 @@ OpenGl_Caps& OpenGl_Caps::operator= (const OpenGl_Caps& theCopy)
   vboDisable        = theCopy.vboDisable;
   pntSpritesDisable = theCopy.pntSpritesDisable;
   keepArrayData     = theCopy.keepArrayData;
+  buffersNoSwap     = theCopy.buffersNoSwap;
   contextStereo     = theCopy.contextStereo;
   contextDebug      = theCopy.contextDebug;
   contextNoAccel    = theCopy.contextNoAccel;
index ff4c466..3cd0ade 100755 (executable)
@@ -33,6 +33,15 @@ public: //! @name flags to disable particular functionality, should be used only
 
 public: //! @name context creation parameters
 
+  /**
+   * Specify that driver should not swap back/front buffers at the end of frame.
+   * Useful when OCCT Viewer is integrated into existing OpenGL rendering pipeline as part,
+   * thus swapping part is performed outside.
+   *
+   * OFF by default.
+   */
+  Standard_Boolean buffersNoSwap;
+
   /**
    * Request stereoscopic context (with Quad Buffer). This flag requires support in OpenGL driver.
    *
old mode 100755 (executable)
new mode 100644 (file)
index 9e9003e..3221eb9
 #include <OpenGl_Trihedron.hxx>
 #include <OpenGl_Workspace.hxx>
 
+#include <Aspect_GraphicDeviceDefinitionError.hxx>
+#include <Message_Messenger.hxx>
 #include <OSD_Environment.hxx>
 #include <Standard_NotImplemented.hxx>
 
-#if (!defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
+#if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
   #include <X11/Xlib.h> // XOpenDisplay()
 #endif
 
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  #include <EGL/egl.h>
+#endif
+
 IMPLEMENT_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
 
@@ -44,8 +50,14 @@ namespace
 // function : OpenGl_GraphicDriver
 // purpose  :
 // =======================================================================
-OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
+OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
+                                            const Standard_Boolean                  theToStealActiveContext)
 : Graphic3d_GraphicDriver (theDisp),
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  myEglDisplay ((Aspect_Display )EGL_NO_DISPLAY),
+  myEglContext ((Aspect_RenderingContext )EGL_NO_CONTEXT),
+  myEglConfig  (NULL),
+#endif
   myCaps           (new OpenGl_Caps()),
   myMapOfView      (1, NCollection_BaseAllocator::CommonBaseAllocator()),
   myMapOfWS        (1, NCollection_BaseAllocator::CommonBaseAllocator()),
@@ -53,7 +65,7 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio
   myUserDrawCallback (NULL),
   myTempText (new OpenGl_Text())
 {
-#if (!defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
+#if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
   if (myDisplayConnection.IsNull())
   {
     //Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: cannot connect to X server!");
@@ -65,6 +77,7 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio
              || ::getenv ("CALL_SYNCHRO_X")  != NULL;
   XSynchronize (aDisplay, toSync);
 
+#if !defined(HAVE_EGL)
   // does the server know about OpenGL & GLX?
   int aDummy;
   if (!XQueryExtension (aDisplay, "GLX", &aDummy, &aDummy, &aDummy))
@@ -74,6 +87,133 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio
   #endif
   }
 #endif
+#endif
+
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  if (theToStealActiveContext)
+  {
+    myEglDisplay = (Aspect_Display )eglGetCurrentDisplay();
+    myEglContext = (Aspect_RenderingContext )eglGetCurrentContext();
+    EGLSurface aEglSurf = eglGetCurrentSurface(EGL_DRAW);
+    if ((EGLDisplay )myEglDisplay == EGL_NO_DISPLAY
+     || (EGLContext )myEglContext == EGL_NO_CONTEXT)
+    {
+      Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: no active EGL context to steal!");
+      return;
+    }
+
+    TCollection_AsciiString anEglInfo = TCollection_AsciiString()
+      + "EGL info"
+      + "\n  Version:     " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_VERSION)
+      + "\n  Vendor:      " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_VENDOR)
+      + "\n  Client APIs: " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_CLIENT_APIS)
+      + "\n  Extensions:  " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_EXTENSIONS);
+    ::Message::DefaultMessenger()->Send (anEglInfo, Message_Info);
+
+    EGLint aCfgId = 0;
+    eglQuerySurface((EGLDisplay )myEglDisplay, aEglSurf, EGL_CONFIG_ID, &aCfgId);
+    const EGLint aConfigAttribs[] =
+    {
+      EGL_CONFIG_ID, aCfgId,
+      EGL_NONE
+    };
+
+    EGLint aNbConfigs = 0;
+    if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE)
+    {
+      Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL does not provide compatible configurations!");
+    }
+    return;
+  }
+
+#if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
+  myEglDisplay = (Aspect_Display )eglGetDisplay (aDisplay);
+#else
+  myEglDisplay = (Aspect_Display )eglGetDisplay (EGL_DEFAULT_DISPLAY);
+#endif
+  if ((EGLDisplay )myEglDisplay == EGL_NO_DISPLAY)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: no EGL display!");
+    return;
+  }
+
+  EGLint aVerMajor = 0; EGLint aVerMinor = 0;
+  if (eglInitialize ((EGLDisplay )myEglDisplay, &aVerMajor, &aVerMinor) != EGL_TRUE)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL display is unavailable!");
+    return;
+  }
+
+  TCollection_AsciiString anEglInfo = TCollection_AsciiString()
+    + "EGL info"
+    + "\n  Version:     " + aVerMajor + "." + aVerMinor + " (" + eglQueryString ((EGLDisplay )myEglDisplay, EGL_VERSION)
+    + "\n  Vendor:      " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_VENDOR)
+    + "\n  Client APIs: " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_CLIENT_APIS)
+    + "\n  Extensions:  " + eglQueryString ((EGLDisplay )myEglDisplay, EGL_EXTENSIONS);
+  ::Message::DefaultMessenger()->Send (anEglInfo, Message_Info);
+
+  const EGLint aConfigAttribs[] =
+  {
+    EGL_RED_SIZE,     8,
+    EGL_GREEN_SIZE,   8,
+    EGL_BLUE_SIZE,    8,
+    EGL_ALPHA_SIZE,   0,
+    EGL_DEPTH_SIZE,   24,
+    EGL_STENCIL_SIZE, 8,
+  #if defined(GL_ES_VERSION_2_0)
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+  #else
+    EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+  #endif
+    EGL_NONE
+  };
+
+  EGLint aNbConfigs = 0;
+  if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL does not provide compatible configurations!");
+    return;
+  }
+
+#if defined(GL_ES_VERSION_2_0)
+  if (eglBindAPI (EGL_OPENGL_ES_API) != EGL_TRUE)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL does not provide OpenGL ES client!");
+    return;
+  }
+#else
+  if (eglBindAPI (EGL_OPENGL_API) != EGL_TRUE)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL does not provide OpenGL client!");
+    return;
+  }
+#endif
+
+#if defined(GL_ES_VERSION_2_0)
+  EGLint anEglCtxAttribs[] =
+  {
+    EGL_CONTEXT_CLIENT_VERSION, 2,
+    EGL_NONE
+  };
+#else
+  EGLint* anEglCtxAttribs = NULL;
+#endif
+
+  myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs);
+  if ((EGLContext )myEglContext == EGL_NO_CONTEXT)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL is unable to create OpenGL context!");
+    return;
+  }
+  if (eglMakeCurrent ((EGLDisplay )myEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, (EGLContext )myEglContext) != EGL_TRUE)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: EGL is unable bind OpenGL context!");
+    return;
+  }
+#else
+  // not yet implemented
+  (void )theToStealActiveContext;
+#endif
 }
 
 // =======================================================================
index d2b8ea5..4d7b553 100644 (file)
@@ -84,7 +84,7 @@ public:
   Standard_Size Increment() { return ++myCounter; }
 
 private:
-  
+
   Standard_Size myCounter;
 };
 
@@ -93,8 +93,11 @@ class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
 {
 public:
 
-  //! Constructor
-  Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp);
+  //! Constructor.
+  //! @param theDisp connection to display, required on Linux but optional on other systems
+  //! @param theToStealActiveContext option to use OpenGL context currently bound to the thread rather than creating own one, currently implemented only for Android
+  Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
+                                        const Standard_Boolean                  theToStealActiveContext = Standard_False);
 
   Standard_EXPORT Standard_Integer InquireLightLimit ();
   Standard_EXPORT Standard_Integer InquireViewLimit ();
@@ -319,12 +322,24 @@ public:
   //! marks primitive set for rebuild.
   Standard_EXPORT void InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId);
 
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  Aspect_Display          getRawGlDisplay() const { return myEglDisplay; }
+  Aspect_RenderingContext getRawGlContext() const { return myEglContext;  }
+  void*                   getRawGlConfig()  const { return myEglConfig; }
+#endif
+
 public:
 
   DEFINE_STANDARD_RTTI(OpenGl_GraphicDriver)
 
 private:
 
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  Aspect_Display          myEglDisplay; //!< EGL connection to the Display : EGLDisplay
+  Aspect_RenderingContext myEglContext; //!< EGL rendering context         : EGLContext
+  void*                   myEglConfig;  //!< EGL configuration             : EGLConfig
+#endif
+
   Handle(OpenGl_Caps)                                             myCaps;
   NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>      myMapOfView;
   NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> myMapOfWS;
index 7d77710..12ca8a9 100644 (file)
@@ -499,7 +499,7 @@ Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView)
   }
 
   Handle(OpenGl_Context)   aShareCtx = GetSharedContext();
-  Handle(OpenGl_Workspace) aWS       = new OpenGl_Workspace (myDisplayConnection, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
+  Handle(OpenGl_Workspace) aWS       = new OpenGl_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
   Handle(OpenGl_View)      aView     = new OpenGl_View (theCView.Context, &myStateCounter);
   myMapOfWS  .Bind (theCView.WsId,   aWS);
   myMapOfView.Bind (theCView.ViewId, aView);
index 462dcaa..7c4e11e 100644 (file)
 #include <OpenGl_Window.hxx>
 
 #include <OpenGl_Context.hxx>
+#include <OpenGl_GraphicDriver.hxx>
 
 #include <Aspect_GraphicDeviceDefinitionError.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  #include <EGL/egl.h>
+#endif
+
 IMPLEMENT_STANDARD_HANDLE(OpenGl_Window,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Window,MMgt_TShared)
 
@@ -34,7 +39,9 @@ namespace
 {
   static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
 
-#if defined(_WIN32)
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  //
+#elif defined(_WIN32)
 
   // WGL_ARB_pixel_format
 #ifndef WGL_NUMBER_PIXEL_FORMATS_ARB
@@ -126,7 +133,7 @@ namespace
 // function : OpenGl_Window
 // purpose  :
 // =======================================================================
-OpenGl_Window::OpenGl_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
+OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
                               const CALL_DEF_WINDOW&        theCWindow,
                               Aspect_RenderingContext       theGContext,
                               const Handle(OpenGl_Caps)&    theCaps,
@@ -141,8 +148,47 @@ OpenGl_Window::OpenGl_Window (const Handle(Aspect_DisplayConnection)& theDisplay
   myBgColor.rgb[1] = theCWindow.Background.g;
   myBgColor.rgb[2] = theCWindow.Background.b;
 
-#if defined(_WIN32)
-  (void )theDisplayConnection;
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  EGLDisplay anEglDisplay = (EGLDisplay )theDriver->getRawGlDisplay();
+  EGLContext anEglContext = (EGLContext )theDriver->getRawGlContext();
+  EGLConfig  anEglConfig  = (EGLConfig  )theDriver->getRawGlConfig();
+  if (anEglDisplay == EGL_NO_DISPLAY
+   || anEglContext == EGL_NO_CONTEXT
+   || anEglConfig == NULL)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL does not provide compatible configurations!");
+    return;
+  }
+
+  EGLSurface anEglSurf = EGL_NO_SURFACE;
+  if (theGContext == (EGLContext )EGL_NO_CONTEXT)
+  {
+    // create new surface
+    anEglSurf = eglCreateWindowSurface (anEglDisplay, anEglConfig, (EGLNativeWindowType )theCWindow.XWindow, NULL);
+    if (anEglSurf == EGL_NO_SURFACE)
+    {
+      Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL is unable to create surface for window!");
+      return;
+    }
+  }
+  else if (theGContext != anEglContext)
+  {
+    Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL is used in unsupported combination!");
+    return;
+  }
+  else
+  {
+    anEglSurf = eglGetCurrentSurface(EGL_DRAW);
+    if (anEglSurf == EGL_NO_SURFACE)
+    {
+      Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL is unable to retrieve current surface!");
+      return;
+    }
+  }
+
+  myGlContext->Init ((Aspect_Drawable )anEglSurf, (Aspect_Display )anEglDisplay, (Aspect_RenderingContext )anEglContext);
+#elif defined(_WIN32)
+  (void )theDriver;
   HWND  aWindow   = (HWND )theCWindow.XWindow;
   HDC   aWindowDC = GetDC (aWindow);
   HGLRC aGContext = (HGLRC )theGContext;
@@ -356,7 +402,7 @@ OpenGl_Window::OpenGl_Window (const Handle(Aspect_DisplayConnection)& theDisplay
   Window aParent = (Window )theCWindow.XWindow;
   Window aWindow = 0;
 
-  Display*   aDisp     = theDisplayConnection->GetDisplay();
+  Display*   aDisp     = theDriver->GetDisplayConnection()->GetDisplay();
   GLXContext aGContext = (GLXContext )theGContext;
 
   XWindowAttributes wattr;
@@ -538,7 +584,8 @@ OpenGl_Window::OpenGl_Window (const Handle(Aspect_DisplayConnection)& theDisplay
 // =======================================================================
 OpenGl_Window::~OpenGl_Window()
 {
-  if (!myOwnGContext)
+  if (!myOwnGContext
+   ||  myGlContext.IsNull())
   {
     myGlContext.Nullify();
     return;
@@ -547,7 +594,13 @@ 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(_WIN32)
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+  if ((EGLSurface )myGlContext->myWindow != EGL_NO_SURFACE)
+  {
+    eglDestroySurface ((EGLDisplay )myGlContext->myDisplay,
+                       (EGLSurface )myGlContext->myWindow);
+  }
+#elif defined(_WIN32)
   HWND  aWindow          = (HWND  )myGlContext->myWindow;
   HDC   aWindowDC        = (HDC   )myGlContext->myWindowDC;
   HGLRC aWindowGContext  = (HGLRC )myGlContext->myGContext;
@@ -603,7 +656,7 @@ Standard_Boolean OpenGl_Window::Activate()
 // =======================================================================
 void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
 {
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__)
   Display* aDisp = (Display* )myGlContext->myDisplay;
   if (aDisp == NULL)
     return;
@@ -616,7 +669,7 @@ void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
   myWidth  = (Standard_Integer )theCWindow.dx;
   myHeight = (Standard_Integer )theCWindow.dy;
 
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__)
   XResizeWindow (aDisp, myGlContext->myWindow, (unsigned int )myWidth, (unsigned int )myHeight);
   XSync (aDisp, False);
 #endif
@@ -675,7 +728,10 @@ void OpenGl_Window::Init()
   if (!Activate())
     return;
 
-#if defined(_WIN32)
+#if defined(HAVE_EGL) || defined(__ANDROID__)
+ eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_WIDTH,  &myWidth);
+ eglQuerySurface ((EGLDisplay )myGlContext->myDisplay, (EGLSurface )myGlContext->myWindow, EGL_HEIGHT, &myHeight);
+#elif defined(_WIN32)
   RECT cr;
   GetClientRect ((HWND )myGlContext->myWindow, &cr);
   myWidth  = cr.right - cr.left;
index 7aac39f..6b68697 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <Handle_OpenGl_Context.hxx>
 #include <Handle_OpenGl_Window.hxx>
-#include <Aspect_DisplayConnection.hxx>
+#include <Handle_OpenGl_GraphicDriver.hxx>
 
 #include <MMgt_TShared.hxx>
 
@@ -33,7 +33,7 @@ class OpenGl_Window : public MMgt_TShared
 public:
 
   //! Main constructor - prepare GL context for specified window.
-  OpenGl_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
+  OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver,
                  const CALL_DEF_WINDOW&        theCWindow,
                  Aspect_RenderingContext       theGContext,
                  const Handle(OpenGl_Caps)&    theCaps,
index 0d6a19f..67799e2 100644 (file)
@@ -133,12 +133,12 @@ void OpenGl_Material::Init (const OPENGL_SURF_PROP& theProp)
 // function : OpenGl_Workspace
 // purpose  :
 // =======================================================================
-OpenGl_Workspace::OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
+OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver,
                                     const CALL_DEF_WINDOW&        theCWindow,
                                     Aspect_RenderingContext       theGContext,
                                     const Handle(OpenGl_Caps)&    theCaps,
                                     const Handle(OpenGl_Context)& theShareCtx)
-: OpenGl_Window (theDisplayConnection, theCWindow, theGContext, theCaps, theShareCtx),
+: OpenGl_Window (theDriver, theCWindow, theGContext, theCaps, theShareCtx),
   NamedStatus (0),
   HighlightColor (&THE_WHITE_COLOR),
   //
@@ -589,7 +589,7 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView,
   // fetch OpenGl context state
   aGlCtx->FetchState();
 
-  Tint toSwap = (aGlCtx->IsRender()); // swap buffers
+  Tint toSwap = (aGlCtx->IsRender() && !aGlCtx->caps->buffersNoSwap) ? 1 : 0; // swap buffers
   GLint aViewPortBack[4];
   OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO;
   if (aFrameBuffer != NULL)
old mode 100755 (executable)
new mode 100644 (file)
index fa4a05f..77041d8
@@ -131,7 +131,7 @@ class OpenGl_Workspace : public OpenGl_Window
 public:
 
   //! Main constructor - prepare GL context for specified window.
-  OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
+  OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver,
                     const CALL_DEF_WINDOW&        theCWindow,
                     Aspect_RenderingContext       theGContext,
                     const Handle(OpenGl_Caps)&    theCaps,
index 26761bd..35c4a9a 100644 (file)
@@ -114,22 +114,8 @@ void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
   MyWindow = theWindow;
   MyCView.WsId = MyCView.ViewId;
   MyCView.DefWindow.IsDefined = 1;
-#if defined(_WIN32)
-  const Handle(WNT_Window) aWin   = Handle(WNT_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = (HWND )(aWin->HWindow());
-  MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
-#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
-  const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = (Aspect_Drawable )aWin->HView();
-  MyCView.DefWindow.XParentWindow = NULL;
-  //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
-#elif defined(__ANDROID__)
-  //
-#else
-  const Handle(Xw_Window) aWin    = Handle(Xw_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = aWin->XWindow();
-  //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
-#endif
+  MyCView.DefWindow.XWindow       = theWindow->NativeHandle();
+  MyCView.DefWindow.XParentWindow = theWindow->NativeParentHandle();
 
   Standard_Integer Width, Height;
   theWindow->Size (Width, Height);
index 42f1779..8534f36 100644 (file)
@@ -21,6 +21,7 @@ class Window from WNT inherits Window from Aspect
  uses
 
     Handle             from Aspect,
+    Drawable           from Aspect,
     TypeOfResize       from Aspect,
     NameOfColor        from Quantity,
     Color              from Quantity,
@@ -166,6 +167,14 @@ class Window from WNT inherits Window from Aspect
        ---Purpose: Returns the Windows NT handle parent of the created window <me>.
         ---C++:     inline
 
+    NativeHandle ( me ) returns Drawable from Aspect is virtual;
+    ---Purpose: Returns native Window handle (HWND)
+    ---C++:     inline
+
+    NativeParentHandle ( me ) returns Drawable from Aspect is virtual;
+    ---Purpose: Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on)
+    ---C++:     inline
+
  fields
 
     aXLeft          : Integer      from Standard is protected; -- Window coordinates
index 8bd80f5..ca2184d 100644 (file)
@@ -27,3 +27,13 @@ inline Aspect_Handle WNT_Window::HParentWindow() const
 {
   return myHParentWindow;
 }
+
+inline Aspect_Drawable WNT_Window::NativeHandle() const
+{
+  return (Aspect_Drawable )myHWindow;
+}
+
+inline Aspect_Drawable WNT_Window::NativeParentHandle() const
+{
+  return (Aspect_Drawable )myHParentWindow;
+}
index e3a49d0..53f0c14 100755 (executable)
@@ -98,6 +98,18 @@ public:
   //! @return connection to X Display
   Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const;
 
+  //! @return native Window handle
+  virtual Aspect_Drawable NativeHandle() const
+  {
+    return (Aspect_Drawable )XWindow();
+  }
+
+  //! @return parent of native Window handle
+  virtual Aspect_Drawable NativeParentHandle() const
+  {
+    return 0;
+  }
+
 protected:
 
   Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection