Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/AIS/AIS_InteractiveContext.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& theIOb
if (!myObjects.IsBound(theIObj))
{
setObjectStatus(theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
theIObj->ViewAffinity()->SetVisible(true); // reset view affinity mask
theIObj->ViewAffinity()->SetVisible(true); // reset view affinity mask
theIObj->ViewOcclusionMask()->SetVisible(true); // reset view occlusion mask
myMainVwr->StructureManager()->RegisterObject(theIObj, theIObj->ViewAffinity());
myMainPM->Display(theIObj, theDispMode);
if (theSelectionMode != -1)
Expand Down Expand Up @@ -491,7 +492,8 @@ void AIS_InteractiveContext::Load(const Handle(AIS_InteractiveObject)& theIObj,
PrsMgr_DisplayStatus_Erased,
aDispMode,
theSelMode != -1 ? theSelMode : aSelModeDef);
theIObj->ViewAffinity()->SetVisible(true); // reset view affinity mask
theIObj->ViewAffinity()->SetVisible(true); // reset view affinity mask
theIObj->ViewOcclusionMask()->SetVisible(true); // reset view occlusion mask
myMainVwr->StructureManager()->RegisterObject(theIObj, theIObj->ViewAffinity());
}

Expand Down
1 change: 1 addition & 0 deletions src/Graphic3d/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,4 @@ Graphic3d_Layer.cxx
Graphic3d_Layer.hxx
Graphic3d_ZLayerId.hxx
Graphic3d_ZLayerSettings.hxx
Graphic3d_ViewOcclusionMask.hxx
17 changes: 16 additions & 1 deletion src/Graphic3d/Graphic3d_CStructure.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <Graphic3d_ViewAffinity.hxx>
#include <Graphic3d_TransformPers.hxx>
#include <Graphic3d_ZLayerId.hxx>
#include <Graphic3d_ViewOcclusionMask.hxx>
#include <TopLoc_Datum3D.hxx>
#include <NCollection_IndexedMap.hxx>

Expand Down Expand Up @@ -173,6 +174,19 @@ public:
//! The method is called during traverse of BVH tree.
void MarkAsNotCulled() const { myIsCulled = Standard_False; }

//! Returns true if the structure occluded in specified view, otherwise
//! returns false.
Standard_Boolean IsOccluded(const Standard_Integer theViewId) const
{
return (!OcclusionMask->IsVisible(theViewId));
}

//! Marks structure as Occluded by other structure in specified view,!
void SetOcclusionSate(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.
Standard_Boolean BndBoxClipCheck() const { return myBndBoxClipCheck; }
Expand Down Expand Up @@ -227,7 +241,8 @@ public:
Standard_Integer theDepth = -1) const;

public:
Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
Handle(Graphic3d_ViewOcclusionMask) OcclusionMask; //!< view occlusion mask

protected:
//! Create empty structure.
Expand Down
12 changes: 12 additions & 0 deletions src/Graphic3d/Graphic3d_CView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ void Graphic3d_CView::DisplayedStructures(Graphic3d_MapOfStructure& theStructure

//=================================================================================================

void Graphic3d_CView::OccludedStructures(Graphic3d_MapOfStructure& theStructures) const
{
for (Graphic3d_MapOfStructure::Iterator aStructIter(myStructsDisplayed); aStructIter.More();
aStructIter.Next())
{
if (aStructIter.Value()->CStructure()->IsOccluded(this->myId))
theStructures.Add(aStructIter.Key());
}
}

//=================================================================================================

Bnd_Box Graphic3d_CView::MinMaxValues(const Standard_Boolean theToIncludeAuxiliary) const
{
if (!IsDefined())
Expand Down
6 changes: 6 additions & 0 deletions src/Graphic3d/Graphic3d_CView.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public:
//! Returns the set of structures displayed in this view.
Standard_EXPORT void DisplayedStructures(Graphic3d_MapOfStructure& theStructures) const;

//! Returns number of occluded structures in the view
Standard_EXPORT void OccludedStructures(Graphic3d_MapOfStructure& theStructures) const;

//! Update occlusion test for displayed structures in the view
Standard_EXPORT virtual void UpdateOcclusion() = 0;

//! Returns number of displayed structures in the view.
virtual Standard_Integer NumberOfDisplayedStructures() const
{
Expand Down
3 changes: 2 additions & 1 deletion src/Graphic3d/Graphic3d_FrameStatsTimer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ enum Graphic3d_FrameStatsTimer
Graphic3d_FrameStatsTimer_CpuCulling,
Graphic3d_FrameStatsTimer_CpuPicking,
Graphic3d_FrameStatsTimer_CpuDynamics,
Graphic3d_FrameStatsTimer_OcclusionCulling,
};

enum
{
Graphic3d_FrameStatsTimer_NB = Graphic3d_FrameStatsTimer_CpuDynamics + 1
Graphic3d_FrameStatsTimer_NB = Graphic3d_FrameStatsTimer_OcclusionCulling + 1
};

#endif // _Graphic3d_FrameStatsTimer_HeaderFile
1 change: 1 addition & 0 deletions src/Graphic3d/Graphic3d_RenderingParams.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void Graphic3d_RenderingParams::DumpJson(Standard_OStream& theOStream,
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, CameraApertureRadius)
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, CameraFocalPlaneDist)
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, FrustumCullingState)
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, OcclusionQueryState)

OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, ToneMappingMethod)
OCCT_DUMP_FIELD_VALUE_NUMERICAL(theOStream, Exposure)
Expand Down
11 changes: 11 additions & 0 deletions src/Graphic3d/Graphic3d_RenderingParams.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public:
FrustumCulling_NoUpdate //!< culling is active, but the list of culled entities is not updated
};

//! State of occlusion query
enum OcclusionQuery
{
OcclusionQuery_Off, //!< occlusion query is disabled
OcclusionQuery_On, //!< occlusion query is active
OcclusionQuery_NoUpdate //!< occlusion query is active, but the list of occluded entities is not
//!< updated
};

public:
//! Creates default rendering parameters.
Graphic3d_RenderingParams()
Expand Down Expand Up @@ -144,6 +153,7 @@ public:
CameraApertureRadius(0.0f),
CameraFocalPlaneDist(1.0f),
FrustumCullingState(FrustumCulling_On),
OcclusionQueryState(OcclusionQuery_On),
ToneMappingMethod(Graphic3d_ToneMappingMethod_Disabled),
Exposure(0.f),
WhitePoint(1.f),
Expand Down Expand Up @@ -258,6 +268,7 @@ public: //! @name Ray-Tracing/Path-Tracing parameters
Standard_ShortReal CameraApertureRadius; //!< aperture radius of perspective camera used for depth-of-field, 0.0 by default (no DOF) (path tracing only)
Standard_ShortReal CameraFocalPlaneDist; //!< focal distance of perspective camera used for depth-of field, 1.0 by default (path tracing only)
FrustumCulling FrustumCullingState; //!< state of frustum culling optimization; FrustumCulling_On by default
OcclusionQuery OcclusionQueryState; //!< state of occlusion query; OcclusionQuery_OFF by default

Graphic3d_ToneMappingMethod ToneMappingMethod; //!< specifies tone mapping method for path tracing, Graphic3d_ToneMappingMethod_Disabled by default
Standard_ShortReal Exposure; //!< exposure value used for tone mapping (path tracing), 0.0 by default
Expand Down
25 changes: 25 additions & 0 deletions src/Graphic3d/Graphic3d_ViewOcclusionMask.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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_ViewOcclusionMask_HeaderFile
#define _Graphic3d_ViewOcclusionMask_HeaderFile

#include <Graphic3d_ViewAffinity.hxx>

//! define occlusion mask as alias for view affinity mask .
typedef Graphic3d_ViewAffinity Graphic3d_ViewOcclusionMask;

#endif //_Graphic3d_ViewOcclusionMask_HeaderFile
2 changes: 2 additions & 0 deletions src/OpenGl/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ OpenGl_TextBuilder.hxx
OpenGl_TextBuilder.cxx
OpenGl_HaltonSampler.hxx
OpenGl_ShaderProgramDumpLevel.hxx
OpenGl_OcclusionQuery.hxx
OpenGl_OcclusionQuery.cxx
77 changes: 73 additions & 4 deletions src/OpenGl/OpenGl_LayerList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <OpenGl_VertexBuffer.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_OcclusionQuery.hxx>

namespace
{
Expand Down Expand Up @@ -894,10 +895,78 @@ void OpenGl_LayerList::Render(const Handle(OpenGl_Workspace)& theWorkspace,
theWorkspace->SetRenderFilter(aPrevFilter);
}

//=======================================================================
// function : renderTransparent
// purpose : Render transparent objects using blending operator.
//=======================================================================
//=================================================================================================

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);

// Remember global settings for glDepth mask and write mask
GLboolean aPrevColorMask[4];
GLboolean aPrevDepthMask;
aCtx->core11fwd->glGetBooleanv(GL_COLOR_WRITEMASK, aPrevColorMask);
aCtx->core11fwd->glGetBooleanv(GL_DEPTH_WRITEMASK, &aPrevDepthMask);

