]> OCCT Git - occt-copy.git/commitdiff
0024867: Visualization - polygon offsets look broken
authorduv <duv@opencascade.com>
Thu, 24 Apr 2014 06:18:28 +0000 (10:18 +0400)
committerabv <abv@opencascade.com>
Thu, 24 Apr 2014 12:55:47 +0000 (16:55 +0400)
If specific layer setting is not enabled, default value extracted from current OpenGl state will be used.

src/OpenGl/OpenGl_AspectFace.cxx
src/OpenGl/OpenGl_AspectFace.hxx
src/OpenGl/OpenGl_Layer.cxx
src/OpenGl/OpenGl_Layer.hxx
src/OpenGl/OpenGl_LayerList.cxx
src/OpenGl/OpenGl_View_2.cxx
src/OpenGl/OpenGl_Workspace.cxx
src/OpenGl/OpenGl_Workspace.hxx
src/OpenGl/OpenGl_Workspace_5.cxx
tests/bugs/vis/bug24867 [new file with mode: 0644]

index 6912030a0c466c3cde6e524183c6c7d629ce0f64..337e117954e1cbbcde97c6510c4613518e3dab77 100644 (file)
@@ -44,7 +44,6 @@ namespace
     {{ 1.0F, 1.0F, 1.0F, 1.0F }}  // material color
   };
 
-  static TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
   static const TCollection_AsciiString THE_EMPTY_KEY;
 };
 
index 0d5e14f0a17f0791f6d488c06741da90eb7a98cd..ba0d4f1ab60c43a190ad9b10093184eb56128367 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <InterfaceGraphic_telem.hxx>
 #include <Aspect_InteriorStyle.hxx>
+#include <Aspect_PolygonOffsetMode.hxx>
 #include <TCollection_AsciiString.hxx>
 
 #include <Handle_Graphic3d_TextureParams.hxx>
@@ -35,6 +36,8 @@
 #define OPENGL_SPECULAR_MASK (1<<2)
 #define OPENGL_EMISSIVE_MASK (1<<3)
 
+static const TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
+
 class CALL_DEF_CONTEXTFILLAREA;
 
 struct OPENGL_SURF_PROP
index bbaa5466122b11d4c1ed547dc64fddc014552f2d..ca3c425397a4d5b6c65860b2aa71915250aef13a 100644 (file)
 // commercial license or contractual agreement.
 
 #include <OpenGl_Layer.hxx>
-
+#include <OpenGl_Workspace.hxx>
 #include <OpenGl_GlCore11.hxx>
 
-//=======================================================================
-//function : OpenGl_LayerSettings
-//purpose  : 
-//=======================================================================
-OpenGl_LayerSettings::OpenGl_LayerSettings()
-  : DepthOffsetFactor (1.0f),
-    DepthOffsetUnits  (1.0f),
-    Flags (OpenGl_LayerDepthTest
-          | OpenGl_LayerDepthWrite
-          | OpenGl_LayerDepthClear)
-{
-  //
-}
-
 //=======================================================================
 //function : OpenGl_Layer
 //purpose  : 
@@ -45,36 +31,43 @@ OpenGl_Layer::OpenGl_Layer (const Standard_Integer theNbPriorities)
 //function : Render
 //purpose  : 
 //=======================================================================
-void OpenGl_Layer::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
+void OpenGl_Layer::Render (const Handle(OpenGl_Workspace) &theWorkspace, const OpenGl_GlobalLayerSettings& theDefaultSettings) const
 {
+  TEL_POFFSET_PARAM anAppliedOffsetParams = theWorkspace->AppliedPolygonOffset();
+
   // separate depth buffers
-  if (IsSettingEnabled (OpenGl_LayerDepthClear))
+  if (IsSettingEnabled (Graphic3d_ZLayerDepthClear))
   {
     glClear (GL_DEPTH_BUFFER_BIT);
   }
-
   // handle depth test
-  if (IsSettingEnabled (OpenGl_LayerDepthTest))
+  if (IsSettingEnabled (Graphic3d_ZLayerDepthTest))
   {
-    glDepthFunc (GL_LESS);
+    // assuming depth test is enabled by default
+    glDepthFunc (theDefaultSettings.DepthFunc);
   }
   else
   {
     glDepthFunc (GL_ALWAYS);
   }
-
+  
   // handle depth offset
-  if (IsSettingEnabled (OpenGl_LayerDepthOffset))
+  if (IsSettingEnabled (Graphic3d_ZLayerDepthOffset))
   {
-    glPolygonOffset (myLayerSettings.DepthOffsetFactor, myLayerSettings.DepthOffsetUnits);
+    theWorkspace->SetPolygonOffset (Aspect_POM_Fill,
+                                    myLayerSettings.DepthOffsetFactor,
+                                    myLayerSettings.DepthOffsetUnits);
   }
   else
   {
-    glPolygonOffset (0.f, 0.f);
+    theWorkspace->SetPolygonOffset (anAppliedOffsetParams.mode,
+                                    anAppliedOffsetParams.factor,
+                                    anAppliedOffsetParams.units);
   }
 
   // handle depth write
-  if (IsSettingEnabled (OpenGl_LayerDepthWrite))
+  if (IsSettingEnabled (Graphic3d_ZLayerDepthWrite))
   {
     glDepthMask (GL_TRUE);
   }
@@ -84,5 +77,10 @@ void OpenGl_Layer::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
   }
 
   // render priority list
