0023813: TKOpenGl, OpenGl_Texture ignores stride image property
[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 205{
e276548b 206 if (!myCaps->vboDisable && ACView.IsRaytracing)
207 {
208 if (ACView.WasRedrawnGL)
209 {
210 myDeviceLostFlag = Standard_True;
211 }
212
213 myCaps->keepArrayData = Standard_True;
214 }
215
2166f0fa
SK
216 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
217 if (aCView)
218 {
219 /*if( width <= 0 || height <= 0 )
220 aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
221 else
222 aCView->WS->RedrawArea(ACView, ACUnderLayer, ACOverLayer, x, y, width, height);*/
223 // Always do full redraw
224 aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer);
7fd59977 225 }
7fd59977 226}
227
2166f0fa
SK
228Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& ACView, const Standard_Integer theWidth, const Standard_Integer theHeight)
229{
230 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
231 if (aCView)
232 return aCView->WS->FBOCreate(theWidth, theHeight);
233 return (Graphic3d_PtrFrameBuffer)NULL;
7fd59977 234}
235
fd4a6963 236Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth,
237 const Standard_Integer theHeight)
2166f0fa 238{
7fd59977 239 // activate OpenGL context
2166f0fa 240 if (!Activate())
7fd59977 241 return NULL;
2166f0fa 242
7fd59977 243 // create the FBO
fd4a6963 244 const Handle(OpenGl_Context)& aCtx = GetGlContext();
7fd59977 245 OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer();
fd4a6963 246 if (!aFrameBuffer->Init (aCtx, theWidth, theHeight))
7fd59977 247 {
fd4a6963 248 aFrameBuffer->Release (aCtx.operator->());
7fd59977 249 delete aFrameBuffer;
250 return NULL;
251 }
252 return (Graphic3d_PtrFrameBuffer )aFrameBuffer;
253}
254
2166f0fa 255void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr)
7fd59977 256{
257 if (theFBOPtr == NULL)
7fd59977 258 return;
2166f0fa
SK
259 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
260 if (aCView)
261 {
262 aCView->WS->FBORelease(theFBOPtr);
263 theFBOPtr = NULL;
7fd59977 264 }
2166f0fa
SK
265}
266
267void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr)
268{
7fd59977 269 // activate OpenGL context
fd4a6963 270 if (!Activate()
271 || theFBOPtr == NULL)
272 {
7fd59977 273 return;
fd4a6963 274 }
2166f0fa 275
7fd59977 276 // release the object
2166f0fa 277 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr;
fd4a6963 278 if (aFrameBuffer != NULL)
279 {
280 aFrameBuffer->Release (GetGlContext().operator->());
281 }
7fd59977 282 delete aFrameBuffer;
7fd59977 283}
284
285void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& ,
286 const Graphic3d_PtrFrameBuffer theFBOPtr,
287 Standard_Integer& theWidth, Standard_Integer& theHeight,
288 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
289{
290 if (theFBOPtr == NULL)
291 {
292 return;
293 }
294 const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr;
295 theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size
296 theHeight = aFrameBuffer->GetVPSizeY();
297 theWidthMax = aFrameBuffer->GetSizeX(); // texture size
298 theHeightMax = aFrameBuffer->GetSizeY();
299}
300
301void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& ,
302 Graphic3d_PtrFrameBuffer& theFBOPtr,
303 const Standard_Integer theWidth, const Standard_Integer theHeight)
304{
305 if (theFBOPtr == NULL)
306 {
307 return;
308 }
309 OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr;
310 aFrameBuffer->ChangeViewport (theWidth, theHeight);
311}
312
692613e5 313inline bool getDataFormat (const Image_PixMap& theData,
314 GLenum& thePixelFormat,
315 GLenum& theDataType)
7fd59977 316{
692613e5 317 thePixelFormat = GL_RGB;
318 theDataType = GL_UNSIGNED_BYTE;
319 switch (theData.Format())
7fd59977 320 {
692613e5 321 case Image_PixMap::ImgGray:
322 thePixelFormat = GL_DEPTH_COMPONENT;
323 theDataType = GL_UNSIGNED_BYTE;
324 return true;
325 case Image_PixMap::ImgRGB:
326 thePixelFormat = GL_RGB;
327 theDataType = GL_UNSIGNED_BYTE;
328 return true;
329 case Image_PixMap::ImgBGR:
330 thePixelFormat = GL_BGR;
331 theDataType = GL_UNSIGNED_BYTE;
332 return true;
333 case Image_PixMap::ImgRGBA:
334 case Image_PixMap::ImgRGB32:
335 thePixelFormat = GL_RGBA;
336 theDataType = GL_UNSIGNED_BYTE;
337 return true;
338 case Image_PixMap::ImgBGRA:
339 case Image_PixMap::ImgBGR32:
340 thePixelFormat = GL_BGRA;
341 theDataType = GL_UNSIGNED_BYTE;
342 return true;
343 case Image_PixMap::ImgGrayF:
344 thePixelFormat = GL_DEPTH_COMPONENT;
345 theDataType = GL_FLOAT;
346 return true;
347 case Image_PixMap::ImgRGBF:
348 thePixelFormat = GL_RGB;
349 theDataType = GL_FLOAT;
350 return true;
351 case Image_PixMap::ImgBGRF:
352 thePixelFormat = GL_BGR;
353 theDataType = GL_FLOAT;
354 return true;
355 case Image_PixMap::ImgRGBAF:
356 thePixelFormat = GL_RGBA;
357 theDataType = GL_FLOAT;
358 return true;
359 case Image_PixMap::ImgBGRAF:
360 thePixelFormat = GL_BGRA;
361 theDataType = GL_FLOAT;
362 return true;
363 default:
364 return false;
7fd59977 365 }
366}
367
692613e5 368Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView,
369 Image_PixMap& theImage,
370 const Graphic3d_BufferType& theBufferType)
7fd59977 371{
692613e5 372 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
373 return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType);
2166f0fa
SK
374}
375
692613e5 376Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr,
377 Image_PixMap& theImage,
378 const Graphic3d_BufferType& theBufferType)
7fd59977 379{
692613e5 380 GLenum aFormat, aType;
381 if (theImage.IsEmpty()
382 || !getDataFormat (theImage, aFormat, aType)
383 || ((theBufferType == Graphic3d_BT_Depth) && (aFormat != GL_DEPTH_COMPONENT))
384 || !Activate())
7fd59977 385 {
386 return Standard_False;
387 }
388
7fd59977 389 // bind FBO if used
7fd59977 390 GLint aReadBufferPrev = GL_BACK;
692613e5 391 if (theFBOPtr != NULL && theFBOPtr->IsValid())
7fd59977 392 {
692613e5 393 theFBOPtr->BindBuffer (GetGlContext());
7fd59977 394 }
395 else
396 {
397 glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev);
398 GLint aDrawBufferPrev = GL_BACK;
399 glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev);
400 glReadBuffer (aDrawBufferPrev);
401 }
402
74706083 403 // setup alignment
404 const GLint anExtraBytes = (GLint )theImage.RowExtraBytes();
405 const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL
692613e5 406 glPixelStorei (GL_PACK_ALIGNMENT, anAligment);
407
74706083 408 const GLint aPixelsWidth = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes());
409 glPixelStorei (GL_PACK_ROW_LENGTH, (anExtraBytes >= anAligment) ? aPixelsWidth : 0);
410
411 if (theImage.IsTopDown())
692613e5 412 {
413 // copy row by row
414 for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
415 {
74706083 416 // Image_PixMap rows indexation always starts from the upper corner
417 // while order in memory depends on the flag and processed by ChangeRow() method
418 glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow));
692613e5 419 }
420 }
421 else
7fd59977 422 {
692613e5 423 glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData());
7fd59977 424 }
7fd59977 425
74706083 426 glPixelStorei (GL_PACK_ALIGNMENT, 1);
427 glPixelStorei (GL_PACK_ROW_LENGTH, 0);
7fd59977 428
692613e5 429 if (theFBOPtr != NULL && theFBOPtr->IsValid())
7fd59977 430 {
692613e5 431 theFBOPtr->UnbindBuffer (GetGlContext());
7fd59977 432 }
433 else
434 {
435 glReadBuffer (aReadBufferPrev);
436 }
437 return Standard_True;
438}
439
dd8a4ce9 440void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView)
2166f0fa 441{
fd4a6963 442 Handle(OpenGl_Context) aCtx = GetSharedContext();
443 Handle(OpenGl_View) aView;
444 Handle(OpenGl_Workspace) aWindow;
445 if (myMapOfWS.Find (theCView.WsId, aWindow))
446 {
dd8a4ce9 447 myMapOfWS.UnBind (theCView.WsId);
fd4a6963 448 }
449 if (!aWindow.IsNull())
450 {
451 if (aWindow->GetGlContext()->MakeCurrent())
452 {
453 aCtx = aWindow->GetGlContext();
454 }
455 else
456 {
457 // try to hijack another context if any
458 const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext();
459 if (!anOtherCtx.IsNull()
460 && anOtherCtx != aWindow->GetGlContext())
461 {
462 aCtx = anOtherCtx;
463 aCtx->MakeCurrent();
464 }
465 }
466 }
467 if (myMapOfView.Find (theCView.ViewId, aView))
468 {
469 aView->ReleaseGlResources (aCtx);
470 myMapOfView.UnBind (theCView.ViewId);
471 }
7fd59977 472
fd4a6963 473 if (myMapOfWS.IsEmpty())
dd8a4ce9 474 {
475 // The last view removed but some objects still present.
476 // Release GL resources now without object destruction.
477 for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
478 aStructIt.More (); aStructIt.Next())
479 {
480 OpenGl_Structure* aStruct = aStructIt.ChangeValue();
fd4a6963 481 aStruct->ReleaseGlResources (aCtx);
dd8a4ce9 482 }
fd4a6963 483 myTempText->Release (aCtx);
484 myGlDisplay->ReleaseAttributes (aCtx.operator->());
485 myDeviceLostFlag = !myMapOfStructure.IsEmpty();
dd8a4ce9 486 }
487
bf75be98 488 OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView;
2166f0fa 489 delete aCView;
dd8a4ce9 490 ((Graphic3d_CView *)&theCView)->ptrView = NULL;
fd4a6963 491
492 aCtx.Nullify();
493 aView.Nullify();
494 aWindow.Nullify();
7fd59977 495}
496
2166f0fa
SK
497void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView)
498{
499 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
500 if (aCView)
501 aCView->View->SetLights(ACView.Context);
7fd59977 502}
503
4269bd1b 504void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView)
2166f0fa 505{
4269bd1b 506 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
2166f0fa 507 if (aCView)
4269bd1b 508 {
509 aCView->View->SetClipPlanes (theCView.Context.ClipPlanes);
510 }
511}
512
513void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CStructure& theCStructure)
514{
515 OpenGl_Structure* aStructure = (OpenGl_Structure *)theCStructure.ptrStructure;
516 if (aStructure)
517 {
518 aStructure->SetClipPlanes (theCStructure.ClipPlanes);
519 }
7fd59977 520}
521
2166f0fa
SK
522void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView)
523{
524 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
525 if (aCView)
526 {
527 aCView->View->SetVisualisation(ACView.Context);
528 aCView->WS->UseZBuffer() = ( ACView.Context.Visualization == 0? (ACView.Context.ZBufferActivity == 1) : (ACView.Context.ZBufferActivity != 0) );
7fd59977 529 }
7fd59977 530}
531
2166f0fa
SK
532void OpenGl_GraphicDriver::TransformStructure (const Graphic3d_CStructure& ACStructure)
533{
534 OpenGl_Structure *astructure = (OpenGl_Structure *)ACStructure.ptrStructure;
535 if (astructure)
536 astructure->SetTransformation(&(ACStructure.Transformation[0][0]));
7fd59977 537}
538
2166f0fa
SK
539void OpenGl_GraphicDriver::Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag)
540{
541 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
542 if (aCView)
543 aCView->WS->UseTransparency(AFlag);
544}
7fd59977 545
2166f0fa
SK
546void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer)
547{
548 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
549 if (aCView)
550 aCView->WS->Update(ACView,ACUnderLayer,ACOverLayer);
551}
7fd59977 552
5e27df78 553Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView)
2166f0fa 554{
fd4a6963 555 if (myGlDisplay.IsNull()
556 || myMapOfView.IsBound (theCView.ViewId)
557 || myMapOfWS .IsBound (theCView.WsId))
2166f0fa 558 {
fd4a6963 559 return Standard_False;
7fd59977 560 }
561
fd4a6963 562 Handle(OpenGl_Context) aShareCtx = GetSharedContext();
563 Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (myGlDisplay, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx);
392ac980 564 Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context, &myStateCounter);
fd4a6963 565 myMapOfWS .Bind (theCView.WsId, aWS);
5e27df78 566 myMapOfView.Bind (theCView.ViewId, aView);
7fd59977 567
5e27df78 568 OpenGl_CView* aCView = new OpenGl_CView();
2166f0fa 569 aCView->View = aView;
fd4a6963 570 aCView->WS = aWS;
5e27df78 571 theCView.ptrView = aCView;
7fd59977 572
2166f0fa
SK
573 return Standard_True;
574}
7fd59977 575
2166f0fa
SK
576void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
577{
578 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
579 if (aCView)
580 {
fd4a6963 581 aCView->View->SetMapping (myGlDisplay, ACView);
529afc1a 582 if (!AWait)
2166f0fa
SK
583 {
584 aCView->WS->Resize(ACView.DefWindow);
7fd59977 585 }
7fd59977 586 }
2166f0fa 587}
7fd59977 588
2166f0fa
SK
589void OpenGl_GraphicDriver::ViewOrientation (const Graphic3d_CView& ACView, const Standard_Boolean AWait)
590{
591 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
592 if (aCView)
593 {
594 aCView->View->SetOrientation(ACView);
529afc1a 595 if (!AWait)
2166f0fa
SK
596 {
597 aCView->WS->Resize(ACView.DefWindow);
7fd59977 598 }
7fd59977 599 }
2166f0fa 600}
7fd59977 601
2166f0fa
SK
602void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView)
603{
604 const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView;
605 if (aCView)
606 aCView->View->SetBackfacing(ACView.Backfacing);
607}
59f45b7c 608
609//=======================================================================
610//function : AddZLayer
bf75be98 611//purpose :
59f45b7c 612//=======================================================================
613
614void OpenGl_GraphicDriver::AddZLayer (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->AddZLayer (theLayerId);
620}
621
622//=======================================================================
623//function : RemoveZLayer
624//purpose :
625//=======================================================================
626
627void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView,
628 const Standard_Integer theLayerId)
629{
630 const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView;
631 if (aCView)
632 aCView->View->RemoveZLayer (theLayerId);
633}