diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index f83c2db19f..b1812c88f0 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -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 diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index 0a4f2344a7..2c5d0117fb 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -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: diff --git a/src/Graphic3d/Graphic3d_CView.hxx b/src/Graphic3d/Graphic3d_CView.hxx index 53351b7c08..5a2506aeff 100644 --- a/src/Graphic3d/Graphic3d_CView.hxx +++ b/src/Graphic3d/Graphic3d_CView.hxx @@ -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 index 1df044772e..0000000000 --- a/src/Graphic3d/Graphic3d_OcclusionQuery.cxx +++ /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 - -#include - -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 index a0426f0c00..0000000000 --- a/src/Graphic3d/Graphic3d_OcclusionQuery.hxx +++ /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 -#include -#include - -//! 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 index b7e88cbab3..0000000000 --- a/src/Graphic3d/Graphic3d_ViewOcclusionMask.cxx +++ /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 - -#include - -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 diff --git a/src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx b/src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx index d71f245934..15d6e5ce65 100644 --- a/src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx +++ b/src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx @@ -17,62 +17,9 @@ #ifndef _Graphic3d_ViewOcclusionMask_HeaderFile #define _Graphic3d_ViewOcclusionMask_HeaderFile -#include -#include -#include +#include -//! 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 diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 54983a99eb..65d4bdac2e 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -25,6 +25,7 @@ #include #include #include +#include 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 diff --git a/src/OpenGl/OpenGl_LayerList.hxx b/src/OpenGl/OpenGl_LayerList.hxx index 00235c48b4..bfe0bb1728 100644 --- a/src/OpenGl/OpenGl_LayerList.hxx +++ b/src/OpenGl/OpenGl_LayerList.hxx @@ -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& Layers() const { return myLayers; } diff --git a/src/OpenGl/OpenGl_OcclusionQuery.cxx b/src/OpenGl/OpenGl_OcclusionQuery.cxx index 325d8e1694..c06c22671b 100644 --- a/src/OpenGl/OpenGl_OcclusionQuery.cxx +++ b/src/OpenGl/OpenGl_OcclusionQuery.cxx @@ -14,46 +14,97 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include "OpenGl_OcclusionQuery.hxx" +#include #include #include -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 : 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 : +// ======================================================================= +void OpenGl_OcclusionQuery::End(const Handle(OpenGl_Context) & theCtx) const +{ + theCtx->core15->glEndQuery(myType); } // ======================================================================= -// function : BeginQuery() +// function : isResultsReady() // purpose : // ======================================================================= -Standard_EXPORT void OpenGl_OcclusionQuery::BeginQuery() const { - aCtx->core15->glBeginQuery(GL_SAMPLES_PASSED, queryID); +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 : EndQuery() -// purpose : +// function : Release() +// purpose : Destroy the query opengl resources // ======================================================================= -Standard_EXPORT void OpenGl_OcclusionQuery::EndQuery() { - aCtx->core15->glEndQuery(GL_SAMPLES_PASSED); - aCtx->core15->glGetQueryObjectiv(queryID, GL_QUERY_RESULT, &samplesPassed); -} +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 diff --git a/src/OpenGl/OpenGl_OcclusionQuery.hxx b/src/OpenGl/OpenGl_OcclusionQuery.hxx index e2cee43879..7ab423f81f 100644 --- a/src/OpenGl/OpenGl_OcclusionQuery.hxx +++ b/src/OpenGl/OpenGl_OcclusionQuery.hxx @@ -14,38 +14,59 @@ // 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 +#include +#include 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 diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index a89cf7eed6..350867d0ff 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -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()); } //======================================================================= diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index d9f9820491..6d2fe52956 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -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; }; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 87d0b92070..324f496317 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -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 || diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index c2051252ad..5a064497ef 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -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. diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 33a8f8ef09..85d39b4204 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -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()); } diff --git a/tests/v3d/occlusion/boxes b/tests/v3d/occlusion/boxes index 8f63023104..36e02c1780 100644 --- a/tests/v3d/occlusion/boxes +++ b/tests/v3d/occlusion/boxes @@ -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