-  myPriorityList.Render (AWorkspace);
+  myPriorityList.Render (theWorkspace);
+
+  // always restore polygon offset between layers rendering
+  theWorkspace->SetPolygonOffset (anAppliedOffsetParams.mode,
+                                  anAppliedOffsetParams.factor,
+                                  anAppliedOffsetParams.units);
 }
index d36fd9af2a7b79911612c5d9face4e428f8c4539..97410cc23972eeb765b863b6296776d5db07ddeb 100644 (file)
 #define _OpenGl_Layer_Header
 
 #include <OpenGl_PriorityList.hxx>
+#include <Graphic3d_ZLayerSettings.hxx>
+#include <OpenGl_GlCore11.hxx>
 
 class Handle(OpenGl_Workspace);
 
-enum OpenGl_LayerSetting
+struct OpenGl_GlobalLayerSettings
 {
-  OpenGl_LayerDepthTest = 1,
-  OpenGl_LayerDepthWrite = 2,
-  OpenGl_LayerDepthClear = 4,
-  OpenGl_LayerDepthOffset = 8
-};
-
-struct OpenGl_LayerSettings
-{
-  //! Initializes settings
-  OpenGl_LayerSettings();
-
-  //! Returns true if theSetting is enabled.
-  const Standard_Boolean IsSettingEnabled (const OpenGl_LayerSetting theSetting) const
-  {
-    return (Flags & theSetting) == theSetting;
-  }
-
-  Standard_ShortReal DepthOffsetFactor; //!< Factor argument value for OpenGl glPolygonOffset function.
-  Standard_ShortReal DepthOffsetUnits;  //!< Units argument value for OpenGl glPolygonOffset function.
-
-  Standard_Integer Flags; //!< Storage field for settings.
+  GLint DepthFunc;
+  GLboolean DepthMask;
 };
 
 class OpenGl_Layer
@@ -53,16 +36,16 @@ public:
   OpenGl_Layer (const Standard_Integer theNbPriorities = 11);
 
   //! Returns settings of the layer object.
-  const OpenGl_LayerSettings LayerSettings() const { return myLayerSettings; };
+  const Graphic3d_ZLayerSettings LayerSettings() const { return myLayerSettings; };
 
   //! Sets settings of the layer object.
-  void SetLayerSettings (OpenGl_LayerSettings theSettings)
+  void SetLayerSettings (Graphic3d_ZLayerSettings theSettings)
   {
     myLayerSettings = theSettings;
   }
 
   //! Returns true if theSetting is enabled for the layer.
-  const Standard_Boolean IsSettingEnabled (const OpenGl_LayerSetting theSetting) const
+  const Standard_Boolean IsSettingEnabled (const Graphic3d_ZLayerSetting theSetting) const
   {
     return myLayerSettings.IsSettingEnabled (theSetting);
   }
@@ -73,12 +56,12 @@ public:
   //! Returns const reference to associated priority list.
   const OpenGl_PriorityList& PriorityList() const { return myPriorityList; }
 
-  void Render (const Handle(OpenGl_Workspace) &AWorkspace) const;
+  void Render (const Handle(OpenGl_Workspace) &AWorkspace, const OpenGl_GlobalLayerSettings& theDefaultSettings) const;
 
 private:
 
   OpenGl_PriorityList myPriorityList;   //!< Associated priority list object.
 
-  OpenGl_LayerSettings myLayerSettings; //!< Layer setting flags.
+  Graphic3d_ZLayerSettings myLayerSettings; //!< Layer setting flags.
 };
 #endif //_OpenGl_Layer_Header
index e5cc9c0b45d85c31dccde26621e73067815d798a..65b2c44c91d515a4c7ca8f6205a6d37bf03ad8af 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <OpenGl_LayerList.hxx>
 #include <OpenGl_Structure.hxx>
+#include <OpenGl_Workspace.hxx>
 
 #include <InterfaceGraphic_Graphic3d.hxx>
 #include <InterfaceGraphic.hxx>
