diff --git a/src/D3DHost/D3DHost_GraphicDriver.cxx b/src/D3DHost/D3DHost_GraphicDriver.cxx index d2f232f4ab..76a878952c 100644 --- a/src/D3DHost/D3DHost_GraphicDriver.cxx +++ b/src/D3DHost/D3DHost_GraphicDriver.cxx @@ -49,7 +49,7 @@ D3DHost_GraphicDriver::~D3DHost_GraphicDriver() // ======================================================================= Handle(Graphic3d_CView) D3DHost_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr) { - Handle(D3DHost_View) aView = new D3DHost_View (theMgr, this, myCaps, myDeviceLostFlag, &myStateCounter); + Handle(D3DHost_View) aView = new D3DHost_View (theMgr, this, myCaps, &myStateCounter); myMapOfView.Add (aView); diff --git a/src/D3DHost/D3DHost_View.cxx b/src/D3DHost/D3DHost_View.cxx index 1c1d5c2928..e92d4249b2 100644 --- a/src/D3DHost/D3DHost_View.cxx +++ b/src/D3DHost/D3DHost_View.cxx @@ -47,9 +47,8 @@ TCollection_AsciiString D3DHost_View::d3dFormatError (const long theErrCode) D3DHost_View::D3DHost_View (const Handle(Graphic3d_StructureManager)& theMgr, const Handle(D3DHost_GraphicDriver)& theDriver, const Handle(OpenGl_Caps)& theCaps, - Standard_Boolean& theDeviceLostFlag, OpenGl_StateCounter* theCounter) -: OpenGl_View (theMgr, theDriver, theCaps, theDeviceLostFlag, theCounter), +: OpenGl_View (theMgr, theDriver, theCaps, theCounter), myD3dLib (NULL), myD3dDevice (NULL), myD3dParams (new D3DPRESENT_PARAMETERS()), diff --git a/src/D3DHost/D3DHost_View.hxx b/src/D3DHost/D3DHost_View.hxx index 0e14851232..8a7ac76a9b 100644 --- a/src/D3DHost/D3DHost_View.hxx +++ b/src/D3DHost/D3DHost_View.hxx @@ -35,7 +35,6 @@ public: Standard_EXPORT D3DHost_View (const Handle(Graphic3d_StructureManager)& theMgr, const Handle(D3DHost_GraphicDriver)& theDriver, const Handle(OpenGl_Caps)& theCaps, - Standard_Boolean& theDeviceLostFlag, OpenGl_StateCounter* theCounter); //! Default destructor. diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.cxx b/src/Graphic3d/Graphic3d_GraphicDriver.cxx index ec56f6b6ec..773f49dcff 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.cxx +++ b/src/Graphic3d/Graphic3d_GraphicDriver.cxx @@ -23,8 +23,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient) // purpose : // ======================================================================= Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp) -: myDisplayConnection (theDisp), - myDeviceLostFlag (Standard_False) +: myDisplayConnection (theDisp) { // } @@ -38,24 +37,6 @@ const Handle(Aspect_DisplayConnection)& Graphic3d_GraphicDriver::GetDisplayConne return myDisplayConnection; } -// ======================================================================= -// function : IsDeviceLost -// purpose : -// ======================================================================= -Standard_Boolean Graphic3d_GraphicDriver::IsDeviceLost() const -{ - return myDeviceLostFlag; -} - -// ======================================================================= -// function : ResetDeviceLostFlag -// purpose : -// ======================================================================= -void Graphic3d_GraphicDriver::ResetDeviceLostFlag() -{ - myDeviceLostFlag = Standard_False; -} - // ======================================================================= // function : NewIdentification // purpose : diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.hxx b/src/Graphic3d/Graphic3d_GraphicDriver.hxx index 8de5983020..dd240035b5 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.hxx +++ b/src/Graphic3d/Graphic3d_GraphicDriver.hxx @@ -138,10 +138,6 @@ public: //! returns Handle to display connection Standard_EXPORT const Handle(Aspect_DisplayConnection)& GetDisplayConnection() const; - - Standard_EXPORT Standard_Boolean IsDeviceLost() const; - - Standard_EXPORT void ResetDeviceLostFlag(); //! Returns a new identification number for a new structure. Standard_EXPORT Standard_Integer NewIdentification(); @@ -152,28 +148,15 @@ public: DEFINE_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient) protected: - //! Initializes the Driver Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp); +protected: + Handle(Aspect_DisplayConnection) myDisplayConnection; - Standard_Boolean myDeviceLostFlag; - Aspect_GenId myStructGenId; - -private: - - - - }; - - - - - - #endif // _Graphic3d_GraphicDriver_HeaderFile diff --git a/src/Graphic3d/Graphic3d_StructureManager.cxx b/src/Graphic3d/Graphic3d_StructureManager.cxx index 61b90bb1a5..081f726e99 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.cxx +++ b/src/Graphic3d/Graphic3d_StructureManager.cxx @@ -30,7 +30,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_StructureManager,Standard_Transient) // ======================================================================== Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver) : myViewGenId (0, 31), - myGraphicDriver (theDriver) + myGraphicDriver (theDriver), + myDeviceLostFlag (Standard_False) { // } @@ -149,9 +150,10 @@ const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver void Graphic3d_StructureManager::RecomputeStructures() { + myDeviceLostFlag = Standard_False; + // Go through all unique structures including child (connected) ones and ensure that they are computed. Graphic3d_MapOfStructure aStructNetwork; - for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next()) { Handle(Graphic3d_Structure) aStructure = anIter.Key(); diff --git a/src/Graphic3d/Graphic3d_StructureManager.hxx b/src/Graphic3d/Graphic3d_StructureManager.hxx index 6abdcb73ec..c5b7e87eca 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.hxx +++ b/src/Graphic3d/Graphic3d_StructureManager.hxx @@ -38,10 +38,6 @@ typedef NCollection_IndexedMap Graphic3d_IndexedMapOfView; class Graphic3d_GraphicDriver; class Graphic3d_Structure; class Graphic3d_DataStructureManager; -class Standard_Transient; - -class Graphic3d_StructureManager; -DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, Standard_Transient) //! This class allows the definition of a manager to //! which the graphic objects are associated. @@ -51,6 +47,8 @@ DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, Standard_Transient) //! Destroy, Highlight, Visible class Graphic3d_StructureManager : public Standard_Transient { + friend class Graphic3d_Structure; + DEFINE_STANDARD_RTTIEXT(Graphic3d_StructureManager, Standard_Transient) public: //! Initializes the ViewManager. @@ -144,6 +142,8 @@ public: //! Suppresses the highlighting on all the structures in . Standard_EXPORT virtual void UnHighlight(); + //! Recomputes all structures in the manager. + //! Resets Device Lost flag. Standard_EXPORT void RecomputeStructures(); //! Recomputes all structures from theStructures. @@ -155,9 +155,11 @@ public: Standard_EXPORT Handle(Graphic3d_ViewAffinity) ObjectAffinity (const Handle(Standard_Transient)& theObject) const; - friend class Graphic3d_Structure; + //! Returns TRUE if Device Lost flag has been set and presentation data should be reuploaded onto graphics driver. + Standard_Boolean IsDeviceLost() const { return myDeviceLostFlag; } - DEFINE_STANDARD_RTTIEXT(Graphic3d_StructureManager,Standard_Transient) + //! Sets Device Lost flag. + void SetDeviceLost() { myDeviceLostFlag = Standard_True; } protected: @@ -174,6 +176,9 @@ protected: Graphic3d_MapOfObject myRegisteredObjects; Handle(Graphic3d_GraphicDriver) myGraphicDriver; Graphic3d_IndexedMapOfView myDefinedViews; + Standard_Boolean myDeviceLostFlag; }; +DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, Standard_Transient) + #endif // _Graphic3d_StructureManager_HeaderFile diff --git a/src/OpenGl/OpenGl_GraphicDriver.cxx b/src/OpenGl/OpenGl_GraphicDriver.cxx index a409eb19c5..0912755d62 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -218,12 +219,17 @@ void OpenGl_GraphicDriver::ReleaseContext() OpenGl_Structure* aStruct = aStructIt.ChangeValue(); aStruct->ReleaseGlResources (aCtxShared); } - myDeviceLostFlag = myDeviceLostFlag || !myMapOfStructure.IsEmpty(); + const bool isDeviceLost = !myMapOfStructure.IsEmpty(); for (NCollection_Map::Iterator aViewIter (myMapOfView); aViewIter.More(); aViewIter.Next()) { const Handle(OpenGl_View)& aView = aViewIter.Value(); + if (isDeviceLost) + { + aView->StructureManager()->SetDeviceLost(); + } + const Handle(OpenGl_Window)& aWindow = aView->GlWindow(); if (aWindow.IsNull()) { @@ -730,7 +736,7 @@ void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCSt // ======================================================================= Handle(Graphic3d_CView) OpenGl_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr) { - Handle(OpenGl_View) aView = new OpenGl_View (theMgr, this, myCaps, myDeviceLostFlag, &myStateCounter); + Handle(OpenGl_View) aView = new OpenGl_View (theMgr, this, myCaps, &myStateCounter); myMapOfView.Add (aView); @@ -792,7 +798,11 @@ void OpenGl_GraphicDriver::RemoveView (const Handle(Graphic3d_CView)& theView) OpenGl_Structure* aStruct = aStructIt.ChangeValue(); aStruct->ReleaseGlResources (aCtx); } - myDeviceLostFlag = !myMapOfStructure.IsEmpty(); + + if (!myMapOfStructure.IsEmpty()) + { + aView->StructureManager()->SetDeviceLost(); + } } } @@ -872,3 +882,24 @@ Standard_Boolean OpenGl_GraphicDriver::ViewExists (const Handle(Aspect_Window)& return isExist; } + +//======================================================================= +//function : setDeviceLost +//purpose : +//======================================================================= +void OpenGl_GraphicDriver::setDeviceLost() +{ + if (myMapOfStructure.IsEmpty()) + { + return; + } + + for (NCollection_Map::Iterator aViewIter (myMapOfView); aViewIter.More(); aViewIter.Next()) + { + const Handle(OpenGl_View)& aView = aViewIter.Value(); + if (aView->myWasRedrawnGL) + { + aView->StructureManager()->SetDeviceLost(); + } + } +} diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index 5000619a26..49823479a9 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -74,13 +74,10 @@ private: Standard_Size myCounter; }; -class OpenGl_GraphicDriver; - -DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver) - //! This class defines an OpenGl graphic driver class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver { + DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver, Graphic3d_GraphicDriver) public: //! Constructor. @@ -200,9 +197,8 @@ public: //! Insert index layer at proper position. Standard_EXPORT void addZLayerIndex (const Graphic3d_ZLayerId theLayerId); -public: - - DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver) + //! Set device lost flag for redrawn views. + Standard_EXPORT void setDeviceLost(); public: @@ -234,4 +230,6 @@ protected: }; +DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver) + #endif //_OpenGl_GraphicDriver_HeaderFile diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 24de9fec7f..41af8b0365 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -49,12 +49,10 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr, const Handle(OpenGl_GraphicDriver)& theDriver, const Handle(OpenGl_Caps)& theCaps, - Standard_Boolean& theDeviceLostFlag, OpenGl_StateCounter* theCounter) : Graphic3d_CView (theMgr), myDriver (theDriver.operator->()), myCaps (theCaps), - myDeviceLostFlag (theDeviceLostFlag), myWasRedrawnGL (Standard_False), myCulling (Standard_True), myShadingModel (Graphic3d_TOSM_FACET), diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 03f30c7e3d..0607e2690e 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -74,7 +74,6 @@ public: Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr, const Handle(OpenGl_GraphicDriver)& theDriver, const Handle(OpenGl_Caps)& theCaps, - Standard_Boolean& theDeviceLostFlag, OpenGl_StateCounter* theCounter); //! Default destructor. @@ -470,7 +469,6 @@ protected: Handle(OpenGl_Window) myWindow; Handle(OpenGl_Workspace) myWorkspace; Handle(OpenGl_Caps) myCaps; - Standard_Boolean& myDeviceLostFlag; Standard_Boolean myWasRedrawnGL; Standard_Boolean myCulling; diff --git a/src/OpenGl/OpenGl_View_Redraw.cxx b/src/OpenGl/OpenGl_View_Redraw.cxx index 1491a7cd4f..6ad77f0959 100644 --- a/src/OpenGl/OpenGl_View_Redraw.cxx +++ b/src/OpenGl/OpenGl_View_Redraw.cxx @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -145,11 +146,9 @@ void OpenGl_View::Redraw() && !myCaps->vboDisable && !myCaps->keepArrayData) { - if (myWasRedrawnGL) - { - myDeviceLostFlag = Standard_True; - } - + // caps are shared across all views, thus we need to invalidate all of them + // if (myWasRedrawnGL) { myStructureManager->SetDeviceLost(); } + myDriver->setDeviceLost(); myCaps->keepArrayData = Standard_True; } diff --git a/src/V3d/V3d_View.cxx b/src/V3d/V3d_View.cxx index 3e85e84b4f..acf06ef4db 100644 --- a/src/V3d/V3d_View.cxx +++ b/src/V3d/V3d_View.cxx @@ -244,21 +244,19 @@ void V3d_View::Redraw() const return; } - Handle(Graphic3d_GraphicDriver) aGraphicDriver = MyViewer->Driver(); Handle(Graphic3d_StructureManager) aStructureMgr = MyViewer->StructureManager(); for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter) { - if (aGraphicDriver->IsDeviceLost()) + if (aStructureMgr->IsDeviceLost()) { aStructureMgr->RecomputeStructures(); - aGraphicDriver->ResetDeviceLostFlag(); } AutoZFit(); myView->Redraw(); - if (!aGraphicDriver->IsDeviceLost()) + if (!aStructureMgr->IsDeviceLost()) { return; } diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 33a6078cff..7ef669cae5 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -638,18 +638,38 @@ Handle(AIS_Shape) GetAISShapeFromName(const char* name) //============================================================================== void ViewerTest::Clear() { - if ( !a3DView().IsNull() ) { - ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); - while ( it.More() ) { - cout << "Remove " << it.Key2() << endl; - const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (it.Key1()); - TheAISContext()->Remove(anObj,Standard_False); - it.Next(); + if (a3DView().IsNull()) + { + return; + } + + NCollection_Sequence aListRemoved; + for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next()) + { + const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1()); + if (anObj->GetContext() != TheAISContext()) + { + continue; } - TheAISContext()->RebuildSelectionStructs(); - TheAISContext()->UpdateCurrentViewer(); + + std::cout << "Remove " << anObjIter.Key2() << std::endl; + TheAISContext()->Remove (anObj, Standard_False); + aListRemoved.Append (anObj); + } + + TheAISContext()->RebuildSelectionStructs(); + TheAISContext()->UpdateCurrentViewer(); + if (aListRemoved.Size() == GetMapOfAIS().Extent()) + { GetMapOfAIS().Clear(); } + else + { + for (NCollection_Sequence::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next()) + { + GetMapOfAIS().UnBind1 (anObjIter.Value()); + } + } } //============================================================================== diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 82f9678315..02c113be66 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -1120,6 +1120,7 @@ void ViewerTest::RemoveView (const TCollection_AsciiString& theViewName, const S // Remove view resources ViewerTest_myViews.UnBind1(theViewName); + aView->Window()->Unmap(); aView->Remove(); #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) diff --git a/tests/bugs/vis/bug28890 b/tests/bugs/vis/bug28890 new file mode 100644 index 0000000000..cbaa2cff18 --- /dev/null +++ b/tests/bugs/vis/bug28890 @@ -0,0 +1,42 @@ +puts "============" +puts "0028890: Visualization - After closing all views and then display the view again, just the first view has object(s) displayed" +puts "============" +puts "" + +pload MODELING VISUALIZATION +vclear +vclose ALL +box b1_1 0 0 0 1 2 3 +box b1_2 0 3 0 3 1 2 +box b2_1 0 0 0 3 1 2 +box b2_2 0 3 0 1 2 3 + +# fill first Viewer +vinit Driver1/Viewer1/View1 +vzbufftrihedron +vdisplay -dispMode 1 b1_1 b1_2 +vfit +vsetcolor b1_1 RED +vsetcolor b1_2 GREEN + +# fill second Viewer +vinit Driver1/Viewer2/View1 +vzbufftrihedron +vdisplay -dispMode 1 b2_1 b2_2 +vfit +vsetcolor b2_1 RED +vsetcolor b2_2 GREEN + +# enable RayTracing which sets DeviceLost flag +vactivate Driver1/Viewer1/View1 +vraytrace 1 +set aColor1 [vreadpixel 150 250 rgb] +vdump $::imagedir/${::casename}_1.png + +vactivate Driver1/Viewer2/View1 +vraytrace 1 +set aColor2 [vreadpixel 150 250 rgb] +vdump $::imagedir/${::casename}_2.png + +# check that DeviceLost flag is processed by both Viewers +if { "$aColor1" != "$aColor2" } { puts "Error: colors should be equal" }