]> OCCT Git - occt.git/commitdiff
0031702: Visualization, TKOpenGl - hatching interior is ignored in second View within...
authorkgv <kgv@opencascade.com>
Mon, 10 Aug 2020 08:23:56 +0000 (11:23 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 14 Aug 2020 09:46:34 +0000 (12:46 +0300)
Current state variables have been moved out from OpenGl_LineAttributes to OpenGl_Context.

src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_Context.hxx
src/OpenGl/OpenGl_LineAttributes.cxx
src/OpenGl/OpenGl_LineAttributes.hxx
tests/bugs/vis/bug31702 [new file with mode: 0644]

index 01413d530b373486ab43e5d24568c843ad35f85d..257f8d425faa5979f61318fd9ecc3c515f120782 100644 (file)
@@ -221,6 +221,8 @@ OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
   myPBRSpecIBLMapTexUnit   (Graphic3d_TextureUnit_PbrIblSpecular),
   myFrameStats (new OpenGl_FrameStats()),
   myActiveMockTextures (0),
+  myActiveHatchType (Aspect_HS_SOLID),
+  myHatchIsEnabled (false),
 #if !defined(GL_ES_VERSION_2_0)
   myPointSpriteOrig (GL_UPPER_LEFT),
   myRenderMode (GL_RENDER),
@@ -4339,16 +4341,29 @@ Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode)
 // =======================================================================
 bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
 {
-  if (myHatchStyles.IsNull())
+  if (core11 == NULL)
   {
     return false;
   }
-  else if (myHatchStyles->IsEnabled() == theIsEnabled)
+  else if (myHatchIsEnabled == theIsEnabled)
   {
     return theIsEnabled;
   }
 
-  return myHatchStyles->SetEnabled (this, theIsEnabled);
+  const bool anOldIsEnabled = myHatchIsEnabled;
+#if !defined(GL_ES_VERSION_2_0)
+  if (theIsEnabled
+   && myActiveHatchType != Aspect_HS_SOLID)
+  {
+    core11fwd->glEnable (GL_POLYGON_STIPPLE);
+  }
+  else
+  {
+    core11fwd->glDisable (GL_POLYGON_STIPPLE);
+  }
+#endif
+  myHatchIsEnabled = theIsEnabled;
+  return anOldIsEnabled;
 }
 
 // =======================================================================
@@ -4357,26 +4372,43 @@ bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
 // =======================================================================
 Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle)
 {
-  if (theStyle.IsNull())
+  const Standard_Integer aNewStyle = !theStyle.IsNull() ? theStyle->HatchType() : Aspect_HS_SOLID;
+  if (myActiveHatchType == aNewStyle
+   || core11 == NULL)
   {
-    return 0;
+    return myActiveHatchType;
   }
 
-  if (myHatchStyles.IsNull())
+#if !defined(GL_ES_VERSION_2_0)
+  if (aNewStyle == Aspect_HS_SOLID)
   {
-    if (!GetResource ("OpenGl_LineAttributes", myHatchStyles))
+    if (myHatchIsEnabled)
     {
-      // share and register for release once the resource is no longer used
-      myHatchStyles = new OpenGl_LineAttributes();
-      ShareResource ("OpenGl_LineAttributes", myHatchStyles);
+      core11fwd->glDisable (GL_POLYGON_STIPPLE);
     }
+    return myActiveHatchType;
   }
-  if (myHatchStyles->TypeOfHatch() == theStyle->HatchType())
+
+  if (myHatchStyles.IsNull()
+  && !GetResource ("OpenGl_LineAttributes", myHatchStyles))
   {
-    return theStyle->HatchType();
+    // share and register for release once the resource is no longer used
+    myHatchStyles = new OpenGl_LineAttributes();
+    ShareResource ("OpenGl_LineAttributes", myHatchStyles);
   }
 
-  return myHatchStyles->SetTypeOfHatch (this, theStyle);
+  const Standard_Integer anOldType = myActiveHatchType;
+  myActiveHatchType = aNewStyle;
+  myHatchStyles->SetTypeOfHatch (this, theStyle);
+  if (myHatchIsEnabled
+   && anOldType == Aspect_HS_SOLID)
+  {
+    core11fwd->glEnable (GL_POLYGON_STIPPLE);
+  }
+  return anOldType;
+#else
+  return myActiveHatchType;
+#endif
 }
 
 // =======================================================================
