1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0030434: Visualization, TKV3d - add "NoUpdate" state of frustum culling optimization

Frustum culling is now managed by Graphic3d_RenderingParams::FrustumCullingState flag
and can be switched into Graphic3d_RenderingParams::FrustumCulling_NoUpdate state
useful for debugging the algorithm.

Draw Harness command vrustumculling has been replaced by vrenderparams -frustumCulling.
This commit is contained in:
osa 2019-01-09 17:01:18 +03:00 committed by bugmaster
parent 30a1b24e19
commit 0e3025bc14
19 changed files with 124 additions and 120 deletions

View File

@ -1082,7 +1082,6 @@ void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther)
SetBackgroundImage (theOther->BackgroundImage());
SetBackgroundImageStyle (theOther->BackgroundImageStyle());
SetTextureEnv (theOther->TextureEnv());
SetCullingEnabled (theOther->IsCullingEnabled());
SetShadingModel (theOther->ShadingModel());
SetBackfacingModel (theOther->BackfacingModel());
SetCamera (new Graphic3d_Camera (theOther->Camera()));

View File

@ -381,12 +381,6 @@ public:
//! Sets environment texture for the view.
virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0;
//! Returns the state of frustum culling optimization.
virtual Standard_Boolean IsCullingEnabled() const = 0;
//! Enables or disables frustum culling optimization.
virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) = 0;
//! Return backfacing model used for the view.
virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0;

View File

@ -80,6 +80,14 @@ public:
| PerfCounters_FrameTimeMax,
};
//! State of frustum culling optimization.
enum FrustumCulling
{
FrustumCulling_Off, //!< culling is disabled
FrustumCulling_On, //!< culling is active, and the list of culled entities is automatically updated before redraw
FrustumCulling_NoUpdate //!< culling is active, but the list of culled entities is not updated
};
public:
//! Creates default rendering parameters.
@ -108,6 +116,7 @@ public:
NbRayTracingTiles (16 * 16),
CameraApertureRadius (0.0f),
CameraFocalPlaneDist (1.0f),
FrustumCullingState (FrustumCulling_On),
ToneMappingMethod (Graphic3d_ToneMappingMethod_Disabled),
Exposure (0.f),
WhitePoint (1.f),
@ -181,6 +190,7 @@ public:
Standard_Integer NbRayTracingTiles; //!< total number of screen tiles used in adaptive sampling mode (PT only)
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
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

View File

@ -485,23 +485,28 @@ void OpenGl_Layer::updateBVH() const
// =======================================================================
void OpenGl_Layer::UpdateCulling (const Standard_Integer theViewId,
const OpenGl_BVHTreeSelector& theSelector,
const Standard_Boolean theToTraverse)
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState)
{
updateBVH();
myNbStructuresNotCulled = myNbStructures;
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitives.Structures()); aStructIter.More(); aStructIter.Next())
if (theFrustumCullingState != Graphic3d_RenderingParams::FrustumCulling_NoUpdate)
{
const OpenGl_Structure* aStruct = aStructIter.Value();
aStruct->SetCulled (theToTraverse);
}
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitivesTrsfPers.Structures()); aStructIter.More(); aStructIter.Next())
{
const OpenGl_Structure* aStruct = aStructIter.Value();
aStruct->SetCulled (theToTraverse);
Standard_Boolean toTraverse =
(theFrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On);
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitives.Structures()); aStructIter.More(); aStructIter.Next())
{
const OpenGl_Structure* aStruct = aStructIter.Value();
aStruct->SetCulled (toTraverse);
}
for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (myBVHPrimitivesTrsfPers.Structures()); aStructIter.More(); aStructIter.Next())
{
const OpenGl_Structure* aStruct = aStructIter.Value();
aStruct->SetCulled (toTraverse);
}
}
if (!theToTraverse)
if (theFrustumCullingState != Graphic3d_RenderingParams::FrustumCulling_On)
{
return;
}

View File

@ -126,7 +126,7 @@ public:
//! Traverses through BVH tree to determine which structures are in view volume.
void UpdateCulling (const Standard_Integer theViewId,
const OpenGl_BVHTreeSelector& theSelector,
const Standard_Boolean theToTraverse);
const Graphic3d_RenderingParams::FrustumCulling theFrustumCullingState);
//! Returns TRUE if layer is empty or has been discarded entirely by culling test.
bool IsCulled() const { return myNbStructuresNotCulled == 0; }

View File