// Turn off writing to depth and color buffers
aCtx->core11fwd->glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

// Start record occlusion test computational cost
const Handle(OpenGl_FrameStats)& aStats = theWorkspace->GetGlContext()->FrameStats();
OSD_Timer& aTimer =
aStats->ActiveDataFrame().ChangeTimer(Graphic3d_FrameStatsTimer_OcclusionCulling);
aTimer.Start();

// Loop for all layers
for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter(myLayers); aLayerIter.More();
aLayerIter.Next())
{

const Handle(Graphic3d_Layer)& aLayer = aLayerIter.ChangeValue();

// Exclude frustum culled layer
if (aLayer->IsCulled())
continue;

aCtx->core11fwd->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Render priority list
const Standard_Integer aViewId = theWorkspace->View()->Identification();

for (Standard_Integer aPriorityIter = Graphic3d_DisplayPriority_Bottom;
aPriorityIter <= Graphic3d_DisplayPriority_Topmost;
++aPriorityIter)
{
const Graphic3d_IndexedMapOfStructure& aStructures =
aLayer->Structures((Graphic3d_DisplayPriority)aPriorityIter);
for (OpenGl_Structure::StructIterator aStructIter(aStructures); aStructIter.More();
aStructIter.Next())
{
const OpenGl_Structure* aStruct = aStructIter.Value();

// Exclude view frustum culled structs
if (aStruct->IsCulled() || !aStruct->IsVisible(aViewId) || aStruct->IsForHighlight)
continue;

aStruct->UpdateOcclusion(theWorkspace);
}
}
}

// Back to prev settings
aCtx->core11fwd->glDepthMask(aPrevDepthMask);
aCtx->core11fwd->glColorMask(aPrevColorMask[0],
aPrevColorMask[1],
aPrevColorMask[2],
aPrevColorMask[3]);

aTimer.Stop();
aStats->ActiveDataFrame()[Graphic3d_FrameStatsTimer_CpuCulling] = aTimer.UserTimeCPU();
}

//=================================================================================================

void OpenGl_LayerList::renderTransparent(const Handle(OpenGl_Workspace)& theWorkspace,
OpenGl_LayerStack::iterator& theLayerIter,
const OpenGl_GlobalLayerSettings& theGlobalSettings,
Expand Down
3 changes: 3 additions & 0 deletions src/OpenGl/OpenGl_LayerList.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public:
OpenGl_FrameBuffer* theReadDrawFbo,
OpenGl_FrameBuffer* theOitAccumFbo) const;

//! Update occlusion test
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; }

Expand Down
101 changes: 101 additions & 0 deletions src/OpenGl/OpenGl_OcclusionQuery.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 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 <OpenGl_OcclusionQuery.hxx>

#include <OpenGl_Context.hxx>
#include <OpenGl_GlCore15.hxx>

IMPLEMENT_STANDARD_RTTIEXT(OpenGl_OcclusionQuery, OpenGl_Resource)

//=================================================================================================

OpenGl_OcclusionQuery::OpenGl_OcclusionQuery()
: myID(0),
inUse(false),
started(false)
{
}

//=================================================================================================

OpenGl_OcclusionQuery::~OpenGl_OcclusionQuery()
{
Release(NULL);
}

//=================================================================================================

void OpenGl_OcclusionQuery::Create(const Handle(OpenGl_Context)& theCtx, GLenum theQueryType)
{
theCtx->core15->glGenQueries(1, &myID);
myType = theQueryType;
inUse = false;
started = false;
}

//=================================================================================================

void OpenGl_OcclusionQuery::Begin(const Handle(OpenGl_Context)& theCtx)
{
inUse = true;
started = true;
theCtx->core15->glBeginQuery(myType, myID);
}

//=================================================================================================

void OpenGl_OcclusionQuery::End(const Handle(OpenGl_Context)& theCtx) const
{
theCtx->core15->glEndQuery(myType);
}

//=================================================================================================

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;
}

//=================================================================================================

int OpenGl_OcclusionQuery::GetResults(const Handle(OpenGl_Context)& theCtx)
{
inUse = false;
GLint aResult;
theCtx->core15->glGetQueryObjectiv(myID, GL_QUERY_RESULT, &aResult);
return aResult;
}

//=================================================================================================

void OpenGl_OcclusionQuery::Release(OpenGl_Context* theCtx)
{
if (myID == 0)
return;
if (theCtx != NULL)
{
theCtx->core15->glDeleteQueries(1, &myID);
myID = 0;
started = false;
}
}
Loading
Loading