From 1a96d253a5f2ad7d0096b03b2bc44d2236270358 Mon Sep 17 00:00:00 2001
From: kgv <kgv@opencascade.com>
Date: Mon, 22 Mar 2021 20:32:02 +0300
Subject: [PATCH] 0032222: Visualization, V3d_Viewer - use
 Graphic3d_TOSM_FRAGMENT by default instead of Graphic3d_TOSM_VERTEX

---
 src/AIS/AIS_ViewController.cxx               |  1 +
 src/PrsMgr/PrsMgr_PresentationManager.cxx    |  6 +---
 src/PrsMgr/PrsMgr_PresentationManager.hxx    |  8 -----
 src/QABugs/QABugs_19.cxx                     |  1 +
 src/V3d/V3d_Plane.cxx                        |  2 ++
 src/V3d/V3d_Trihedron.cxx                    |  1 +
 src/V3d/V3d_View.hxx                         | 37 ++++----------------
 src/V3d/V3d_Viewer.cxx                       |  2 +-
 src/V3d/V3d_Viewer.hxx                       | 15 +-------
 src/ViewerTest/ViewerTest.cxx                |  9 ++---
 src/ViewerTest/ViewerTest_ViewerCommands.cxx |  1 +
 tests/bugs/vis/bug29791                      |  4 +--
 tests/mesh/end                               |  2 ++
 13 files changed, 25 insertions(+), 64 deletions(-)

diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx
index 3d9ac792c7..0c0399723b 100644
--- a/src/AIS/AIS_ViewController.cxx
+++ b/src/AIS/AIS_ViewController.cxx
@@ -27,6 +27,7 @@
 #include <Message_Messenger.hxx>
 #include <gp_Quaternion.hxx>
 #include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
 #include <WNT_HIDSpaceMouse.hxx>
 
 // =======================================================================
diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cxx b/src/PrsMgr/PrsMgr_PresentationManager.cxx
index 4aba5811be..b0be613603 100644
--- a/src/PrsMgr/PrsMgr_PresentationManager.cxx
+++ b/src/PrsMgr/PrsMgr_PresentationManager.cxx
@@ -15,17 +15,13 @@
 #include <PrsMgr_PresentationManager.hxx>
 
 #include <TopLoc_Datum3D.hxx>
-#include <Graphic3d_GraphicDriver.hxx>
 #include <Prs3d_Drawer.hxx>
-#include <Prs3d_Presentation.hxx>
 #include <Prs3d_PresentationShadow.hxx>
 #include <PrsMgr_PresentableObject.hxx>
 #include <PrsMgr_Presentation.hxx>
 #include <PrsMgr_Presentations.hxx>
-#include <Standard_NoSuchObject.hxx>
-#include <Standard_Type.hxx>
-#include <TColStd_ListIteratorOfListOfTransient.hxx>
 #include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager, Standard_Transient)
 
diff --git a/src/PrsMgr/PrsMgr_PresentationManager.hxx b/src/PrsMgr/PrsMgr_PresentationManager.hxx
index 03c75a83bf..5160c520c6 100644
--- a/src/PrsMgr/PrsMgr_PresentationManager.hxx
+++ b/src/PrsMgr/PrsMgr_PresentationManager.hxx
@@ -17,17 +17,10 @@
 #ifndef _PrsMgr_PresentationManager_HeaderFile
 #define _PrsMgr_PresentationManager_HeaderFile
 
-#include <Graphic3d_NameOfMaterial.hxx>
 #include <Graphic3d_StructureManager.hxx>
 #include <Graphic3d_ZLayerId.hxx>
-#include <Standard_Transient.hxx>
 #include <PrsMgr_ListOfPresentations.hxx>
 #include <Quantity_Color.hxx>
-#include <Quantity_NameOfColor.hxx>
-#include <Standard.hxx>
-#include <Standard_Boolean.hxx>
-#include <Standard_Integer.hxx>
-#include <Standard_Type.hxx>
 
 class Graphic3d_Structure;
 typedef Graphic3d_Structure Prs3d_Presentation;