@ -528,7 +528,7 @@ void OpenGl_LayerList::UpdateCulling (const Handle(OpenGl_Workspace)& theWorkspa
continue;
}
aLayer.UpdateCulling (aViewId, aSelector, theWorkspace->IsCullingEnabled());
aLayer.UpdateCulling (aViewId, aSelector, theWorkspace->View()->RenderingParams().FrustumCullingState);
}
aTimer.Stop();

View File

@ -50,7 +50,6 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
myDriver (theDriver.operator->()),
myCaps (theCaps),
myWasRedrawnGL (Standard_False),
myCulling (Standard_True),
myBackfacing (Graphic3d_TOBM_AUTOMATIC),
myBgColor (Quantity_NOC_BLACK),
myCamera (new Graphic3d_Camera()),

View File

@ -241,12 +241,6 @@ public:
//! Sets environment texture for the view.
Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
//! Returns the state of frustum culling optimization.
virtual Standard_Boolean IsCullingEnabled() const Standard_OVERRIDE { return myCulling; }
//! Enables or disables frustum culling optimization.
virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myCulling = theIsEnabled; }
//! Return backfacing model used for the view.
virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
@ -457,7 +451,6 @@ protected:
Handle(OpenGl_Caps) myCaps;
Standard_Boolean myWasRedrawnGL;
Standard_Boolean myCulling;
Graphic3d_TypeOfBackfacingModel myBackfacing;
Quantity_ColorRGBA myBgColor;
Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;

View File

@ -429,15 +429,6 @@ Standard_Integer OpenGl_Workspace::Height() const
return !myView->GlWindow().IsNull() ? myView->GlWindow()->Height() : 0;
}
// =======================================================================
// function : IsCullingEnabled
// purpose :
// =======================================================================
Standard_Boolean OpenGl_Workspace::IsCullingEnabled() const
{
return myView->IsCullingEnabled();
}
// =======================================================================
// function : FBOCreate
// purpose :

View File

@ -3173,24 +3173,6 @@ void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
theCamera->Transform (aPanTrsf);
}
// =======================================================================
// function : IsCullingEnabled
// purpose :
// =======================================================================
Standard_Boolean V3d_View::IsCullingEnabled() const
{
return myView->IsCullingEnabled();
}
// =======================================================================
// function : SetFrustumCulling
// purpose :
// =======================================================================
void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip)
{
myView->SetCullingEnabled (theToClip);
}
// =======================================================================
// function : DiagnosticInformation
// purpose :

View File

@ -911,10 +911,10 @@ public:
Standard_EXPORT Graphic3d_RenderingParams& ChangeRenderingParams();
//! @return flag value of objects culling mechanism
Standard_EXPORT Standard_Boolean IsCullingEnabled() const;
Standard_Boolean IsCullingEnabled() const { return RenderingParams().FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On; }
//! Turn on/off automatic culling of objects outside frustrum (ON by default)
Standard_EXPORT void SetFrustumCulling (const Standard_Boolean theMode);
//! Turn on/off automatic culling of objects outside frustum (ON by default)
void SetFrustumCulling (Standard_Boolean theMode) { ChangeRenderingParams().FrustumCullingState = theMode ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off; }
//! Fill in the dictionary with diagnostic info.
//! Should be called within rendering thread.

View File

