0030635: Visualization - move OpenGl_Layer to Graphic3d_Layer
[occt.git] / src / Graphic3d / Graphic3d_GraphicDriver.cxx
index 773f49d..8421319 100644 (file)
@@ -25,7 +25,71 @@ IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_GraphicDriver,Standard_Transient)
 Graphic3d_GraphicDriver::Graphic3d_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp)
 : myDisplayConnection (theDisp)
 {
-  //
+  // default layers are always presented in display layer sequence it can not be removed
+  {
+    Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetImmediate          (Standard_False);
+    aSettings.SetEnvironmentTexture (Standard_False);
+    aSettings.SetEnableDepthTest    (Standard_False);
+    aSettings.SetEnableDepthWrite   (Standard_False);
+    aSettings.SetClearDepth         (Standard_False);
+    aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
+    myLayerIds.Add             (Graphic3d_ZLayerId_BotOSD);
+    myLayerSeq.Append          (Graphic3d_ZLayerId_BotOSD);
+    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, aSettings);
+  }
+
+  {
+    Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetImmediate          (Standard_False);
+    aSettings.SetEnvironmentTexture (Standard_True);
+    aSettings.SetEnableDepthTest    (Standard_True);
+    aSettings.SetEnableDepthWrite   (Standard_True);
+    aSettings.SetClearDepth         (Standard_False);
+    aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
+    myLayerIds.Add             (Graphic3d_ZLayerId_Default);
+    myLayerSeq.Append          (Graphic3d_ZLayerId_Default);
+    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aSettings);
+  }
+
+  {
+    Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetImmediate          (Standard_True);
+    aSettings.SetEnvironmentTexture (Standard_True);
+    aSettings.SetEnableDepthTest    (Standard_True);
+    aSettings.SetEnableDepthWrite   (Standard_True);
+    aSettings.SetClearDepth         (Standard_False);
+    aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
+    myLayerIds.Add             (Graphic3d_ZLayerId_Top);
+    myLayerSeq.Append          (Graphic3d_ZLayerId_Top);
+    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aSettings);
+  }
+
+  {
+    Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetImmediate          (Standard_True);
+    aSettings.SetEnvironmentTexture (Standard_True);
+    aSettings.SetEnableDepthTest    (Standard_True);
+    aSettings.SetEnableDepthWrite   (Standard_True);
+    aSettings.SetClearDepth         (Standard_True);
+    aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
+    myLayerIds.Add             (Graphic3d_ZLayerId_Topmost);
+    myLayerSeq.Append          (Graphic3d_ZLayerId_Topmost);
+    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aSettings);
+  }
+
+  {
+    Graphic3d_ZLayerSettings aSettings;
+    aSettings.SetImmediate          (Standard_True);
+    aSettings.SetEnvironmentTexture (Standard_False);
+    aSettings.SetEnableDepthTest    (Standard_False);
+    aSettings.SetEnableDepthWrite   (Standard_False);
+    aSettings.SetClearDepth         (Standard_False);
+    aSettings.SetPolygonOffset (Graphic3d_PolygonOffset());
+    myLayerIds.Add             (Graphic3d_ZLayerId_TopOSD);
+    myLayerSeq.Append          (Graphic3d_ZLayerId_TopOSD);
+    myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, aSettings);
+  }
 }
 
 // =======================================================================
@@ -53,4 +117,83 @@ Standard_Integer Graphic3d_GraphicDriver::NewIdentification()
 void Graphic3d_GraphicDriver::RemoveIdentification(const Standard_Integer theId)
 {
   myStructGenId.Free(theId);
-}
\ No newline at end of file
+}
+
+//=======================================================================
+//function : ZLayerSettings
+//purpose  :
+//=======================================================================
+const Graphic3d_ZLayerSettings& Graphic3d_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const
+{
+  Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId), "Graphic3d_GraphicDriver::ZLayerSettings, Layer with theLayerId does not exist");
+  return myMapOfZLayerSettings.Find (theLayerId);
+}
+
+//=======================================================================
+//function : addZLayerIndex
+//purpose  :
+//=======================================================================
+void Graphic3d_GraphicDriver::addZLayerIndex (const Graphic3d_ZLayerId theLayerId)
+{
+  // remove index
+  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+  {
+    if (aLayerIt.Value() == theLayerId)
+    {
+      myLayerSeq.Remove (aLayerIt);
+      break;
+    }
+  }
+
+  if (myMapOfZLayerSettings.Find (theLayerId).IsImmediate())
+  {
+    myLayerSeq.Append (theLayerId);
+    return;
+  }
+
+  for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next())
+  {
+    const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerIt.Value());
+    if (aSettings.IsImmediate())
+    {
+      aLayerIt.Previous();
+      if (aLayerIt.More())
+      {
+        myLayerSeq.InsertAfter (aLayerIt, theLayerId);
+        return;
+      }
+
+      // first non-immediate layer
+      myLayerSeq.Prepend (theLayerId);
+      return;
+    }
+  }
+
+  // no immediate layers
+  myLayerSeq.Append (theLayerId);
+}
+
+//=======================================================================
+//function : SetZLayerSettings
+//purpose  :
+//=======================================================================
+void Graphic3d_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
+                                                 const Graphic3d_ZLayerSettings& theSettings)
+{
+  Graphic3d_ZLayerSettings* aSettings = myMapOfZLayerSettings.ChangeSeek (theLayerId);
+  if (aSettings != NULL)
+  {
+    const bool isChanged = (aSettings->IsImmediate() != theSettings.IsImmediate());
+    *aSettings = theSettings;
+    if (isChanged)
+    {
+      addZLayerIndex (theLayerId);
+    }
+  }
+  else
+  {
+    // abnormal case
+    myMapOfZLayerSettings.Bind (theLayerId, theSettings);
+    addZLayerIndex (theLayerId);
+  }
+}