]> OCCT Git - occt.git/commitdiff
review fix
authorhossamali <Hossam.Ali@opencascade.com>
Wed, 13 Mar 2024 15:08:37 +0000 (15:08 +0000)
committerhossamali <Hossam.Ali@opencascade.com>
Mon, 18 Mar 2024 23:19:35 +0000 (23:19 +0000)
17 files changed:
src/Graphic3d/FILES
src/Graphic3d/Graphic3d_CStructure.hxx
src/Graphic3d/Graphic3d_CView.hxx
src/Graphic3d/Graphic3d_OcclusionQuery.cxx [deleted file]
src/Graphic3d/Graphic3d_OcclusionQuery.hxx [deleted file]
src/Graphic3d/Graphic3d_ViewOcclusionMask.cxx [deleted file]
src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx
src/OpenGl/OpenGl_LayerList.cxx
src/OpenGl/OpenGl_LayerList.hxx
src/OpenGl/OpenGl_OcclusionQuery.cxx
src/OpenGl/OpenGl_OcclusionQuery.hxx
src/OpenGl/OpenGl_Structure.cxx
src/OpenGl/OpenGl_Structure.hxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/occlusion/boxes

index f83c2db19f783c88f5cafc752d84727b18f97c5c..b1812c88f0b0343b7aa37f4639106a0b05a2f404 100755 (executable)
@@ -208,7 +208,4 @@ Graphic3d_Layer.cxx
 Graphic3d_Layer.hxx
 Graphic3d_ZLayerId.hxx
 Graphic3d_ZLayerSettings.hxx
-Graphic3d_OcclusionQuery.hxx
-Graphic3d_OcclusionQuery.cxx
 Graphic3d_ViewOcclusionMask.hxx
-Graphic3d_ViewOcclusionMask.cxx
index 0a4f2344a762aa5d7f5b474b53dbe7d4abb0c1e6..2c5d0117fb47e5c49c51ad3d989b51fca3867a8f 100644 (file)
@@ -167,13 +167,15 @@ public:
 
   //! Returns True if the structure occulded in specified view, otherwise
   //! returns False.
-  Standard_Boolean IsOccluded(const Standard_Integer theViewId) const {
+  Standard_Boolean IsOccluded(const Standard_Integer theViewId) const 
+  {
     return (!OcclusionMask->IsVisible(theViewId));
   }
 
   //! Marks structure as Occluded by other strcuture in specified view,!
-  void SetOccluded(const Standard_Integer theViewId) const {
-    OcclusionMask->SetVisible(Standard_False, theViewId);
+  void SetOccluionSate(const Standard_Integer theViewId, const bool theIsVisible) const 
+  {
+    OcclusionMask->SetVisible(theViewId, !theIsVisible);
   }
 
   //! Returns whether check of object's bounding box clipping is enabled before drawing of object; TRUE by default.
@@ -229,8 +231,8 @@ public:
 
 public:
 
-  Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
-  Handle(Graphic3d_ViewOcclusionMask) OcclusionMask; //!< view occlusion mask
+  Handle(Graphic3d_ViewAffinity) ViewAffinity;        //!< view affinity mask
+  Handle(Graphic3d_ViewOcclusionMask) OcclusionMask;  //!< view occlusion mask
 
 protected:
 
index 53351b7c08c275269285af84988fe23ee53154ee..5a2506aeff479e7a1f634228b1adaa9675137fa4 100644 (file)
@@ -132,6 +132,9 @@ public:
 
   //! Returns number of occluded strcutures in the view
   Standard_EXPORT void OccludedStructures(Graphic3d_MapOfStructure& theStructures) const;
+  //! update occlusion test for dispalyed strcutures in the view
+  Standard_EXPORT virtual void UpdateOcclusion() = 0 ;
 
   //! Returns number of displayed structures in the view.
   virtual Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); }