index aed802a306704c427708b20a6385438c15df31e7..916478e1a47f26f7fe4a6c014f7e3d01ee522e5d 100644 (file)
@@ -652,10 +652,7 @@ public:
   Standard_EXPORT Standard_Integer SetPolygonMode (const Standard_Integer theMode);
 
   //! @return cached enabled state of polygon hatching rasterization.
-  bool IsPolygonHatchEnabled() const
-  {
-    return !myHatchStyles.IsNull() && myHatchStyles->TypeOfHatch() != 0;
-  }
+  bool IsPolygonHatchEnabled() const { return myHatchIsEnabled; }
 
   //! Sets enabled state of polygon hatching rasterization
   //! without affecting currently selected hatching pattern.
@@ -663,10 +660,7 @@ public:
   Standard_EXPORT bool SetPolygonHatchEnabled (const bool theIsEnabled);
 
   //! @return cached state of polygon hatch type.
-  Standard_Integer PolygonHatchStyle() const
-  {
-    return myHatchStyles.IsNull() ? Aspect_HS_SOLID : myHatchStyles->TypeOfHatch();
-  }
+  Standard_Integer PolygonHatchStyle() const { return myActiveHatchType; }
 
   //! Sets polygon hatch pattern.
   //! Zero-index value is a default alias for solid filling.
@@ -1180,6 +1174,8 @@ private: //! @name fields tracking current state
   Standard_Integer              myActiveMockTextures; //!< currently active mock sampler objects
   Handle(OpenGl_FrameBuffer)    myDefaultFbo;      //!< default Frame Buffer Object
   Handle(OpenGl_LineAttributes) myHatchStyles;     //!< resource holding predefined hatch styles patterns
+  Standard_Integer              myActiveHatchType; //!< currently activated type of polygon hatch
+  Standard_Boolean              myHatchIsEnabled;  //!< current enabled state of polygon hatching rasterization
   Handle(OpenGl_Texture)        myTextureRgbaBlack;//!< mock black texture returning (0, 0, 0, 0)
   Handle(OpenGl_Texture)        myTextureRgbaWhite;//!< mock white texture returning (1, 1, 1, 1)
   Standard_Integer              myViewport[4];     //!< current viewport
index c4b09b4d3288de25844c87c9573794c806a2361e..58b01486d8f9815b45db0aa02a9e566298605359 100644 (file)
@@ -25,8 +25,6 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
 // purpose  :
 // =======================================================================
 OpenGl_LineAttributes::OpenGl_LineAttributes()
-: myTypeOfHatch (0),
-  myIsEnabled (true)
 {
   //
 }
@@ -46,9 +44,9 @@ OpenGl_LineAttributes::~OpenGl_LineAttributes()
 // =======================================================================
 void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
 {
-  // Delete surface patterns
 #if !defined(GL_ES_VERSION_2_0)
-  if (theGlCtx != NULL && theGlCtx->IsValid())
+  if (theGlCtx != NULL
+   && theGlCtx->IsValid())
   {
     for (OpenGl_MapOfHatchStylesAndIds::Iterator anIter (myStyles); anIter.More(); anIter.Next())
     {
@@ -56,9 +54,9 @@ void OpenGl_LineAttributes::Release (OpenGl_Context* theGlCtx)
     }
   }
 #else
-    (void )theGlCtx;
+  (void )theGlCtx;
 #endif
-    myStyles.Clear();
+  myStyles.Clear();
 }
 
 // =======================================================================
