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