0031505: Point Cloud Rendering - fix on-screen statistics about number of visible...
authorkgv <kgv@opencascade.com>
Fri, 17 Apr 2020 07:36:57 +0000 (10:36 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 17 Apr 2020 15:36:43 +0000 (18:36 +0300)
OpenGl_Element now provide methods ::UpdateMemStats() and ::UpdateDrawStats()
for unified request of statistics used by OpenGl_FrameStats instead of direct handling of OpenGl_PrimitiveArray.
Graphic3d_FrameStatsCounter counters list has been extended by Graphic3d_FrameStatsCounter_NbLinesNotCulled.

src/Graphic3d/Graphic3d_FrameStats.cxx
src/Graphic3d/Graphic3d_FrameStatsCounter.hxx
src/Graphic3d/Graphic3d_RenderingParams.hxx
src/OpenGl/OpenGl_Element.cxx
src/OpenGl/OpenGl_Element.hxx
src/OpenGl/OpenGl_FrameStats.cxx
src/OpenGl/OpenGl_PrimitiveArray.cxx
src/OpenGl/OpenGl_PrimitiveArray.hxx
src/OpenGl/OpenGl_Text.cxx
src/OpenGl/OpenGl_Text.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx

index eabb962..01e0c65 100644 (file)
@@ -305,6 +305,7 @@ TCollection_AsciiString Graphic3d_FrameStats::FormatStats (Graphic3d_RenderingPa
   if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Groups) != 0
    || (theFlags & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0
    || (theFlags & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0
+   || (theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0
    || (theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0
    || (!myIsLongLineFormat
     && ((theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0
@@ -338,6 +339,10 @@ TCollection_AsciiString Graphic3d_FrameStats::FormatStats (Graphic3d_RenderingPa
   {
     formatCounter (aBuf, aValWidth, " Triangles: ", aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled], "\n");
   }
+  if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
+  {
+    formatCounter (aBuf, aValWidth, "     Lines: ", aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled], "\n");
+  }
   if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
   {
     formatCounter (aBuf, aValWidth, "    Points: ", aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled], "\n");
@@ -437,6 +442,10 @@ void Graphic3d_FrameStats::FormatStats (TColStd_IndexedDataMapOfStringString&
   {
     addInfo (theDict, "Rendered triangles", aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled]);
   }
+  if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
+  {
+    addInfo (theDict, "Rendered lines", aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled]);
+  }
   if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
   {
     addInfo (theDict, "Rendered points", aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled]);
index f0a41e5..137cc4c 100644 (file)
@@ -28,7 +28,9 @@ enum Graphic3d_FrameStatsCounter
   Graphic3d_FrameStatsCounter_NbElemsPointNotCulled,  //!< number of not culled OpenGl_PrimitiveArray drawing points
   Graphic3d_FrameStatsCounter_NbElemsTextNotCulled,   //!< number of not culled OpenGl_Text
   Graphic3d_FrameStatsCounter_NbTrianglesNotCulled,   //!< number of not culled (as structure) triangles
+  Graphic3d_FrameStatsCounter_NbLinesNotCulled,       //!< number of not culled (as structure) line segments
   Graphic3d_FrameStatsCounter_NbPointsNotCulled,      //!< number of not culled (as structure) points
+  //Graphic3d_FrameStatsCounter_NbGlyphsNotCulled,    //!< number glyphs, to be considered in future
   Graphic3d_FrameStatsCounter_EstimatedBytesGeom,     //!< estimated GPU memory used for geometry
   Graphic3d_FrameStatsCounter_EstimatedBytesFbos,     //!< estimated GPU memory used for FBOs
   Graphic3d_FrameStatsCounter_EstimatedBytesTextures, //!< estimated GPU memory used for textures
index fa18c5b..f445930 100644 (file)
@@ -60,19 +60,20 @@ public:
     //
     PerfCounters_Triangles   = 0x040, //!< count Triangles
     PerfCounters_Points      = 0x080, //!< count Points
+    PerfCounters_Lines       = 0x100, //!< count Line segments
     //
-    PerfCounters_EstimMem    = 0x100, //!< estimated GPU memory usage
+    PerfCounters_EstimMem    = 0x200, //!< estimated GPU memory usage
     //
-    PerfCounters_FrameTime   = 0x200, //!< frame CPU utilization time (rendering thread); @sa Graphic3d_FrameStatsTimer
-    PerfCounters_FrameTimeMax= 0x400, //!< maximum frame times
+    PerfCounters_FrameTime   = 0x400, //!< frame CPU utilization time (rendering thread); @sa Graphic3d_FrameStatsTimer
+    PerfCounters_FrameTimeMax= 0x800, //!< maximum frame times
     //
-    PerfCounters_SkipImmediate = 0x800, //!< do not include immediate viewer updates (e.g. lazy updates without redrawing entire view content)
+    PerfCounters_SkipImmediate = 0x1000, //!< do not include immediate viewer updates (e.g. lazy updates without redrawing entire view content)
     //! show basic statistics
     PerfCounters_Basic = PerfCounters_FrameRate | PerfCounters_CPU | PerfCounters_Layers | PerfCounters_Structures,
     //! extended (verbose) statistics
     PerfCounters_Extended = PerfCounters_Basic
                           | PerfCounters_Groups | PerfCounters_GroupArrays
-                          | PerfCounters_Triangles | PerfCounters_Points
+                          | PerfCounters_Triangles | PerfCounters_Points | PerfCounters_Lines
                           | PerfCounters_EstimMem,
     //! all counters
     PerfCounters_All = PerfCounters_Extended
index 6f8d872..28fcc76 100755 (executable)
@@ -15,6 +15,7 @@
 
 #include <OpenGl_Element.hxx>
 
+#include <Graphic3d_FrameStatsData.hxx>
 #include <Standard_Dump.hxx>
 
 // =======================================================================
@@ -36,6 +37,25 @@ OpenGl_Element::~OpenGl_Element()
 }
 
 // =======================================================================
+// function : UpdateMemStats
+// purpose  :
+// =======================================================================
+void OpenGl_Element::UpdateMemStats (Graphic3d_FrameStatsDataTmp& theStats) const
+{
+  theStats[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += EstimatedDataSize();
+}
+
+// =======================================================================
+// function : UpdateDrawStats
+// purpose  :
+// =======================================================================
+void OpenGl_Element::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& ,
+                                      bool ) const
+{
+  //
+}
+
+// =======================================================================
 // function : DumpJson
 // purpose  :
 // =======================================================================
index 324aa7d..f4c6769 100644 (file)
@@ -19,6 +19,7 @@
 #include <OpenGl_RenderFilter.hxx>
 #include <Standard_Type.hxx>
 
+class Graphic3d_FrameStatsDataTmp;
 class OpenGl_Workspace;
 class OpenGl_Context;
 
@@ -63,6 +64,16 @@ public:
   //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
   virtual Standard_Size EstimatedDataSize() const { return 0; }
 
+  //! Increment memory usage statistics.
+  //! Default implementation puts EstimatedDataSize() into Graphic3d_FrameStatsCounter_EstimatedBytesGeom.
+  Standard_EXPORT virtual void UpdateMemStats (Graphic3d_FrameStatsDataTmp& theStats) const;
+
+  //! Increment draw calls statistics.
+  //! @param theStats [in] [out] frame counters to increment
+  //! @param theIsDetailed  [in] indicate detailed dump (more counters - number of triangles, points, etc.)
+  Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+                                                 bool theIsDetailed) const;
+
   //! Update parameters of the drawable elements.
   virtual void SynchronizeAspects() {}
 
index b34eb69..9828dd4 100644 (file)
@@ -92,6 +92,7 @@ void OpenGl_FrameStats::updateStatistics (const Handle(Graphic3d_CView)& theView
   const Graphic3d_RenderingParams::PerfCounters aBits = theView->RenderingParams().CollectedStats;
   const Standard_Boolean toCountMem     = (aBits & Graphic3d_RenderingParams::PerfCounters_EstimMem)  != 0;
   const Standard_Boolean toCountTris    = (aBits & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0
+                                       || (aBits & Graphic3d_RenderingParams::PerfCounters_Lines)     != 0
                                        || (aBits & Graphic3d_RenderingParams::PerfCounters_Points)    != 0;
   const Standard_Boolean toCountElems   = (aBits & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0 || toCountTris || toCountMem;
   const Standard_Boolean toCountGroups  = (aBits & Graphic3d_RenderingParams::PerfCounters_Groups)      != 0 || toCountElems;
@@ -207,7 +208,7 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
             const OpenGl_Group* aGroup = aGroupIter.Value();
             for (const OpenGl_ElementNode* aNodeIter = aGroup->FirstNode(); aNodeIter != NULL; aNodeIter = aNodeIter->next)
             {
-              myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += aNodeIter->elem->EstimatedDataSize();
+              aNodeIter->elem->UpdateMemStats (myCountersTmp);
             }
           }
         }
@@ -227,92 +228,9 @@ void OpenGl_FrameStats::updateStructures (Standard_Integer theViewId,
         {
           if (theToCountMem)
           {
-            myCountersTmp[Graphic3d_FrameStatsCounter_EstimatedBytesGeom] += aNodeIter->elem->EstimatedDataSize();
-          }
-          if (const OpenGl_PrimitiveArray* aPrim = dynamic_cast<const OpenGl_PrimitiveArray*> (aNodeIter->elem))
-          {
-            ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
-            if (aPrim->IsFillDrawMode())
-            {
-              ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled];
-              if (!theToCountTris)
-              {
-                continue;
-              }
-
-              const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo();
-              if (anAttribs.IsNull()
-              || !anAttribs->IsValid())
-              {
-                continue;
-              }
-
-              const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo();
-              const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb();
-              const Standard_Integer aNbBounds  = !aPrim->Bounds().IsNull() ? aPrim->Bounds()->NbBounds : 1;
-              switch (aPrim->DrawMode())
-              {
-                case GL_TRIANGLES:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3;
-                  break;
-                }
-                case GL_TRIANGLE_STRIP:
-                case GL_TRIANGLE_FAN:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds;
-                  break;
-                }
-                case GL_TRIANGLES_ADJACENCY:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6;
-                  break;
-                }
-                case GL_TRIANGLE_STRIP_ADJACENCY:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds;
-                  break;
-                }
-              #if !defined(GL_ES_VERSION_2_0)
-                case GL_QUADS:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2;
-                  break;
-                }
-                case GL_QUAD_STRIP:
-                {
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2;
-                  break;
-                }
-              #endif
-              }
-            }
-            else if (aPrim->DrawMode() == GL_POINTS)
-            {
-              ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled];
-              if (theToCountTris)
-              {
-                const Handle(OpenGl_VertexBuffer)& anAttribs = aPrim->AttributesVbo();
-                if (!anAttribs.IsNull()
-                  && anAttribs->IsValid())
-                {
-                  const Handle(OpenGl_VertexBuffer)& anIndices = aPrim->IndexVbo();
-                  const Standard_Integer aNbIndices = !anIndices.IsNull() ? anIndices->GetElemsNb() : anAttribs->GetElemsNb();
-                  myCountersTmp[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices;
-                }
-              }
-            }
-            else
-            {
-              ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled];
-            }
-          }
-          else if (const OpenGl_Text* aText = dynamic_cast<const OpenGl_Text*> (aNodeIter->elem))
-          {
-            (void )aText;
-            ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
-            ++myCountersTmp[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled];
+            aNodeIter->elem->UpdateMemStats (myCountersTmp);
           }