@@ -69,12 +67,7 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
                                           const Handle(Graphic3d_HatchStyle)& theStyle)
 {
 #if !defined(GL_ES_VERSION_2_0)
-  if (theGlCtx->core11 == NULL)
-  {
-    return 0;
-  }
-
-  const unsigned int aListId = glGenLists(1);
+  const unsigned int aListId = theGlCtx->core11->glGenLists(1);
   theGlCtx->core11->glNewList ((GLuint)aListId, GL_COMPILE);
   theGlCtx->core11->glPolygonStipple ((const GLubyte*)theStyle->Pattern());
   theGlCtx->core11->glEndList();
@@ -90,17 +83,16 @@ unsigned int OpenGl_LineAttributes::init (const OpenGl_Context* theGlCtx,
 // function : SetTypeOfHatch
 // purpose  :
 // =======================================================================
-int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
-                                           const Handle(Graphic3d_HatchStyle)& theStyle)
+bool OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
+                                            const Handle(Graphic3d_HatchStyle)& theStyle)
 {
-  // Return if not initialized
-  if (theStyle.IsNull())
+  if (theStyle.IsNull()
+   || theStyle->HatchType() == Aspect_HS_SOLID
+   || theGlCtx->core11 == NULL)
   {
-    return 0;
+    return false;
   }
 
-  const int anOldType = myTypeOfHatch;
-
   unsigned int aGpuListId = 0;
   if (!myStyles.Find (theStyle, aGpuListId))
   {
@@ -109,66 +101,7 @@ int OpenGl_LineAttributes::SetTypeOfHatch (const OpenGl_Context*               t
   }
 
 #if !defined(GL_ES_VERSION_2_0)
-  if (theGlCtx->core11 == NULL)
-  {
-    return 0;
-  }
-  else if (theStyle->HatchType() != 0)
-  {
-    theGlCtx->core11->glCallList ((GLuint)aGpuListId);
-
-    if (myIsEnabled)
-    {
-      theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
-    }
-  }
-  else
-  {
-    theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
-  }
-#else
-  (void )theGlCtx;
-#endif
-  myTypeOfHatch = theStyle->HatchType();
-
-  return anOldType;
-}
-
-// =======================================================================
-// function : SetEnabled
-// purpose  :
-// =======================================================================
-bool OpenGl_LineAttributes::SetEnabled (const OpenGl_Context* theGlCtx,
-                                        const bool theToEnable)
-{
-  // Return if not initialized
-  if (myStyles.IsEmpty())
-  {
-    return false;
-  }
-
-  const bool anOldIsEnabled = myIsEnabled;
-
-#if !defined(GL_ES_VERSION_2_0)
-  if (theGlCtx->core11 == NULL)
-  {
-    return 0;
-  }
-  else if (theToEnable)
-  {
-    if (myTypeOfHatch != 0)
-    {
-      theGlCtx->core11fwd->glEnable (GL_POLYGON_STIPPLE);
-    }
-  }
-  else
-  {
-    theGlCtx->core11fwd->glDisable (GL_POLYGON_STIPPLE);
-  }
-#else
-  (void )theGlCtx;
+  theGlCtx->core11->glCallList ((GLuint)aGpuListId);
 #endif
-  myIsEnabled = theToEnable;
-
-  return anOldIsEnabled;
+  return true;
 }
index 926f12b8daae9a9b332db52797e1b01ee7d753a3..deefbf06756f005fb9dc8c4be0fb770260cd149c 100644 (file)
@@ -18,9 +18,6 @@
 
 #include <OpenGl_Resource.hxx>
 
-#include <Aspect_TypeOfLine.hxx>
-#include <Aspect_TypeOfMarker.hxx>
-#include <Font_FontAspect.hxx>
 #include <Graphic3d_HatchStyle.hxx>
 #include <NCollection_DataMap.hxx>
 
@@ -28,26 +25,16 @@ typedef NCollection_DataMap<Handle(Graphic3d_HatchStyle), unsigned int> OpenGl_M
 
 class OpenGl_Context;
 
-//! Utility class to manage OpenGL state of polygon hatching rasterization
-//! and keeping its cached state. The hatching rasterization is implemented
-//! using glPolygonStipple function of OpenGL. State of hatching is controlled
-//! by two parameters - type of hatching and IsEnabled parameter.
-//! The hatching rasterization is enabled only if non-zero index pattern type
-//! is selected (zero by default is reserved for solid filling) and if
-//! IsEnabled flag is set to true. The IsEnabled parameter is useful for temporarily
-//! turning on/off the hatching rasterization without making any costly GL calls
-//! for changing the hatch pattern. This is a sharable resource class - it creates
-//! OpenGL context objects for each hatch pattern to achieve quicker switching between
-//! them, thesse GL objects are freed when the resource is released by owner context.
-//! @note The implementation is not supported by Core Profile and by ES version.
+DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
+
+//! Utility class to manage OpenGL resources of polygon hatching styles.
+//! @note the implementation is not supported by Core Profile and by ES version.
 class OpenGl_LineAttributes : public OpenGl_Resource
 {
+  DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes, OpenGl_Resource)
 public:
 
   //! Default constructor.
-  //! By default the parameters are:
-  //! - IsEnabled (true),
-  //! - TypeOfHatch (0).
   Standard_EXPORT OpenGl_LineAttributes();
 
   //! Default destructor.
@@ -59,35 +46,19 @@ public:
   //! Returns estimated GPU memory usage - not implemented.
   virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
 
-  //! Index of currently selected type of hatch.
-  int TypeOfHatch() const { return myTypeOfHatch; }
-
   //! Sets type of the hatch.
-  Standard_EXPORT int SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
-                                      const Handle(Graphic3d_HatchStyle)& theStyle);
-
-  //! Current enabled state of the hatching rasterization.
-  bool IsEnabled() const { return myIsEnabled; }
-
-  //! Turns on/off the hatching rasterization rasterization.
-  Standard_EXPORT bool SetEnabled (const OpenGl_Context* theGlCtx, const bool theToEnable);
+  Standard_EXPORT bool SetTypeOfHatch (const OpenGl_Context*               theGlCtx,
+                                       const Handle(Graphic3d_HatchStyle)& theStyle);
 