@@ -36,7 +29,6 @@ class TopLoc_Datum3D;
 class Prs3d_Drawer;
 class PrsMgr_Presentation;
 class PrsMgr_PresentableObject;
-class Standard_NoSuchObject;
 class V3d_Viewer;
 
 DEFINE_STANDARD_HANDLE(PrsMgr_PresentationManager, Standard_Transient)
diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx
index 2d4e27858c..1c5cf01c06 100644
--- a/src/QABugs/QABugs_19.cxx
+++ b/src/QABugs/QABugs_19.cxx
@@ -54,6 +54,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Shape.hxx>
 #include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
 #include <ViewerTest.hxx>
 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
 #include <XmlDrivers_DocumentStorageDriver.hxx>
diff --git a/src/V3d/V3d_Plane.cxx b/src/V3d/V3d_Plane.cxx
index 2fef4590cd..3a26015bd4 100755
--- a/src/V3d/V3d_Plane.cxx
+++ b/src/V3d/V3d_Plane.cxx
@@ -14,10 +14,12 @@
 // commercial license or contractual agreement.
 
 #include <V3d_Plane.hxx>
+
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_ArrayOfQuadrangles.hxx>
 #include <gp_Pln.hxx>
+#include <V3d_Viewer.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(V3d_Plane,Standard_Transient)
 
diff --git a/src/V3d/V3d_Trihedron.cxx b/src/V3d/V3d_Trihedron.cxx
index bd6400725d..61159f0921 100644
--- a/src/V3d/V3d_Trihedron.cxx
+++ b/src/V3d/V3d_Trihedron.cxx
@@ -28,6 +28,7 @@
 #include <Prs3d_TextAspect.hxx>
 #include <Prs3d_ToolSphere.hxx>
 #include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT (V3d_Trihedron, Standard_Transient)
 
diff --git a/src/V3d/V3d_View.hxx b/src/V3d/V3d_View.hxx
index 3c0ce8ecae..738a38e291 100644
--- a/src/V3d/V3d_View.hxx
+++ b/src/V3d/V3d_View.hxx
@@ -24,13 +24,10 @@
 #include <Aspect_Handle.hxx>
 #include <Aspect_RenderingContext.hxx>
 #include <Aspect_TypeOfTriedronPosition.hxx>
-
 #include <Bnd_Box.hxx>
-
 #include <gp_Ax3.hxx>
 #include <gp_Dir.hxx>
 #include <gp_Pnt.hxx>
-
 #include <Graphic3d_BufferType.hxx>
 #include <Graphic3d_Camera.hxx>
 #include <Graphic3d_ClipPlane.hxx>
@@ -40,46 +37,26 @@
 #include <Graphic3d_SequenceOfHClipPlane.hxx>
 #include <Graphic3d_TypeOfShadingModel.hxx>
 #include <Graphic3d_Vertex.hxx>
-
 #include <Image_PixMap.hxx>
-
-#include <Standard_Transient.hxx>
-
 #include <Quantity_TypeOfColor.hxx>
-
-#include <Standard.hxx>
-#include <Standard_Address.hxx>
-#include <Standard_Boolean.hxx>
-#include <Standard_CString.hxx>
-#include <Standard_Integer.hxx>
-#include <Standard_Real.hxx>
-#include <Standard_Type.hxx>
-
 #include <TColStd_Array2OfReal.hxx>
 #include <TColStd_ListIteratorOfListOfTransient.hxx>
-
 #include <V3d_ImageDumpOptions.hxx>
+#include <V3d_ListOfLight.hxx>
+#include <V3d_Viewer.hxx>
 #include <V3d_Trihedron.hxx>
 #include <V3d_TypeOfAxe.hxx>
-
 #include <V3d_TypeOfBackfacingModel.hxx>
 #include <V3d_TypeOfOrientation.hxx>
 #include <V3d_TypeOfView.hxx>
 #include <V3d_TypeOfVisualization.hxx>