+          aNodeIter->elem->UpdateDrawStats (myCountersTmp, theToCountTris);
         }
       }
     }
index 97c28f2..38f0475 100644 (file)
@@ -777,6 +777,99 @@ Standard_Size OpenGl_PrimitiveArray::EstimatedDataSize() const
 }
 
 // =======================================================================
+// function : UpdateDrawStats
+// purpose  :
+// =======================================================================
+void OpenGl_PrimitiveArray::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+                                             bool theIsDetailed) const
+{
+  ++theStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
+  if (myIsFillType)
+  {
+    ++theStats[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled];
+  }
+  else if (myDrawMode == GL_POINTS)
+  {
+    ++theStats[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled];
+  }
+  else
+  {
+    ++theStats[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled];
+  }
+
+  if (!theIsDetailed
+  ||  myVboAttribs.IsNull()
+  || !myVboAttribs->IsValid())
+  {
+    return;
+  }
+
+  const Standard_Integer aNbIndices = !myVboIndices.IsNull() ? myVboIndices->GetElemsNb() : myVboAttribs->GetElemsNb();
+  const Standard_Integer aNbBounds  = !myBounds.IsNull() ? myBounds->NbBounds : 1;
+  switch (myDrawMode)
+  {
+    case GL_POINTS:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled] += aNbIndices;
+      break;
+    }
+    case GL_LINES:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 2;
+      break;
+    }
+    case GL_LINE_STRIP:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - aNbBounds;
+      break;
+    }
+    case GL_LINES_ADJACENCY:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices / 4;
+      break;
+    }
+    case GL_LINE_STRIP_ADJACENCY:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled] += aNbIndices - 4 * aNbBounds;
+      break;
+    }
+    case GL_TRIANGLES:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 3;
+      break;
+    }
+    case GL_TRIANGLE_STRIP:
+    case GL_TRIANGLE_FAN:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 2 * aNbBounds;
+      break;
+    }
+    case GL_TRIANGLES_ADJACENCY:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 6;
+      break;
+    }
+    case GL_TRIANGLE_STRIP_ADJACENCY:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices - 4 * aNbBounds;
+      break;
+    }
+  #if !defined(GL_ES_VERSION_2_0)
+    case GL_QUADS:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aNbIndices / 2;
+      break;
+    }
+    case GL_QUAD_STRIP:
+    {
+      theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += (aNbIndices / 2 - aNbBounds) * 2;
+      break;
+    }
+  #endif
+  }
+}
+
+// =======================================================================
 // function : Render
 // purpose  :
 // =======================================================================