@@ -279,14 +280,22 @@ void OpenGl_LayerList::ChangeLayer (const OpenGl_Structure *theStructure,
 
 void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace) &theWorkspace) const
 {
+  OpenGl_GlobalLayerSettings aDefaultSettings;
+  
+  glGetIntegerv (GL_DEPTH_FUNC, &aDefaultSettings.DepthFunc);
+  glGetBooleanv (GL_DEPTH_WRITEMASK, &aDefaultSettings.DepthMask);
+
   OpenGl_SequenceOfLayers::Iterator anIts;
-  for(anIts.Init (myLayers); anIts.More (); anIts.Next ())
+  for (anIts.Init (myLayers); anIts.More(); anIts.Next())
   {
     const OpenGl_Layer& aLayer = anIts.Value ();
     if (aLayer.PriorityList().NbStructures () > 0)
     {
       // render layer
-      aLayer.Render (theWorkspace);
+      aLayer.Render (theWorkspace, aDefaultSettings);
     }
   }
+
+  glDepthMask (aDefaultSettings.DepthMask);
+  glDepthFunc (aDefaultSettings.DepthFunc);
 }
index b9a0405c002ab06b9375c56b8d2e0b9abf1a569d..89c3d2f910cc148aad02db5830823384a76ce586 100644 (file)
@@ -1518,13 +1518,6 @@ void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure,
 void OpenGl_View::SetZLayerSettings (const Standard_Integer theLayerId,
                                      const Graphic3d_ZLayerSettings theSettings)
 {
-  // Convert Graphic3d_ZLayerSettings to OpenGl_LayerSettings
-  OpenGl_LayerSettings aConvertedSettings;
-
-  aConvertedSettings.DepthOffsetFactor = theSettings.DepthOffsetFactor;
-  aConvertedSettings.DepthOffsetUnits  = theSettings.DepthOffsetUnits;
-  aConvertedSettings.Flags             = theSettings.Flags;
-
-  myZLayers.Layer (theLayerId).SetLayerSettings (aConvertedSettings);
+  myZLayers.Layer (theLayerId).SetLayerSettings (theSettings);
 }
 
index 48b5c615e315a6cca666d10856e88fa067c1b0bb..422bf8d3e913f7fec4bdb2ec08ac7da18f98a369 100644 (file)
@@ -166,8 +166,8 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
   TextParam_applied (NULL),
   ViewMatrix_applied (&myDefaultMatrix),
   StructureMatrix_applied (&myDefaultMatrix),
-  myModelViewMatrix (myDefaultMatrix),
-  PolygonOffset_applied (NULL)
+  PolygonOffset_applied (THE_DEFAULT_POFFSET),
+  myModelViewMatrix (myDefaultMatrix)
 {
   theDisplay->InitAttributes();
 
@@ -268,7 +268,7 @@ void OpenGl_Workspace::ResetAppliedAspect()
   AspectText_applied    = NULL;
   TextParam_set         = &myDefaultTextParam;
   TextParam_applied     = NULL;
-  PolygonOffset_applied = NULL;
+  PolygonOffset_applied = THE_DEFAULT_POFFSET;
 
   AspectLine(Standard_True);
   AspectFace(Standard_True);
index 965f1429425eea700355e5d12de7cc4d8f152324..b8c2f8131c7250944cf139820f85c06915402aac 100755 (executable)
@@ -38,6 +38,7 @@
 #include <Aspect_CLayer2d.hxx>
 #include <Aspect_Handle.hxx>
 #include <Aspect_PrintAlgo.hxx>
+#include <Aspect_PolygonOffsetMode.hxx>
 
 #include <InterfaceGraphic_Graphic3d.hxx>
 #include <InterfaceGraphic_Visual3d.hxx>
@@ -227,6 +228,12 @@ public:
   //! @return applied model structure matrix.
   inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; }
 
+  //! Sets and applies current polygon offset.
+  void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits);
+
+  //! Returns currently applied polygon offset params.
+  const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; }
+
 protected:
 
   void CopyBuffers (const Standard_Boolean theFrontToBack);
@@ -443,12 +450,11 @@ protected: //! @name fields related to status
   OpenGl_Material myMatBack;  //!< current back  material state
   OpenGl_Material myMatTmp;   //!< temporary variable
 
-  //! Model matrix with applied structure transformations
-  OpenGl_Matrix myModelViewMatrix;
+  OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations
 
-  const TEL_POFFSET_PARAM* PolygonOffset_applied;
+  TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset.
 
-  OpenGl_AspectFace myAspectFaceHl; // Hiddenline aspect
+  OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect
 
 public: //! @name type definition
 
