0023654: Problem with displaying vertices in OCC view after closing all OCC views...
[occt.git] / src / OpenGl / OpenGl_GraphicDriver_7.cxx
CommitLineData
b311480e 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
7fd59977 20
2166f0fa 21#include <OpenGl_GraphicDriver.hxx>
7fd59977 22
7fd59977 23#include <OpenGl_FrameBuffer.hxx>
24
2166f0fa
SK
25#include <OpenGl_Structure.hxx>
26#include <OpenGl_CView.hxx>
27#include <OpenGl_Display.hxx>
eb4320f2 28#include <OpenGl_Text.hxx>
7fd59977 29
2166f0fa 30/*----------------------------------------------------------------------*/
7fd59977 31
2166f0fa
SK
32void 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);
7fd59977 37}
38
2166f0fa
SK
39void 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);
7fd59977 44}
45
2166f0fa
SK
46void 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);
7fd59977 52 }
7fd59977 53}
54
2166f0fa 55void OpenGl_GraphicDriver::GradientBackground (const Graphic3d_CView& ACView,
7fd59977 56 const Quantity_Color& AColor1,
57 const Quantity_Color& AColor2,
2166f0fa
SK
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);
7fd59977 64 }
7fd59977 65}
66
2166f0fa
SK
67void OpenGl_GraphicDriver::Blink (const Graphic3d_CStructure &, const Standard_Boolean)
68{
69 // Do nothing
7fd59977 70}
71
5e27df78 72void OpenGl_GraphicDriver::BoundaryBox (const Graphic3d_CStructure& theCStructure,
73 const Standard_Boolean toCreate)
2166f0fa 74{
5e27df78 75 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
76 if (aStructure == NULL)
2166f0fa 77 return;
7fd59977 78
5e27df78 79 if (toCreate)
80 aStructure->SetHighlightBox (GetSharedContext(), theCStructure.BoundBox);
2166f0fa 81 else
5e27df78 82 aStructure->ClearHighlightBox (GetSharedContext());
7fd59977 83}
84
5e27df78 85void 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)
2166f0fa 90{
5e27df78 91 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
92 if (aStructure == NULL)
2166f0fa 93 return;
7fd59977 94
5e27df78 95 if (toCreate)
96 aStructure->SetHighlightColor (GetSharedContext(), R, G, B);
2166f0fa 97 else
5e27df78 98 aStructure->ClearHighlightColor (GetSharedContext());
7fd59977 99}
100
2166f0fa
SK
101void 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;
2166f0fa 109 astructure->SetNamedStatus( aStatus );
7fd59977 110 }
7fd59977 111}
112
2166f0fa
SK
113void 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);
529afc1a 119 if (!AWait)
2166f0fa
SK
120 {
121 aCView->WS->Resize(ACView.DefWindow);
2166f0fa 122 }
7fd59977 123 }
7fd59977 124}
125
2166f0fa
SK
126void 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);
7fd59977 133 }
7fd59977 134}
135
2166f0fa
SK
136void 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);
7fd59977 141}
142
2166f0fa
SK
143Standard_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;
7fd59977 148
2166f0fa
SK
149 Standard_Integer aWidth = aCView->WS->Width();
150 Standard_Integer aHeight = aCView->WS->Height();
2166f0fa
SK
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;
7fd59977 157 }
158
2166f0fa 159 return Standard_False;
7fd59977 160}
161
35e08fe8 162Standard_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)
2166f0fa
SK
163{
164 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
165 if (!aCView)
166 return Standard_False;
7fd59977 167
2166f0fa
SK
168 const Standard_Integer aWidth = aCView->WS->Width();
169 const Standard_Integer aHeight = aCView->WS->Height();
7fd59977 170
2166f0fa 171 /*
bf75be98 172 Patched by P.Dolbey: the window pixel height decreased by one
2166f0fa
SK
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 );
7fd59977 177}
178
35e08fe8 179Standard_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)
2166f0fa
SK
180{
181 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
182 if (!aCView)
183 return Standard_False;
7fd59977 184
2166f0fa
SK
185 const Standard_Integer aWidth = aCView->WS->Width();
186 const Standard_Integer aHeight = aCView->WS->Height();
7fd59977 187
2166f0fa 188 return aCView->View->ProjectRasterToObjectWithRay( aWidth, aHeight, AU, AYM-Aym-AV, Ax, Ay, Az, Dx, Dy, Dz );
7fd59977 189}
190
529afc1a 191void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& theCView)
2166f0fa 192{
529afc1a
K
193 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
194 if (aCView != NULL)
195 aCView->WS->Resize (theCView.DefWindow);
2166f0fa 196}
7fd59977 197
35e08fe8 198void 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*/)
2166f0fa
SK
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);
7fd59977 215 }
7fd59977 216}
217
2166f0fa
SK
218Graphic3d_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;
7fd59977 224}
225
2166f0fa
SK
226Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight)
227{
7fd59977 228 // activate OpenGL context
2166f0fa 229 if (!Activate())
7fd59977 230 return NULL;
2166f0fa 231
7fd59977 232 // create the FBO
233 OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
2166f0fa 234 if (!aFrameBuffer->Init (GetGlContext(), theWidth, theHeight))
7fd59977 235 {
236 delete aFrameBuffer;
237 return NULL;
238 }
239 return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
240}
241
2166f0fa 242void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr)
7fd59977 243{
244 if (theFBOPtr == NULL)
7fd59977 245 return;
2166f0fa
SK
246 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
247 if (aCView)
248 {
249 aCView->WS->FBORelease(theFBOPtr);
250 theFBOPtr = NULL;
7fd59977 251 }
2166f0fa
SK
252}
253
254void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr)
255{
7fd59977 256 // activate OpenGL context
2166f0fa 257 if (!Activate())
7fd59977 258 return;
2166f0fa 259
7fd59977 260 // release the object
2166f0fa
SK
261 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr;
262 aFrameBuffer->Release (GetGlContext());
7fd59977 263 delete aFrameBuffer;
7fd59977 264}
265
266void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& ,
267 const Graphic3d_PtrFrameBuffer theFBOPtr,
268 Standard_Integer& theWidth, Standard_Integer& theHeight,
269 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
270{
271 if (theFBOPtr == NULL)
272 {
273 return;
274 }
275 const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr;
276 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
277 theHeight = aFrameBuffer->GetVPSizeY();
278 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
279 theHeightMax = aFrameBuffer->GetSizeY();
280}
281
282void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& ,
283 Graphic3d_PtrFrameBuffer& theFBOPtr,
284 const Standard_Integer theWidth, const Standard_Integer theHeight)
285{
286 if (theFBOPtr == NULL)
287 {
288 return;
289 }
290 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
291 aFrameBuffer->ChangeViewport (theWidth, theHeight);
292}
293
692613e5 294inline bool getDataFormat (const Image_PixMap& theData,
295 GLenum& thePixelFormat,
296 GLenum& theDataType)
7fd59977 297{
692613e5 298 thePixelFormat = GL_RGB;
299 theDataType = GL_UNSIGNED_BYTE;
300 switch (theData.Format())
7fd59977 301 {
692613e5 302 case Image_PixMap::ImgGray:
303 thePixelFormat = GL_DEPTH_COMPONENT;
304 theDataType = GL_UNSIGNED_BYTE;
305 return true;
306 case Image_PixMap::ImgRGB:
307 thePixelFormat = GL_RGB;
308 theDataType = GL_UNSIGNED_BYTE;
309 return true;
310 case Image_PixMap::ImgBGR:
311 thePixelFormat = GL_BGR;
312 theDataType = GL_UNSIGNED_BYTE;
313 return true;
314 case Image_PixMap::ImgRGBA:
315 case Image_PixMap::ImgRGB32:
316 thePixelFormat = GL_RGBA;
317 theDataType = GL_UNSIGNED_BYTE;
318 return true;
319 case Image_PixMap::ImgBGRA:
320 case Image_PixMap::ImgBGR32:
321 thePixelFormat = GL_BGRA;
322 theDataType = GL_UNSIGNED_BYTE;
323 return true;
324 case Image_PixMap::ImgGrayF:
325 thePixelFormat = GL_DEPTH_COMPONENT;
326 theDataType = GL_FLOAT;
327 return true;
328 case Image_PixMap::ImgRGBF:
329 thePixelFormat = GL_RGB;
330 theDataType = GL_FLOAT;
331 return true;
332 case Image_PixMap::ImgBGRF:
333 thePixelFormat = GL_BGR;
334 theDataType = GL_FLOAT;
335 return true;
336 case Image_PixMap::ImgRGBAF:
337 thePixelFormat = GL_RGBA;
338 theDataType = GL_FLOAT;
339 return true;
340 case Image_PixMap::ImgBGRAF:
341 thePixelFormat = GL_BGRA;
342 theDataType = GL_FLOAT;
343 return true;
344 default:
345 return false;
7fd59977 346 }
347}
348
692613e5 349Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView,
350 Image_PixMap& theImage,
351 const Graphic3d_BufferType& theBufferType)
7fd59977 352{
692613e5 353 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
354 return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType);
2166f0fa
SK
355}
356
692613e5 357Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr,
358 Image_PixMap& theImage,
359 const Graphic3d_BufferType& theBufferType)
7fd59977 360{
692613e5 361 GLenum aFormat, aType;
362 if (theImage.IsEmpty()
363 || !getDataFormat (theImage, aFormat, aType)
364 || ((theBufferType == Graphic3d_BT_Depth) && (aFormat != GL_DEPTH_COMPONENT))
365 || !Activate())
7fd59977 366 {
367 return Standard_False;
368 }
369
7fd59977 370 // bind FBO if used
7fd59977 371 GLint aReadBufferPrev = GL_BACK;
692613e5 372 if (theFBOPtr != NULL && theFBOPtr->IsValid())
7fd59977 373 {
692613e5 374 theFBOPtr->BindBuffer (GetGlContext());
7fd59977 375 }
376 else
377 {
378 glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
379 GLint aDrawBufferPrev = GL_BACK;
380 glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
381 glReadBuffer (aDrawBufferPrev);
382 }
383
384 GLint anAlignBack = 1;
385 glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack);
692613e5 386 GLint anExtraBytes = (GLint )theImage.RowExtraBytes();
387 GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
388 glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
389
390 if (anExtraBytes >= anAligment)
391 {
392 // copy row by row
393 for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
394 {
395 glReadPixels (0, GLint(aRow), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
396 }
397 }
398 else
7fd59977 399 {
692613e5 400 // read pixels
401 glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
402 theImage.SetTopDown (false); // image bottom-up in OpenGL
7fd59977 403 }
7fd59977 404
7fd59977 405 glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
406
692613e5 407 if (theFBOPtr != NULL && theFBOPtr->IsValid())
7fd59977 408 {
692613e5 409 theFBOPtr->UnbindBuffer (GetGlContext());
7fd59977 410 }
411 else
412 {
413 glReadBuffer (aReadBufferPrev);
414 }
415 return Standard_True;
416}
417
dd8a4ce9 418void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView)
2166f0fa 419{
dd8a4ce9 420 Handle(OpenGl_Context) aShareCtx = GetSharedContext();
421 if (myMapOfView.IsBound (theCView.ViewId))
422 myMapOfView.UnBind (theCView.ViewId);
7fd59977 423
dd8a4ce9 424 if (myMapOfWS.IsBound (theCView.WsId))
425 myMapOfWS.UnBind (theCView.WsId);
7fd59977 426
dd8a4ce9 427 if (myMapOfWS.IsEmpty() && !myMapOfStructure.IsEmpty())
428 {
429 // The last view removed but some objects still present.
430 // Release GL resources now without object destruction.
431 for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
432 aStructIt.More (); aStructIt.Next())
433 {
434 OpenGl_Structure* aStruct = aStructIt.ChangeValue();
435 aStruct->ReleaseGlResources (aShareCtx);
436 }
eb4320f2 437 myTempText->Release (aShareCtx);
438 myDeviceLostFlag = Standard_True;
dd8a4ce9 439 }
440
bf75be98 441 OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView;
442 aCView->View->ReleaseGlResources (aShareCtx);
2166f0fa 443 delete aCView;
dd8a4ce9 444 ((Graphic3d_CView *)&theCView)->ptrView = NULL;
7fd59977 445}
446
2166f0fa
SK
447void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView)
448{
449 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
450 if (aCView)
451 aCView->View->SetLights(ACView.Context);
7fd59977 452}
453
4269bd1b 454void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView)
2166f0fa 455{
4269bd1b 456 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
2166f0fa 457 if (aCView)
4269bd1b 458 {
459 aCView->View->SetClipPlanes (theCView.Context.ClipPlanes);
460 }
461}
462
463void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CStructure& theCStructure)
464{
465 OpenGl_Structure* aStructure = (OpenGl_Structure *)theCStructure.ptrStructure;
466 if (aStructure)
467 {
468 aStructure->SetClipPlanes (theCStructure.ClipPlanes);
469 }
7fd59977 470}
471
2166f0fa
SK
472void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView)
473{
474 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
475 if (aCView)
476 {
477 aCView->View->SetVisualisation(ACView.Context);
478 aCView->WS->UseZBuffer() = ( ACView.Context.Visualization == 0? (ACView.Context.ZBufferActivity == 1) : (ACView.Context.ZBufferActivity != 0) );
7fd59977 479 }
7fd59977 480}
481
2166f0fa
SK
482void OpenGl_GraphicDriver::TransformStructure (const Graphic3d_CStructure& ACStructure)
483{
484 OpenGl_Structure *astructure = (OpenGl_Structure *)ACStructure.ptrStructure;
485 if (astructure)
486 astructure->SetTransformation(&(ACStructure.Transformation[0][0]));
7fd59977 487}
488
2166f0fa
SK
489void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
490{
491 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
492 if (aCView)
493 aCView->WS->UseTransparency(AFlag);
494}
7fd59977 495
2166f0fa
SK
496void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer)
497{
498 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
499 if (aCView)
500 aCView->WS->Update(ACView,ACUnderLayer,ACOverLayer);
501}
7fd59977 502
5e27df78 503Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView)
2166f0fa
SK
504{
505 if (openglDisplay.IsNull())
506 return Standard_False;
7fd59977 507
5e27df78 508 if (myMapOfView.IsBound (theCView.ViewId))
509 myMapOfView.UnBind (theCView.ViewId);
7fd59977 510
5e27df78 511 if (myMapOfWS.IsBound (theCView.WsId))
512 myMapOfWS.UnBind (theCView.WsId);
7fd59977 513
5e27df78 514 Handle(OpenGl_Workspace) aWS = Handle(OpenGl_Workspace)::DownCast(openglDisplay->GetWindow (theCView.DefWindow.XWindow));
515 if (aWS.IsNull())
2166f0fa 516 {
5e27df78 517 Handle(OpenGl_Context) aShareCtx = GetSharedContext();
58655684 518 aWS = new OpenGl_Workspace (openglDisplay, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
5e27df78 519 openglDisplay->SetWindow (theCView.DefWindow.XWindow, aWS);
7fd59977 520 }
521
5e27df78 522 myMapOfWS.Bind (theCView.WsId, aWS);
7fd59977 523
5e27df78 524 Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context);
525 myMapOfView.Bind (theCView.ViewId, aView);
7fd59977 526
5e27df78 527 OpenGl_CView* aCView = new OpenGl_CView();
2166f0fa
SK
528 aCView->View = aView;
529 aCView->WS = aWS;
5e27df78 530 theCView.ptrView = aCView;
7fd59977 531
2166f0fa
SK
532 return Standard_True;
533}
7fd59977 534
2166f0fa
SK
535void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
536{
537 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
538 if (aCView)
539 {
540 aCView->View->SetMapping(ACView);
529afc1a 541 if (!AWait)
2166f0fa
SK
542 {
543 aCView->WS->Resize(ACView.DefWindow);
7fd59977 544 }
7fd59977 545 }
2166f0fa 546}
7fd59977 547
2166f0fa
SK
548void OpenGl_GraphicDriver::ViewOrientation (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
549{
550 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
551 if (aCView)
552 {
553 aCView->View->SetOrientation(ACView);
529afc1a 554 if (!AWait)
2166f0fa
SK
555 {
556 aCView->WS->Resize(ACView.DefWindow);
7fd59977 557 }
7fd59977 558 }
2166f0fa 559}
7fd59977 560
2166f0fa
SK
561void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView)
562{
563 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
564 if (aCView)
565 aCView->View->SetBackfacing(ACView.Backfacing);
566}
59f45b7c 567
568//=======================================================================
569//function : AddZLayer
bf75be98 570//purpose :
59f45b7c 571//=======================================================================
572
573void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView,
574 const Standard_Integer theLayerId)
575{
576 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
577 if (aCView)
578 aCView->View->AddZLayer (theLayerId);
579}
580
581//=======================================================================
582//function : RemoveZLayer
583//purpose :
584//=======================================================================
585
586void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView,
587 const Standard_Integer theLayerId)
588{
589 const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView;
590 if (aCView)
591 aCView->View->RemoveZLayer (theLayerId);
592}