-protected:
+private:
 
   unsigned int init (const OpenGl_Context* theGlCtx,
                      const Handle(Graphic3d_HatchStyle)& theStyle);
 
 protected:
 
-  int myTypeOfHatch; //!< Currently activated type of hatch
-  bool myIsEnabled; //!< Current enabled state of hatching rasterization.
   OpenGl_MapOfHatchStylesAndIds myStyles; //!< Hatch patterns
 
-public:
-
-  DEFINE_STANDARD_RTTIEXT(OpenGl_LineAttributes,OpenGl_Resource)
 };
 
-DEFINE_STANDARD_HANDLE(OpenGl_LineAttributes, OpenGl_Resource)
-
 #endif // _OpenGl_LineAttributes_Header
diff --git a/tests/bugs/vis/bug31702 b/tests/bugs/vis/bug31702
new file mode 100644 (file)
index 0000000..10408af
--- /dev/null
@@ -0,0 +1,23 @@
+puts "============"
+puts "0031702: Visualization, TKOpenGl - hatching interior is ignored in second View within the Viewer"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+vclear
+vclose *
+vinit v1/v1
+box b1 100 200 300
+vdisplay -dispMode 1 b1
+vfit
+vaspects b1 -interior hatch
+if { [vreadpixel 201 200 -rgb -name] != "BLACK" } { puts "Error: no hatching in first view" }
+vdump ${imagedir}/${casename}_v1.png
+
+vinit v2/v1
+box b2 100 200 300
+vdisplay -dispMode 1 b2
+vfit
+vaspects b2 -interior hatch
+if { [vreadpixel 201 200 -rgb -name] != "BLACK" } { puts "Error: no hatching in second view" }
+vdump ${imagedir}/${casename}_v2.png