diff --git a/src/Graphic3d/Graphic3d_OcclusionQuery.cxx b/src/Graphic3d/Graphic3d_OcclusionQuery.cxx
deleted file mode 100644 (file)
index 1df0447..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// Created on: 2024-02-20
-// Created by: Hossam Ali
-// Copyright (c) 2024 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in
-// OCCT distribution for complete text of the license and disclaimer of any
-// warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Graphic3d_OcclusionQuery.hxx>
-
-#include <Standard_Dump.hxx>
-
-IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_OcclusionQuery, Standard_Transient)
-
-// =======================================================================
-// function : GetNumSamplesPassed
-// purpose  :
-// =======================================================================
-unsigned int Graphic3d_OcclusionQuery::GetNumSamplesPassed() const {
-  return samplesPassed;
-}
-
-// =======================================================================
-// function : AnySamplesPassed
-// purpose  :
-// =======================================================================
-bool Graphic3d_OcclusionQuery::AnySamplesPassed() const {
-  return samplesPassed > 0;
-}
-
-// =======================================================================
-// function : DumpJson
-// purpose  :
-// =======================================================================
-void Graphic3d_OcclusionQuery::DumpJson(Standard_OStream &theOStream,
-                                        Standard_Integer) const {
-  OCCT_DUMP_TRANSIENT_CLASS_BEGIN(theOStream)
-
-  OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, queryID)
-  OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, samplesPassed)
-}
\ No newline at end of file
diff --git a/src/Graphic3d/Graphic3d_OcclusionQuery.hxx b/src/Graphic3d/Graphic3d_OcclusionQuery.hxx
deleted file mode 100644 (file)
index a0426f0..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Created on: 2024-02-20
-// Created by: Hossam Ali
-// Copyright (c) 2024 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in
-// OCCT distribution for complete text of the license and disclaimer of any
-// warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#ifndef _Graphic3d_OcclusionQuery_HeaderFile
-#define _Graphic3d_OcclusionQuery_HeaderFile
-
-#include <Standard.hxx>
-#include <Standard_Transient.hxx>
-#include <Standard_Type.hxx>
-
-//! Base class provides access to occlusion query functionality.
-class Graphic3d_OcclusionQuery : public Standard_Transient {
-public:
-  //! Empty constructor.
-  Graphic3d_OcclusionQuery() : queryID(0), samplesPassed(0) {}
-
-  //! Begins occlusion query. Until the query is ended, samples that pass the
-  //! rendering pipeline are counted.
-  Standard_EXPORT virtual void BeginQuery() const = 0;
-
-  //! Ends occlusion query and caches the result - number of samples that passed
-  //! the rendering pipeline.
-  Standard_EXPORT virtual void EndQuery() = 0;
-
-  //! Gets number of samples that have passed the rendering pipeline.
-  unsigned int GetNumSamplesPassed() const;
-
-  //! Helper method that returns if any samples have passed the rendering
-  //! pipeline.
-  bool AnySamplesPassed() const;
-
-  //! Dumps the content of me into the stream
-  Standard_EXPORT void DumpJson(Standard_OStream &theOStream,
-                                Standard_Integer theDepth = -1) const;
-
-protected:
-  unsigned int queryID; // Query object ID
-  int samplesPassed;    // Number of samples passed in last query
-
-public:
-  DEFINE_STANDARD_RTTIEXT(Graphic3d_OcclusionQuery, Standard_Transient)
-};
-
-DEFINE_STANDARD_HANDLE(Graphic3d_OcclusionQuery, Standard_Transient)
-
-#endif // _Graphic3d_OcclusionQuery_HeaderFile
diff --git a/src/Graphic3d/Graphic3d_ViewOcclusionMask.cxx b/src/Graphic3d/Graphic3d_ViewOcclusionMask.cxx
deleted file mode 100644 (file)
index b7e88cb..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// Created on: 2024-02-20
-// Created by: Hossam Ali
-// Copyright (c) 2024 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in
-// OCCT distribution for complete text of the license and disclaimer of any
-// warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Graphic3d_ViewOcclusionMask.hxx>
-
-#include <Standard_Dump.hxx>
-
-IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_ViewOcclusionMask, Standard_Transient)
-
-// =======================================================================
-// function : DumpJson
-// purpose  :
-// =======================================================================
-void Graphic3d_ViewOcclusionMask::DumpJson(Standard_OStream &theOStream,
-                                       Standard_Integer) const {
-  OCCT_DUMP_TRANSIENT_CLASS_BEGIN(theOStream)
-
-  OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, myMask)
-}
\ No newline at end of file
index d71f245934d84fceff87d736ba607d46022d47d3..15d6e5ce65d374377835834027a0eee909cb5e53 100644 (file)
 #ifndef _Graphic3d_ViewOcclusionMask_HeaderFile
 #define _Graphic3d_ViewOcclusionMask_HeaderFile
 
