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