index 6947e63..7f98265 100644 (file)
@@ -61,6 +61,10 @@ public:
   //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
   Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
 
+  //! Increment draw calls statistics.
+  Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+                                                bool theIsDetailed) const Standard_OVERRIDE;
+
   //! Return true if VBOs initialization has been performed.
   //! VBO initialization is performed during first Render() call.
   //! Notice that this flag does not indicate VBOs validity.
index 4692b5e..a3c5be6 100644 (file)
@@ -232,6 +232,27 @@ Standard_Size OpenGl_Text::EstimatedDataSize() const
 }
 
 // =======================================================================
+// function : UpdateDrawStats
+// purpose  :
+// =======================================================================
+void OpenGl_Text::UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+                                   bool theIsDetailed) const
+{
+  ++theStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled];
+  ++theStats[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled];
+  if (theIsDetailed)
+  {
+    for (Standard_Integer anIter = myVertsVbo.Lower(); anIter <= myVertsVbo.Upper(); ++anIter)
+    {
+      if (const Handle(OpenGl_VertexBuffer)& aVerts = myVertsVbo.Value (anIter))
+      {
+        theStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled] += aVerts->GetElemsNb() / 3; // 2 non-indexed triangles per glyph
+      }
+    }
+  }
+}
+
+// =======================================================================
 // function : StringSize
 // purpose  :
 // =======================================================================