index d88f2d0b322df71df35b120391191ca995f32ba9..d2f493a36645f34b8045fb0ee68aa0ad162834c0 100644 (file)
 
 /*----------------------------------------------------------------------*/
 
-static void TelUpdatePolygonOffsets( const TEL_POFFSET_PARAM *pdata )
+static void TelUpdatePolygonOffsets (const TEL_POFFSET_PARAM& theOffsetData)
 {
-  if ( ( pdata->mode & Aspect_POM_Fill ) == Aspect_POM_Fill )
-    glEnable ( GL_POLYGON_OFFSET_FILL );
+  if ((theOffsetData.mode & Aspect_POM_Fill) == Aspect_POM_Fill)
+  {
+    glEnable (GL_POLYGON_OFFSET_FILL);
+  }
   else
-    glDisable ( GL_POLYGON_OFFSET_FILL );
+  {
+    glDisable (GL_POLYGON_OFFSET_FILL);
+  }
 
-  if ( ( pdata->mode & Aspect_POM_Line ) == Aspect_POM_Line )
-    glEnable ( GL_POLYGON_OFFSET_LINE );
+  if ((theOffsetData.mode & Aspect_POM_Line) == Aspect_POM_Line)
+  {
+    glEnable (GL_POLYGON_OFFSET_LINE);
+  }
   else
-    glDisable( GL_POLYGON_OFFSET_LINE );
+  {
+    glDisable (GL_POLYGON_OFFSET_LINE);
+  }
 
-  if ( ( pdata->mode & Aspect_POM_Point ) == Aspect_POM_Point )
-    glEnable ( GL_POLYGON_OFFSET_POINT );
+  if ((theOffsetData.mode & Aspect_POM_Point) == Aspect_POM_Point)
+  {
+    glEnable (GL_POLYGON_OFFSET_POINT);
+  }
   else
-    glDisable( GL_POLYGON_OFFSET_POINT );
+  {
+    glDisable (GL_POLYGON_OFFSET_POINT);
+  }
 
-  glPolygonOffset( pdata->factor, pdata->units );
+  glPolygonOffset (theOffsetData.factor, theOffsetData.units);
 }
 
 /*----------------------------------------------------------------------*/
@@ -396,13 +408,13 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th
   // Aspect_POM_None means: do not change current settings
   if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None)
   {
-    if (PolygonOffset_applied         == NULL
-     || PolygonOffset_applied->mode   != AspectFace_set->PolygonOffset().mode
-     || PolygonOffset_applied->factor != AspectFace_set->PolygonOffset().factor
-     || PolygonOffset_applied->units  != AspectFace_set->PolygonOffset().units)
+    if (PolygonOffset_applied.mode   != AspectFace_set->PolygonOffset().mode
+     || PolygonOffset_applied.factor != AspectFace_set->PolygonOffset().factor
+     || PolygonOffset_applied.units  != AspectFace_set->PolygonOffset().units)
     {
-      PolygonOffset_applied = &AspectFace_set->PolygonOffset();
-      TelUpdatePolygonOffsets (PolygonOffset_applied);
+      SetPolygonOffset (AspectFace_set->PolygonOffset().mode,
+                        AspectFace_set->PolygonOffset().factor,
+                        AspectFace_set->PolygonOffset().units);
     }
   }
 
@@ -429,6 +441,21 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th
   return AspectFace_set;
 }
 
+//=======================================================================
+//function : SetPolygonOffset
+//purpose  :
+//=======================================================================
+void OpenGl_Workspace::SetPolygonOffset (int theMode,
+                                         Standard_ShortReal theFactor,
+                                         Standard_ShortReal theUnits)
+{
+  PolygonOffset_applied.mode   = theMode;
+  PolygonOffset_applied.factor = theFactor;
+  PolygonOffset_applied.units  = theUnits;
+
+  TelUpdatePolygonOffsets (PolygonOffset_applied);
+}
+
 /*----------------------------------------------------------------------*/
 
 const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply)
diff --git a/tests/bugs/vis/bug24867 b/tests/bugs/vis/bug24867
new file mode 100644 (file)
index 0000000..b256172
--- /dev/null
@@ -0,0 +1,20 @@
+puts "============"
+puts "CR24867"
+puts "============"
+puts ""
+
+#######################################################################
+#  Test for displaying highlighted representation of a complex shape
+#######################################################################
+
+restore [locate_data_file Bottom.brep] obj 
+vinit
+vdisplay obj
+vsetdispmode 1
+vfit
+
+vmoveto 235 213
+vdump $imagedir/${casename}_highlighted.png
+
+vselect 235 213
+vdump $imagedir/${casename}_selected.png