diff --git a/src/Graphic3d/Graphic3d_CView.cxx b/src/Graphic3d/Graphic3d_CView.cxx index a8ff322758..e88505feb4 100644 --- a/src/Graphic3d/Graphic3d_CView.cxx +++ b/src/Graphic3d/Graphic3d_CView.cxx @@ -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())); diff --git a/src/Graphic3d/Graphic3d_CView.hxx b/src/Graphic3d/Graphic3d_CView.hxx index bc802d051c..1a2eda6fe8 100644 --- a/src/Graphic3d/Graphic3d_CView.hxx +++ b/src/Graphic3d/Graphic3d_CView.hxx @@ -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; diff --git a/src/Graphic3d/Graphic3d_RenderingParams.hxx b/src/Graphic3d/Graphic3d_RenderingParams.hxx index 001cef24bc..cbb8c822ed 100644 --- a/src/Graphic3d/Graphic3d_RenderingParams.hxx +++ b/src/Graphic3d/Graphic3d_RenderingParams.hxx @@ -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 diff --git a/src/OpenGl/OpenGl_Layer.cxx b/src/OpenGl/OpenGl_Layer.cxx index 120bbef951..53d0b5cea6 100644 --- a/src/OpenGl/OpenGl_Layer.cxx +++ b/src/OpenGl/OpenGl_Layer.cxx @@ -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; } diff --git a/src/OpenGl/OpenGl_Layer.hxx b/src/OpenGl/OpenGl_Layer.hxx index 613e46d776..8fe3f46ec6 100644 --- a/src/OpenGl/OpenGl_Layer.hxx +++ b/src/OpenGl/OpenGl_Layer.hxx @@ -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; } diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 9e812784e8..2948219289 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -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(); diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index f6b3fa6c9b..4e9a35d101 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -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()), diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index c24873b86f..29a74188d9 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -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; diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index 8e355a264d..ab9fa99203 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -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 : diff --git a/src/V3d/V3d_View.cxx b/src/V3d/V3d_View.cxx index 547af8334d..0874f5e648 100644 --- a/src/V3d/V3d_View.cxx +++ b/src/V3d/V3d_View.cxx @@ -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 : diff --git a/src/V3d/V3d_View.hxx b/src/V3d/V3d_View.hxx index d0ec47a448..85701bcf79 100644 --- a/src/V3d/V3d_View.hxx +++ b/src/V3d/V3d_View.hxx @@ -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. diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 69beafb549..a2c3ce8682 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -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", diff --git a/tests/bugs/vis/bug24307_1 b/tests/bugs/vis/bug24307_1 index 5cf52b2b4c..810badf5d1 100644 --- a/tests/bugs/vis/bug24307_1 +++ b/tests/bugs/vis/bug24307_1 @@ -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 diff --git a/tests/bugs/vis/bug24307_2 b/tests/bugs/vis/bug24307_2 index f0e909ffc5..06852760e9 100644 --- a/tests/bugs/vis/bug24307_2 +++ b/tests/bugs/vis/bug24307_2 @@ -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) diff --git a/tests/bugs/vis/bug25400 b/tests/bugs/vis/bug25400 index 0114171de8..d49c084e58 100644 --- a/tests/bugs/vis/bug25400 +++ b/tests/bugs/vis/bug25400 @@ -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 diff --git a/tests/bugs/vis/bug25679 b/tests/bugs/vis/bug25679 index 591c650cc0..285151e05d 100644 --- a/tests/bugs/vis/bug25679 +++ b/tests/bugs/vis/bug25679 @@ -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] diff --git a/tests/bugs/vis/bug25760_1 b/tests/bugs/vis/bug25760_1 index 26d1ea5e4a..8ab433bd71 100644 --- a/tests/bugs/vis/bug25760_1 +++ b/tests/bugs/vis/bug25760_1 @@ -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" diff --git a/tests/bugs/vis/bug25760_2 b/tests/bugs/vis/bug25760_2 index dfb98e3711..a3f327a84d 100644 --- a/tests/bugs/vis/bug25760_2 +++ b/tests/bugs/vis/bug25760_2 @@ -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" diff --git a/tests/bugs/vis/bug30434 b/tests/bugs/vis/bug30434 new file mode 100644 index 0000000000..e1ebfa8441 --- /dev/null +++ b/tests/bugs/vis/bug30434 @@ -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