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),
61 myFboColorFormat (GL_SRGB8_ALPHA8), // note that GL_SRGB8 is not required to be renderable, unlike GL_RGB8, GL_RGBA8, GL_SRGB8_ALPHA8
62 myFboDepthFormat (GL_DEPTH24_STENCIL8),
63 myToFlipOutput (Standard_False),
66 myHasFboBlit (Standard_True),
67 myToDisableOIT (Standard_False),
68 myToDisableOITMSAA (Standard_False),
69 myToDisableMSAA (Standard_False),
70 myTransientDrawToFront (Standard_True),
71 myBackBufferRestored (Standard_False),
72 myIsImmediateDrawn (Standard_False),
73 myTextureParams (new OpenGl_Aspects()),
74 myCubeMapParams (new OpenGl_Aspects()),
75 myBackgroundType (Graphic3d_TOB_NONE),
76 myPBREnvState (OpenGl_PBREnvState_NONEXISTENT),
77 myPBREnvRequest (OpenGl_PBREnvRequest_NONE),
78 // ray-tracing fields initialization
79 myRaytraceInitStatus (OpenGl_RT_NONE),
80 myIsRaytraceDataValid (Standard_False),
81 myIsRaytraceWarnTextures (Standard_False),
82 myRaytraceBVHBuilder (new BVH_BinnedBuilder<Standard_ShortReal, 3, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeAverage,
83 BVH_Constants_MaxTreeDepth,
85 OSD_Parallel::NbLogicalProcessors() + 1)),
86 myRaytraceSceneRadius (0.0f),
87 myRaytraceSceneEpsilon (1.0e-6f),
88 myToUpdateEnvironmentMap (Standard_False),
89 myRaytraceLayerListState (0),
90 myPrevCameraApertureRadius(0.f),
91 myPrevCameraFocalPlaneDist(0.f)
93 for (int i = 0; i < Graphic3d_TypeOfBackground_NB; ++i)
95 myBackgrounds[i] = new OpenGl_BackgroundArray(Graphic3d_TypeOfBackground(i));
98 myWorkspace = new OpenGl_Workspace (this, NULL);
100 Handle(Graphic3d_CLight) aLight = new Graphic3d_CLight (Graphic3d_TOLS_AMBIENT);
101 aLight->SetHeadlight (false);
102 aLight->SetColor (Quantity_NOC_WHITE);
103 myLights = new Graphic3d_LightSet();
104 myNoShadingLight = new Graphic3d_LightSet();
105 myNoShadingLight->Add (aLight);
107 myMainSceneFbos[0] = new OpenGl_FrameBuffer();
108 myMainSceneFbos[1] = new OpenGl_FrameBuffer();
109 myMainSceneFbosOit[0] = new OpenGl_FrameBuffer();
110 myMainSceneFbosOit[1] = new OpenGl_FrameBuffer();
111 myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
112 myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
113 myImmediateSceneFbosOit[0] = new OpenGl_FrameBuffer();
114 myImmediateSceneFbosOit[1] = new OpenGl_FrameBuffer();
115 myXrSceneFbo = new OpenGl_FrameBuffer();
116 myOpenGlFBO = new OpenGl_FrameBuffer();
117 myOpenGlFBO2 = new OpenGl_FrameBuffer();
118 myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
119 myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
120 myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
121 myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
124 // =======================================================================
125 // function : Destructor
127 // =======================================================================
128 OpenGl_View::~OpenGl_View()
130 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
131 for (int i = 0; i < Graphic3d_TypeOfBackground_NB; ++i)
133 OpenGl_Element::Destroy(NULL, myBackgrounds[i]);
136 OpenGl_Element::Destroy (NULL, myTextureParams);
137 OpenGl_Element::Destroy (NULL, myCubeMapParams);
140 // =======================================================================
141 // function : releaseSrgbResources
143 // =======================================================================
144 void OpenGl_View::releaseSrgbResources (const Handle(OpenGl_Context)& theCtx)
146 myRenderParams.RebuildRayTracingShaders = true;
148 if (!myTextureEnv.IsNull())
150 if (!theCtx.IsNull())
152 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
154 theCtx->DelayedRelease (aTextureIter.ChangeValue());
155 aTextureIter.ChangeValue().Nullify();
158 myTextureEnv.Nullify();
161 if (myTextureParams != NULL)
163 myTextureParams->Release (theCtx.get());
166 if (myCubeMapParams != NULL)
168 myCubeMapParams->Release (theCtx.get());
171 for (int i = 0; i < Graphic3d_TypeOfBackground_NB; ++i)
173 if (myBackgrounds[i] != NULL)
175 myBackgrounds[i]->Release (theCtx.get());
179 myMainSceneFbos[0] ->Release (theCtx.get());
180 myMainSceneFbos[1] ->Release (theCtx.get());
181 myMainSceneFbosOit[0] ->Release (theCtx.get());
182 myMainSceneFbosOit[1] ->Release (theCtx.get());
183 myImmediateSceneFbos[0] ->Release (theCtx.get());
184 myImmediateSceneFbos[1] ->Release (theCtx.get());
185 myImmediateSceneFbosOit[0]->Release (theCtx.get());
186 myImmediateSceneFbosOit[1]->Release (theCtx.get());
187 myXrSceneFbo ->Release (theCtx.get());
188 myOpenGlFBO ->Release (theCtx.get());
189 myOpenGlFBO2 ->Release (theCtx.get());
190 myFullScreenQuad .Release (theCtx.get());
191 myFullScreenQuadFlip .Release (theCtx.get());
193 // Technically we should also re-initialize all sRGB/RGB8 color textures.
194 // But for now consider this sRGB disabling/enabling to be done at application start-up
195 // and re-create dynamically only frame buffers.
198 // =======================================================================
199 // function : ReleaseGlResources
201 // =======================================================================
202 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
204 myGraduatedTrihedron.Release (theCtx.get());
205 myFrameStatsPrs.Release (theCtx.get());
207 releaseSrgbResources (theCtx);
209 releaseRaytraceResources (theCtx);
211 if (!myPBREnvironment.IsNull())
213 myPBREnvironment->Release (theCtx.get());
218 // =======================================================================
221 // =======================================================================
222 void OpenGl_View::Remove()
229 myDriver->RemoveView (this);
232 Graphic3d_CView::Remove();
235 // =======================================================================
236 // function : SetLocalOrigin
238 // =======================================================================
239 void OpenGl_View::SetLocalOrigin (const gp_XYZ& theOrigin)
241 myLocalOrigin = theOrigin;
242 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
245 aCtx->ShaderManager()->SetLocalOrigin (theOrigin);
249 // =======================================================================
250 // function : SetTextureEnv
252 // =======================================================================
253 void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
255 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
256 if (!aCtx.IsNull() && !myTextureEnv.IsNull())
258 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
260 aCtx->DelayedRelease (aTextureIter.ChangeValue());
261 aTextureIter.ChangeValue().Nullify();
265 myToUpdateEnvironmentMap = Standard_True;
266 myTextureEnvData = theTextureEnv;
267 myTextureEnv.Nullify();
268 initTextureEnv (aCtx);
271 // =======================================================================
272 // function : initTextureEnv
274 // =======================================================================
275 void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
277 if (myTextureEnvData.IsNull()
278 || theContext.IsNull()
279 || !theContext->MakeCurrent())
284 Handle(OpenGl_Texture) aTextureEnv = new OpenGl_Texture (myTextureEnvData->GetId(), myTextureEnvData->GetParams());
285 if (Handle(Image_PixMap) anImage = myTextureEnvData->GetImage (theContext->SupportedTextureFormats()))
287 aTextureEnv->Init (theContext, *anImage, myTextureEnvData->Type(), true);
289 myTextureEnv = new OpenGl_TextureSet (aTextureEnv);
290 myTextureEnv->ChangeTextureSetBits() = Graphic3d_TextureSetBits_BaseColor;
293 // =======================================================================
294 // function : SetImmediateModeDrawToFront
296 // =======================================================================
297 Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
299 const Standard_Boolean aPrevMode = myTransientDrawToFront;
300 myTransientDrawToFront = theDrawToFrontBuffer;
304 // =======================================================================
305 // function : SetWindow
307 // =======================================================================
308 void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
309 const Aspect_RenderingContext theContext)
311 myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
312 Standard_ASSERT_RAISE (!myWindow.IsNull(),
313 "OpenGl_View::SetWindow, "
314 "Failed to create OpenGl window.");
316 myWorkspace = new OpenGl_Workspace (this, myWindow);
317 myWorldViewProjState.Reset();
318 myToUpdateEnvironmentMap = Standard_True;
319 myHasFboBlit = Standard_True;
322 // Environment texture resource does not support lazy initialization.
323 initTextureEnv (myWorkspace->GetGlContext());
326 // =======================================================================
327 // function : Resized
329 // =======================================================================
330 void OpenGl_View::Resized()
332 if (myWindow.IsNull())
338 // =======================================================================
339 // function : SetMinMaxValuesCallback
341 // =======================================================================
342 static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
344 OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
348 Bnd_Box aBox = theView->MinMaxValues();
351 gp_Pnt aMin = aBox.CornerMin();
352 gp_Pnt aMax = aBox.CornerMax();
354 Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
355 Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
356 aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
360 // =======================================================================
361 // function : GraduatedTrihedronDisplay
363 // =======================================================================
364 void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
366 myGTrihedronData = theTrihedronData;
367 myGTrihedronData.PtrView = this;
368 myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
369 myGraduatedTrihedron.SetValues (myGTrihedronData);
370 myToShowGradTrihedron = true;
373 // =======================================================================
374 // function : GraduatedTrihedronErase
376 // =======================================================================
377 void OpenGl_View::GraduatedTrihedronErase()
379 myGTrihedronData.PtrView = NULL;
380 myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
381 myToShowGradTrihedron = false;
384 // =======================================================================
385 // function : GraduatedTrihedronMinMaxValues
387 // =======================================================================
388 void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
390 myGraduatedTrihedron.SetMinMax (theMin, theMax);
393 // =======================================================================
394 // function : BufferDump
396 // =======================================================================
397 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
399 if (theBufferType != Graphic3d_BT_RGB_RayTraceHdrLeft)
401 return myWorkspace->BufferDump(myFBO, theImage, theBufferType);
404 if (!myRaytraceParameters.AdaptiveScreenSampling)
406 return myWorkspace->BufferDump(myAccumFrames % 2 ? myRaytraceFBO2[0] : myRaytraceFBO1[0], theImage, theBufferType);
409 #if defined(GL_ES_VERSION_2_0)
412 if (theImage.Format() != Image_Format_RGBF)
417 const GLuint aW = myRaytraceOutputTexture[0]->SizeX();
418 const GLuint aH = myRaytraceOutputTexture[0]->SizeY();
419 if (aW / 3 != theImage.SizeX() || aH / 2 != theImage.SizeY())
424 std::vector<GLfloat> aValues;
427 aValues.resize (aW * aH);
429 catch (const std::bad_alloc&)
434 glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[0]->TextureId());
435 glGetTexImage (GL_TEXTURE_RECTANGLE, 0, OpenGl_TextureFormat::Create<GLfloat, 1>().Format(), GL_FLOAT, &aValues[0]);
436 glBindTexture (GL_TEXTURE_RECTANGLE, 0);
437 for (unsigned int aRow = 0; aRow < aH; aRow += 2)
439 for (unsigned int aCol = 0; aCol < aW; aCol += 3)
441 float* anImageValue = theImage.ChangeValue<float[3]> ((aH - aRow) / 2 - 1, aCol / 3);
442 float aInvNbSamples = 1.f / aValues[aRow * aW + aCol + aW];
443 anImageValue[0] = aValues[aRow * aW + aCol] * aInvNbSamples;
444 anImageValue[1] = aValues[aRow * aW + aCol + 1] * aInvNbSamples;
445 anImageValue[2] = aValues[aRow * aW + aCol + 1 + aW] * aInvNbSamples;
453 // =======================================================================
454 // function : GradientBackground
456 // =======================================================================
457 Aspect_GradientBackground OpenGl_View::GradientBackground() const
459 Quantity_Color aColor1, aColor2;
460 aColor1.SetValues (myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (0).r(),
461 myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (0).g(),
462 myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (0).b(), Quantity_TOC_RGB);
463 aColor2.SetValues (myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (1).r(),
464 myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (1).g(),
465 myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientColor (1).b(), Quantity_TOC_RGB);
466 return Aspect_GradientBackground (aColor1, aColor2, myBackgrounds[Graphic3d_TOB_GRADIENT]->GradientFillMethod());
469 // =======================================================================
470 // function : SetGradientBackground
472 // =======================================================================
473 void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
475 Quantity_Color aColor1, aColor2;
476 theBackground.Colors (aColor1, aColor2);
477 myBackgrounds[Graphic3d_TOB_GRADIENT]->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
479 myBackgroundType = Graphic3d_TOB_GRADIENT;
482 // =======================================================================
483 // function : SetBackgroundImage
485 // =======================================================================
486 void OpenGl_View::SetBackgroundImage (const Handle(Graphic3d_TextureMap)& theTextureMap,
487 Standard_Boolean theToUpdatePBREnv)
489 if (theTextureMap.IsNull()
490 || !theTextureMap->IsDone())
492 if (myBackgroundType == Graphic3d_TOB_TEXTURE
493 || myBackgroundType == Graphic3d_TOB_CUBEMAP)
495 myBackgroundType = Graphic3d_TOB_NONE;
496 if (theToUpdatePBREnv)
498 myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
504 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
505 Handle(Graphic3d_TextureSet) aTextureSet = new Graphic3d_TextureSet (theTextureMap);
506 anAspect->SetInteriorStyle (Aspect_IS_SOLID);
507 anAspect->SetSuppressBackFaces (false);
508 anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
509 anAspect->SetTextureSet (aTextureSet);
510 anAspect->SetTextureMapOn (true);
512 if (Handle(Graphic3d_Texture2D) aTextureMap = Handle(Graphic3d_Texture2D)::DownCast (theTextureMap))
514 if (theToUpdatePBREnv && myBackgroundType == Graphic3d_TOB_CUBEMAP)
516 myPBREnvRequest = OpenGl_PBREnvRequest_CLEAR;
519 myTextureParams->SetAspect (anAspect);
520 myBackgroundType = Graphic3d_TOB_TEXTURE;
521 myBackgroundImage = aTextureMap;
525 if (Handle(Graphic3d_CubeMap) aCubeMap = Handle(Graphic3d_CubeMap)::DownCast (theTextureMap))
527 if (theToUpdatePBREnv)
529 myPBREnvRequest = OpenGl_PBREnvRequest_BAKE;
532 aCubeMap->SetMipmapsGeneration (Standard_True);
533 if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
535 anAspect->SetShaderProgram (aCtx->ShaderManager()->GetBgCubeMapProgram());
538 myCubeMapParams->SetAspect (anAspect);
540 const OpenGl_Aspects* anAspectsBackup = myWorkspace->SetAspects (myCubeMapParams);
541 myWorkspace->ApplyAspects();
542 myWorkspace->SetAspects (anAspectsBackup);
543 myWorkspace->ApplyAspects();
545 myBackgroundType = Graphic3d_TOB_CUBEMAP;
546 myBackgroundCubeMap = aCubeMap;
550 throw Standard_ProgramError ("OpenGl_View::SetBackgroundImage() - invalid texture map set for background");
553 // =======================================================================
554 // function : BackgroundImageStyle
556 // =======================================================================
557 Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
559 return myBackgrounds[Graphic3d_TOB_TEXTURE]->TextureFillMethod();
562 // =======================================================================
563 // function : SetBackgroundImageStyle
565 // =======================================================================
566 void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
568 myBackgrounds[Graphic3d_TOB_TEXTURE]->SetTextureFillMethod (theFillStyle);
571 // =======================================================================
572 // function : BackgroundCubeMap
574 // =======================================================================
575 Handle(Graphic3d_CubeMap) OpenGl_View::BackgroundCubeMap() const
577 return myBackgroundCubeMap;
580 // =======================================================================
581 // function : SpecIBLMapLevels
583 // =======================================================================
584 unsigned int OpenGl_View::SpecIBLMapLevels() const
586 return myPBREnvironment.IsNull() ? 0 : myPBREnvironment->SpecMapLevelsNumber();
589 //=======================================================================
590 //function : InsertLayerBefore
592 //=======================================================================
593 void OpenGl_View::InsertLayerBefore (const Graphic3d_ZLayerId theLayerId,
594 const Graphic3d_ZLayerSettings& theSettings,
595 const Graphic3d_ZLayerId theLayerAfter)
597 myZLayers.InsertLayerBefore (theLayerId, theSettings, theLayerAfter);
600 //=======================================================================
601 //function : InsertLayerAfter
603 //=======================================================================
604 void OpenGl_View::InsertLayerAfter (const Graphic3d_ZLayerId theLayerId,
605 const Graphic3d_ZLayerSettings& theSettings,
606 const Graphic3d_ZLayerId theLayerBefore)
608 myZLayers.InsertLayerAfter (theLayerId, theSettings, theLayerBefore);
611 //=======================================================================
612 //function : RemoveZLayer
614 //=======================================================================
615 void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
617 myZLayers.RemoveLayer (theLayerId);
620 //=======================================================================
621 //function : SetZLayerSettings
623 //=======================================================================
624 void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
625 const Graphic3d_ZLayerSettings& theSettings)
627 myZLayers.SetLayerSettings (theLayerId, theSettings);
630 //=======================================================================
631 //function : ZLayerMax
633 //=======================================================================
634 Standard_Integer OpenGl_View::ZLayerMax() const
636 Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
637 for (NCollection_List<Handle(Graphic3d_Layer)>::Iterator aLayerIter (myZLayers.Layers()); aLayerIter.More(); aLayerIter.Next())
639 aLayerMax = Max (aLayerMax, aLayerIter.Value()->LayerId());
644 //=======================================================================
647 //=======================================================================
648 const NCollection_List<Handle(Graphic3d_Layer)>& OpenGl_View::Layers() const
650 return myZLayers.Layers();
653 //=======================================================================
656 //=======================================================================
657 Handle(Graphic3d_Layer) OpenGl_View::Layer (const Graphic3d_ZLayerId theLayerId) const
659 Handle(Graphic3d_Layer) aLayer;
660 if (theLayerId != Graphic3d_ZLayerId_UNKNOWN)
662 myZLayers.LayerIDs().Find (theLayerId, aLayer);
667 //=======================================================================
668 //function : MinMaxValues
670 //=======================================================================
671 Bnd_Box OpenGl_View::MinMaxValues (const Standard_Boolean theToIncludeAuxiliary) const
678 Bnd_Box aBox = base_type::MinMaxValues (theToIncludeAuxiliary);
683 //=======================================================================
686 //=======================================================================
687 Handle(Standard_Transient) OpenGl_View::FBO() const
689 return Handle(Standard_Transient)(myFBO);
692 //=======================================================================
695 //=======================================================================
696 void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
698 myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
701 //=======================================================================
702 //function : FBOCreate
704 //=======================================================================
705 Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
706 const Standard_Integer theHeight)
708 return myWorkspace->FBOCreate (theWidth, theHeight);
711 //=======================================================================
712 //function : FBORelease
714 //=======================================================================
715 void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
717 Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
718 if (aFrameBuffer.IsNull())
723 myWorkspace->FBORelease (aFrameBuffer);
727 //=======================================================================
728 //function : FBOGetDimensions
730 //=======================================================================
731 void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
732 Standard_Integer& theWidth,
733 Standard_Integer& theHeight,
734 Standard_Integer& theWidthMax,
735 Standard_Integer& theHeightMax)
737 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
738 if (aFrameBuffer.IsNull())
743 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
744 theHeight = aFrameBuffer->GetVPSizeY();
745 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
746 theHeightMax = aFrameBuffer->GetSizeY();
749 //=======================================================================
750 //function : FBOChangeViewport
752 //=======================================================================
753 void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
754 const Standard_Integer theWidth,
755 const Standard_Integer theHeight)
757 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
758 if (aFrameBuffer.IsNull())
763 aFrameBuffer->ChangeViewport (theWidth, theHeight);
766 //=======================================================================
767 //function : displayStructure
769 //=======================================================================
770 void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
771 const Standard_Integer thePriority)
773 const OpenGl_Structure* aStruct = static_cast<const OpenGl_Structure*> (theStructure.get());
774 const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
775 myZLayers.AddStructure (aStruct, aZLayer, thePriority);
778 //=======================================================================
779 //function : eraseStructure
781 //=======================================================================
782 void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
784 const OpenGl_Structure* aStruct = static_cast<const OpenGl_Structure*> (theStructure.get());
785 myZLayers.RemoveStructure (aStruct);
788 //=======================================================================
789 //function : changeZLayer
791 //=======================================================================
792 void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
793 const Graphic3d_ZLayerId theNewLayerId)
795 const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
796 const OpenGl_Structure* aStruct = static_cast<const OpenGl_Structure*> (theStructure.get());
797 myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
799 Update (theNewLayerId);
802 //=======================================================================
803 //function : changePriority
805 //=======================================================================
806 void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
807 const Standard_Integer theNewPriority)
809 const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
810 const OpenGl_Structure* aStruct = static_cast<const OpenGl_Structure*> (theStructure.get());
811 myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
814 //=======================================================================
815 //function : DiagnosticInformation
817 //=======================================================================
818 void OpenGl_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
819 Graphic3d_DiagnosticInfo theFlags) const
821 base_type::DiagnosticInformation (theDict, theFlags);
822 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
823 if (!myWorkspace->Activate()
829 aCtx->DiagnosticInformation (theDict, theFlags);
830 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
832 TCollection_AsciiString aResRatio (myRenderParams.ResolutionRatio());
833 theDict.ChangeFromIndex (theDict.Add ("ResolutionRatio", aResRatio)) = aResRatio;
837 //=======================================================================
838 //function : StatisticInformation
840 //=======================================================================
841 void OpenGl_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
843 if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
845 const Handle(OpenGl_FrameStats)& aStats = aCtx->FrameStats();
846 const Graphic3d_RenderingParams& aRendParams = myWorkspace->View()->RenderingParams();
847 aStats->FormatStats (theDict, aRendParams.CollectedStats);
851 //=======================================================================
852 //function : StatisticInformation
854 //=======================================================================
855 TCollection_AsciiString OpenGl_View::StatisticInformation() const
857 if (const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext())
859 const Handle(OpenGl_FrameStats)& aStats = aCtx->FrameStats();
860 const Graphic3d_RenderingParams& aRendParams = myWorkspace->View()->RenderingParams();
861 return aStats->FormatStats (aRendParams.CollectedStats);
863 return TCollection_AsciiString();