-#include <V3d_Viewer.hxx>
-#include <V3d_ViewerPointer.hxx>
 
 class Aspect_Grid;
 class Aspect_Window;
 class Graphic3d_Group;
 class Graphic3d_Structure;
 class Graphic3d_TextureEnv;
-class Standard_MultiplyDefined;
-class Standard_TypeMismatch;
-class V3d_BadValue;
-class V3d_UnMapped;
 
-class V3d_View;
 DEFINE_STANDARD_HANDLE(V3d_View, Standard_Transient)
 
 //! Defines the application object VIEW for the
@@ -259,9 +236,6 @@ public:
   Standard_EXPORT void SetAxis (const Standard_Real X, const Standard_Real Y, const Standard_Real Z,
                                 const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz);
 
-  //! Defines the shading model for the visualization. Various models are available.
-  Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel);
-
   //! Sets the environment texture to use. No environment texture by default.
   Standard_EXPORT void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture);
 
@@ -714,9 +688,12 @@ public:
   //! the visual axis measured from the Y axis of the screen.
   Standard_EXPORT Standard_Real Twist() const;
 
-  //! Returns the current shading model.
+  //! Returns the current shading model; Graphic3d_TOSM_FRAGMENT by default.
   Standard_EXPORT Graphic3d_TypeOfShadingModel ShadingModel() const;
 
+  //! Defines the shading model for the visualization.
+  Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel);
+
   Standard_EXPORT Handle(Graphic3d_TextureEnv) TextureEnv() const;
 
   //! Returns the current visualisation mode.
@@ -1038,7 +1015,7 @@ protected:
 
 private:
 
-  V3d_ViewerPointer MyViewer;
+  V3d_Viewer* MyViewer;
   V3d_ListOfLight myActiveLights;
   gp_Dir myDefaultViewAxis;
   gp_Pnt myDefaultViewPoint;
diff --git a/src/V3d/V3d_Viewer.cxx b/src/V3d/V3d_Viewer.cxx
index 4306c26a9a..439ed247e8 100644
--- a/src/V3d/V3d_Viewer.cxx
+++ b/src/V3d/V3d_Viewer.cxx
@@ -57,7 +57,7 @@ V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver)
   myGridEcho (Standard_True),
   myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
 {
-  myDefaultRenderingParams.ShadingModel = Graphic3d_TOSM_VERTEX;
+  //
 }
 
 // ========================================================================
diff --git a/src/V3d/V3d_Viewer.hxx b/src/V3d/V3d_Viewer.hxx
index a51543ea06..898782d775 100644
--- a/src/V3d/V3d_Viewer.hxx
+++ b/src/V3d/V3d_Viewer.hxx
@@ -23,33 +23,20 @@
 #include <Aspect_GradientFillMethod.hxx>
 #include <Aspect_GridDrawMode.hxx>
 #include <Aspect_GridType.hxx>
-
 #include <gp_Ax3.hxx>
 #include <Graphic3d_StructureManager.hxx>
-#include <Graphic3d_TypeOfShadingModel.hxx>
 #include <Graphic3d_Vertex.hxx>
 #include <Graphic3d_ZLayerSettings.hxx>
-
-#include <Standard.hxx>
-#include <Standard_Boolean.hxx>
-#include <Standard_CString.hxx>
-#include <Standard_ExtString.hxx>
-#include <Standard_Integer.hxx>
-#include <Standard_Real.hxx>
-#include <Standard_Type.hxx>
-
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfTransient.hxx>
 #include <TColStd_SequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
-
 #include <V3d_ListOfLight.hxx>
 #include <V3d_ListOfView.hxx>
 #include <V3d_TypeOfOrientation.hxx>
 #include <V3d_TypeOfView.hxx>
 #include <V3d_TypeOfVisualization.hxx>
-
 #include <Quantity_Color.hxx>
 
 class Aspect_Grid;