-#include <Standard.hxx>
-#include <Standard_Transient.hxx>
-#include <Standard_Type.hxx>
+#include <Graphic3d_ViewAffinity.hxx>
 
-//! Structure display state.
-class Graphic3d_ViewOcclusionMask : public Standard_Transient
-{
-public:
+//! define occlusion mask as alias for view affinity mask .
+typedef Graphic3d_ViewAffinity Graphic3d_ViewOcclusionMask;
 
-  //! Empty constructor.
-  Graphic3d_ViewOcclusionMask()
-  {
-    SetVisible (Standard_True);
-  }
-
-  //! Return visibility flag.
-  bool IsVisible (const Standard_Integer theViewId) const
-  {
-    const unsigned int aBit = 1 << theViewId;
-    return (myMask & aBit) != 0;
-  }
-
-  //! Setup visibility flag for all views.
-  void SetVisible (const Standard_Boolean theIsVisible)
-  {
-    ::memset (&myMask, theIsVisible ? 0xFF : 0x00, sizeof(myMask));
-  }
-
-  //! Setup visibility flag.
-  void SetVisible (const Standard_Integer theViewId,
-                   const bool             theIsVisible)
-  {
-    const unsigned int aBit = 1 << theViewId;
-    if (theIsVisible)
-    {
-      myMask |=  aBit;
-    }
-    else
-    {
-      myMask &= ~aBit;
-    }
-  }
-
-  //! Dumps the content of me into the stream
-  Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
-
-private:
-
-  unsigned int myMask; //!< affinity mask
-
-public:
-
-  DEFINE_STANDARD_RTTIEXT(Graphic3d_ViewOcclusionMask,Standard_Transient)
-
-};
-
-DEFINE_STANDARD_HANDLE(Graphic3d_ViewOcclusionMask, Standard_Transient)
-
-#endif // _Graphic3d_ViewOcclusionMask_HeaderFile
+#endif //_Graphic3d_ViewOcclusionMask_HeaderFile
\ No newline at end of file
index 54983a99ebcf372f1a98431142158844be7211f6..65d4bdac2e7dfe96d2e8bf1dcb9285111c6892ea 100644 (file)
@@ -25,6 +25,7 @@
 #include <OpenGl_VertexBuffer.hxx>
 #include <OpenGl_View.hxx>
 #include <OpenGl_Workspace.hxx>
