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 <Standard_CLocaleSentry.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
42 // =======================================================================
43 // function : Constructor
45 // =======================================================================
46 OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
47 const Handle(OpenGl_GraphicDriver)& theDriver,
48 const Handle(OpenGl_Caps)& theCaps,
49 Standard_Boolean& theDeviceLostFlag,
50 OpenGl_StateCounter* theCounter)
51 : Graphic3d_CView (theMgr),
52 myDriver (theDriver.operator->()),
54 myDeviceLostFlag (theDeviceLostFlag),
55 myWasRedrawnGL (Standard_False),
56 myCulling (Standard_True),
57 myShadingModel (Graphic3d_TOSM_FACET),
58 myBackfacing (Graphic3d_TOBM_AUTOMATIC),
59 myBgColor (Quantity_NOC_BLACK),
60 myCamera (new Graphic3d_Camera()),
61 myToShowGradTrihedron (false),
62 myStateCounter (theCounter),
63 myLastLightSourceState (0, 0),
64 myFboColorFormat (GL_RGBA8),
65 myFboDepthFormat (GL_DEPTH24_STENCIL8),
66 myToFlipOutput (Standard_False),
68 myHasFboBlit (Standard_True),
69 myToDisableMSAA (Standard_False),
70 myTransientDrawToFront (Standard_True),
71 myBackBufferRestored (Standard_False),
72 myIsImmediateDrawn (Standard_False),
73 myTextureParams (new OpenGl_AspectFace()),
74 myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
75 myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
76 // ray-tracing fields initialization
77 myRaytraceInitStatus (OpenGl_RT_NONE),
78 myIsRaytraceDataValid (Standard_False),
79 myIsRaytraceWarnTextures (Standard_False),
80 myToUpdateEnvironmentMap (Standard_False),
81 myRaytraceLayerListState (0)
83 myWorkspace = new OpenGl_Workspace (this, NULL);
86 aLight.Type = Graphic3d_TOLS_AMBIENT;
87 aLight.IsHeadlight = Standard_False;
88 aLight.Color.r() = 1.;
89 aLight.Color.g() = 1.;
90 aLight.Color.b() = 1.;
91 myNoShadingLight.Append (aLight);
93 myCurrLightSourceState = myStateCounter->Increment();
94 myMainSceneFbos[0] = new OpenGl_FrameBuffer();
95 myMainSceneFbos[1] = new OpenGl_FrameBuffer();
96 myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
97 myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
98 myOpenGlFBO = new OpenGl_FrameBuffer();
99 myOpenGlFBO2 = new OpenGl_FrameBuffer();
100 myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
101 myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
102 myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
103 myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
106 // =======================================================================
107 // function : Destructor
109 // =======================================================================
110 OpenGl_View::~OpenGl_View()
112 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
113 OpenGl_Element::Destroy (NULL, myBgGradientArray);
114 OpenGl_Element::Destroy (NULL, myBgTextureArray);
115 OpenGl_Element::Destroy (NULL, myTextureParams);
118 // =======================================================================
119 // function : ReleaseGlResources
121 // =======================================================================
122 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
124 myGraduatedTrihedron.Release (theCtx.operator->());
126 if (!myTextureEnv.IsNull())
128 theCtx->DelayedRelease (myTextureEnv);
129 myTextureEnv.Nullify();
132 if (myTextureParams != NULL)
134 myTextureParams->Release (theCtx.operator->());
136 if (myBgGradientArray != NULL)
138 myBgGradientArray->Release (theCtx.operator->());
140 if (myBgTextureArray != NULL)
142 myBgTextureArray->Release (theCtx.operator->());
145 myMainSceneFbos[0] ->Release (theCtx.operator->());
146 myMainSceneFbos[1] ->Release (theCtx.operator->());
147 myImmediateSceneFbos[0]->Release (theCtx.operator->());
148 myImmediateSceneFbos[1]->Release (theCtx.operator->());
149 myOpenGlFBO ->Release (theCtx.operator->());
150 myOpenGlFBO2 ->Release (theCtx.operator->());
151 myFullScreenQuad .Release (theCtx.operator->());
152 myFullScreenQuadFlip .Release (theCtx.operator->());
154 releaseRaytraceResources (theCtx);
157 // =======================================================================
160 // =======================================================================
161 void OpenGl_View::Remove()
168 myDriver->RemoveView (this);
171 Graphic3d_CView::Remove();
174 // =======================================================================
175 // function : SetTextureEnv
177 // =======================================================================
178 void OpenGl_View::SetCamera(const Handle(Graphic3d_Camera)& theCamera)
180 myCamera = theCamera;
183 // =======================================================================
184 // function : SetLocalOrigin
186 // =======================================================================
187 void OpenGl_View::SetLocalOrigin (const gp_XYZ& theOrigin)
189 myLocalOrigin = theOrigin;
190 const Handle(OpenGl_Context)& aCtx = myWorkspace->GetGlContext();
193 aCtx->ShaderManager()->SetLocalOrigin (theOrigin);
197 // =======================================================================
198 // function : SetTextureEnv
200 // =======================================================================
201 void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
203 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
204 if (!aCtx.IsNull() && !myTextureEnv.IsNull())
206 aCtx->DelayedRelease (myTextureEnv);
209 myToUpdateEnvironmentMap = Standard_True;
210 myTextureEnvData = theTextureEnv;
211 myTextureEnv.Nullify();
212 initTextureEnv (aCtx);
215 // =======================================================================
216 // function : initTextureEnv
218 // =======================================================================
219 void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
221 if (myTextureEnvData.IsNull()
222 || theContext.IsNull()
223 || !theContext->MakeCurrent())
228 myTextureEnv = new OpenGl_Texture (myTextureEnvData->GetParams());
229 Handle(Image_PixMap) anImage = myTextureEnvData->GetImage();
230 if (!anImage.IsNull())
232 myTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type());
236 // =======================================================================
237 // function : SetImmediateModeDrawToFront
239 // =======================================================================
240 Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
242 const Standard_Boolean aPrevMode = myTransientDrawToFront;
243 myTransientDrawToFront = theDrawToFrontBuffer;
247 // =======================================================================
248 // function : SetWindow
250 // =======================================================================
251 void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
252 const Aspect_RenderingContext theContext)
254 myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
255 Standard_ASSERT_RAISE (!myWindow.IsNull(),
256 "OpenGl_View::SetWindow, "
257 "Failed to create OpenGl window.");
259 myWorkspace = new OpenGl_Workspace (this, myWindow);
260 myWorldViewProjState.Reset();
261 myToUpdateEnvironmentMap = Standard_True;
262 myHasFboBlit = Standard_True;
265 // Environment texture resource does not support lazy initialization.
266 initTextureEnv (myWorkspace->GetGlContext());
269 // =======================================================================
270 // function : Resized
272 // =======================================================================
273 void OpenGl_View::Resized()
275 if (myWindow.IsNull())
281 // =======================================================================
282 // function : SetMinMaxValuesCallback
284 // =======================================================================
285 static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
287 OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
291 Bnd_Box aBox = theView->MinMaxValues();
294 gp_Pnt aMin = aBox.CornerMin();
295 gp_Pnt aMax = aBox.CornerMax();
297 Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
298 Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
299 aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
303 // =======================================================================
304 // function : GraduatedTrihedronDisplay
306 // =======================================================================
307 void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
309 myGTrihedronData = theTrihedronData;
310 myGTrihedronData.PtrView = this;
311 myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
312 myGraduatedTrihedron.SetValues (myGTrihedronData);
313 myToShowGradTrihedron = true;
316 // =======================================================================
317 // function : GraduatedTrihedronErase
319 // =======================================================================
320 void OpenGl_View::GraduatedTrihedronErase()
322 myGTrihedronData.PtrView = NULL;
323 myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
324 myToShowGradTrihedron = false;
327 // =======================================================================
328 // function : GraduatedTrihedronMinMaxValues
330 // =======================================================================
331 void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
333 myGraduatedTrihedron.SetMinMax (theMin, theMax);
336 // =======================================================================
337 // function : BufferDump
339 // =======================================================================
340 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
342 return myWorkspace->BufferDump (myFBO, theImage, theBufferType);
345 // =======================================================================
346 // function : Background
348 // =======================================================================
349 Aspect_Background OpenGl_View::Background() const
351 return Aspect_Background (myBgColor.GetRGB());
354 // =======================================================================
355 // function : SetBackground
357 // =======================================================================
358 void OpenGl_View::SetBackground (const Aspect_Background& theBackground)
360 myBgColor.SetRGB (theBackground.Color());
363 // =======================================================================
364 // function : GradientBackground
366 // =======================================================================
367 Aspect_GradientBackground OpenGl_View::GradientBackground() const
369 Quantity_Color aColor1, aColor2;
370 aColor1.SetValues (myBgGradientArray->GradientColor (0).r(),
371 myBgGradientArray->GradientColor (0).g(),
372 myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB);
373 aColor2.SetValues (myBgGradientArray->GradientColor (1).r(),
374 myBgGradientArray->GradientColor (1).g(),
375 myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB);
376 return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod());
379 // =======================================================================
380 // function : SetGradientBackground
382 // =======================================================================
383 void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
385 Quantity_Color aColor1, aColor2;
386 theBackground.Colors (aColor1, aColor2);
387 myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
390 // =======================================================================
391 // function : SetBackgroundImage
393 // =======================================================================
394 void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
396 // Prepare aspect for texture storage
397 myBackgroundImagePath = theFilePath;
398 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
399 Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
400 aTextureMap->EnableRepeat();
401 aTextureMap->DisableModulate();
402 aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
403 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
404 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
405 anAspect->SetTextureMap (aTextureMap);
406 anAspect->SetInteriorStyle (Aspect_IS_SOLID);
407 anAspect->SetSuppressBackFaces (false);
408 // Enable texture mapping
409 if (aTextureMap->IsDone())
411 anAspect->SetTextureMapOn();
415 anAspect->SetTextureMapOff();
419 // Set texture parameters
420 myTextureParams->SetAspect (anAspect);
423 // =======================================================================
424 // function : BackgroundImageStyle
426 // =======================================================================
427 Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
429 return myBgTextureArray->TextureFillMethod();
432 // =======================================================================
433 // function : SetBackgroundImageStyle
435 // =======================================================================
436 void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
438 myBgTextureArray->SetTextureFillMethod (theFillStyle);
441 //=======================================================================
442 //function : AddZLayer
444 //=======================================================================
445 void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
447 myZLayers.AddLayer (theLayerId);
450 //=======================================================================
451 //function : RemoveZLayer
453 //=======================================================================
454 void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
456 myZLayers.RemoveLayer (theLayerId);
459 //=======================================================================
460 //function : SetZLayerSettings
462 //=======================================================================
463 void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
464 const Graphic3d_ZLayerSettings& theSettings)
466 myZLayers.SetLayerSettings (theLayerId, theSettings);
469 //=======================================================================
470 //function : ZLayerMax
472 //=======================================================================
473 Standard_Integer OpenGl_View::ZLayerMax() const
475 Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
476 for (OpenGl_LayerSeqIds::Iterator aMapIt(myZLayers.LayerIDs()); aMapIt.More(); aMapIt.Next())
478 aLayerMax = Max (aLayerMax, aMapIt.Value());
484 //=======================================================================
485 //function : InvalidateZLayerBoundingBox
487 //=======================================================================
488 void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const
490 if (myZLayers.LayerIDs().IsBound (theLayerId))
492 myZLayers.Layer (theLayerId).InvalidateBoundingBox();
496 const Standard_Integer aLayerMax = ZLayerMax();
497 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < aLayerMax; ++aLayerId)
499 if (myZLayers.LayerIDs().IsBound (aLayerId))
501 const OpenGl_Layer& aLayer = myZLayers.Layer (aLayerId);
502 if (aLayer.NbOfTransformPersistenceObjects() > 0)
504 aLayer.InvalidateBoundingBox();
511 //=======================================================================
512 //function : ZLayerBoundingBox
514 //=======================================================================
515 Bnd_Box OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
516 const Handle(Graphic3d_Camera)& theCamera,
517 const Standard_Integer theWindowWidth,
518 const Standard_Integer theWindowHeight,
519 const Standard_Boolean theToIncludeAuxiliary) const
522 if (myZLayers.LayerIDs().IsBound (theLayerId))
524 aBox = myZLayers.Layer (theLayerId).BoundingBox (Identification(),
528 theToIncludeAuxiliary);
531 // add bounding box of gradient/texture background for proper Z-fit
532 if (theToIncludeAuxiliary
533 && theLayerId == Graphic3d_ZLayerId_BotOSD
534 && (myBgTextureArray->IsDefined()
535 || myBgGradientArray->IsDefined()))
537 // Background is drawn using 2D transformation persistence
538 // (e.g. it is actually placed in 3D coordinates within active camera position).
539 // We add here full-screen plane with 2D transformation persistence
540 // for simplicity (myBgTextureArray might define a little bit different options
541 // but it is updated within ::Render())
542 const Graphic3d_Mat4d& aProjectionMat = theCamera->ProjectionMatrix();
543 const Graphic3d_Mat4d& aWorldViewMat = theCamera->OrientationMatrix();
544 Graphic3d_BndBox3d aBox2d (Graphic3d_Vec3d (0.0, 0.0, 0.0),
545 Graphic3d_Vec3d (double(theWindowWidth), double(theWindowHeight), 0.0));
547 Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER);
548 aTrsfPers.Apply (theCamera,
554 aBox.Add (gp_Pnt (aBox2d.CornerMin().x(), aBox2d.CornerMin().y(), aBox2d.CornerMin().z()));
555 aBox.Add (gp_Pnt (aBox2d.CornerMax().x(), aBox2d.CornerMax().y(), aBox2d.CornerMax().z()));
561 //=======================================================================
562 //function : considerZoomPersistenceObjects
564 //=======================================================================
565 Standard_Real OpenGl_View::considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
566 const Handle(Graphic3d_Camera)& theCamera,
567 const Standard_Integer theWindowWidth,
568 const Standard_Integer theWindowHeight) const
570 if (myZLayers.LayerIDs().IsBound (theLayerId))
572 return myZLayers.Layer (theLayerId).considerZoomPersistenceObjects (Identification(),
581 //=======================================================================
584 //=======================================================================
585 Handle(Standard_Transient) OpenGl_View::FBO() const
587 return Handle(Standard_Transient)(myFBO);
590 //=======================================================================
593 //=======================================================================
594 void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
596 myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
599 //=======================================================================
600 //function : FBOCreate
602 //=======================================================================
603 Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
604 const Standard_Integer theHeight)
606 return myWorkspace->FBOCreate (theWidth, theHeight);
609 //=======================================================================
610 //function : FBORelease
612 //=======================================================================
613 void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
615 Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
616 if (aFrameBuffer.IsNull())
621 myWorkspace->FBORelease (aFrameBuffer);
625 //=======================================================================
626 //function : FBOGetDimensions
628 //=======================================================================
629 void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
630 Standard_Integer& theWidth,
631 Standard_Integer& theHeight,
632 Standard_Integer& theWidthMax,
633 Standard_Integer& theHeightMax)
635 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
636 if (aFrameBuffer.IsNull())
641 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
642 theHeight = aFrameBuffer->GetVPSizeY();
643 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
644 theHeightMax = aFrameBuffer->GetSizeY();
647 //=======================================================================
648 //function : FBOChangeViewport
650 //=======================================================================
651 void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
652 const Standard_Integer theWidth,
653 const Standard_Integer theHeight)
655 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
656 if (aFrameBuffer.IsNull())
661 aFrameBuffer->ChangeViewport (theWidth, theHeight);
664 // =======================================================================
667 // =======================================================================
669 Standard_Boolean OpenGl_View::Export (const Standard_CString theFileName,
670 const Graphic3d_ExportFormat theFormat,
671 const Graphic3d_SortType theSortType)
673 // gl2psBeginPage() will call OpenGL functions
674 // so we should activate correct GL context before redraw scene call
675 if (!myWorkspace->Activate())
677 return Standard_False;
680 Standard_Integer aFormat = -1;
681 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
684 case Graphic3d_EF_PostScript:
687 case Graphic3d_EF_EnhPostScript:
690 case Graphic3d_EF_TEX:
693 case Graphic3d_EF_PDF:
696 case Graphic3d_EF_SVG:
699 case Graphic3d_EF_PGF:
702 case Graphic3d_EF_EMF:
703 //aFormat = GL2PS_EMF;
704 aFormat = GL2PS_PGF + 1; // 6
707 // unsupported format
708 return Standard_False;
713 case Graphic3d_ST_Simple:
714 aSortType = GL2PS_SIMPLE_SORT;
716 case Graphic3d_ST_BSP_Tree:
717 aSortType = GL2PS_BSP_SORT;
724 aViewport[2] = myWindow->Width();
725 aViewport[3] = myWindow->Height();
727 GLint aBufferSize = 1024 * 1024;
728 GLint anErrCode = GL2PS_SUCCESS;
730 // gl2ps uses standard write functions and do not check locale
731 Standard_CLocaleSentry aLocaleSentry;
733 while (aBufferSize > 0)
735 // current patch for EMF support in gl2ps uses WinAPI functions to create file
736 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
737 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
738 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
740 0, 0, 0, aBufferSize, aFileH, theFileName);
741 if (anErrCode != GL2PS_SUCCESS)
743 // initialization failed
750 anErrCode = gl2psEndPage();
754 if (anErrCode == GL2PS_OVERFLOW)
759 return anErrCode == GL2PS_SUCCESS;
762 Standard_Boolean OpenGl_View::Export (const Standard_CString /*theFileName*/,
763 const Graphic3d_ExportFormat /*theFormat*/,
764 const Graphic3d_SortType /*theSortType*/)
766 return Standard_False;
770 //=======================================================================
771 //function : displayStructure
773 //=======================================================================
774 void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
775 const Standard_Integer thePriority)
777 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
778 const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
779 myZLayers.AddStructure (aStruct, aZLayer, thePriority);
782 //=======================================================================
783 //function : eraseStructure
785 //=======================================================================
786 void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
788 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
789 myZLayers.RemoveStructure (aStruct);
792 //=======================================================================
793 //function : changeZLayer
795 //=======================================================================
796 void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
797 const Graphic3d_ZLayerId theNewLayerId)
799 const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
800 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
801 myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
803 Update (theNewLayerId);
806 //=======================================================================
807 //function : changePriority
809 //=======================================================================
810 void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
811 const Standard_Integer theNewPriority)
813 const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
814 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
815 myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
818 //=======================================================================
819 //function : DiagnosticInformation
821 //=======================================================================
822 void OpenGl_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
823 Graphic3d_DiagnosticInfo theFlags) const
825 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
826 if (!myWorkspace->Activate()
832 aCtx->DiagnosticInformation (theDict, theFlags);
833 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
835 TCollection_AsciiString aResRatio (myRenderParams.ResolutionRatio());
836 theDict.ChangeFromIndex (theDict.Add ("ResolutionRatio", aResRatio)) = aResRatio;