return Standard_True;
}
-void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& ACView)
+void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView)
{
- if (myMapOfView.IsBound (ACView.ViewId))
- myMapOfView.UnBind (ACView.ViewId);
+ Handle(OpenGl_Context) aShareCtx = GetSharedContext();
+ if (myMapOfView.IsBound (theCView.ViewId))
+ myMapOfView.UnBind (theCView.ViewId);
+
+ if (myMapOfWS.IsBound (theCView.WsId))
+ myMapOfWS.UnBind (theCView.WsId);
- if (myMapOfWS.IsBound (ACView.WsId))
- myMapOfWS.UnBind (ACView.WsId);
+ if (myMapOfWS.IsEmpty() && !myMapOfStructure.IsEmpty())
+ {
+ // The last view removed but some objects still present.
+ // Release GL resources now without object destruction.
+ for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
+ aStructIt.More (); aStructIt.Next())
+ {
+ OpenGl_Structure* aStruct = aStructIt.ChangeValue();
+ aStruct->ReleaseGlResources (aShareCtx);
+ }
+ }
- OpenGl_CView *aCView = (OpenGl_CView *)ACView.ptrView;
+ OpenGl_CView *aCView = (OpenGl_CView *)theCView.ptrView;
delete aCView;
- ((Graphic3d_CView *)&ACView)->ptrView = NULL;
+ ((Graphic3d_CView *)&theCView)->ptrView = NULL;
}
void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView)
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
#include <OpenGl_IndexBuffer.hxx>
#include <OpenGl_Context.hxx>
{
if (!myVbos[anIter].IsNull())
{
- theContext->DelayedRelease (myVbos[anIter]);
+ if (!theContext.IsNull())
+ {
+ theContext->DelayedRelease (myVbos[anIter]);
+ }
myVbos[anIter].Nullify();
}
}
ClearHighlightColor (theGlCtx);
}
+// =======================================================================
+// function : ReleaseGlResources
+// purpose :
+// =======================================================================
+void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx)
+{
+ for (OpenGl_ListOfGroup::Iterator anIter (myGroups); anIter.More(); anIter.Next())
+ {
+ OpenGl_Group* aGroup = const_cast<OpenGl_Group*& > (anIter.ChangeValue());
+ if (aGroup != NULL)
+ {
+ aGroup->Release (theGlCtx);
+ }
+ }
+ if (myAspectLine != NULL)
+ {
+ myAspectLine->Release (theGlCtx);
+ }
+ if (myAspectFace != NULL)
+ {
+ myAspectFace->Release (theGlCtx);
+ }
+ if (myAspectMarker != NULL)
+ {
+ myAspectMarker->Release (theGlCtx);
+ }
+ if (myAspectText != NULL)
+ {
+ myAspectText->Release (theGlCtx);
+ }
+ if (myHighlightBox != NULL)
+ {
+ myHighlightBox->Release (theGlCtx);
+ }
+}
+
//=======================================================================
//function : SetZLayer
//purpose :
virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
+ //! This method releases GL resources without actual elements destruction.
+ //! As result structure could be correctly destroyed layter without GL context
+ //! (after last window was closed for example).
+ //!
+ //! Notice however that reusage of this structure after calling this method is incorrect
+ //! and will lead to broken visualization due to loosed data.
+ void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
+
protected:
virtual ~OpenGl_Structure();
Handle(Aspect_Window) asp = anOldView->Window();
aViewer->SetViewOff (anOldView);
- anOldView->Remove();
- anOldView.Nullify();
Handle(V3d_View) aNewView = aViewer->CreateView();
ViewerTest::CurrentView (aNewView);
aNewView->SetWindow (asp);
if (!asp->IsMapped()) asp->Map();
+ anOldView->Remove();
+ anOldView.Nullify();
+
aNewView->Update();
// replace view in event manager