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_Trihedron.hxx>
33 #include <OpenGl_Window.hxx>
34 #include <OpenGl_Workspace.hxx>
35 #include <Standard_CLocaleSentry.hxx>
37 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView)
43 // =======================================================================
44 // function : Constructor
46 // =======================================================================
47 OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
48 const Handle(OpenGl_GraphicDriver)& theDriver,
49 const Handle(OpenGl_Caps)& theCaps,
50 Standard_Boolean& theDeviceLostFlag,
51 OpenGl_StateCounter* theCounter)
52 : Graphic3d_CView (theMgr),
53 myDriver (theDriver.operator->()),
55 myDeviceLostFlag (theDeviceLostFlag),
56 myWasRedrawnGL (Standard_False),
57 myCulling (Standard_True),
58 myShadingModel (Graphic3d_TOSM_FACET),
59 myBackfacing (Graphic3d_TOBM_AUTOMATIC),
60 myBgColor (Quantity_NOC_BLACK),
61 myCamera (new Graphic3d_Camera()),
62 myUseGLLight (Standard_True),
63 myToShowTrihedron (false),
64 myToShowGradTrihedron (false),
65 myStateCounter (theCounter),
66 myLastLightSourceState (0, 0),
67 myFboColorFormat (GL_RGBA8),
68 myFboDepthFormat (GL_DEPTH24_STENCIL8),
69 myToFlipOutput (Standard_False),
71 myHasFboBlit (Standard_True),
72 myToDisableMSAA (Standard_False),
73 myTransientDrawToFront (Standard_True),
74 myBackBufferRestored (Standard_False),
75 myIsImmediateDrawn (Standard_False),
76 myTextureParams (new OpenGl_AspectFace()),
77 myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)),
78 myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)),
79 // ray-tracing fields initialization
80 myRaytraceInitStatus (OpenGl_RT_NONE),
81 myIsRaytraceDataValid (Standard_False),
82 myIsRaytraceWarnTextures (Standard_False),
83 myToUpdateEnvironmentMap (Standard_False),
84 myRaytraceLayerListState (0)
86 myWorkspace = new OpenGl_Workspace (this, NULL);
89 aLight.Type = Graphic3d_TOLS_AMBIENT;
90 aLight.IsHeadlight = Standard_False;
91 aLight.Color.r() = 1.;
92 aLight.Color.g() = 1.;
93 aLight.Color.b() = 1.;
94 myNoShadingLight.Append (aLight);
96 myCurrLightSourceState = myStateCounter->Increment();
97 myMainSceneFbos[0] = new OpenGl_FrameBuffer();
98 myMainSceneFbos[1] = new OpenGl_FrameBuffer();
99 myImmediateSceneFbos[0] = new OpenGl_FrameBuffer();
100 myImmediateSceneFbos[1] = new OpenGl_FrameBuffer();
101 myOpenGlFBO = new OpenGl_FrameBuffer();
102 myOpenGlFBO2 = new OpenGl_FrameBuffer();
103 myRaytraceFBO1[0] = new OpenGl_FrameBuffer();
104 myRaytraceFBO1[1] = new OpenGl_FrameBuffer();
105 myRaytraceFBO2[0] = new OpenGl_FrameBuffer();
106 myRaytraceFBO2[1] = new OpenGl_FrameBuffer();
109 // =======================================================================
110 // function : Destructor
112 // =======================================================================
113 OpenGl_View::~OpenGl_View()
115 ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context
116 OpenGl_Element::Destroy (NULL, myBgGradientArray);
117 OpenGl_Element::Destroy (NULL, myBgTextureArray);
118 OpenGl_Element::Destroy (NULL, myTextureParams);
121 // =======================================================================
122 // function : ReleaseGlResources
124 // =======================================================================
125 void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx)
127 myTrihedron .Release (theCtx.operator->());
128 myGraduatedTrihedron.Release (theCtx.operator->());
130 if (!myTextureEnv.IsNull())
132 theCtx->DelayedRelease (myTextureEnv);
133 myTextureEnv.Nullify();
136 if (myTextureParams != NULL)
138 myTextureParams->Release (theCtx.operator->());
140 if (myBgGradientArray != NULL)
142 myBgGradientArray->Release (theCtx.operator->());
144 if (myBgTextureArray != NULL)
146 myBgTextureArray->Release (theCtx.operator->());
149 myMainSceneFbos[0] ->Release (theCtx.operator->());
150 myMainSceneFbos[1] ->Release (theCtx.operator->());
151 myImmediateSceneFbos[0]->Release (theCtx.operator->());
152 myImmediateSceneFbos[1]->Release (theCtx.operator->());
153 myOpenGlFBO ->Release (theCtx.operator->());
154 myOpenGlFBO2 ->Release (theCtx.operator->());
155 myFullScreenQuad .Release (theCtx.operator->());
156 myFullScreenQuadFlip .Release (theCtx.operator->());
158 releaseRaytraceResources (theCtx);
161 // =======================================================================
164 // =======================================================================
165 void OpenGl_View::Remove()
172 myDriver->RemoveView (this);
175 Graphic3d_CView::Remove();
178 // =======================================================================
179 // function : SetTextureEnv
181 // =======================================================================
182 void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv)
184 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
185 if (!aCtx.IsNull() && !myTextureEnv.IsNull())
187 aCtx->DelayedRelease (myTextureEnv);
190 myToUpdateEnvironmentMap = Standard_True;
191 myTextureEnvData = theTextureEnv;
192 myTextureEnv.Nullify();
193 initTextureEnv (aCtx);
196 // =======================================================================
197 // function : initTextureEnv
199 // =======================================================================
200 void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext)
202 if (myTextureEnvData.IsNull()
203 || theContext.IsNull()
204 || !theContext->MakeCurrent())
209 myTextureEnv = new OpenGl_Texture (myTextureEnvData->GetParams());
210 Handle(Image_PixMap) anImage = myTextureEnvData->GetImage();
211 if (!anImage.IsNull())
213 myTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type());
217 // =======================================================================
218 // function : SetImmediateModeDrawToFront
220 // =======================================================================
221 Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer)
223 const Standard_Boolean aPrevMode = myTransientDrawToFront;
224 myTransientDrawToFront = theDrawToFrontBuffer;
228 // =======================================================================
229 // function : SetWindow
231 // =======================================================================
232 void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow,
233 const Aspect_RenderingContext theContext)
235 myWindow = myDriver->CreateRenderWindow (theWindow, theContext);
236 Standard_ASSERT_RAISE (!myWindow.IsNull(),
237 "OpenGl_View::SetWindow, "
238 "Failed to create OpenGl window.");
240 myWorkspace = new OpenGl_Workspace (this, myWindow);
241 myWorldViewProjState.Reset();
242 myToUpdateEnvironmentMap = Standard_True;
243 myHasFboBlit = Standard_True;
246 // Environment texture resource does not support lazy initialization.
247 initTextureEnv (myWorkspace->GetGlContext());
250 // =======================================================================
251 // function : Resized
253 // =======================================================================
254 void OpenGl_View::Resized()
256 if (myWindow.IsNull())
262 // =======================================================================
263 // function : TriedronDisplay
265 // =======================================================================
266 void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
267 const Quantity_NameOfColor theColor,
268 const Standard_Real theScale,
269 const Standard_Boolean theAsWireframe)
271 myToShowTrihedron = true;
272 myTrihedron.SetWireframe (theAsWireframe);
273 myTrihedron.SetPosition (thePosition);
274 myTrihedron.SetScale (theScale);
275 myTrihedron.SetLabelsColor (theColor);
278 // =======================================================================
279 // function : TriedronErase
281 // =======================================================================
282 void OpenGl_View::TriedronErase()
284 myToShowTrihedron = false;
285 myTrihedron.Release (myWorkspace->GetGlContext().operator->());
288 // =======================================================================
289 // function : ZBufferTriedronSetup
291 // =======================================================================
292 void OpenGl_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
293 const Quantity_NameOfColor theYColor,
294 const Quantity_NameOfColor theZColor,
295 const Standard_Real theSizeRatio,
296 const Standard_Real theAxisDiametr,
297 const Standard_Integer theNbFacettes)
299 myTrihedron.SetArrowsColors (theXColor, theYColor, theZColor);
300 myTrihedron.SetSizeRatio (theSizeRatio);
301 myTrihedron.SetNbFacets (theNbFacettes);
302 myTrihedron.SetArrowDiameter (theAxisDiametr);
305 // =======================================================================
306 // function : TriedronEcho
308 // =======================================================================
309 void OpenGl_View::TriedronEcho (const Aspect_TypeOfTriedronEcho /*theType*/)
314 // =======================================================================
315 // function : SetMinMaxValuesCallback
317 // =======================================================================
318 static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
320 OpenGl_View* aView = dynamic_cast<OpenGl_View*>(theView);
324 Bnd_Box aBox = theView->MinMaxValues();
327 gp_Pnt aMin = aBox.CornerMin();
328 gp_Pnt aMax = aBox.CornerMax();
330 Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z());
331 Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
332 aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec);
336 // =======================================================================
337 // function : GraduatedTrihedronDisplay
339 // =======================================================================
340 void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
342 myGTrihedronData = theTrihedronData;
343 myGTrihedronData.PtrView = this;
344 myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
345 myGraduatedTrihedron.SetValues (myGTrihedronData);
346 myToShowGradTrihedron = true;
349 // =======================================================================
350 // function : GraduatedTrihedronErase
352 // =======================================================================
353 void OpenGl_View::GraduatedTrihedronErase()
355 myGTrihedronData.PtrView = NULL;
356 myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
357 myToShowGradTrihedron = false;
360 // =======================================================================
361 // function : GraduatedTrihedronMinMaxValues
363 // =======================================================================
364 void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax)
366 myGraduatedTrihedron.SetMinMax (theMin, theMax);
369 // =======================================================================
370 // function : BufferDump
372 // =======================================================================
373 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
375 return myWorkspace->BufferDump (myFBO, theImage, theBufferType);
378 // =======================================================================
379 // function : Background
381 // =======================================================================
382 Aspect_Background OpenGl_View::Background() const
384 return Aspect_Background (myBgColor.GetRGB());
387 // =======================================================================
388 // function : SetBackground
390 // =======================================================================
391 void OpenGl_View::SetBackground (const Aspect_Background& theBackground)
393 myBgColor.SetRGB (theBackground.Color());
396 // =======================================================================
397 // function : GradientBackground
399 // =======================================================================
400 Aspect_GradientBackground OpenGl_View::GradientBackground() const
402 Quantity_Color aColor1, aColor2;
403 aColor1.SetValues (myBgGradientArray->GradientColor (0).r(),
404 myBgGradientArray->GradientColor (0).g(),
405 myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB);
406 aColor2.SetValues (myBgGradientArray->GradientColor (1).r(),
407 myBgGradientArray->GradientColor (1).g(),
408 myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB);
409 return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod());
412 // =======================================================================
413 // function : SetGradientBackground
415 // =======================================================================
416 void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground)
418 Quantity_Color aColor1, aColor2;
419 theBackground.Colors (aColor1, aColor2);
420 myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod());
423 // =======================================================================
424 // function : SetBackgroundImage
426 // =======================================================================
427 void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath)
429 // Prepare aspect for texture storage
430 myBackgroundImagePath = theFilePath;
431 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
432 Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath));
433 aTextureMap->EnableRepeat();
434 aTextureMap->DisableModulate();
435 aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL,
436 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
437 Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
438 anAspect->SetTextureMap (aTextureMap);
439 anAspect->SetInteriorStyle (Aspect_IS_SOLID);
440 anAspect->SetSuppressBackFaces (false);
441 // Enable texture mapping
442 if (aTextureMap->IsDone())
444 anAspect->SetTextureMapOn();
448 anAspect->SetTextureMapOff();
452 // Set texture parameters
453 myTextureParams->SetAspect (anAspect);
456 // =======================================================================
457 // function : BackgroundImageStyle
459 // =======================================================================
460 Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const
462 return myBgTextureArray->TextureFillMethod();
465 // =======================================================================
466 // function : SetBackgroundImageStyle
468 // =======================================================================
469 void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle)
471 myBgTextureArray->SetTextureFillMethod (theFillStyle);
474 //=======================================================================
475 //function : AddZLayer
477 //=======================================================================
478 void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId)
480 myZLayers.AddLayer (theLayerId);
483 //=======================================================================
484 //function : RemoveZLayer
486 //=======================================================================
487 void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
489 myZLayers.RemoveLayer (theLayerId);
492 //=======================================================================
493 //function : SetZLayerSettings
495 //=======================================================================
496 void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
497 const Graphic3d_ZLayerSettings& theSettings)
499 myZLayers.SetLayerSettings (theLayerId, theSettings);
502 //=======================================================================
503 //function : ZLayerMax
505 //=======================================================================
506 Standard_Integer OpenGl_View::ZLayerMax() const
508 Standard_Integer aLayerMax = Graphic3d_ZLayerId_Default;
509 for (OpenGl_LayerSeqIds::Iterator aMapIt(myZLayers.LayerIDs()); aMapIt.More(); aMapIt.Next())
511 aLayerMax = Max (aLayerMax, aMapIt.Value());
517 //=======================================================================
518 //function : InvalidateZLayerBoundingBox
520 //=======================================================================
521 void OpenGl_View::InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const
523 if (myZLayers.LayerIDs().IsBound (theLayerId))
525 myZLayers.Layer (theLayerId).InvalidateBoundingBox();
529 for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId < ZLayerMax(); ++aLayerId)
531 if (myZLayers.LayerIDs().IsBound (aLayerId))
533 const OpenGl_Layer& aLayer = myZLayers.Layer (aLayerId);
534 if (aLayer.NbOfTransformPersistenceObjects() > 0)
536 aLayer.InvalidateBoundingBox();
543 //=======================================================================
544 //function : ZLayerBoundingBox
546 //=======================================================================
547 Graphic3d_BndBox4f OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
548 const Handle(Graphic3d_Camera)& theCamera,
549 const Standard_Integer theWindowWidth,
550 const Standard_Integer theWindowHeight,
551 const Standard_Boolean theToIncludeAuxiliary) const
553 Graphic3d_BndBox4f aBox;
554 if (myZLayers.LayerIDs().IsBound (theLayerId))
556 aBox = myZLayers.Layer (theLayerId).BoundingBox (Identification(),
560 theToIncludeAuxiliary);
563 // add bounding box of gradient/texture background for proper Z-fit
564 if (theToIncludeAuxiliary
565 && theLayerId == Graphic3d_ZLayerId_BotOSD
566 && (myBgTextureArray->IsDefined()
567 || myBgGradientArray->IsDefined()))
569 // Background is drawn using 2D transformation persistence
570 // (e.g. it is actually placed in 3D coordinates within active camera position).
571 // We add here full-screen plane with 2D transformation persistence
572 // for simplicity (myBgTextureArray might define a little bit different options
573 // but it is updated within ::Render())
574 const Graphic3d_Mat4& aProjectionMat = theCamera->ProjectionMatrixF();
575 const Graphic3d_Mat4& aWorldViewMat = theCamera->OrientationMatrixF();
576 Graphic3d_BndBox4f aBox2d (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
577 Graphic3d_Vec4 (float(theWindowWidth), float(theWindowHeight), 0.0f, 0.0f));
579 Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER);
580 aTrsfPers.Apply (theCamera,
586 aBox.Combine (aBox2d);
592 //=======================================================================
593 //function : considerZoomPersistenceObjects
595 //=======================================================================
596 Standard_Real OpenGl_View::considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
597 const Handle(Graphic3d_Camera)& theCamera,
598 const Standard_Integer theWindowWidth,
599 const Standard_Integer theWindowHeight) const
601 if (myZLayers.LayerIDs().IsBound (theLayerId))
603 return myZLayers.Layer (theLayerId).considerZoomPersistenceObjects (Identification(),
612 //=======================================================================
615 //=======================================================================
616 Handle(Standard_Transient) OpenGl_View::FBO() const
618 return Handle(Standard_Transient)(myFBO);
621 //=======================================================================
624 //=======================================================================
625 void OpenGl_View::SetFBO (const Handle(Standard_Transient)& theFbo)
627 myFBO = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
630 //=======================================================================
631 //function : FBOCreate
633 //=======================================================================
634 Handle(Standard_Transient) OpenGl_View::FBOCreate (const Standard_Integer theWidth,
635 const Standard_Integer theHeight)
637 return myWorkspace->FBOCreate (theWidth, theHeight);
640 //=======================================================================
641 //function : FBORelease
643 //=======================================================================
644 void OpenGl_View::FBORelease (Handle(Standard_Transient)& theFbo)
646 Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
647 if (aFrameBuffer.IsNull())
652 myWorkspace->FBORelease (aFrameBuffer);
656 //=======================================================================
657 //function : FBOGetDimensions
659 //=======================================================================
660 void OpenGl_View::FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
661 Standard_Integer& theWidth,
662 Standard_Integer& theHeight,
663 Standard_Integer& theWidthMax,
664 Standard_Integer& theHeightMax)
666 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
667 if (aFrameBuffer.IsNull())
672 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
673 theHeight = aFrameBuffer->GetVPSizeY();
674 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
675 theHeightMax = aFrameBuffer->GetSizeY();
678 //=======================================================================
679 //function : FBOChangeViewport
681 //=======================================================================
682 void OpenGl_View::FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
683 const Standard_Integer theWidth,
684 const Standard_Integer theHeight)
686 const Handle(OpenGl_FrameBuffer) aFrameBuffer = Handle(OpenGl_FrameBuffer)::DownCast (theFbo);
687 if (aFrameBuffer.IsNull())
692 aFrameBuffer->ChangeViewport (theWidth, theHeight);
695 // =======================================================================
698 // =======================================================================
700 Standard_Boolean OpenGl_View::Export (const Standard_CString theFileName,
701 const Graphic3d_ExportFormat theFormat,
702 const Graphic3d_SortType theSortType)
704 // gl2psBeginPage() will call OpenGL functions
705 // so we should activate correct GL context before redraw scene call
706 if (!myWorkspace->Activate())
708 return Standard_False;
711 Standard_Integer aFormat = -1;
712 Standard_Integer aSortType = Graphic3d_ST_BSP_Tree;
715 case Graphic3d_EF_PostScript:
718 case Graphic3d_EF_EnhPostScript:
721 case Graphic3d_EF_TEX:
724 case Graphic3d_EF_PDF:
727 case Graphic3d_EF_SVG:
730 case Graphic3d_EF_PGF:
733 case Graphic3d_EF_EMF:
734 //aFormat = GL2PS_EMF;
735 aFormat = GL2PS_PGF + 1; // 6
738 // unsupported format
739 return Standard_False;
744 case Graphic3d_ST_Simple:
745 aSortType = GL2PS_SIMPLE_SORT;
747 case Graphic3d_ST_BSP_Tree:
748 aSortType = GL2PS_BSP_SORT;
755 aViewport[2] = myWindow->Width();
756 aViewport[3] = myWindow->Height();
758 GLint aBufferSize = 1024 * 1024;
759 GLint anErrCode = GL2PS_SUCCESS;
761 // gl2ps uses standard write functions and do not check locale
762 Standard_CLocaleSentry aLocaleSentry;
764 while (aBufferSize > 0)
766 // current patch for EMF support in gl2ps uses WinAPI functions to create file
767 FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL;
768 anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType,
769 GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/,
771 0, 0, 0, aBufferSize, aFileH, theFileName);
772 if (anErrCode != GL2PS_SUCCESS)
774 // initialization failed
781 anErrCode = gl2psEndPage();
785 if (anErrCode == GL2PS_OVERFLOW)
790 return anErrCode == GL2PS_SUCCESS;
793 Standard_Boolean OpenGl_View::Export (const Standard_CString /*theFileName*/,
794 const Graphic3d_ExportFormat /*theFormat*/,
795 const Graphic3d_SortType /*theSortType*/)
797 return Standard_False;
801 //=======================================================================
802 //function : displayStructure
804 //=======================================================================
805 void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
806 const Standard_Integer thePriority)
808 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
809 const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer();
810 myZLayers.AddStructure (aStruct, aZLayer, thePriority);
813 //=======================================================================
814 //function : eraseStructure
816 //=======================================================================
817 void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure)
819 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
820 myZLayers.RemoveStructure (aStruct);
823 //=======================================================================
824 //function : changeZLayer
826 //=======================================================================
827 void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure,
828 const Graphic3d_ZLayerId theNewLayerId)
830 const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer();
831 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
832 myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId);
833 Update (Aspect_TOU_WAIT, anOldLayer);
834 Update (Aspect_TOU_WAIT, theNewLayerId);
837 //=======================================================================
838 //function : changePriority
840 //=======================================================================
841 void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure,
842 const Standard_Integer theNewPriority)
844 const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer();
845 const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure.operator->());
846 myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority);
849 //=======================================================================
850 //function : DiagnosticInformation
852 //=======================================================================
853 void OpenGl_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
854 Graphic3d_DiagnosticInfo theFlags) const
856 Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext();
857 if (!myWorkspace->Activate()
863 aCtx->DiagnosticInformation (theDict, theFlags);
864 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
866 TCollection_AsciiString aResRatio (myRenderParams.ResolutionRatio());
867 theDict.ChangeFromIndex (theDict.Add ("ResolutionRatio", aResRatio)) = aResRatio;