@@ -166,7 +153,7 @@ public:
   //! Gives the default visualization mode.
   void SetDefaultVisualization (const V3d_TypeOfVisualization theType) { myVisualization = theType; }
 
-  //! Returns the default type of Shading
+  //! Returns the default type of Shading; Graphic3d_TOSM_FRAGMENT by default.
   Graphic3d_TypeOfShadingModel DefaultShadingModel() const { return myDefaultRenderingParams.ShadingModel; }
 
   //! Gives the default type of SHADING.
diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx
index 3a3ed1c91b..1b5d5397ed 100644
--- a/src/ViewerTest/ViewerTest.cxx
+++ b/src/ViewerTest/ViewerTest.cxx
@@ -18,6 +18,7 @@
 
 #include <ViewerTest.hxx>
 #include <ViewerTest_CmdParser.hxx>
+#include <ViewerTest_AutoUpdater.hxx>
 
 #include <Draw.hxx>
 #include <TopLoc_Location.hxx>
@@ -37,14 +38,13 @@
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Trihedron.hxx>
 #include <AIS_Axis.hxx>
-#include <PrsDim.hxx>
-#include <PrsDim_Relation.hxx>
 #include <AIS_TypeFilter.hxx>
 #include <AIS_SignatureFilter.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <Aspect_InteriorStyle.hxx>
 #include <Aspect_Window.hxx>
+#include <Aspect_XRSession.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Graphic3d_CStructure.hxx>
@@ -58,6 +58,8 @@
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
+#include <PrsDim.hxx>
+#include <PrsDim_Relation.hxx>
 #include <Select3D_SensitiveWire.hxx>
 #include <Select3D_SensitivePrimitiveArray.hxx>
 #include <Select3D_SensitiveTriangulation.hxx>
@@ -65,8 +67,7 @@
 #include <StdSelect_BRepOwner.hxx>
 #include <StdSelect_ViewerSelector3d.hxx>
 #include <TopTools_MapOfShape.hxx>
-#include <ViewerTest_AutoUpdater.hxx>
-#include <Aspect_XRSession.hxx>
+#include <V3d_Viewer.hxx>
 
 #include <stdio.h>
 
diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx
index 21ed5533a5..f17aae1350 100644
--- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx
+++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx
@@ -91,6 +91,7 @@
 #include <V3d_PositionalLight.hxx>
 #include <V3d_SpotLight.hxx>
 #include <V3d_Trihedron.hxx>
+#include <V3d_Viewer.hxx>
 
 #include <tcl.h>
 
diff --git a/tests/bugs/vis/bug29791 b/tests/bugs/vis/bug29791
index fd3cb5bf27..6a9ba07d4d 100644
--- a/tests/bugs/vis/bug29791
+++ b/tests/bugs/vis/bug29791
@@ -18,8 +18,8 @@ vfit
 vmoveto 150 200
 vstate -entities
 vselect 150 200
-if { [vreadpixel 150 200 rgb name] != "BLACK" } { puts "Error: object is not clipped" }
-if { [vreadpixel 350 200 rgb name] != "PERU"  } { puts "Error: object should NOT be selected" }
+if { [vreadpixel 150 200 rgb name] != "BLACK"     } { puts "Error: object is not clipped" }
+if { [vreadpixel 350 200 rgb name] != "GOLDENROD" } { puts "Error: object should NOT be selected" }
 vdump $imagedir/${casename}_1.png
 
 # depth range starts behinds the picking ray
diff --git a/tests/mesh/end b/tests/mesh/end
index 9ee09492b4..5a69d8b266 100644
--- a/tests/mesh/end
+++ b/tests/mesh/end
@@ -23,6 +23,8 @@ tclean res
 
 if { [string compare $command "shading"] == 0 } {
     vinit View1
+    # prefer vertex shading
+    vrenderparams -shadingModel VERT
     vdisplay -noupdate -redisplay res
     vsetdispmode res 1
     vfit