1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2013 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_GraphicDriver.hxx>
17 #include <OpenGl_Context.hxx>
18 #include <OpenGl_Flipper.hxx>
19 #include <OpenGl_GraduatedTrihedron.hxx>
20 #include <OpenGl_Group.hxx>
21 #include <OpenGl_View.hxx>
22 #include <OpenGl_StencilTest.hxx>
23 #include <OpenGl_Text.hxx>
24 #include <OpenGl_Trihedron.hxx>
25 #include <OpenGl_Workspace.hxx>
27 #include <Aspect_GraphicDeviceDefinitionError.hxx>
28 #include <Aspect_IdentDefinitionError.hxx>
29 #include <Message_Messenger.hxx>
30 #include <OSD_Environment.hxx>
31 #include <Standard_NotImplemented.hxx>
34 #include <WNT_Window.hxx>
35 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
36 #include <Cocoa_Window.hxx>
38 #include <Xw_Window.hxx>
41 #if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__QNX__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
42 #include <X11/Xlib.h> // XOpenDisplay()
45 #if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
51 static const Handle(OpenGl_Context) TheNullGlCtx;
54 // =======================================================================
55 // function : OpenGl_GraphicDriver
57 // =======================================================================
58 OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
59 const Standard_Boolean theToInitialize)
60 : Graphic3d_GraphicDriver (theDisp),
61 myIsOwnContext (Standard_False),
62 #if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
63 myEglDisplay ((Aspect_Display )EGL_NO_DISPLAY),
64 myEglContext ((Aspect_RenderingContext )EGL_NO_CONTEXT),
67 myCaps (new OpenGl_Caps()),
68 myMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator()),
69 myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator())
71 #if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__QNX__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
72 if (myDisplayConnection.IsNull())
74 //Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: cannot connect to X server!");
78 Display* aDisplay = myDisplayConnection->GetDisplay();
79 Bool toSync = ::getenv ("CSF_GraphicSync") != NULL
80 || ::getenv ("CALL_SYNCHRO_X") != NULL;
81 XSynchronize (aDisplay, toSync);
83 #if !defined(HAVE_EGL)
84 // does the server know about OpenGL & GLX?
86 if (!XQueryExtension (aDisplay, "GLX", &aDummy, &aDummy, &aDummy))
88 ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, this system doesn't appear to support OpenGL!", Message_Warning);
95 Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: default context can not be initialized!");
98 // default layers are always presented in display layer sequence it can not be removed
99 Graphic3d_ZLayerSettings anUnderlaySettings;
100 anUnderlaySettings.Flags = 0;
101 anUnderlaySettings.IsImmediate = false;
102 myLayerIds.Add (Graphic3d_ZLayerId_BotOSD);
103 myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD);
104 myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, anUnderlaySettings);
106 Graphic3d_ZLayerSettings aDefSettings;
107 aDefSettings.Flags = Graphic3d_ZLayerDepthTest
108 | Graphic3d_ZLayerDepthWrite;
109 aDefSettings.IsImmediate = false;
110 myLayerIds.Add (Graphic3d_ZLayerId_Default);
111 myLayerSeq.Append (Graphic3d_ZLayerId_Default);
112 myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aDefSettings);
114 Graphic3d_ZLayerSettings aTopSettings;
115 aTopSettings.Flags = Graphic3d_ZLayerDepthTest
116 | Graphic3d_ZLayerDepthWrite;
117 aTopSettings.IsImmediate = true;
118 myLayerIds.Add (Graphic3d_ZLayerId_Top);
119 myLayerSeq.Append (Graphic3d_ZLayerId_Top);
120 myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aTopSettings);
122 Graphic3d_ZLayerSettings aTopmostSettings;
123 aTopmostSettings.Flags = Graphic3d_ZLayerDepthTest
124 | Graphic3d_ZLayerDepthWrite
125 | Graphic3d_ZLayerDepthClear;
126 aTopmostSettings.IsImmediate = true;
127 myLayerIds.Add (Graphic3d_ZLayerId_Topmost);
128 myLayerSeq.Append (Graphic3d_ZLayerId_Topmost);
129 myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aTopmostSettings);
131 Graphic3d_ZLayerSettings anOsdSettings;
132 anOsdSettings.Flags = 0;
133 anOsdSettings.IsImmediate = true;
134 myLayerIds.Add (Graphic3d_ZLayerId_TopOSD);
135 myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD);
136 myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, anOsdSettings);
139 // =======================================================================
140 // function : ~OpenGl_GraphicDriver
142 // =======================================================================
143 OpenGl_GraphicDriver::~OpenGl_GraphicDriver()
148 // =======================================================================
149 // function : ReleaseContext
151 // =======================================================================
152 void OpenGl_GraphicDriver::ReleaseContext()
154 Handle(OpenGl_Context) aCtxShared;
155 for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIter (myMapOfView);
156 aViewIter.More(); aViewIter.Next())
158 const Handle(OpenGl_View)& aView = aViewIter.ChangeValue();
159 const Handle(OpenGl_Window)& aWindow = aView->GlWindow();
160 if (aWindow.IsNull())
165 const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext();
166 if (aCtx->MakeCurrent()
167 && aCtxShared.IsNull())
173 if (!aCtxShared.IsNull())
175 aCtxShared->MakeCurrent();
177 for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIter (myMapOfView);
178 aViewIter.More(); aViewIter.Next())
180 const Handle(OpenGl_View)& aView = aViewIter.ChangeValue();
181 aView->ReleaseGlResources (aCtxShared);
184 for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
185 aStructIt.More (); aStructIt.Next())
187 OpenGl_Structure* aStruct = aStructIt.ChangeValue();
188 aStruct->ReleaseGlResources (aCtxShared);
190 myDeviceLostFlag = myDeviceLostFlag || !myMapOfStructure.IsEmpty();
192 for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIter (myMapOfView);
193 aViewIter.More(); aViewIter.Next())
195 const Handle(OpenGl_View)& aView = aViewIter.ChangeValue();
196 const Handle(OpenGl_Window)& aWindow = aView->GlWindow();
197 if (aWindow.IsNull())
202 aWindow->GetGlContext()->forcedRelease();
205 #if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
208 if (myEglContext != (Aspect_RenderingContext )EGL_NO_CONTEXT)
210 if (eglMakeCurrent ((EGLDisplay )myEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE)
212 ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, FAILED to release OpenGL context!", Message_Warning);
214 eglDestroyContext ((EGLDisplay )myEglDisplay, (EGLContext )myEglContext);
217 if (myEglDisplay != (Aspect_Display )EGL_NO_DISPLAY)
219 if (eglTerminate ((EGLDisplay )myEglDisplay) != EGL_TRUE)
221 ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, EGL, eglTerminate FAILED!", Message_Warning);
226 myEglDisplay = (Aspect_Display )EGL_NO_DISPLAY;
227 myEglContext = (Aspect_RenderingContext )EGL_NO_CONTEXT;
230 myIsOwnContext = Standard_False;
233 // =======================================================================
234 // function : InitContext
236 // =======================================================================
237 Standard_Boolean OpenGl_GraphicDriver::InitContext()
240 #if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
242 #if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__QNX__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
243 if (myDisplayConnection.IsNull())
245 return Standard_False;
247 Display* aDisplay = myDisplayConnection->GetDisplay();
248 myEglDisplay = (Aspect_Display )eglGetDisplay (aDisplay);
250 myEglDisplay = (Aspect_Display )eglGetDisplay (EGL_DEFAULT_DISPLAY);
252 if ((EGLDisplay )myEglDisplay == EGL_NO_DISPLAY)
254 ::Message::DefaultMessenger()->Send ("Error: no EGL display!", Message_Fail);
255 return Standard_False;
258 EGLint aVerMajor = 0; EGLint aVerMinor = 0;
259 if (eglInitialize ((EGLDisplay )myEglDisplay, &aVerMajor, &aVerMinor) != EGL_TRUE)
261 ::Message::DefaultMessenger()->Send ("Error: EGL display is unavailable!", Message_Fail);
262 return Standard_False;
265 EGLint aConfigAttribs[] =
273 #if defined(GL_ES_VERSION_2_0)
274 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
276 EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
281 EGLint aNbConfigs = 0;
282 if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE
283 || myEglConfig == NULL)
286 aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer
287 if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE
288 || myEglConfig == NULL)
290 ::Message::DefaultMessenger()->Send ("Error: EGL does not provide compatible configurations!", Message_Fail);
291 return Standard_False;
295 #if defined(GL_ES_VERSION_2_0)
296 EGLint anEglCtxAttribs[] =
298 EGL_CONTEXT_CLIENT_VERSION, 2,
301 if (eglBindAPI (EGL_OPENGL_ES_API) != EGL_TRUE)
303 ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL ES client!", Message_Fail);
304 return Standard_False;
307 EGLint* anEglCtxAttribs = NULL;
308 if (eglBindAPI (EGL_OPENGL_API) != EGL_TRUE)
310 ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL client!", Message_Fail);
311 return Standard_False;
315 myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs);
316 if ((EGLContext )myEglContext == EGL_NO_CONTEXT)
318 ::Message::DefaultMessenger()->Send ("Error: EGL is unable to create OpenGL context!", Message_Fail);
319 return Standard_False;
321 if (eglMakeCurrent ((EGLDisplay )myEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, (EGLContext )myEglContext) != EGL_TRUE)
323 ::Message::DefaultMessenger()->Send ("Error: EGL is unable bind OpenGL context!", Message_Fail);
324 return Standard_False;
327 myIsOwnContext = Standard_True;
328 return Standard_True;
331 #if defined(HAVE_EGL) || defined(__ANDROID__) || defined(__QNX__)
332 // =======================================================================
333 // function : InitEglContext
335 // =======================================================================
336 Standard_Boolean OpenGl_GraphicDriver::InitEglContext (Aspect_Display theEglDisplay,
337 Aspect_RenderingContext theEglContext,
341 #if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__QNX__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
342 if (myDisplayConnection.IsNull())
344 return Standard_False;
348 if ((EGLDisplay )theEglDisplay == EGL_NO_DISPLAY
349 || (EGLContext )theEglContext == EGL_NO_CONTEXT
350 || theEglConfig == NULL)
352 return Standard_False;
354 myEglDisplay = theEglDisplay;
355 myEglContext = theEglContext;
356 myEglConfig = theEglConfig;
357 return Standard_True;
361 // =======================================================================
362 // function : InquireLightLimit
364 // =======================================================================
365 Standard_Integer OpenGl_GraphicDriver::InquireLightLimit()
367 return OpenGLMaxLights;
370 // =======================================================================
371 // function : InquireViewLimit
373 // =======================================================================
374 Standard_Integer OpenGl_GraphicDriver::InquireViewLimit()
379 // =======================================================================
380 // function : InquirePlaneLimit
382 // =======================================================================
383 Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit()
385 // NOTE the 2 first planes are reserved for ZClipping
386 const Handle(OpenGl_Context)& aCtx = GetSharedContext();
387 return aCtx.IsNull() ? 0 : Max (aCtx->MaxClipPlanes() - 2, 0);
390 // =======================================================================
391 // function : DefaultTextHeight
393 // =======================================================================
394 Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
399 // =======================================================================
400 // function : EnableVBO
402 // =======================================================================
403 void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn)
405 myCaps->vboDisable = !theToTurnOn;
408 // =======================================================================
409 // function : GetSharedContext
411 // =======================================================================
412 const Handle(OpenGl_Context)& OpenGl_GraphicDriver::GetSharedContext() const
414 if (myMapOfView.IsEmpty())
419 NCollection_Map<Handle(OpenGl_View)>::Iterator anIter (myMapOfView);
420 for (; anIter.More(); anIter.Next())
422 Handle(OpenGl_Window) aWindow = anIter.Value()->GlWindow();
423 if (aWindow.IsNull())
428 return aWindow->GetGlContext();
434 // =======================================================================
435 // function : MemoryInfo
437 // =======================================================================
438 Standard_Boolean OpenGl_GraphicDriver::MemoryInfo (Standard_Size& theFreeBytes,
439 TCollection_AsciiString& theInfo) const
441 // this is extra work (for OpenGl_Context initialization)...
442 OpenGl_Context aGlCtx;
445 return Standard_False;
447 theFreeBytes = aGlCtx.AvailableMemory();
448 theInfo = aGlCtx.MemoryInfo();
449 return !theInfo.IsEmpty();
452 // =======================================================================
453 // function : SetBuffersNoSwap
455 // =======================================================================
456 void OpenGl_GraphicDriver::SetBuffersNoSwap (const Standard_Boolean theIsNoSwap)
458 myCaps->buffersNoSwap = theIsNoSwap;
461 // =======================================================================
462 // function : TextSize
464 // =======================================================================
465 void OpenGl_GraphicDriver::TextSize (const Handle(Graphic3d_CView)& theView,
466 const Standard_CString theText,
467 const Standard_ShortReal theHeight,
468 Standard_ShortReal& theWidth,
469 Standard_ShortReal& theAscent,
470 Standard_ShortReal& theDescent) const
472 const Handle(OpenGl_Context)& aCtx = GetSharedContext();
478 const Standard_ShortReal aHeight = (theHeight < 2.0f) ? DefaultTextHeight() : theHeight;
479 OpenGl_TextParam aTextParam;
480 aTextParam.Height = (int )aHeight;
481 OpenGl_AspectText aTextAspect;
482 CALL_DEF_CONTEXTTEXT aDefaultContextText =
489 { 1.F, 1.F, 1.F }, //Color
490 (int)Aspect_TOST_NORMAL, //Style
491 (int)Aspect_TODT_NORMAL, //DisplayType
492 { 1.F, 1.F, 1.F }, //ColorSubTitle
495 (int)Font_FA_Regular, //TextFontAspect
498 aTextAspect.SetAspect(aDefaultContextText);
499 TCollection_ExtendedString anExtText = theText;
500 NCollection_String aText = (Standard_Utf16Char* )anExtText.ToExtString();
501 OpenGl_Text::StringSize(aCtx, aText, aTextAspect, aTextParam, theView->RenderingParams().Resolution, theWidth, theAscent, theDescent);
504 //=======================================================================
505 //function : AddZLayer
507 //=======================================================================
508 void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_ZLayerId theLayerId)
512 Standard_ASSERT_RAISE (theLayerId > 0,
513 "OpenGl_GraphicDriver::AddZLayer, "
514 "negative and zero IDs are reserved");
517 myLayerIds.Add (theLayerId);
518 myLayerSeq.Append (theLayerId);
520 // Default z-layer settings
521 myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
523 // Add layer to all views
524 NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
525 for (; aViewIt.More(); aViewIt.Next())
527 aViewIt.Value()->AddZLayer (theLayerId);
531 //=======================================================================
532 //function : RemoveZLayer
534 //=======================================================================
535 void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
537 Standard_ASSERT_RAISE (theLayerId > 0,
538 "OpenGl_GraphicDriver::AddZLayer, "
539 "negative and zero IDs are reserved"
540 "and can not be removed");
542 Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId),
543 "OpenGl_GraphicDriver::RemoveZLayer, "
544 "Layer with theLayerId does not exist");
546 // Remove layer from all of the views
547 NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
548 for (; aViewIt.More(); aViewIt.Next())
550 aViewIt.Value()->RemoveZLayer (theLayerId);
553 // Unset Z layer for all of the structures.
554 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
555 for( ; aStructIt.More (); aStructIt.Next ())
557 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
558 if (aStruct->ZLayer() == theLayerId)
559 aStruct->SetZLayer (Graphic3d_ZLayerId_Default);
563 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
565 if (myLayerSeq (aIdx) == theLayerId)
567 myLayerSeq.Remove (aIdx);
572 myMapOfZLayerSettings.UnBind (theLayerId);
573 myLayerIds.Remove (theLayerId);
576 //=======================================================================
579 //=======================================================================
580 void OpenGl_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
582 theLayerSeq.Assign (myLayerSeq);
585 //=======================================================================
586 //function : SetZLayerSettings
588 //=======================================================================
589 void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
590 const Graphic3d_ZLayerSettings& theSettings)
592 // Change Z layer settings in all managed views
593 NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
594 for (; aViewIt.More(); aViewIt.Next())
596 aViewIt.Value()->SetZLayerSettings (theLayerId, theSettings);
599 if (myMapOfZLayerSettings.IsBound (theLayerId))
601 myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings;
605 myMapOfZLayerSettings.Bind (theLayerId, theSettings);
609 //=======================================================================
610 //function : ZLayerSettings
612 //=======================================================================
613 Graphic3d_ZLayerSettings OpenGl_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId)
615 Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId),
616 "OpenGl_GraphicDriver::ZLayerSettings, "
617 "Layer with theLayerId does not exist");
619 return myMapOfZLayerSettings.Find (theLayerId);
622 // =======================================================================
623 // function : Structure
625 // =======================================================================
626 Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::CreateStructure (const Handle(Graphic3d_StructureManager)& theManager)
628 Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager);
629 myMapOfStructure.Bind (aStructure->Id, aStructure.operator->());
633 // =======================================================================
634 // function : Structure
636 // =======================================================================
637 void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure)
639 OpenGl_Structure* aStructure = NULL;
640 if (!myMapOfStructure.Find (theCStructure->Id, aStructure))
645 myMapOfStructure.UnBind (theCStructure->Id);
646 aStructure->Release (GetSharedContext());
647 theCStructure.Nullify();
650 // =======================================================================
653 // =======================================================================
654 Handle(Graphic3d_CView) OpenGl_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr)
656 Handle(OpenGl_View) aView = new OpenGl_View (theMgr, this, myCaps, myDeviceLostFlag, &myStateCounter);
658 myMapOfView.Add (aView);
660 for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
662 const Graphic3d_ZLayerId aLayerID = aLayerIt.Value();
663 const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID);
664 aView->AddZLayer (aLayerID);
665 aView->SetZLayerSettings (aLayerID, aSettings);
671 // =======================================================================
672 // function : RemoveView
674 // =======================================================================
675 void OpenGl_GraphicDriver::RemoveView (const Handle(Graphic3d_CView)& theView)
677 Handle(OpenGl_Context) aCtx = GetSharedContext();
678 Handle(OpenGl_View) aView = Handle(OpenGl_View)::DownCast (theView);
684 if (!myMapOfView.Remove (aView))
689 Handle(OpenGl_Window) aWindow = aView->GlWindow();
690 if (!aWindow.IsNull()
691 && aWindow->GetGlContext()->MakeCurrent())
693 aCtx = aWindow->GetGlContext();
697 // try to hijack another context if any
698 const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext();
699 if (!anOtherCtx.IsNull()
700 && anOtherCtx != aWindow->GetGlContext())
707 aView->ReleaseGlResources (aCtx);
708 if (myMapOfView.IsEmpty())
710 // The last view removed but some objects still present.
711 // Release GL resources now without object destruction.
712 for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
713 aStructIt.More (); aStructIt.Next())
715 OpenGl_Structure* aStruct = aStructIt.ChangeValue();
716 aStruct->ReleaseGlResources (aCtx);
718 myDeviceLostFlag = !myMapOfStructure.IsEmpty();
722 // =======================================================================
725 // =======================================================================
726 Handle(OpenGl_Window) OpenGl_GraphicDriver::CreateRenderWindow (const Handle(Aspect_Window)& theWindow,
727 const Aspect_RenderingContext theContext)
729 Handle(OpenGl_Context) aShareCtx = GetSharedContext();
730 Handle(OpenGl_Window) aWindow = new OpenGl_Window (this, theWindow, theContext, myCaps, aShareCtx);
734 //=======================================================================
735 //function : ViewExists
737 //=======================================================================
738 Standard_Boolean OpenGl_GraphicDriver::ViewExists (const Handle(Aspect_Window)& AWindow, Handle(Graphic3d_CView)& theView)
740 Standard_Boolean isExist = Standard_False;
742 // Parse the list of views to find
743 // a view with the specified window
746 const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
747 Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow ();
748 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
749 const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
750 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
751 UIView* TheSpecifiedWindowId = THEWindow->HView();
753 NSView* TheSpecifiedWindowId = THEWindow->HView();
755 #elif defined(__ANDROID__) || defined(__QNX__)
756 int TheSpecifiedWindowId = -1;
758 const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
759 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
762 NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIt (myMapOfView);
763 for(; aViewIt.More(); aViewIt.Next())
765 const Handle(OpenGl_View)& aView = aViewIt.Value();
766 if (aView->IsDefined() && aView->IsActive())
768 const Handle(Aspect_Window) AspectWindow = aView->Window();
771 const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
772 Aspect_Handle TheWindowIdOfView = theWindow->HWindow ();
773 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
774 const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
775 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
776 UIView* TheWindowIdOfView = theWindow->HView();
778 NSView* TheWindowIdOfView = theWindow->HView();
780 #elif defined(__ANDROID__) || defined(__QNX__)
781 int TheWindowIdOfView = 0;
783 const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
784 int TheWindowIdOfView = int (theWindow->XWindow ());
786 // Comparaison on window IDs
787 if (TheWindowIdOfView == TheSpecifiedWindowId)
789 isExist = Standard_True;