0027341: Incorrect exact HLR results
[occt.git] / src / OpenGl / OpenGl_View.cxx
index 4b3ae3b..7d2b9b6 100644 (file)
@@ -34,6 +34,8 @@
 #include <OpenGl_Workspace.hxx>
 #include <Standard_CLocaleSentry.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
+
 #ifdef HAVE_GL2PS
 #include <gl2ps.h>
 #endif
@@ -64,18 +66,19 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
   myAntiAliasing   (Standard_False),
   myCulling        (Standard_True),
   myShadingModel   (Graphic3d_TOSM_FACET),
-  mySurfaceDetail  (Graphic3d_TOD_ALL),
   myBackfacing     (Graphic3d_TOBM_AUTOMATIC),
   myBgColor        (myDefaultBg),
   myFog            (myDefaultFog),
   myZClip          (myDefaultZClip),
   myCamera         (new Graphic3d_Camera()),
-  myFBO            (NULL),
   myUseGLLight     (Standard_True),
   myToShowTrihedron      (false),
   myToShowGradTrihedron  (false),
   myStateCounter         (theCounter),
   myLastLightSourceState (0, 0),
+  myFboColorFormat       (GL_RGBA8),
+  myFboDepthFormat       (GL_DEPTH24_STENCIL8),
+  myToFlipOutput         (Standard_False),
   myFrameCounter         (0),
   myHasFboBlit           (Standard_True),
   myTransientDrawToFront (Standard_True),
@@ -101,11 +104,25 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
     if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasing = v;
   }
 
+  OpenGl_Light       aLight;
+  aLight.Type        = Graphic3d_TOLS_AMBIENT;
+  aLight.IsHeadlight = Standard_False;
+  aLight.Color.r()   = 1.;
+  aLight.Color.g()   = 1.;
+  aLight.Color.b()   = 1.;
+  myNoShadingLight.Append (aLight);
+
   myCurrLightSourceState  = myStateCounter->Increment();
   myMainSceneFbos[0]      = new OpenGl_FrameBuffer();
   myMainSceneFbos[1]      = new OpenGl_FrameBuffer();
   myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
   myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
+  myOpenGlFBO             = new OpenGl_FrameBuffer();
+  myOpenGlFBO2            = new OpenGl_FrameBuffer();
+  myRaytraceFBO1[0]       = new OpenGl_FrameBuffer();
+  myRaytraceFBO1[1]       = new OpenGl_FrameBuffer();
+  myRaytraceFBO2[0]       = new OpenGl_FrameBuffer();
+  myRaytraceFBO2[1]       = new OpenGl_FrameBuffer();
 }
 
 // =======================================================================
@@ -152,6 +169,8 @@ void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
   myMainSceneFbos[1]     ->Release (theCtx.operator->());
   myImmediateSceneFbos[0]->Release (theCtx.operator->());
   myImmediateSceneFbos[1]->Release (theCtx.operator->());
+  myOpenGlFBO            ->Release (theCtx.operator->());
+  myOpenGlFBO2           ->Release (theCtx.operator->());
   myFullScreenQuad        .Release (theCtx.operator->());
   myFullScreenQuadFlip    .Release (theCtx.operator->());
 
@@ -366,22 +385,6 @@ void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, c
   myGraduatedTrihedron.SetMinMax (theMin, theMax);
 }
 
-// =======================================================================
-// function : ReadDepths
-// purpose  :
-// =======================================================================
-void OpenGl_View::ReadDepths (const Standard_Integer theX,
-                              const Standard_Integer theY,
-                              const Standard_Integer theWidth,
-                              const Standard_Integer theHeight,
-                              const Standard_Address theBuffer) const
-{
-  if (myWindow.IsNull())
-    return;
-
-  myWindow->ReadDepths (theX, theY, theWidth, theHeight, (float*)theBuffer);
-}
-
 // =======================================================================
 // function : BufferDump
 // purpose  :
@@ -522,26 +525,26 @@ void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId        theLayerId,
 //function : FBO
 //purpose  :
 //=======================================================================
-Graphic3d_PtrFrameBuffer OpenGl_View::FBO() const
+Handle(Standard_Transient) OpenGl_View::FBO() const
 {
-  return reinterpret_cast<Graphic3d_PtrFrameBuffer> (myFBO);
+  return Handle(Standard_Transient)(myFBO);
 }
 
 //=======================================================================
 //function : SetFBO
 //purpose  :
 //=======================================================================
-void OpenGl_View::SetFBO (const Graphic3d_PtrFrameBuffer theFBO)
+void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
 {
-  myFBO = reinterpret_cast<OpenGl_FrameBuffer*> (theFBO);
+  myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
 }
 
 //=======================================================================
 //function : FBOCreate
 //purpose  :
 //=======================================================================
-Graphic3d_PtrFrameBuffer OpenGl_View::FBOCreate (const Standard_Integer theWidth,
-                                                 const Standard_Integer theHeight)
+Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
+                                                   const Standard_Integer theHeight)
 {
   return myWorkspace->FBOCreate (theWidth, theHeight);
 }
@@ -550,22 +553,34 @@ Graphic3d_PtrFrameBuffer OpenGl_View::FBOCreate (const Standard_Integer theWidth
 //function : FBORelease
 //purpose  :
 //=======================================================================
-void OpenGl_View::FBORelease (Graphic3d_PtrFrameBuffer& theFBOPtr)
+void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
 {
-  myWorkspace->FBORelease (theFBOPtr);
+  Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+  if (aFrameBuffer.IsNull())
+  {
+    return;
+  }
+
+  myWorkspace->FBORelease (aFrameBuffer);
+  theFbo.Nullify();
 }
 
 //=======================================================================
 //function : FBOGetDimensions
 //purpose  :
 //=======================================================================
-void OpenGl_View::FBOGetDimensions (const Graphic3d_PtrFrameBuffer theFBOPtr,
+void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
                                     Standard_Integer& theWidth,
                                     Standard_Integer& theHeight,
                                     Standard_Integer& theWidthMax,
                                     Standard_Integer& theHeightMax)
 {
-  const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr;
+  const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+  if (aFrameBuffer.IsNull())
+  {
+    return;
+  }
+
   theWidth     = aFrameBuffer->GetVPSizeX(); // current viewport size
   theHeight    = aFrameBuffer->GetVPSizeY();
   theWidthMax  = aFrameBuffer->GetSizeX(); // texture size
@@ -576,11 +591,16 @@ void OpenGl_View::FBOGetDimensions (const Graphic3d_PtrFrameBuffer theFBOPtr,
 //function : FBOChangeViewport
 //purpose  :
 //=======================================================================
-void OpenGl_View::FBOChangeViewport (Graphic3d_PtrFrameBuffer& theFBOPtr,
+void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
                                      const Standard_Integer theWidth,
                                      const Standard_Integer theHeight)
 {
-  OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
+  const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
+  if (aFrameBuffer.IsNull())
+  {
+    return;
+  }
+
   aFrameBuffer->ChangeViewport (theWidth, theHeight);
 }