DeviceLost flag has been moved from Graphic3d_GraphicDriver to Graphic3d_StructureManager,
so that all Viewers sharing the same Driver instance are properly invalidated.
Fixed clearing of objects by vclear command in case of multiple Viewers.
// =======================================================================
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);
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()),
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.
// purpose :
// =======================================================================
Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
-: myDisplayConnection (theDisp),
- myDeviceLostFlag (Standard_False)
+: myDisplayConnection (theDisp)
{
//
}
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 :
//! 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();
DEFINE_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
protected:
-
//! Initializes the Driver
Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp);
- Handle(Aspect_DisplayConnection) myDisplayConnection;
- Standard_Boolean myDeviceLostFlag;
+protected:
+ Handle(Aspect_DisplayConnection) myDisplayConnection;
Aspect_GenId myStructGenId;
-
-private:
-
-
-
-
};
-
-
-
-
-
-
#endif // _Graphic3d_GraphicDriver_HeaderFile
// ========================================================================
Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver)
: myViewGenId (0, 31),
- myGraphicDriver (theDriver)
+ myGraphicDriver (theDriver),
+ myDeviceLostFlag (Standard_False)
{
//
}
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();
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.
//! Destroy, Highlight, Visible
class Graphic3d_StructureManager : public Standard_Transient
{
+ friend class Graphic3d_Structure;
+ DEFINE_STANDARD_RTTIEXT(Graphic3d_StructureManager, Standard_Transient)
public:
//! Initializes the ViewManager.
//! Suppresses the highlighting on all the structures in <me>.
Standard_EXPORT virtual void UnHighlight();
+ //! Recomputes all structures in the manager.
+ //! Resets Device Lost flag.
Standard_EXPORT void RecomputeStructures();
//! Recomputes all structures from theStructures.
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:
Graphic3d_MapOfObject myRegisteredObjects;
Handle(Graphic3d_GraphicDriver) myGraphicDriver;
Graphic3d_IndexedMapOfView myDefinedViews;
+ Standard_Boolean myDeviceLostFlag;
};
+DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, Standard_Transient)
+
#endif // _Graphic3d_StructureManager_HeaderFile
#include <Aspect_GraphicDeviceDefinitionError.hxx>
#include <Aspect_IdentDefinitionError.hxx>
+#include <Graphic3d_StructureManager.hxx>
#include <Message_Messenger.hxx>
#include <OSD_Environment.hxx>
#include <Standard_NotImplemented.hxx>
OpenGl_Structure* aStruct = aStructIt.ChangeValue();
aStruct->ReleaseGlResources (aCtxShared);
}
- myDeviceLostFlag = myDeviceLostFlag || !myMapOfStructure.IsEmpty();
+ const bool isDeviceLost = !myMapOfStructure.IsEmpty();
for (NCollection_Map<Handle(OpenGl_View)>::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())
{
// =======================================================================
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);
OpenGl_Structure* aStruct = aStructIt.ChangeValue();
aStruct->ReleaseGlResources (aCtx);
}
- myDeviceLostFlag = !myMapOfStructure.IsEmpty();
+
+ if (!myMapOfStructure.IsEmpty())
+ {
+ aView->StructureManager()->SetDeviceLost();
+ }
}
}
return isExist;
}
+
+//=======================================================================
+//function : setDeviceLost
+//purpose :
+//=======================================================================
+void OpenGl_GraphicDriver::setDeviceLost()
+{
+ if (myMapOfStructure.IsEmpty())
+ {
+ return;
+ }
+
+ for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIter (myMapOfView); aViewIter.More(); aViewIter.Next())
+ {
+ const Handle(OpenGl_View)& aView = aViewIter.Value();
+ if (aView->myWasRedrawnGL)
+ {
+ aView->StructureManager()->SetDeviceLost();
+ }
+ }
+}
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.
//! 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:
};
+DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
+
#endif //_OpenGl_GraphicDriver_HeaderFile
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),
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.
Handle(OpenGl_Window) myWindow;
Handle(OpenGl_Workspace) myWorkspace;
Handle(OpenGl_Caps) myCaps;
- Standard_Boolean& myDeviceLostFlag;
Standard_Boolean myWasRedrawnGL;
Standard_Boolean myCulling;
#include <OpenGl_GlCore11.hxx>
#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_StructureManager.hxx>
#include <Graphic3d_TextureParams.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
#include <Graphic3d_TransformUtils.hxx>
&& !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;
}
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;
}
//==============================================================================
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();
- }
- TheAISContext()->RebuildSelectionStructs();
- TheAISContext()->UpdateCurrentViewer();
+ if (a3DView().IsNull())
+ {
+ return;
+ }
+
+ NCollection_Sequence<Handle(AIS_InteractiveObject)> 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;
+ }
+
+ 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<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next())
+ {
+ GetMapOfAIS().UnBind1 (anObjIter.Value());
+ }
+ }
}
//==============================================================================
// Remove view resources
ViewerTest_myViews.UnBind1(theViewName);
+ aView->Window()->Unmap();
aView->Remove();
#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
--- /dev/null
+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" }