c1d9f574697ac24534e1cf24f24265e13049fb44
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_7.cxx
1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <OpenGl_GraphicDriver.hxx>
22
23 #include <OpenGl_FrameBuffer.hxx>
24
25 #include <OpenGl_Structure.hxx>
26 #include <OpenGl_CView.hxx>
27 #include <OpenGl_Display.hxx>
28 #include <OpenGl_Text.hxx>
29
30 /*----------------------------------------------------------------------*/
31
32 void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView)
33 {
34   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
35   if (aCView)
36     aCView->WS->SetActiveView(aCView->View);
37 }
38
39 void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
40 {
41   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
42   if (aCView)
43     aCView->View->SetAntiAliasing(AFlag);
44 }
45
46 void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView)
47 {
48   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
49   if (aCView)
50   {
51     aCView->WS->SetBackgroundColor(ACView.DefWindow.Background.r,ACView.DefWindow.Background.g,ACView.DefWindow.Background.b);
52   }
53 }
54
55 void OpenGl_GraphicDriver::GradientBackground (const Graphic3d_CView& ACView,
56                                               const Quantity_Color& AColor1,
57                                               const Quantity_Color& AColor2,
58                                               const Aspect_GradientFillMethod AType)
59 {
60   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
61   if (aCView)
62   {
63     aCView->View->SetBackgroundGradient(AColor1,AColor2,AType);
64   }
65 }
66
67 void OpenGl_GraphicDriver::Blink (const Graphic3d_CStructure &, const Standard_Boolean)
68 {
69   // Do nothing
70 }
71
72 void OpenGl_GraphicDriver::BoundaryBox (const Graphic3d_CStructure& theCStructure,
73                                         const Standard_Boolean      toCreate)
74 {
75   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
76   if (aStructure == NULL)
77     return;
78
79   if (toCreate)
80     aStructure->SetHighlightBox (GetSharedContext(), theCStructure.BoundBox);
81   else
82     aStructure->ClearHighlightBox (GetSharedContext());
83 }
84
85 void OpenGl_GraphicDriver::HighlightColor (const Graphic3d_CStructure& theCStructure,
86                                            const Standard_ShortReal R,
87                                            const Standard_ShortReal G,
88                                            const Standard_ShortReal B,
89                                            const Standard_Boolean   toCreate)
90 {
91   OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
92   if (aStructure == NULL)
93     return;
94
95   if (toCreate)
96     aStructure->SetHighlightColor (GetSharedContext(), R, G, B);
97   else
98     aStructure->ClearHighlightColor (GetSharedContext());
99 }
100
101 void OpenGl_GraphicDriver::NameSetStructure (const Graphic3d_CStructure& ACStructure)
102 {
103   OpenGl_Structure *astructure = (OpenGl_Structure *)ACStructure.ptrStructure;
104   if (astructure)
105   {
106     Standard_Integer aStatus = 0;
107     if (ACStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
108     if (!ACStructure.visible) aStatus |= OPENGL_NS_HIDE;
109     astructure->SetNamedStatus( aStatus );
110   }
111 }
112
113 void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
114 {
115   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
116   if (aCView)
117   {
118     aCView->View->SetClipLimit(ACView);
119     if (!AWait)
120     {
121       aCView->WS->Resize(ACView.DefWindow);
122     }
123   }
124 }
125
126 void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView)
127 {
128   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
129   if (aCView)
130   {
131     const Handle(OpenGl_View) aDummyView;
132     aCView->WS->SetActiveView(aDummyView);
133   }
134 }
135
136 void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
137 {
138   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
139   if (aCView)
140     aCView->View->SetFog(ACView, AFlag);
141 }
142
143 Standard_Boolean OpenGl_GraphicDriver::ProjectRaster (const Graphic3d_CView& ACView, const Standard_ShortReal AX, const Standard_ShortReal AY, const Standard_ShortReal AZ, Standard_Integer& AU, Standard_Integer& AV)
144 {
145   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
146   if (!aCView)
147     return Standard_False;
148
149   Standard_Integer aWidth = aCView->WS->Width();
150   Standard_Integer aHeight = aCView->WS->Height();
151   Standard_ShortReal xr, yr;
152   if (aCView->View->ProjectObjectToRaster(aWidth, aHeight, AX, AY, AZ, xr, yr))
153   {
154     AU = (Standard_Integer) xr;
155     AV = aHeight - (Standard_Integer) yr;
156     return Standard_True;
157   }
158
159   return Standard_False;
160 }
161
162 Standard_Boolean OpenGl_GraphicDriver::UnProjectRaster (const Graphic3d_CView& ACView, const Standard_Integer /*Axm*/, const Standard_Integer Aym, const Standard_Integer /*AXM*/, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az)
163 {
164   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
165   if (!aCView)
166     return Standard_False;
167
168   const Standard_Integer aWidth = aCView->WS->Width();
169   const Standard_Integer aHeight = aCView->WS->Height();
170
171   /*
172   Patched by P.Dolbey: the window pixel height decreased by one
173   in order for yr to remain within valid coordinate range [0; Ym -1]
174   where Ym means window pixel height.
175   */
176   return aCView->View->ProjectRasterToObject( aWidth, aHeight, AU, (AYM-1)-Aym-AV, Ax, Ay, Az );
177 }
178
179 Standard_Boolean OpenGl_GraphicDriver::UnProjectRasterWithRay (const Graphic3d_CView& ACView, const Standard_Integer /*Axm*/, const Standard_Integer Aym, const Standard_Integer /*AXM*/, const Standard_Integer AYM, const Standard_Integer AU, const Standard_Integer AV, Standard_ShortReal& Ax, Standard_ShortReal& Ay, Standard_ShortReal& Az, Standard_ShortReal& Dx, Standard_ShortReal& Dy, Standard_ShortReal& Dz)
180 {
181   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
182   if (!aCView)
183     return Standard_False;
184
185   const Standard_Integer aWidth = aCView->WS->Width();
186   const Standard_Integer aHeight = aCView->WS->Height();
187
188   return aCView->View->ProjectRasterToObjectWithRay( aWidth, aHeight, AU, AYM-Aym-AV, Ax, Ay, Az, Dx, Dy, Dz );
189 }
190
191 void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& theCView)
192 {
193   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
194   if (aCView != NULL)
195     aCView->WS->Resize (theCView.DefWindow);
196 }
197
198 void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView, 
199                                    const Aspect_CLayer2d& ACUnderLayer, 
200                                    const Aspect_CLayer2d& ACOverLayer, 
201                                    const Standard_Integer /*x*/, 
202                                    const Standard_Integer /*y*/, 
203                                    const Standard_Integer /*width*/, 
204                                    const Standard_Integer /*height*/)
205 {
206   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
207   if (aCView)
208   {
209     /*if( width <= 0 || height <= 0  )
210       aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
211     else
212       aCView->WS->RedrawArea(ACView, ACUnderLayer, ACOverLayer, x, y, width, height);*/
213     // Always do full redraw
214     aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
215   }
216 }
217
218 Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& ACView, const Standard_Integer theWidth, const Standard_Integer theHeight)
219 {
220   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
221   if (aCView)
222     return aCView->WS->FBOCreate(theWidth, theHeight);
223   return (Graphic3d_PtrFrameBuffer)NULL;
224 }
225
226 Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth,
227                                                       const Standard_Integer theHeight)
228 {
229   // activate OpenGL context
230   if (!Activate())
231     return NULL;
232
233   // create the FBO
234   const Handle(OpenGl_Context)& aCtx = GetGlContext();
235   OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
236   if (!aFrameBuffer->Init (aCtx, theWidth, theHeight))
237   {
238     aFrameBuffer->Release (aCtx.operator->());
239     delete aFrameBuffer;
240     return NULL;
241   }
242   return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
243 }
244
245 void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr)
246 {
247   if (theFBOPtr == NULL)
248     return;
249   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
250   if (aCView)
251   {
252     aCView->WS->FBORelease(theFBOPtr);
253     theFBOPtr = NULL;
254   }
255 }
256
257 void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr)
258 {
259   // activate OpenGL context
260   if (!Activate()
261    || theFBOPtr == NULL)
262   {
263     return;
264   }
265
266   // release the object
267   OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr;
268   if (aFrameBuffer != NULL)
269   {
270     aFrameBuffer->Release (GetGlContext().operator->());
271   }
272   delete aFrameBuffer;
273 }
274
275 void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& ,
276                                              const Graphic3d_PtrFrameBuffer theFBOPtr,
277                                              Standard_Integer& theWidth,    Standard_Integer& theHeight,
278                                              Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
279 {
280   if (theFBOPtr == NULL)
281   {
282     return;
283   }
284   const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr;
285   theWidth  = aFrameBuffer->GetVPSizeX(); // current viewport size
286   theHeight = aFrameBuffer->GetVPSizeY();
287   theWidthMax  = aFrameBuffer->GetSizeX(); // texture size
288   theHeightMax = aFrameBuffer->GetSizeY();
289 }
290
291 void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& ,
292                                               Graphic3d_PtrFrameBuffer& theFBOPtr,
293                                               const Standard_Integer theWidth, const Standard_Integer theHeight)
294 {
295   if (theFBOPtr == NULL)
296   {
297     return;
298   }
299   OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
300   aFrameBuffer->ChangeViewport (theWidth, theHeight);
301 }
302
303 inline bool getDataFormat (const Image_PixMap& theData,
304                            GLenum&             thePixelFormat,
305                            GLenum&             theDataType)
306 {
307   thePixelFormat = GL_RGB;
308   theDataType    = GL_UNSIGNED_BYTE;
309   switch (theData.Format())
310   {
311     case Image_PixMap::ImgGray:
312       thePixelFormat = GL_DEPTH_COMPONENT;
313       theDataType    = GL_UNSIGNED_BYTE;
314       return true;
315     case Image_PixMap::ImgRGB:
316       thePixelFormat = GL_RGB;
317       theDataType    = GL_UNSIGNED_BYTE;
318       return true;
319     case Image_PixMap::ImgBGR:
320       thePixelFormat = GL_BGR;
321       theDataType    = GL_UNSIGNED_BYTE;
322       return true;
323     case Image_PixMap::ImgRGBA:
324     case Image_PixMap::ImgRGB32:
325       thePixelFormat = GL_RGBA;
326       theDataType    = GL_UNSIGNED_BYTE;
327       return true;
328     case Image_PixMap::ImgBGRA:
329     case Image_PixMap::ImgBGR32:
330       thePixelFormat = GL_BGRA;
331       theDataType    = GL_UNSIGNED_BYTE;
332       return true;
333     case Image_PixMap::ImgGrayF:
334       thePixelFormat = GL_DEPTH_COMPONENT;
335       theDataType    = GL_FLOAT;
336       return true;
337     case Image_PixMap::ImgRGBF:
338       thePixelFormat = GL_RGB;
339       theDataType    = GL_FLOAT;
340       return true;
341     case Image_PixMap::ImgBGRF:
342       thePixelFormat = GL_BGR;
343       theDataType    = GL_FLOAT;
344       return true;
345     case Image_PixMap::ImgRGBAF:
346       thePixelFormat = GL_RGBA;
347       theDataType    = GL_FLOAT;
348       return true;
349     case Image_PixMap::ImgBGRAF:
350       thePixelFormat = GL_BGRA;
351       theDataType    = GL_FLOAT;
352       return true;
353     default:
354       return false;
355   }
356 }
357
358 Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView&      theCView,
359                                                    Image_PixMap&               theImage,
360                                                    const Graphic3d_BufferType& theBufferType)
361 {
362   const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
363   return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType);
364 }
365
366 Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer*         theFBOPtr,
367                                                Image_PixMap&               theImage,
368                                                const Graphic3d_BufferType& theBufferType)
369 {
370   GLenum aFormat, aType;
371   if (theImage.IsEmpty()
372    || !getDataFormat (theImage, aFormat, aType)
373    || ((theBufferType == Graphic3d_BT_Depth) && (aFormat != GL_DEPTH_COMPONENT))
374    || !Activate())
375   {
376     return Standard_False;
377   }
378
379   // bind FBO if used
380   GLint aReadBufferPrev = GL_BACK;
381   if (theFBOPtr != NULL && theFBOPtr->IsValid())
382   {
383     theFBOPtr->BindBuffer (GetGlContext());
384   }
385   else
386   {
387     glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
388     GLint aDrawBufferPrev = GL_BACK;
389     glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
390     glReadBuffer (aDrawBufferPrev);
391   }
392
393   GLint anAlignBack = 1;
394   glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack);
395   GLint anExtraBytes = (GLint )theImage.RowExtraBytes();
396   GLint anAligment   = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
397   glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
398
399   if (anExtraBytes >= anAligment)
400   {
401     // copy row by row
402     for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
403     {
404       glReadPixels (0, GLint(aRow), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
405     }
406   }
407   else
408   {
409     // read pixels
410     glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
411     theImage.SetTopDown (false); // image bottom-up in OpenGL
412   }
413
414   glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
415
416   if (theFBOPtr != NULL && theFBOPtr->IsValid())
417   {
418     theFBOPtr->UnbindBuffer (GetGlContext());
419   }
420   else
421   {
422     glReadBuffer (aReadBufferPrev);
423   }
424   return Standard_True;
425 }
426
427 void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView)
428 {
429   Handle(OpenGl_Context)   aCtx = GetSharedContext();
430   Handle(OpenGl_View)      aView;
431   Handle(OpenGl_Workspace) aWindow;
432   if (myMapOfWS.Find (theCView.WsId, aWindow))
433   {
434     myMapOfWS.UnBind (theCView.WsId);
435   }
436   if (!aWindow.IsNull())
437   {
438     if (aWindow->GetGlContext()->MakeCurrent())
439     {
440       aCtx = aWindow->GetGlContext();
441     }
442     else
443     {
444       // try to hijack another context if any
445       const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext();
446       if (!anOtherCtx.IsNull()
447        && anOtherCtx != aWindow->GetGlContext())
448       {
449         aCtx = anOtherCtx;
450         aCtx->MakeCurrent();
451       }
452     }
453   }
454   if (myMapOfView.Find (theCView.ViewId, aView))
455   {
456     aView->ReleaseGlResources (aCtx);
457     myMapOfView.UnBind (theCView.ViewId);
458   }
459
460   if (myMapOfWS.IsEmpty())
461   {
462     // The last view removed but some objects still present.
463     // Release GL resources now without object destruction.
464     for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
465          aStructIt.More (); aStructIt.Next())
466     {
467       OpenGl_Structure* aStruct = aStructIt.ChangeValue();
468       aStruct->ReleaseGlResources (aCtx);
469     }
470     myTempText->Release (aCtx);
471     myGlDisplay->ReleaseAttributes (aCtx.operator->());
472     myDeviceLostFlag = !myMapOfStructure.IsEmpty();
473   }
474
475   OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView;
476   delete aCView;
477   ((Graphic3d_CView *)&theCView)->ptrView = NULL;
478
479   aCtx.Nullify();
480   aView.Nullify();
481   aWindow.Nullify();
482 }
483
484 void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView)
485 {
486   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
487   if (aCView)
488     aCView->View->SetLights(ACView.Context);
489 }
490
491 void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView)
492 {
493   const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
494   if (aCView)
495   {
496     aCView->View->SetClipPlanes (theCView.Context.ClipPlanes);
497   }
498 }
499
500 void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CStructure& theCStructure)
501 {
502   OpenGl_Structure* aStructure = (OpenGl_Structure *)theCStructure.ptrStructure;
503   if (aStructure)
504   {
505     aStructure->SetClipPlanes (theCStructure.ClipPlanes);
506   }
507 }
508
509 void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView)
510 {
511   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
512   if (aCView)
513   {
514     aCView->View->SetVisualisation(ACView.Context);
515     aCView->WS->UseZBuffer() = ( ACView.Context.Visualization == 0? (ACView.Context.ZBufferActivity == 1) : (ACView.Context.ZBufferActivity != 0) );
516   }
517 }
518
519 void OpenGl_GraphicDriver::TransformStructure (const Graphic3d_CStructure& ACStructure)
520 {
521   OpenGl_Structure *astructure = (OpenGl_Structure *)ACStructure.ptrStructure;
522   if (astructure)
523     astructure->SetTransformation(&(ACStructure.Transformation[0][0]));
524 }
525
526 void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
527 {
528   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
529   if (aCView)
530     aCView->WS->UseTransparency(AFlag);
531 }
532
533 void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer)
534 {
535   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
536   if (aCView)
537     aCView->WS->Update(ACView,ACUnderLayer,ACOverLayer);
538 }
539
540 Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView)
541 {
542   if (myGlDisplay.IsNull()
543    || myMapOfView.IsBound (theCView.ViewId)
544    || myMapOfWS  .IsBound (theCView.WsId))
545   {
546     return Standard_False;
547   }
548
549   Handle(OpenGl_Context)   aShareCtx = GetSharedContext();
550   Handle(OpenGl_Workspace) aWS       = new OpenGl_Workspace (myGlDisplay, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
551   Handle(OpenGl_View)      aView     = new OpenGl_View (theCView.Context);
552   myMapOfWS  .Bind (theCView.WsId,   aWS);
553   myMapOfView.Bind (theCView.ViewId, aView);
554
555   OpenGl_CView* aCView = new OpenGl_CView();
556   aCView->View = aView;
557   aCView->WS   = aWS;
558   theCView.ptrView = aCView;
559
560   return Standard_True;
561 }
562
563 void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
564 {
565   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
566   if (aCView)
567   {
568     aCView->View->SetMapping (myGlDisplay, ACView);
569     if (!AWait)
570     {
571       aCView->WS->Resize(ACView.DefWindow);
572     }
573   }
574 }
575
576 void OpenGl_GraphicDriver::ViewOrientation (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
577 {
578   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
579   if (aCView)
580   {
581     aCView->View->SetOrientation(ACView);
582     if (!AWait)
583     {
584       aCView->WS->Resize(ACView.DefWindow);
585     }
586   }
587 }
588
589 void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView)
590 {
591   const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
592   if (aCView)
593     aCView->View->SetBackfacing(ACView.Backfacing);
594 }
595
596 //=======================================================================
597 //function : AddZLayer
598 //purpose  :
599 //=======================================================================
600
601 void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView,
602                                       const Standard_Integer theLayerId)
603 {
604   const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
605   if (aCView)
606     aCView->View->AddZLayer (theLayerId);
607 }
608
609 //=======================================================================
610 //function : RemoveZLayer
611 //purpose  :
612 //=======================================================================
613
614 void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView,
615                                          const Standard_Integer theLayerId)
616 {
617   const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView;
618   if (aCView)
619     aCView->View->RemoveZLayer (theLayerId);
620 }