1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_View.hxx>
18 #include <Aspect_RenderingContext.hxx>
19 #include <Aspect_Window.hxx>
20 #include <Graphic3d_AspectFillArea3d.hxx>
21 #include <Graphic3d_Texture2Dmanual.hxx>
22 #include <Graphic3d_TextureEnv.hxx>
23 #include <Graphic3d_Mat4d.hxx>
24 #include <NCollection_Mat4.hxx>
25 #include <OpenGl_Context.hxx>
26 #include <OpenGl_FrameBuffer.hxx>
27 #include <OpenGl_GlCore11.hxx>
28 #include <OpenGl_GraduatedTrihedron.hxx>
29 #include <OpenGl_GraphicDriver.hxx>
30 #include <OpenGl_ShaderManager.hxx>
31 #include <OpenGl_Texture.hxx>
32 #include <OpenGl_Window.hxx>
33 #include <OpenGl_Workspace.hxx>
34 #include <OSD_Parallel.hxx>
35 #include <Standard_CLocaleSentry.hxx>
37 #include "../Graphic3d/Graphic3d_Structure.pxx"
39 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
41 // =======================================================================
42 // function : Constructor
44 // =======================================================================
45 OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
46 const Handle(OpenGl_GraphicDriver)& theDriver,
47 const Handle(OpenGl_Caps)& theCaps,
48 OpenGl_StateCounter* theCounter)
49 : Graphic3d_CView (theMgr),
50 myDriver (theDriver.operator->()),
52 myWasRedrawnGL (Standard_False),
53 myBackfacing (Graphic3d_TOBM_AUTOMATIC),
54 myToShowGradTrihedron (false),
55 myZLayers (Structure_MAX_PRIORITY - Structure_MIN_PRIORITY + 1),
56 myStateCounter (theCounter),
57 myCurrLightSourceState (theCounter->Increment()),
59 myLastLightSourceState (0, 0),
60 myFboColorFormat (GL_RGBA8),
61 myFboDepthFormat (GL_DEPTH24_STENCIL8),
62 myToFlipOutput (Standard_False),
64 myHasFboBlit (Standard_True),
65 myToDisableOIT (Standard_False),
66 myToDisableOITMSAA (Standard_False),
67 myToDisableMSAA (Standard_False),
68 myTransientDrawToFront (Standard_True),
69 myBackBufferRestored (Standard_False),
70 myIsImmediateDrawn (Standard_False),
71 myTextureParams (new OpenGl_Aspects()),
72 myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
73 myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
74 // ray-tracing fields initialization
75 myRaytraceInitStatus (OpenGl_RT_NONE),
76 myIsRaytraceDataValid (Standard_False),
77 myIsRaytraceWarnTextures (Standard_False),
78 myRaytraceBVHBuilder (new BVH_BinnedBuilder<Standard_ShortReal, 3, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeAverage,
79 BVH_Constants_MaxTreeDepth,
81 OSD_Parallel::NbLogicalProcessors() + 1)),
82 myRaytraceSceneRadius (0.0f),
83 myRaytraceSceneEpsilon (1.0e-6f),
84 myToUpdateEnvironmentMap (Standard_False),
85 myRaytraceLayerListState (0),
86 myPrevCameraApertureRadius(0.f),
87 myPrevCameraFocalPlaneDist(0.f)
89 myWorkspace = new OpenGl_Workspace (this, NULL);
91 Handle(Graphic3d_CLight) aLight = new Graphic3d_CLight (Graphic3d_TOLS_AMBIENT);
92 aLight->SetHeadlight (false);
93 aLight->SetColor (Quantity_NOC_WHITE);
94 myNoShadingLight = new Graphic3d_LightSet();
95 myNoShadingLight->Add (aLight);
97 myMainSceneFbos[0] = new OpenGl_FrameBuffer();
98 myMainSceneFbos[1] = new OpenGl_FrameBuffer();
99 myMainSceneFbosOit[0] = new OpenGl_FrameBuffer();
100 myMainSceneFbosOit[1] = new OpenGl_FrameBuffer();
101 myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
102 myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
103 myImmediateSceneFbosOit[0] = new OpenGl_FrameBuffer();
104 myImmediateSceneFbosOit[1] = new OpenGl_FrameBuffer();
105 myOpenGlFBO = new OpenGl_FrameBuffer();
106 myOpenGlFBO2 = new OpenGl_FrameBuffer();
107 myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
108 myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
109 myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
110 myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
113 // =======================================================================
114 // function : Destructor
116 // =======================================================================
117 OpenGl_View::~OpenGl_View()
119 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
120 OpenGl_Element::Destroy (NULL, myBgGradientArray);
121 OpenGl_Element::Destroy (NULL, myBgTextureArray);
122 OpenGl_Element::Destroy (NULL, myTextureParams);
125 // =======================================================================
126 // function : ReleaseGlResources
128 // =======================================================================
129 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
131 myGraduatedTrihedron.Release (theCtx.get());
132 myFrameStatsPrs.Release (theCtx.get());
134 if (!myTextureEnv.IsNull())
136 if (!theCtx.IsNull())
138 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
140 theCtx->DelayedRelease (aTextureIter.ChangeValue());
141 aTextureIter.ChangeValue().Nullify();
144 myTextureEnv.Nullify();
147 if (myTextureParams != NULL)
149 myTextureParams->Release (theCtx.get());
151 if (myBgGradientArray != NULL)
153 myBgGradientArray->Release (theCtx.get());
155 if (myBgTextureArray != NULL)
157 myBgTextureArray->Release (theCtx.get());
160 myMainSceneFbos[0] ->Release (theCtx.get());
161 myMainSceneFbos[1] ->Release (theCtx.get());
162 myMainSceneFbosOit[0] ->Release (theCtx.get());
163 myMainSceneFbosOit[1] ->Release (theCtx.get());
164 myImmediateSceneFbos[0] ->Release (theCtx.get());
165 myImmediateSceneFbos[1] ->Release (theCtx.get());
166 myImmediateSceneFbosOit[0]->Release (theCtx.get());
167 myImmediateSceneFbosOit[1]->Release (theCtx.get());
168 myOpenGlFBO ->Release (theCtx.get());
169 myOpenGlFBO2 ->Release (theCtx.get());
170 myFullScreenQuad .Release (theCtx.get());
171 myFullScreenQuadFlip .Release (theCtx.get());
173 releaseRaytraceResources (theCtx);
176 // =======================================================================
179 // =======================================================================
180 void OpenGl_View::Remove()
187 myDriver->RemoveView (this);
190 Graphic3d_CView::Remove();
193 // =======================================================================
194 // function : SetLocalOrigin
196 // =======================================================================
197 void OpenGl_View::SetLocalOrigin (const gp_XYZ& theOrigin)
199 myLocalOrigin = theOrigin;
200 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
203 aCtx->ShaderManager()->SetLocalOrigin (theOrigin);
207 // =======================================================================
208 // function : SetTextureEnv
210 // =======================================================================
211 void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
213 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
214 if (!aCtx.IsNull() && !myTextureEnv.IsNull())
216 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
218 aCtx->DelayedRelease (aTextureIter.ChangeValue());
219 aTextureIter.ChangeValue().Nullify();
223 myToUpdateEnvironmentMap = Standard_True;
224 myTextureEnvData = theTextureEnv;
225 myTextureEnv.Nullify();
226 initTextureEnv (aCtx);
229 // =======================================================================
230 // function : initTextureEnv
232 // =======================================================================
233 void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
235 if (myTextureEnvData.IsNull()
236 || theContext.IsNull()
237 || !theContext->MakeCurrent())
242 myTextureEnv = new OpenGl_TextureSet (1);
243 Handle(OpenGl_Texture)& aTextureEnv = myTextureEnv->ChangeFirst();
244 aTextureEnv = new OpenGl_Texture (myTextureEnvData->GetId(), myTextureEnvData->GetParams());
245 Handle(Image_PixMap) anImage = myTextureEnvData->GetImage();
246 if (!anImage.IsNull())
248 aTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type());
252 // =======================================================================
253 // function : SetImmediateModeDrawToFront
255 // =======================================================================
256 Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
258 const Standard_Boolean aPrevMode = myTransientDrawToFront;
259 myTransientDrawToFront = theDrawToFrontBuffer;
263 // =======================================================================
264 // function : SetWindow
266 // =======================================================================
267 void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
268 const Aspect_RenderingContext theContext)
270 myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
271 Standard_ASSERT_RAISE (!myWindow.IsNull(),
272 "OpenGl_View::SetWindow, "
273 "Failed to create OpenGl window.");
275 myWorkspace = new OpenGl_Workspace (this, myWindow);
276 myWorldViewProjState.Reset();
277 myToUpdateEnvironmentMap = Standard_True;
278 myHasFboBlit = Standard_True;
281 // Environment texture resource does not support lazy initialization.
282 initTextureEnv (myWorkspace->GetGlContext());
285 // =======================================================================
286 // function : Resized
288 // =======================================================================
289 void OpenGl_View::Resized()
291 if (myWindow.IsNull())
297 // =======================================================================
298 // function : SetMinMaxValuesCallback
300 // =======================================================================
301 static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
303 OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
307 Bnd_Box aBox = theView->MinMaxValues();
310 gp_Pnt aMin = aBox.CornerMin();
311 gp_Pnt aMax = aBox.CornerMax();
313 Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
314 Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
315 aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
319 // =======================================================================
320 // function : GraduatedTrihedronDisplay
322 // =======================================================================
323 void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
325 myGTrihedronData = theTrihedronData;
326 myGTrihedronData.PtrView = this;
327 myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
328 myGraduatedTrihedron.SetValues (myGTrihedronData);
329 myToShowGradTrihedron = true;
332 // =======================================================================
333 // function : GraduatedTrihedronErase
335 // =======================================================================
336 void OpenGl_View::GraduatedTrihedronErase()
338 myGTrihedronData.PtrView = NULL;
339 myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
340 myToShowGradTrihedron = false;
343 // =======================================================================
344 // function : GraduatedTrihedronMinMaxValues
346 // =======================================================================
347 void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
349 myGraduatedTrihedron.SetMinMax (theMin, theMax);
352 // =======================================================================
353 // function : BufferDump
355 // =======================================================================
356 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
358 if (theBufferType != Graphic3d_BT_RGB_RayTraceHdrLeft)
360 return myWorkspace->BufferDump(myFBO, theImage, theBufferType);
363 if (!myRaytraceParameters.AdaptiveScreenSampling)
365 return myWorkspace->BufferDump(myAccumFrames % 2 ? myRaytraceFBO2[0] : myRaytraceFBO1[0], theImage, theBufferType);
368 #if defined(GL_ES_VERSION_2_0)
371 if (theImage.Format() != Image_Format_RGBF)
376 const GLuint aW = myRaytraceOutputTexture[0]->SizeX();
377 const GLuint aH = myRaytraceOutputTexture[0]->SizeY();
378 if (aW / 3 != theImage.SizeX() || aH / 2 != theImage.SizeY())
383 std::vector<GLfloat> aValues;
386 aValues.resize (aW * aH);
388 catch (const std::bad_alloc&)
393 glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[0]->TextureId());
394 glGetTexImage (GL_TEXTURE_RECTANGLE, 0, OpenGl_TextureFormat::Create<GLfloat, 1>().Format(), GL_FLOAT, &aValues[0]);
395 glBindTexture (GL_TEXTURE_RECTANGLE, 0);
396 for (unsigned int aRow = 0; aRow < aH; aRow += 2)
398 for (unsigned int aCol = 0; aCol < aW; aCol += 3)
400 float* anImageValue = theImage.ChangeValue<float[3]> ((aH - aRow) / 2 - 1, aCol / 3);
401 float aInvNbSamples = 1.f / aValues[aRow * aW + aCol + aW];
402 anImageValue[0] = aValues[aRow * aW + aCol] * aInvNbSamples;
403 anImageValue[1] = aValues[aRow * aW + aCol + 1] * aInvNbSamples;
404 anImageValue[2] = aValues[aRow * aW + aCol + 1 + aW] * aInvNbSamples;
412 // =======================================================================
413 // function : GradientBackground
415 // =======================================================================
416 Aspect_GradientBackground OpenGl_View::GradientBackground() const
418 Quantity_Color aColor1, aColor2;
419 aColor1.SetValues (myBgGradientArray->GradientColor (0).r(),
420 myBgGradientArray->GradientColor (0).g(),
421 myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB);
422 aColor2.SetValues (myBgGradientArray->GradientColor (1).r(),
423 myBgGradientArray->GradientColor (1).g(),
424 myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB);
425 return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod());
428 // =======================================================================
429 // function : SetGradientBackground
431 // =======================================================================
432 void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
434 Quantity_Color aColor1, aColor2;
435 theBackground.Colors (aColor1, aColor2);
436 myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
439 // =======================================================================
440 // function : SetBackgroundImage
442 // =======================================================================
443 void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
445 // Prepare aspect for texture storage
446 myBackgroundImagePath = theFilePath;
447 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
448 Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
449 aTextureMap->EnableRepeat();
450 aTextureMap->DisableModulate();
451 aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
452 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
453 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
454 anAspect->SetTextureMap (aTextureMap);
455 anAspect->SetInteriorStyle (Aspect_IS_SOLID);
456 anAspect->SetSuppressBackFaces (false);
457 // Enable texture mapping
458 if (aTextureMap->IsDone())
460 anAspect->SetTextureMapOn();
464 anAspect->SetTextureMapOff();
468 // Set texture parameters
469 myTextureParams->SetAspect (anAspect);
472 // =======================================================================
473 // function : BackgroundImageStyle
475 // =======================================================================
476 Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
478 return myBgTextureArray->TextureFillMethod();
481 // =======================================================================
482 // function : SetBackgroundImageStyle
484 // =======================================================================
485 void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
487 myBgTextureArray->SetTextureFillMethod (theFillStyle);
490 //=======================================================================
491 //function : AddZLayer
493 //=======================================================================
494 void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
496 myZLayers.AddLayer (theLayerId);
499 //=======================================================================
500 //function : RemoveZLayer
502 //=======================================================================
503 void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
505 myZLayers.RemoveLayer (theLayerId);
508 //=======================================================================
509 //function : SetZLayerSettings
511 //=======================================================================
512 void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
513 const Graphic3d_ZLayerSettings& theSettings)
515 myZLayers.SetLayerSettings (theLayerId, theSettings);
518 //=======================================================================
519 //function : ZLayerMax
521 //=======================================================================
522 Standard_Integer OpenGl_View::ZLayerMax() const
524 Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
525 for (OpenGl_LayerSeqIds::Iterator aMapIt(myZLayers.LayerIDs()); aMapIt.More(); aMapIt.Next())
527 aLayerMax = Max (aLayerMax, aMapIt.Value());
533 //=======================================================================
534 //function : InvalidateZLayerBoundingBox
536 //=======================================================================
537 void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const
539 if (myZLayers.LayerIDs().IsBound (theLayerId))
541 myZLayers.Layer (theLayerId).InvalidateBoundingBox();
545 const Standard_Integer aLayerMax = ZLayerMax();
546 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < aLayerMax; ++aLayerId)
548 if (myZLayers.LayerIDs().IsBound (aLayerId))
550 const OpenGl_Layer& aLayer = myZLayers.Layer (aLayerId);
551 if (aLayer.NbOfTransformPersistenceObjects() > 0)
553 aLayer.InvalidateBoundingBox();
560 //=======================================================================
561 //function : ZLayerBoundingBox
563 //=======================================================================
564 Bnd_Box OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
565 const Handle(Graphic3d_Camera)& theCamera,
566 const Standard_Integer theWindowWidth,
567 const Standard_Integer theWindowHeight,
568 const Standard_Boolean theToIncludeAuxiliary) const
571 if (myZLayers.LayerIDs().IsBound (theLayerId))
573 aBox = myZLayers.Layer (theLayerId).BoundingBox (Identification(),
577 theToIncludeAuxiliary);
580 // add bounding box of gradient/texture background for proper Z-fit
581 if (theToIncludeAuxiliary
582 && theLayerId == Graphic3d_ZLayerId_BotOSD
583 && (myBgTextureArray->IsDefined()
584 || myBgGradientArray->IsDefined()))
586 // Background is drawn using 2D transformation persistence
587 // (e.g. it is actually placed in 3D coordinates within active camera position).
588 // We add here full-screen plane with 2D transformation persistence
589 // for simplicity (myBgTextureArray might define a little bit different options
590 // but it is updated within ::Render())
591 const Graphic3d_Mat4d& aProjectionMat = theCamera->ProjectionMatrix();
592 const Graphic3d_Mat4d& aWorldViewMat = theCamera->OrientationMatrix();
593 Graphic3d_BndBox3d aBox2d (Graphic3d_Vec3d (0.0, 0.0, 0.0),
594 Graphic3d_Vec3d (double(theWindowWidth), double(theWindowHeight), 0.0));
596 Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER);
597 aTrsfPers.Apply (theCamera,
603 aBox.Add (gp_Pnt (aBox2d.CornerMin().x(), aBox2d.CornerMin().y(), aBox2d.CornerMin().z()));
604 aBox.Add (gp_Pnt (aBox2d.CornerMax().x(), aBox2d.CornerMax().y(), aBox2d.CornerMax().z()));
610 //=======================================================================
611 //function : considerZoomPersistenceObjects
613 //=======================================================================
614 Standard_Real OpenGl_View::considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
615 const Handle(Graphic3d_Camera)& theCamera,
616 const Standard_Integer theWindowWidth,
617 const Standard_Integer theWindowHeight) const
619 if (myZLayers.LayerIDs().IsBound (theLayerId))
621 return myZLayers.Layer (theLayerId).considerZoomPersistenceObjects (Identification(),
630 //=======================================================================
633 //=======================================================================
634 Handle(Standard_Transient) OpenGl_View::FBO() const
636 return Handle(Standard_Transient)(myFBO);
639 //=======================================================================
642 //=======================================================================
643 void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
645 myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
648 //=======================================================================
649 //function : FBOCreate
651 //=======================================================================
652 Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
653 const Standard_Integer theHeight)
655 return myWorkspace->FBOCreate (theWidth, theHeight);
658 //=======================================================================
659 //function : FBORelease
661 //=======================================================================
662 void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
664 Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
665 if (aFrameBuffer.IsNull())
670 myWorkspace->FBORelease (aFrameBuffer);
674 //=======================================================================
675 //function : FBOGetDimensions
677 //=======================================================================
678 void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
679 Standard_Integer& theWidth,
680 Standard_Integer& theHeight,
681 Standard_Integer& theWidthMax,
682 Standard_Integer& theHeightMax)
684 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
685 if (aFrameBuffer.IsNull())
690 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
691 theHeight = aFrameBuffer->GetVPSizeY();
692 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
693 theHeightMax = aFrameBuffer->GetSizeY();
696 //=======================================================================
697 //function : FBOChangeViewport
699 //=======================================================================
700 void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
701 const Standard_Integer theWidth,
702 const Standard_Integer theHeight)
704 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
705 if (aFrameBuffer.IsNull())
710 aFrameBuffer->ChangeViewport (theWidth, theHeight);
713 //=======================================================================
714 //function : displayStructure
716 //=======================================================================
717 void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
718 const Standard_Integer thePriority)
720 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
721 const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
722 myZLayers.AddStructure (aStruct, aZLayer, thePriority);
725 //=======================================================================
726 //function : eraseStructure
728 //=======================================================================
729 void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
731 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
732 myZLayers.RemoveStructure (aStruct);
735 //=======================================================================
736 //function : changeZLayer
738 //=======================================================================
739 void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
740 const Graphic3d_ZLayerId theNewLayerId)
742 const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
743 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
744 myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
746 Update (theNewLayerId);
749 //=======================================================================
750 //function : changePriority
752 //=======================================================================
753 void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
754 const Standard_Integer theNewPriority)
756 const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
757 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
758 myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
761 //=======================================================================
762 //function : DiagnosticInformation
764 //=======================================================================
765 void OpenGl_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
766 Graphic3d_DiagnosticInfo theFlags) const
768 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
769 if (!myWorkspace->Activate()
775 aCtx->DiagnosticInformation (theDict, theFlags);
776 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
778 TCollection_AsciiString aResRatio (myRenderParams.ResolutionRatio());
779 theDict.ChangeFromIndex (theDict.Add ("ResolutionRatio", aResRatio)) = aResRatio;
783 //=======================================================================
784 //function : StatisticInformation
786 //=======================================================================
787 void OpenGl_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
789 if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
791 const Handle(OpenGl_FrameStats)& aStats = aCtx->FrameStats();
792 const Graphic3d_RenderingParams& aRendParams = myWorkspace->View()->RenderingParams();
793 aStats->FormatStats (theDict, aRendParams.CollectedStats);
797 //=======================================================================
798 //function : StatisticInformation
800 //=======================================================================
801 TCollection_AsciiString OpenGl_View::StatisticInformation() const
803 if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
805 const Handle(OpenGl_FrameStats)& aStats = aCtx->FrameStats();
806 const Graphic3d_RenderingParams& aRendParams = myWorkspace->View()->RenderingParams();
807 return aStats->FormatStats (aRendParams.CollectedStats);
809 return TCollection_AsciiString();