index a8a3cb3..5d8ac6f 100755 (executable)
@@ -71,6 +71,10 @@ public:
   //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
   Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
 
+  //! Increment draw calls statistics.
+  Standard_EXPORT virtual void UpdateDrawStats (Graphic3d_FrameStatsDataTmp& theStats,
+                                                bool theIsDetailed) const Standard_OVERRIDE;
+
 public: //! @name methods for compatibility with layers
 
   //! Empty constructor
index c64f279..9bc02b1 100644 (file)
@@ -11325,6 +11325,7 @@ static Standard_Boolean parsePerfStatsFlag (const TCollection_AsciiString& theVa
         || aVal == "triangles")  aFlag = Graphic3d_RenderingParams::PerfCounters_Triangles;
   else if (aVal == "pnts"
         || aVal == "points")     aFlag = Graphic3d_RenderingParams::PerfCounters_Points;
+  else if (aVal == "lines")      aFlag = Graphic3d_RenderingParams::PerfCounters_Lines;
   else if (aVal == "mem"
         || aVal == "gpumem"
         || aVal == "estimmem")   aFlag = Graphic3d_RenderingParams::PerfCounters_EstimMem;
@@ -11519,6 +11520,10 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
       {
         theDI << " tris";
       }
+      if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
+      {
+        theDI << " lines";
+      }
       if ((aParams.CollectedStats & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
       {
         theDI << " pnts";
@@ -12496,6 +12501,7 @@ static Standard_Integer VStatProfiler (Draw_Interpretor& theDI,
             || aFlag == "pointarrays"
             || aFlag == "textarrays") aParam = Graphic3d_RenderingParams::PerfCounters_GroupArrays;
       else if (aFlag == "triangles")  aParam = Graphic3d_RenderingParams::PerfCounters_Triangles;
+      else if (aFlag == "lines")      aParam = Graphic3d_RenderingParams::PerfCounters_Lines;
       else if (aFlag == "points")     aParam = Graphic3d_RenderingParams::PerfCounters_Points;
       else if (aFlag == "geommem"
             || aFlag == "texturemem"