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 myCulling (Standard_True),
54 myBackfacing (Graphic3d_TOBM_AUTOMATIC),
55 myBgColor (Quantity_NOC_BLACK),
56 myCamera (new Graphic3d_Camera()),
57 myToShowGradTrihedron (false),
58 myZLayers (Structure_MAX_PRIORITY - Structure_MIN_PRIORITY + 1),
59 myStateCounter (theCounter),
60 myCurrLightSourceState (theCounter->Increment()),
62 myLastLightSourceState (0, 0),
63 myFboColorFormat (GL_RGBA8),
64 myFboDepthFormat (GL_DEPTH24_STENCIL8),
65 myToFlipOutput (Standard_False),
67 myHasFboBlit (Standard_True),
68 myToDisableOIT (Standard_False),
69 myToDisableOITMSAA (Standard_False),
70 myToDisableMSAA (Standard_False),
71 myTransientDrawToFront (Standard_True),
72 myBackBufferRestored (Standard_False),
73 myIsImmediateDrawn (Standard_False),
74 myTextureParams (new OpenGl_AspectFace()),
75 myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
76 myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
77 // ray-tracing fields initialization
78 myRaytraceInitStatus (OpenGl_RT_NONE),
79 myIsRaytraceDataValid (Standard_False),
80 myIsRaytraceWarnTextures (Standard_False),
81 myRaytraceBVHBuilder (new BVH_BinnedBuilder<Standard_ShortReal, 3, BVH_Constants_NbBinsBest> (BVH_Constants_LeafNodeSizeAverage,
82 BVH_Constants_MaxTreeDepth,
84 OSD_Parallel::NbLogicalProcessors() + 1)),
85 myRaytraceSceneRadius (0.0f),
86 myRaytraceSceneEpsilon (1.0e-6f),
87 myToUpdateEnvironmentMap (Standard_False),
88 myRaytraceLayerListState (0),
89 myPrevCameraApertureRadius(0.f),
90 myPrevCameraFocalPlaneDist(0.f)
92 myWorkspace = new OpenGl_Workspace (this, NULL);
94 Handle(Graphic3d_CLight) aLight = new Graphic3d_CLight (Graphic3d_TOLS_AMBIENT);
95 aLight->SetHeadlight (false);
96 aLight->SetColor (Quantity_NOC_WHITE);
97 myNoShadingLight = new Graphic3d_LightSet();
98 myNoShadingLight->Add (aLight);
100 myMainSceneFbos[0] = new OpenGl_FrameBuffer();
101 myMainSceneFbos[1] = new OpenGl_FrameBuffer();
102 myMainSceneFbosOit[0] = new OpenGl_FrameBuffer();
103 myMainSceneFbosOit[1] = new OpenGl_FrameBuffer();
104 myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
105 myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
106 myImmediateSceneFbosOit[0] = new OpenGl_FrameBuffer();
107 myImmediateSceneFbosOit[1] = new OpenGl_FrameBuffer();
108 myOpenGlFBO = new OpenGl_FrameBuffer();
109 myOpenGlFBO2 = new OpenGl_FrameBuffer();
110 myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
111 myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
112 myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
113 myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
116 // =======================================================================
117 // function : Destructor
119 // =======================================================================
120 OpenGl_View::~OpenGl_View()
122 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
123 OpenGl_Element::Destroy (NULL, myBgGradientArray);
124 OpenGl_Element::Destroy (NULL, myBgTextureArray);
125 OpenGl_Element::Destroy (NULL, myTextureParams);
128 // =======================================================================
129 // function : ReleaseGlResources
131 // =======================================================================
132 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
134 myGraduatedTrihedron.Release (theCtx.operator->());
135 myFrameStatsPrs.Release (theCtx.operator->());
137 if (!myTextureEnv.IsNull())
139 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
141 theCtx->DelayedRelease (aTextureIter.ChangeValue());
142 aTextureIter.ChangeValue().Nullify();
144 myTextureEnv.Nullify();
147 if (myTextureParams != NULL)
149 myTextureParams->Release (theCtx.operator->());
151 if (myBgGradientArray != NULL)
153 myBgGradientArray->Release (theCtx.operator->());
155 if (myBgTextureArray != NULL)
157 myBgTextureArray->Release (theCtx.operator->());
160 myMainSceneFbos[0] ->Release (theCtx.operator->());
161 myMainSceneFbos[1] ->Release (theCtx.operator->());
162 myMainSceneFbosOit[0] ->Release (theCtx.operator->());
163 myMainSceneFbosOit[1] ->Release (theCtx.operator->());
164 myImmediateSceneFbos[0] ->Release (theCtx.operator->());
165 myImmediateSceneFbos[1] ->Release (theCtx.operator->());
166 myImmediateSceneFbosOit[0]->Release (theCtx.operator->());
167 myImmediateSceneFbosOit[1]->Release (theCtx.operator->());
168 myOpenGlFBO ->Release (theCtx.operator->());
169 myOpenGlFBO2 ->Release (theCtx.operator->());
170 myFullScreenQuad .Release (theCtx.operator->());
171 myFullScreenQuadFlip .Release (theCtx.operator->());
173 releaseRaytraceResources (theCtx);
176 // =======================================================================
179 // =======================================================================
180 void OpenGl_View::Remove()
187 myDriver->RemoveView (this);
190 Graphic3d_CView::Remove();
193 // =======================================================================
194 // function : SetTextureEnv
196 // =======================================================================
197 void OpenGl_View::SetCamera(const Handle(Graphic3d_Camera)& theCamera)
199 myCamera = theCamera;
202 // =======================================================================
203 // function : SetLocalOrigin
205 // =======================================================================
206 void OpenGl_View::SetLocalOrigin (const gp_XYZ& theOrigin)
208 myLocalOrigin = theOrigin;
209 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
212 aCtx->ShaderManager()->SetLocalOrigin (theOrigin);
216 // =======================================================================
217 // function : SetTextureEnv
219 // =======================================================================
220 void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
222 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
223 if (!aCtx.IsNull() && !myTextureEnv.IsNull())
225 for (OpenGl_TextureSet::Iterator aTextureIter (myTextureEnv); aTextureIter.More(); aTextureIter.Next())
227 aCtx->DelayedRelease (aTextureIter.ChangeValue());
228 aTextureIter.ChangeValue().Nullify();
232 myToUpdateEnvironmentMap = Standard_True;
233 myTextureEnvData = theTextureEnv;
234 myTextureEnv.Nullify();
235 initTextureEnv (aCtx);
238 // =======================================================================
239 // function : initTextureEnv
241 // =======================================================================
242 void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
244 if (myTextureEnvData.IsNull()
245 || theContext.IsNull()
246 || !theContext->MakeCurrent())
251 myTextureEnv = new OpenGl_TextureSet (1);
252 Handle(OpenGl_Texture)& aTextureEnv = myTextureEnv->ChangeFirst();
253 aTextureEnv = new OpenGl_Texture (myTextureEnvData->GetId(), myTextureEnvData->GetParams());
254 Handle(Image_PixMap) anImage = myTextureEnvData->GetImage();
255 if (!anImage.IsNull())
257 aTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type());
261 // =======================================================================
262 // function : SetImmediateModeDrawToFront
264 // =======================================================================
265 Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
267 const Standard_Boolean aPrevMode = myTransientDrawToFront;
268 myTransientDrawToFront = theDrawToFrontBuffer;
272 // =======================================================================
273 // function : SetWindow
275 // =======================================================================
276 void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
277 const Aspect_RenderingContext theContext)
279 myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
280 Standard_ASSERT_RAISE (!myWindow.IsNull(),
281 "OpenGl_View::SetWindow, "
282 "Failed to create OpenGl window.");
284 myWorkspace = new OpenGl_Workspace (this, myWindow);
285 myWorldViewProjState.Reset();
286 myToUpdateEnvironmentMap = Standard_True;
287 myHasFboBlit = Standard_True;
290 // Environment texture resource does not support lazy initialization.
291 initTextureEnv (myWorkspace->GetGlContext());
294 // =======================================================================
295 // function : Resized
297 // =======================================================================
298 void OpenGl_View::Resized()
300 if (myWindow.IsNull())
306 // =======================================================================
307 // function : SetMinMaxValuesCallback
309 // =======================================================================
310 static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
312 OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
316 Bnd_Box aBox = theView->MinMaxValues();
319 gp_Pnt aMin = aBox.CornerMin();
320 gp_Pnt aMax = aBox.CornerMax();
322 Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
323 Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
324 aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
328 // =======================================================================
329 // function : GraduatedTrihedronDisplay
331 // =======================================================================
332 void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
334 myGTrihedronData = theTrihedronData;
335 myGTrihedronData.PtrView = this;
336 myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
337 myGraduatedTrihedron.SetValues (myGTrihedronData);
338 myToShowGradTrihedron = true;
341 // =======================================================================
342 // function : GraduatedTrihedronErase
344 // =======================================================================
345 void OpenGl_View::GraduatedTrihedronErase()
347 myGTrihedronData.PtrView = NULL;
348 myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
349 myToShowGradTrihedron = false;
352 // =======================================================================
353 // function : GraduatedTrihedronMinMaxValues
355 // =======================================================================
356 void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
358 myGraduatedTrihedron.SetMinMax (theMin, theMax);
361 // =======================================================================
362 // function : BufferDump
364 // =======================================================================
365 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
367 if (theBufferType != Graphic3d_BT_RGB_RayTraceHdrLeft)
369 return myWorkspace->BufferDump(myFBO, theImage, theBufferType);
372 if (!myRaytraceParameters.AdaptiveScreenSampling)
374 return myWorkspace->BufferDump(myAccumFrames % 2 ? myRaytraceFBO2[0] : myRaytraceFBO1[0], theImage, theBufferType);
377 #if defined(GL_ES_VERSION_2_0)
380 if (theImage.Format() != Image_Format_RGBF)
385 const GLuint aW = myRaytraceOutputTexture[0]->SizeX();
386 const GLuint aH = myRaytraceOutputTexture[0]->SizeY();
387 if (aW / 3 != theImage.SizeX() || aH / 2 != theImage.SizeY())
392 std::vector<GLfloat> aValues;
395 aValues.resize (aW * aH);
397 catch (const std::bad_alloc&)
402 glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[0]->TextureId());
403 glGetTexImage (GL_TEXTURE_RECTANGLE, 0, OpenGl_TextureFormat::Create<GLfloat, 1>().Format(), GL_FLOAT, &aValues[0]);
404 glBindTexture (GL_TEXTURE_RECTANGLE, 0);
405 for (unsigned int aRow = 0; aRow < aH; aRow += 2)
407 for (unsigned int aCol = 0; aCol < aW; aCol += 3)
409 float* anImageValue = theImage.ChangeValue<float[3]> ((aH - aRow) / 2 - 1, aCol / 3);
410 float aInvNbSamples = 1.f / aValues[aRow * aW + aCol + aW];
411 anImageValue[0] = aValues[aRow * aW + aCol] * aInvNbSamples;
412 anImageValue[1] = aValues[aRow * aW + aCol + 1] * aInvNbSamples;
413 anImageValue[2] = aValues[aRow * aW + aCol + 1 + aW] * aInvNbSamples;
421 // =======================================================================
422 // function : Background
424 // =======================================================================
425 Aspect_Background OpenGl_View::Background() const
427 return Aspect_Background (myBgColor.GetRGB());
430 // =======================================================================
431 // function : SetBackground
433 // =======================================================================
434 void OpenGl_View::SetBackground (const Aspect_Background& theBackground)
436 myBgColor.SetRGB (theBackground.Color());
439 // =======================================================================
440 // function : GradientBackground
442 // =======================================================================
443 Aspect_GradientBackground OpenGl_View::GradientBackground() const
445 Quantity_Color aColor1, aColor2;
446 aColor1.SetValues (myBgGradientArray->GradientColor (0).r(),
447 myBgGradientArray->GradientColor (0).g(),
448 myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB);
449 aColor2.SetValues (myBgGradientArray->GradientColor (1).r(),
450 myBgGradientArray->GradientColor (1).g(),
451 myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB);
452 return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod());
455 // =======================================================================
456 // function : SetGradientBackground
458 // =======================================================================
459 void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
461 Quantity_Color aColor1, aColor2;
462 theBackground.Colors (aColor1, aColor2);
463 myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
466 // =======================================================================
467 // function : SetBackgroundImage
469 // =======================================================================
470 void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
472 // Prepare aspect for texture storage
473 myBackgroundImagePath = theFilePath;
474 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
475 Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
476 aTextureMap->EnableRepeat();
477 aTextureMap->DisableModulate();
478 aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
479 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
480 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
481 anAspect->SetTextureMap (aTextureMap);
482 anAspect->SetInteriorStyle (Aspect_IS_SOLID);
483 anAspect->SetSuppressBackFaces (false);
484 // Enable texture mapping
485 if (aTextureMap->IsDone())
487 anAspect->SetTextureMapOn();
491 anAspect->SetTextureMapOff();
495 // Set texture parameters
496 myTextureParams->SetAspect (anAspect);
499 // =======================================================================
500 // function : BackgroundImageStyle
502 // =======================================================================
503 Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
505 return myBgTextureArray->TextureFillMethod();
508 // =======================================================================
509 // function : SetBackgroundImageStyle
511 // =======================================================================
512 void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
514 myBgTextureArray->SetTextureFillMethod (theFillStyle);
517 //=======================================================================
518 //function : AddZLayer
520 //=======================================================================
521 void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
523 myZLayers.AddLayer (theLayerId);
526 //=======================================================================
527 //function : RemoveZLayer
529 //=======================================================================
530 void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
532 myZLayers.RemoveLayer (theLayerId);
535 //=======================================================================
536 //function : SetZLayerSettings
538 //=======================================================================
539 void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
540 const Graphic3d_ZLayerSettings& theSettings)
542 myZLayers.SetLayerSettings (theLayerId, theSettings);
545 //=======================================================================
546 //function : ZLayerMax
548 //=======================================================================
549 Standard_Integer OpenGl_View::ZLayerMax() const
551 Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
552 for (OpenGl_LayerSeqIds::Iterator aMapIt(myZLayers.LayerIDs()); aMapIt.More(); aMapIt.Next())
554 aLayerMax = Max (aLayerMax, aMapIt.Value());
560 //=======================================================================
561 //function : InvalidateZLayerBoundingBox
563 //=======================================================================
564 void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const
566 if (myZLayers.LayerIDs().IsBound (theLayerId))
568 myZLayers.Layer (theLayerId).InvalidateBoundingBox();
572 const Standard_Integer aLayerMax = ZLayerMax();
573 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < aLayerMax; ++aLayerId)
575 if (myZLayers.LayerIDs().IsBound (aLayerId))
577 const OpenGl_Layer& aLayer = myZLayers.Layer (aLayerId);
578 if (aLayer.NbOfTransformPersistenceObjects() > 0)
580 aLayer.InvalidateBoundingBox();
587 //=======================================================================
588 //function : ZLayerBoundingBox
590 //=======================================================================
591 Bnd_Box OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
592 const Handle(Graphic3d_Camera)& theCamera,
593 const Standard_Integer theWindowWidth,
594 const Standard_Integer theWindowHeight,
595 const Standard_Boolean theToIncludeAuxiliary) const
598 if (myZLayers.LayerIDs().IsBound (theLayerId))
600 aBox = myZLayers.Layer (theLayerId).BoundingBox (Identification(),
604 theToIncludeAuxiliary);
607 // add bounding box of gradient/texture background for proper Z-fit
608 if (theToIncludeAuxiliary
609 && theLayerId == Graphic3d_ZLayerId_BotOSD
610 && (myBgTextureArray->IsDefined()
611 || myBgGradientArray->IsDefined()))
613 // Background is drawn using 2D transformation persistence
614 // (e.g. it is actually placed in 3D coordinates within active camera position).
615 // We add here full-screen plane with 2D transformation persistence
616 // for simplicity (myBgTextureArray might define a little bit different options
617 // but it is updated within ::Render())
618 const Graphic3d_Mat4d& aProjectionMat = theCamera->ProjectionMatrix();
619 const Graphic3d_Mat4d& aWorldViewMat = theCamera->OrientationMatrix();
620 Graphic3d_BndBox3d aBox2d (Graphic3d_Vec3d (0.0, 0.0, 0.0),
621 Graphic3d_Vec3d (double(theWindowWidth), double(theWindowHeight), 0.0));
623 Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER);
624 aTrsfPers.Apply (theCamera,
630 aBox.Add (gp_Pnt (aBox2d.CornerMin().x(), aBox2d.CornerMin().y(), aBox2d.CornerMin().z()));
631 aBox.Add (gp_Pnt (aBox2d.CornerMax().x(), aBox2d.CornerMax().y(), aBox2d.CornerMax().z()));
637 //=======================================================================
638 //function : considerZoomPersistenceObjects
640 //=======================================================================
641 Standard_Real OpenGl_View::considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
642 const Handle(Graphic3d_Camera)& theCamera,
643 const Standard_Integer theWindowWidth,
644 const Standard_Integer theWindowHeight) const
646 if (myZLayers.LayerIDs().IsBound (theLayerId))
648 return myZLayers.Layer (theLayerId).considerZoomPersistenceObjects (Identification(),
657 //=======================================================================
660 //=======================================================================
661 Handle(Standard_Transient) OpenGl_View::FBO() const
663 return Handle(Standard_Transient)(myFBO);
666 //=======================================================================
669 //=======================================================================
670 void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
672 myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
675 //=======================================================================
676 //function : FBOCreate
678 //=======================================================================
679 Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
680 const Standard_Integer theHeight)
682 return myWorkspace->FBOCreate (theWidth, theHeight);
685 //=======================================================================
686 //function : FBORelease
688 //=======================================================================
689 void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
691 Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
692 if (aFrameBuffer.IsNull())
697 myWorkspace->FBORelease (aFrameBuffer);
701 //=======================================================================
702 //function : FBOGetDimensions
704 //=======================================================================
705 void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
706 Standard_Integer& theWidth,
707 Standard_Integer& theHeight,
708 Standard_Integer& theWidthMax,
709 Standard_Integer& theHeightMax)
711 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
712 if (aFrameBuffer.IsNull())
717 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
718 theHeight = aFrameBuffer->GetVPSizeY();
719 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
720 theHeightMax = aFrameBuffer->GetSizeY();
723 //=======================================================================
724 //function : FBOChangeViewport
726 //=======================================================================
727 void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
728 const Standard_Integer theWidth,
729 const Standard_Integer theHeight)
731 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
732 if (aFrameBuffer.IsNull())
737 aFrameBuffer->ChangeViewport (theWidth, theHeight);
740 //=======================================================================
741 //function : displayStructure
743 //=======================================================================
744 void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
745 const Standard_Integer thePriority)
747 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
748 const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
749 myZLayers.AddStructure (aStruct, aZLayer, thePriority);
752 //=======================================================================
753 //function : eraseStructure
755 //=======================================================================
756 void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
758 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
759 myZLayers.RemoveStructure (aStruct);
762 //=======================================================================
763 //function : changeZLayer
765 //=======================================================================
766 void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
767 const Graphic3d_ZLayerId theNewLayerId)
769 const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
770 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
771 myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
773 Update (theNewLayerId);
776 //=======================================================================
777 //function : changePriority
779 //=======================================================================
780 void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
781 const Standard_Integer theNewPriority)
783 const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
784 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
785 myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
788 //=======================================================================
789 //function : DiagnosticInformation
791 //=======================================================================
792 void OpenGl_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
793 Graphic3d_DiagnosticInfo theFlags) const
795 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
796 if (!myWorkspace->Activate()
802 aCtx->DiagnosticInformation (theDict, theFlags);
803 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
805 TCollection_AsciiString aResRatio (myRenderParams.ResolutionRatio());
806 theDict.ChangeFromIndex (theDict.Add ("ResolutionRatio", aResRatio)) = aResRatio;