@ -10430,6 +10430,9 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
theDI << "depth pre-pass: " << (aParams.ToEnableDepthPrepass ? "on" : "off") << "\n";
theDI << "alpha to coverage: " << (aParams.ToEnableAlphaToCoverage ? "on" : "off") << "\n";
theDI << "frustum culling: " << (aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On ? "on" :
aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off ? "off" :
"noUpdate") << "\n";
theDI << "\n";
return 0;
}
@ -11103,6 +11106,39 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
}
aView->ChangeRenderingParams().StatsMaxChartTime = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter]);
}
else if (aFlag == "-frustumculling"
|| aFlag == "-culling")
{
if (toPrint)
{
theDI << ((aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_On) ? "on" :
(aParams.FrustumCullingState == Graphic3d_RenderingParams::FrustumCulling_Off) ? "off" :
"noUpdate") << " ";
continue;
}
Graphic3d_RenderingParams::FrustumCulling aState = Graphic3d_RenderingParams::FrustumCulling_On;
if (++anArgIter < theArgNb)
{
TCollection_AsciiString aStateStr(theArgVec[anArgIter]);
aStateStr.LowerCase();
bool toEnable = true;
if (ViewerTest::ParseOnOff (aStateStr.ToCString(), toEnable))
{
aState = toEnable ? Graphic3d_RenderingParams::FrustumCulling_On : Graphic3d_RenderingParams::FrustumCulling_Off;
}
else if (aStateStr == "noupdate"
|| aStateStr == "freeze")
{
aState = Graphic3d_RenderingParams::FrustumCulling_NoUpdate;
}
else
{
--anArgIter;
}
}
aParams.FrustumCullingState = aState;
}
else
{
std::cout << "Error: wrong syntax, unknown flag '" << anArg << "'\n";
@ -11159,53 +11195,6 @@ static Standard_Integer VProgressiveMode (Draw_Interpretor& /*theDI*/,
}
#endif
//=======================================================================
//function : VFrustumCulling
//purpose : enables/disables view volume's culling.
//=======================================================================
static int VFrustumCulling (Draw_Interpretor& theDI,
Standard_Integer theArgNb,
const char** theArgVec)
{
Handle(V3d_View) aView = ViewerTest::CurrentView();
if (aView.IsNull())
{
std::cout << theArgVec[0] << " Error: Use 'vinit' command before\n";
return 1;
}
if (theArgNb < 2)
{
theDI << (aView->IsCullingEnabled() ? "on" : "off");
return 0;
}
else if (theArgNb != 2)
{
std::cout << theArgVec[0] << " Syntax error: Specify the mode\n";
return 1;
}
TCollection_AsciiString aModeStr (theArgVec[1]);
aModeStr.LowerCase();
Standard_Boolean toEnable = 0;
if (aModeStr == "on")
{
toEnable = 1;
}
else if (aModeStr == "off")
{
toEnable = 0;
}
else
{
toEnable = Draw::Atoi (theArgVec[1]) != 0;
}
aView->SetFrustumCulling (toEnable);
aView->Redraw();
return 0;
}
//=======================================================================
//function : VXRotate
//purpose :
@ -12628,13 +12617,12 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"\n '-perfUpdateInterval nbSeconds' Performance counters update interval"
"\n '-perfChart nbFrames' Show frame timers chart limited by specified number of frames"
"\n '-perfChartMax seconds' Maximum time in seconds with the chart"
"\n '-frustumCulling on|off|noupdate' Enable/disable objects frustum clipping or"
"\n set state to check structures culled previously."
"\n Unlike vcaps, these parameters dramatically change visual properties."
"\n Command is intended to control presentation quality depending on"
"\n hardware capabilities and performance.",
__FILE__, VRenderParams, group);
theCommands.Add("vfrustumculling",
"vfrustumculling [toEnable]: enables/disables objects clipping",
__FILE__,VFrustumCulling,group);
theCommands.Add ("vplace",
"vplace dx dy"
"\n\t\t: Places the point (in pixels) at the center of the window",

View File

@ -20,7 +20,7 @@ vclear
vinit name=small_wnd l=32 t=32 w=$SMALL_WIN_WIDTH h=$SMALL_WIN_HEIGHT
vactivate small_wnd
vrenderparams -perfUpdateInterval 0
vfrustumculling 0
vrenderparams -frustumculling off
vautozfit 0
vviewparams -scale 1.953125 -eye 0.57735026918962573 -0.57735026918962573 0.57735026918962573
vzrange 1 512
@ -67,7 +67,7 @@ puts ""
verase
puts "Start displaying spheres with clipping..."
vfrustumculling 1
vrenderparams -frustumculling on
vdisplayall
puts [vfps]
vrenderparams -perfCounters none

View File

@ -19,7 +19,7 @@ vclear
vinit name=small_wnd l=32 t=32 w=$SMALL_WIN_WIDTH h=$SMALL_WIN_HEIGHT
vactivate small_wnd
vrenderparams -perfUpdateInterval 0
vfrustumculling 0
vrenderparams -frustumculling off
vautozfit 0
vviewparams -scale 1.953125 -eye 0.57735026918962573 -0.57735026918962573 0.57735026918962573
vzrange 1 512
@ -69,7 +69,7 @@ puts ""
verase
vfrustumculling 1
vrenderparams -frustumculling on
puts "Start displaying boxes with clipping..."
for {set i 0} {$i < $BOXES_NUM} {incr i} {
vdisplay -noupdate $aBoxNames($i)

View File

@ -9,7 +9,7 @@ puts ""
box b 1 2 3
vinit
vdisplay b
vfrustumculling 1
vrenderparams -frustumculling on
vfit
vdump $imagedir/${casename}_default_layer.png

View File

@ -27,9 +27,9 @@ for {set i 0} {$i < $LINES_IN_ROW} {incr i} {
vfit
vfrustumculling 1
vrenderparams -frustumculling on
vdump $aWithCulling
vfrustumculling 0
vrenderparams -frustumculling off
vdump $aNoCulling
set aDiffRes [diffimage $aWithCulling $aNoCulling 0.1 0 0 $aDiff]

View File

@ -62,7 +62,7 @@ set tcl_precision 16
# Test orthographic camera without frustum culling. #
####################################################################
vcamera -ortho
vfrustumculling 0
vrenderparams -frustumculling off
if { [test2d] != 1 } {
puts "Error: 2D projection test failed: view frustum culling is OFF"
@ -72,7 +72,7 @@ if { [test2d] != 1 } {
# Test orthographic camera with frustum culling. #
####################################################################
vcamera -ortho
vfrustumculling 1
vrenderparams -frustumculling on
if { [test2d] != 1 } {
puts "Error: 2D projection test failed: view frustum culling is ON"

View File

@ -88,7 +88,7 @@ set tcl_precision 16
####################################################################
vcamera -ortho
vviewparams -scale 1e-8
vfrustumculling 0
vrenderparams -frustumculling off
if { [test3d 1e-7] != 1 } {
puts "Error: 3D projection test failed: camera is orthographic, view frustum culling is OFF"
@ -100,7 +100,7 @@ if { [test3d 1e-7] != 1 } {
####################################################################
vcamera -ortho
vviewparams -scale 1e-8
vfrustumculling 1
vrenderparams -frustumculling on
if { [test3d 1e-7] != 1 } {
puts "Error: 3D projection test failed: camera is orthographic, view frustum culling is ON"
@ -111,7 +111,7 @@ if { [test3d 1e-7] != 1 } {
# Test camera with less starting distance 1.0 to avoid jittering. #
####################################################################
vcamera -persp
vfrustumculling 0
vrenderparams -frustumculling off
if { [test3d 1.0] != 1 } {
puts "Error: 3D projection test failed: camera is perspective, view frustum culling is OFF"
@ -122,7 +122,7 @@ if { [test3d 1.0] != 1 } {
# Test camera with less starting distance 1.0 to avoid jittering. #
####################################################################
vcamera -persp
vfrustumculling 1
vrenderparams -frustumculling on
if { [test3d 1.0] != 1 } {
puts "Error: 3D projection test failed: camera is perspective, view frustum culling is ON"

43
tests/bugs/vis/bug30434 Normal file
View File

@ -0,0 +1,43 @@
puts "============="
puts "0030434: Visualization, TKV3d - add 'NoUpdate' state of frustum culling optimization"
puts "============="
pload VISUALIZATION
vclear
vinit View1
set THE_NB_POINTS 10
puts "Creating [expr $THE_NB_POINTS * $THE_NB_POINTS * $THE_NB_POINTS] points..."
for {set i 0} {$i < $THE_NB_POINTS} {incr i} {
for {set j 0} {$j < $THE_NB_POINTS} {incr j} {
for {set k 0} {$k < $THE_NB_POINTS} {incr k} {
vpoint p$i$j$k 3.*$i 3.*$j 3.*$k
}
}
}
vcamera -ortho
vfront
vfit
vzoom 2
vrenderparams -frustumculling on
vrenderparams -frustumculling noupdate
vfit
if { [vreadpixel 92 92 rgb name] == "YELLOW" } { puts "Error: point should be clipped earlier" }
vdump $::imagedir/${::casename}_ortho_culled.png
vrenderparams -frustumculling off
if { [vreadpixel 92 92 rgb name] != "YELLOW" } { puts "Error: point should NOT be clipped" }
vdump $::imagedir/${::casename}_ortho_all.png
vcamera -persp
vaxo
vfit
vzoom 3
vrenderparams -frustumculling on
vrenderparams -frustumculling noupdate
vfit
if { [vreadpixel 114 92 rgb name] == "YELLOW" } { puts "Error: point should be clipped earlier" }
vdump $::imagedir/${::casename}_persp_culled.png
vrenderparams -frustumculling off
if { [vreadpixel 114 92 rgb name] != "YELLOW" } { puts "Error: point should NOT be clipped" }
vdump $::imagedir/${::casename}_persp_all.png