+#include <OpenGl_OcclusionQuery.hxx>
 
 namespace
 {
@@ -875,11 +876,8 @@ void OpenGl_LayerList::Render (const Handle(OpenGl_Workspace)& theWorkspace,
 //function : updateOcclusion
 //purpose  : update Occlsuion state for each struct in each layer 
 //=======================================================================
-void OpenGl_LayerList::UpdateOcclusion( const Handle(OpenGl_Workspace) & theWorkspace,
-                                        const Standard_Boolean theToDrawImmediate,
-                                        const OpenGl_FrameBuffer *theReadDrawFbo,
-                                        const OpenGl_FrameBuffer *theOitAccumFbo)
-{
+void OpenGl_LayerList::UpdateOcclusion( const Handle(OpenGl_Workspace) & theWorkspace)
+{  
   const Handle(OpenGl_Context) &aCtx = theWorkspace->GetGlContext();
   aCtx->core11fwd->glEnable(GL_DEPTH_TEST);
   aCtx->core11fwd->glDepthFunc (GL_LESS);
@@ -893,7 +891,6 @@ void OpenGl_LayerList::UpdateOcclusion( const Handle(OpenGl_Workspace) & theWork
 
   // Turn off writing to depth and color buffers 
   aCtx->core11fwd->glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-  aCtx->core11fwd->glDepthMask(GL_FALSE);
 
   // Start record occlusion test computational cost  
   const Handle(OpenGl_FrameStats) &aStats = theWorkspace->GetGlContext()->FrameStats();
@@ -910,11 +907,7 @@ void OpenGl_LayerList::UpdateOcclusion( const Handle(OpenGl_Workspace) & theWork
     if (aLayer->IsCulled())
       continue;
 
-    /// TODO Change below to Graphic3d_Query
-    GLuint query_ID;
-    GLint samplesPassed;
-    
-    aCtx->core20->glGenQueries(1, &query_ID);
+    aCtx->core11fwd->glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
 
     // Render priority list
     const Standard_Integer aViewId = theWorkspace->View()->Identification();
@@ -930,29 +923,9 @@ void OpenGl_LayerList::UpdateOcclusion( const Handle(OpenGl_Workspace) & theWork
         if (aStruct->IsCulled() || !aStruct->IsVisible(aViewId))
           continue;
         
-        // Begin occlusion query 
-        aCtx->core20->glBeginQuery(GL_SAMPLES_PASSED, query_ID);
-
-        // Dry rendering for conservative approximation of the complex object
-        aStruct->RenderOccluder(theWorkspace);
-
-        // End query and count no of samples 
-        aCtx->core20->glEndQuery(GL_SAMPLES_PASSED);
-        aCtx->core20->glGetQueryObjectiv(query_ID, GL_QUERY_RESULT, &samplesPassed);        
-        
-        if (samplesPassed <= 0)
-          aStruct->SetOccluded(aViewId);
-    
-        std::cout << "layerID: " << aLayer->LayerId()
-                  << " structureID: " << aStruct->Identification()
-                  << " clocation: " << aStruct->BoundingBox().Center().z()
-                  << " queryID: " << query_ID
-                  << " sample passsed : " << samplesPassed << std::endl;
-        samplesPassed=0;
+        aStruct->UpdateOcclusion(theWorkspace);
       }
     }
-    // Release query resources
-    aCtx->core20->glDeleteQueries(1, &query_ID);
   }
 
   // Back to prev settings 
index 00235c48b40e0b984a4c71524a603c3c36f018fd..bfe0bb1728ab4b489498dfd65d1dc5108be8c23d 100644 (file)
@@ -107,10 +107,7 @@ public:
                                OpenGl_FrameBuffer*             theOitAccumFbo) const;
 
   //! Update occlusion test
-  Standard_EXPORT void UpdateOcclusion(const Handle(OpenGl_Workspace) & theWorkspace,
-                                       const Standard_Boolean theToDrawImmediate,
-                                       const OpenGl_FrameBuffer *theReadDrawFbo,
-                                       const OpenGl_FrameBuffer *theOitAccumFbo);
+  Standard_EXPORT void UpdateOcclusion(const Handle(OpenGl_Workspace) & theWorkspace);
 
   //! Returns the set of OpenGL Z-layers.
   const NCollection_List<Handle(Graphic3d_Layer)>& Layers() const { return myLayers; }
index 325d8e16942e6f2cd19b988bfcdfbfe6d1157e38..c06c22671b88b7892b820eb656b8a3b5590248f0 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include "OpenGl_OcclusionQuery.hxx"
+#include <OpenGl_OcclusionQuery.hxx>
 
 #include <OpenGl_Context.hxx>
 #include <OpenGl_GlCore15.hxx>
 
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_OcclusionQuery, Graphic3d_OcclusionQuery)
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_OcclusionQuery, OpenGl_Resource)
 
 // =======================================================================
 // function :
 // purpose  :
 // =======================================================================
-Standard_EXPORT
-OpenGl_OcclusionQuery::OpenGl_OcclusionQuery(const Handle(OpenGl_Context) &
-                                             theCtx)
-    : aCtx(theCtx) {
-  aCtx->core15->glGenQueries(1, &queryID);
+OpenGl_OcclusionQuery::OpenGl_OcclusionQuery(): myID(0), inUse(false), started(false)
+{
 }
 
 // =======================================================================
 // function :
 // purpose  :
 // =======================================================================
-Standard_EXPORT OpenGl_OcclusionQuery::~OpenGl_OcclusionQuery() {
-  aCtx->core15->glDeleteQueries(1, &queryID);
-  queryID = 0;
+OpenGl_OcclusionQuery::~OpenGl_OcclusionQuery() 
+{
+  Release(NULL);
 }
-
 // =======================================================================
-// function : BeginQuery()
+// function : Create()
+// purpose  :
+// =======================================================================
+void OpenGl_OcclusionQuery::Create(const Handle(OpenGl_Context) & theCtx,
+                                   GLenum theQueryType) {
+  theCtx->core15->glGenQueries(1, &myID);
+  myType = theQueryType;
+  inUse = false;
+  started = false;
+}
+// =======================================================================
+// function : Begin()
+// purpose  :
+// =======================================================================
+void OpenGl_OcclusionQuery::Begin(const Handle(OpenGl_Context) & theCtx) 
+{
+  inUse = true;
+  started = true;
+  theCtx->core15->glBeginQuery(myType, myID); 
+}
+// =======================================================================
+// function : End()
 // purpose  :
 // =======================================================================
-Standard_EXPORT void OpenGl_OcclusionQuery::BeginQuery() const {
-  aCtx->core15->glBeginQuery(GL_SAMPLES_PASSED, queryID);
+void OpenGl_OcclusionQuery::End(const Handle(OpenGl_Context) & theCtx) const
+{
+  theCtx->core15->glEndQuery(myType);
 }
 
 // =======================================================================
-// function : EndQuery()
+// function : isResultsReady()
 // purpose  :
 // =======================================================================
-Standard_EXPORT void OpenGl_OcclusionQuery::EndQuery() {
-  aCtx->core15->glEndQuery(GL_SAMPLES_PASSED);
-  aCtx->core15->glGetQueryObjectiv(queryID, GL_QUERY_RESULT, &samplesPassed);
+int OpenGl_OcclusionQuery::IsResultsReady(const Handle(OpenGl_Context) & theCtx) const
+{
+  // check if the query started before check for results
+  if(!started)
+    return false;
+
+  GLint aReady = 0;
+  theCtx->core15->glGetQueryObjectiv(myID, GL_QUERY_RESULT_AVAILABLE, &aReady);
+  return aReady;
+  }
+
+// =======================================================================
+// function : GetResults()
+// purpose  :
+// =======================================================================
+int OpenGl_OcclusionQuery::GetResults(const Handle(OpenGl_Context) & theCtx)
+{
+  inUse = false;
+  GLint aResult;
+  theCtx->core15->glGetQueryObjectiv(myID, GL_QUERY_RESULT, &aResult); 
+  return aResult;
 }
+
+// =======================================================================
+// function : Release()
+// purpose  : Destroy the query opengl resources 
+// =======================================================================
+void OpenGl_OcclusionQuery::Release(OpenGl_Context *theCtx) {
+  if (myID == 0)
+    return;
+  if (theCtx != NULL) {
+    theCtx->core15->glDeleteQueries(1, &myID);
+    myID = 0;
+    started = false;
+  }
+}
\ No newline at end of file
index e2cee43879321935750936a6c93492e68180ab4f..7ab423f81f280ff84a229a528feae8fc256584e9 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#ifndef OpenGl_View_HeaderFile
-#define OpenGl_View_HeaderFile
+#ifndef OpenGl_OcclusionQuery_HeaderFile
+#define OpenGl_OcclusionQuery_HeaderFile
 
-#include <Graphic3d_OcclusionQuery.hxx>
+#include <OpenGl_Resource.hxx>
+#include <OpenGl_GlCore15.hxx>
 
 class OpenGl_Context;
 
-DEFINE_STANDARD_HANDLE(OpenGl_OcclusionQuery, Graphic3d_OcclusionQuery)
+DEFINE_STANDARD_HANDLE(OpenGl_OcclusionQuery, OpenGl_Resource)
 
 //! Implementation of OpenGl view.
-class OpenGl_OcclusionQuery : public Graphic3d_OcclusionQuery {
-
+class OpenGl_OcclusionQuery : public OpenGl_Resource {
 public:
+  DEFINE_STANDARD_RTTIEXT(OpenGl_OcclusionQuery, OpenGl_Resource)
+
   //! Constructor.
-  Standard_EXPORT OpenGl_OcclusionQuery(const Handle(OpenGl_Context) & theCtx);
+  Standard_EXPORT OpenGl_OcclusionQuery();
 
   //! Default destructor.
   Standard_EXPORT virtual ~OpenGl_OcclusionQuery();
+  
+  //! Create the occlusion test Gl resources.
+  Standard_EXPORT virtual void Create(const Handle(OpenGl_Context)& theCtx, GLenum theType);
 
   //! Begins occlusion query.
-  Standard_EXPORT virtual void BeginQuery() const Standard_OVERRIDE;
+  Standard_EXPORT virtual void Begin(const Handle(OpenGl_Context) & theCtx);
 
-  //! Ends occlusion query and caches the result
-  Standard_EXPORT virtual void EndQuery() Standard_OVERRIDE;
+  //! Ends occlusion query
+  Standard_EXPORT virtual void End(const Handle(OpenGl_Context) & theCtx) const;
 
-public:
-  DEFINE_STANDARD_ALLOC
-  DEFINE_STANDARD_RTTIEXT(OpenGl_OcclusionQuery,
-                          Graphic3d_OcclusionQuery) // Type definition
+  //! Check if the query results ready for retrive or not.
+  Standard_EXPORT virtual int IsResultsReady(const Handle(OpenGl_Context) & theCtx) const;
+
+  //! Return the query results based on query type.
+  Standard_EXPORT virtual int GetResults(const Handle(OpenGl_Context) & theCtx);
+
+  //! Return is the query in use or not
+  Standard_EXPORT bool IsInUse() { return inUse; }
+
+  //! Return Query ID
+  Standard_EXPORT unsigned int GetID() const {return myID;}; 
+
+  //! Destroys query object.
+  Standard_EXPORT virtual void Release (OpenGl_Context * theCtx) Standard_OVERRIDE;
+
+  //! Returns estimated GPU memory usage - not implemented.
+  virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
 
 private:
-  const Handle(OpenGl_Context) & aCtx;
+  GLuint   myID;                     //!< OpenGL query ID.
+  GLenum   myType;                   //!< OpenGL query Type.
+  bool     inUse;                    //!< store bool answer is the query still inprogress or finished.
+  bool     started;                  //!< bool answer is the query stated before or this the first time.
 };
 
-#endif // _OpenGl_View_Header
+#endif // _OpenGl_OcclusionQuery_Header
index a89cf7eed62a7d6bf6be278ce27b2454bf127d60..350867d0ff149b82534593903e7a34704d9a88ab 100644 (file)
@@ -103,7 +103,8 @@ OpenGl_Structure::OpenGl_Structure (const Handle(Graphic3d_StructureManager)& th
   myInstancedStructure (NULL),
   myIsRaytracable      (Standard_False),
   myModificationState  (0),
-  myIsMirrored         (Standard_False)
+  myIsMirrored         (Standard_False),
+  myQuery(new OpenGl_OcclusionQuery())
 {
   updateLayerTransformation();
 }
@@ -636,6 +637,33 @@ void OpenGl_Structure::RenderOccluder(const Handle(OpenGl_Workspace)& theWorkspa
   aCtx->ApplyModelViewMatrix();
   renderBoundingBox(theWorkspace);
 }
+// =======================================================================
+// function : OcclusionTest 
+// purpose  : 
+// =======================================================================
+void OpenGl_Structure::UpdateOcclusion(const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+  const Handle(OpenGl_Context) &aCtx = theWorkspace->GetGlContext();
+  if (myQuery->GetID()==0)
+      myQuery->Create(aCtx, GL_ANY_SAMPLES_PASSED);
+
+  if(myQuery->IsResultsReady(aCtx))
+  {
+    int aResult = myQuery->GetResults(aCtx);
+    const Standard_Integer aViewId = theWorkspace->View()->Identification();
+    if (aResult<=0)
+      SetOccluionSate(aViewId, Standard_False);
+    else
+      SetOccluionSate(aViewId, Standard_True);
+  }
+
+  if(!myQuery->IsInUse())
+  {
+    myQuery->Begin(aCtx);
+    RenderOccluder(theWorkspace);
+    myQuery->End(aCtx);
+  }
+}
 
 // =======================================================================
 // function : Release
@@ -658,6 +686,8 @@ void OpenGl_Structure::ReleaseGlResources (const Handle(OpenGl_Context)& theGlCt
   {
     aGroupIter.ChangeValue()->Release (theGlCtx);
   }
+
+  myQuery->Release(theGlCtx.get());
 }
 
 //=======================================================================
index d9f98204910df08405eb90e5024345781e78b1c3..6d2fe5295651dcd60ecd677b536c66c9ab3151f5 100644 (file)
@@ -21,6 +21,7 @@
 #include <OpenGl_GraphicDriver.hxx>
 #include <OpenGl_Group.hxx>
 #include <OpenGl_Workspace.hxx>
+#include <OpenGl_OcclusionQuery.hxx>
 
 #include <NCollection_List.hxx>
 
@@ -96,8 +97,11 @@ public:
   //! Renders the structure.
   Standard_EXPORT virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
 
-  //! Render Occluder presenation of this structure 
+  //! Renders occluder presenation of the structure 
   Standard_EXPORT void RenderOccluder(const Handle(OpenGl_Workspace)& theWorkspace) const;
+
+  //! Peforms occlusion test for the strcuture
+  Standard_EXPORT void UpdateOcclusion(const Handle(OpenGl_Workspace)& theWorkspace) const;
   
   //! Releases structure resources.
   Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
@@ -168,12 +172,14 @@ protected:
 protected:
 
   OpenGl_Structure*          myInstancedStructure;
-  Graphic3d_Mat4             myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift)
+  Graphic3d_Mat4             myRenderTrsf;                //!< transformation, actually used for rendering (includes Local Origin shift)
 
   mutable Standard_Boolean   myIsRaytracable;
   mutable Standard_Size      myModificationState;
 
-  Standard_Boolean           myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
+  Standard_Boolean           myIsMirrored;                //!< Used to tell OpenGl to interpret polygons in clockwise order.
+
+  Handle(OpenGl_OcclusionQuery)      myQuery;             //! test the occlusion status of the structure;
 
 };
 
index 87d0b920703cd290bc009fed7b69d7448d7cc26d..324f496317169bda38a9bd20991acd1073c337f9 100644 (file)
@@ -2542,11 +2542,9 @@ void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId)
 //function : updateOcclusionState
 //purpose  :
 //=======================================================================
-void OpenGl_View::updateOcclusion(OpenGl_FrameBuffer*          theReadDrawFbo,
-                                  OpenGl_FrameBuffer*          theOitAccumFbo,
-                                  const Standard_Boolean       theToDrawImmediate)
+void OpenGl_View::UpdateOcclusion()
 {
-  myZLayers.UpdateOcclusion(myWorkspace, theToDrawImmediate,theReadDrawFbo, theOitAccumFbo);
+  myZLayers.UpdateOcclusion(myWorkspace);
  
   // re-validate occlusion results  
   myRenderParams.OcculsionQueryState = Graphic3d_RenderingParams::OcculsionQuery_On;
@@ -2573,7 +2571,7 @@ void OpenGl_View::renderStructs (Graphic3d_Camera::Projection theProjection,
 
   // update occlusion here after update culling to ensure the frusrum culling updated
   if (myRenderParams.OcculsionQueryState == Graphic3d_RenderingParams::OcculsionQuery_NoUpdate)
-    updateOcclusion(theReadDrawFbo, theOitAccumFbo, theToDrawImmediate);
+    UpdateOcclusion();
 
   Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
   Standard_Boolean toRenderGL = theToDrawImmediate ||
index c2051252ade01f523b1faaa8b4d4775498ba0504..5a064497eff2fbee233bb9cfe96c760a120e3e4e 100644 (file)
@@ -183,6 +183,9 @@ public:
   //! Returns additional buffers for depth peeling OIT.
   const Handle(OpenGl_DepthPeeling)& DepthPeelingFbos() const { return myDepthPeelingFbos; }
 
+  //! Perform occlusion test for the set of structures presented in the view  
+  Standard_EXPORT virtual void UpdateOcclusion()  Standard_OVERRIDE;
+
 public:
 
   //! Returns gradient background fill colors.
@@ -380,14 +383,6 @@ protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
   Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace,
                                                Graphic3d_Camera::Projection theProjection);
 
-  //! Update occlusion state for the set of structures presented in the view  
-  //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
-  //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
-  //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
-  Standard_EXPORT virtual void updateOcclusion(OpenGl_FrameBuffer*    theReadDrawFbo,
-                                              OpenGl_FrameBuffer*    theOitAccumFbo,
-                                              const Standard_Boolean       theToDrawImmediate);
-
   //! Render set of structures presented in the view.
   //! @param theProjection [in] the projection that is used for rendering.
   //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
index 33a8f8ef0986f89cfa9ae131f9764c1a5b4e1bb2..85d39b420422987df0c8ccdd37311d9885e2f2e6 100644 (file)
@@ -14045,11 +14045,11 @@ static Standard_Integer VNbOccluded(Draw_Interpretor & /*theDi*/,
     Handle(V3d_View) aView = ViewerTest_myViews.Find1(anIter.Value());
     aView->ChangeRenderingParams().OcculsionQueryState = Graphic3d_RenderingParams::OcculsionQuery_NoUpdate;
     aView->Redraw();
-    
+    aView->View()->UpdateOcclusion();
     Graphic3d_MapOfStructure aOcculdedStructs;
     aView->View()->OccludedStructures(aOcculdedStructs);
 
-    printf("No Occluded Objects in view id: %d --> %d\n",
+    printf("Occluded objects in view: %d = %d\n",
            aView->View()->Identification(), aOcculdedStructs.Extent());
   }
 
index 8f63023104462d75f407596e199f4e0c22da07f6..36e02c1780ab779e67558b3bdaa0eb7288f17c4e 100644 (file)
@@ -12,7 +12,7 @@ box c 12 0 0 10 10 10
 # check left side
 vinit name=View1
 vsetdispmode 1
-vdisplay b c
+vdisplay c b
 vright
 vfit
 vzoom 0.5
@@ -20,7 +20,7 @@ vzoom 0.5
 # check front side
 vinit name=View2
 vsetdispmode 1
-vdisplay b c
+vdisplay c b
 vfront
 vfit