Commit | Line | Data |
---|---|---|
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 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 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> | |
eb4320f2 | 22 | #include <OpenGl_Text.hxx> |
7fd59977 | 23 | |
2166f0fa | 24 | /*----------------------------------------------------------------------*/ |
7fd59977 | 25 | |
2166f0fa SK |
26 | void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView) |
27 | { | |
28 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
29 | if (aCView) | |
a272ed94 | 30 | aCView->WS->SetActiveView(aCView->View, ACView.ViewId); |
7fd59977 | 31 | } |
32 | ||
2166f0fa SK |
33 | void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) |
34 | { | |
35 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
36 | if (aCView) | |
37 | aCView->View->SetAntiAliasing(AFlag); | |
7fd59977 | 38 | } |
39 | ||
2166f0fa SK |
40 | void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView) |
41 | { | |
42 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
43 | if (aCView) | |
44 | { | |
45 | aCView->WS->SetBackgroundColor(ACView.DefWindow.Background.r,ACView.DefWindow.Background.g,ACView.DefWindow.Background.b); | |
7fd59977 | 46 | } |
7fd59977 | 47 | } |
48 | ||
2166f0fa | 49 | void OpenGl_GraphicDriver::GradientBackground (const Graphic3d_CView& ACView, |
7fd59977 | 50 | const Quantity_Color& AColor1, |
51 | const Quantity_Color& AColor2, | |
2166f0fa SK |
52 | const Aspect_GradientFillMethod AType) |
53 | { | |
54 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
55 | if (aCView) | |
56 | { | |
57 | aCView->View->SetBackgroundGradient(AColor1,AColor2,AType); | |
7fd59977 | 58 | } |
7fd59977 | 59 | } |
60 | ||
2166f0fa SK |
61 | void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) |
62 | { | |
63 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
64 | if (aCView) | |
65 | { | |
66 | aCView->View->SetClipLimit(ACView); | |
529afc1a | 67 | if (!AWait) |
2166f0fa SK |
68 | { |
69 | aCView->WS->Resize(ACView.DefWindow); | |
2166f0fa | 70 | } |
7fd59977 | 71 | } |
7fd59977 | 72 | } |
73 | ||
2166f0fa SK |
74 | void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView) |
75 | { | |
76 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
77 | if (aCView) | |
78 | { | |
79 | const Handle(OpenGl_View) aDummyView; | |
a272ed94 | 80 | aCView->WS->SetActiveView (aDummyView, -1); |
7fd59977 | 81 | } |
7fd59977 | 82 | } |
83 | ||
2166f0fa SK |
84 | void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) |
85 | { | |
86 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
87 | if (aCView) | |
88 | aCView->View->SetFog(ACView, AFlag); | |
7fd59977 | 89 | } |
90 | ||
529afc1a | 91 | void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& theCView) |
2166f0fa | 92 | { |
529afc1a K |
93 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; |
94 | if (aCView != NULL) | |
95 | aCView->WS->Resize (theCView.DefWindow); | |
2166f0fa | 96 | } |
7fd59977 | 97 | |
ca3c13d1 | 98 | void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView, |
99 | const Aspect_CLayer2d& ACUnderLayer, | |
100 | const Aspect_CLayer2d& ACOverLayer, | |
101 | const Standard_Integer /*x*/, | |
102 | const Standard_Integer /*y*/, | |
103 | const Standard_Integer /*width*/, | |
35e08fe8 | 104 | const Standard_Integer /*height*/) |
2166f0fa | 105 | { |
a89742cf | 106 | if (ACView.RenderParams.Method == Graphic3d_RM_RAYTRACING |
107 | && !myCaps->vboDisable | |
108 | && !myCaps->keepArrayData) | |
e276548b | 109 | { |
110 | if (ACView.WasRedrawnGL) | |
111 | { | |
112 | myDeviceLostFlag = Standard_True; | |
113 | } | |
114 | ||
115 | myCaps->keepArrayData = Standard_True; | |
116 | } | |
117 | ||
2166f0fa SK |
118 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; |
119 | if (aCView) | |
120 | { | |
121 | /*if( width <= 0 || height <= 0 ) | |
122 | aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer); | |
123 | else | |
124 | aCView->WS->RedrawArea(ACView, ACUnderLayer, ACOverLayer, x, y, width, height);*/ | |
125 | // Always do full redraw | |
126 | aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer); | |
7fd59977 | 127 | } |
7fd59977 | 128 | } |
129 | ||
679ecdee | 130 | void OpenGl_GraphicDriver::RedrawImmediate (const Graphic3d_CView& theCView, |
131 | const Aspect_CLayer2d& theCUnderLayer, | |
132 | const Aspect_CLayer2d& theCOverLayer) | |
133 | { | |
134 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
135 | if (aCView != NULL) | |
136 | { | |
137 | aCView->WS->RedrawImmediate (theCView, theCUnderLayer, theCOverLayer); | |
138 | } | |
139 | } | |
140 | ||
141 | void OpenGl_GraphicDriver::Invalidate (const Graphic3d_CView& theCView) | |
142 | { | |
143 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
144 | if (aCView != NULL) | |
145 | { | |
146 | aCView->WS->Invalidate (theCView); | |
147 | } | |
148 | } | |
149 | ||
2166f0fa SK |
150 | Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& ACView, const Standard_Integer theWidth, const Standard_Integer theHeight) |
151 | { | |
152 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
153 | if (aCView) | |
154 | return aCView->WS->FBOCreate(theWidth, theHeight); | |
155 | return (Graphic3d_PtrFrameBuffer)NULL; | |
7fd59977 | 156 | } |
157 | ||
fd4a6963 | 158 | Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, |
159 | const Standard_Integer theHeight) | |
2166f0fa | 160 | { |
7fd59977 | 161 | // activate OpenGL context |
2166f0fa | 162 | if (!Activate()) |
7fd59977 | 163 | return NULL; |
2166f0fa | 164 | |
7fd59977 | 165 | // create the FBO |
fd4a6963 | 166 | const Handle(OpenGl_Context)& aCtx = GetGlContext(); |
7fd59977 | 167 | OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer(); |
fd4a6963 | 168 | if (!aFrameBuffer->Init (aCtx, theWidth, theHeight)) |
7fd59977 | 169 | { |
fd4a6963 | 170 | aFrameBuffer->Release (aCtx.operator->()); |
7fd59977 | 171 | delete aFrameBuffer; |
172 | return NULL; | |
173 | } | |
174 | return (Graphic3d_PtrFrameBuffer )aFrameBuffer; | |
175 | } | |
176 | ||
2166f0fa | 177 | void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr) |
7fd59977 | 178 | { |
179 | if (theFBOPtr == NULL) | |
7fd59977 | 180 | return; |
2166f0fa SK |
181 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; |
182 | if (aCView) | |
183 | { | |
184 | aCView->WS->FBORelease(theFBOPtr); | |
185 | theFBOPtr = NULL; | |
7fd59977 | 186 | } |
2166f0fa SK |
187 | } |
188 | ||
189 | void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr) | |
190 | { | |
7fd59977 | 191 | // activate OpenGL context |
fd4a6963 | 192 | if (!Activate() |
193 | || theFBOPtr == NULL) | |
194 | { | |
7fd59977 | 195 | return; |
fd4a6963 | 196 | } |
2166f0fa | 197 | |
7fd59977 | 198 | // release the object |
2166f0fa | 199 | OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr; |
fd4a6963 | 200 | if (aFrameBuffer != NULL) |
201 | { | |
202 | aFrameBuffer->Release (GetGlContext().operator->()); | |
203 | } | |
7fd59977 | 204 | delete aFrameBuffer; |
7fd59977 | 205 | } |
206 | ||
207 | void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& , | |
208 | const Graphic3d_PtrFrameBuffer theFBOPtr, | |
209 | Standard_Integer& theWidth, Standard_Integer& theHeight, | |
210 | Standard_Integer& theWidthMax, Standard_Integer& theHeightMax) | |
211 | { | |
212 | if (theFBOPtr == NULL) | |
213 | { | |
214 | return; | |
215 | } | |
216 | const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr; | |
217 | theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size | |
218 | theHeight = aFrameBuffer->GetVPSizeY(); | |
219 | theWidthMax = aFrameBuffer->GetSizeX(); // texture size | |
220 | theHeightMax = aFrameBuffer->GetSizeY(); | |
221 | } | |
222 | ||
223 | void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& , | |
224 | Graphic3d_PtrFrameBuffer& theFBOPtr, | |
225 | const Standard_Integer theWidth, const Standard_Integer theHeight) | |
226 | { | |
227 | if (theFBOPtr == NULL) | |
228 | { | |
229 | return; | |
230 | } | |
231 | OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr; | |
232 | aFrameBuffer->ChangeViewport (theWidth, theHeight); | |
233 | } | |
234 | ||
692613e5 | 235 | inline bool getDataFormat (const Image_PixMap& theData, |
236 | GLenum& thePixelFormat, | |
237 | GLenum& theDataType) | |
7fd59977 | 238 | { |
692613e5 | 239 | thePixelFormat = GL_RGB; |
240 | theDataType = GL_UNSIGNED_BYTE; | |
241 | switch (theData.Format()) | |
7fd59977 | 242 | { |
ca3c13d1 | 243 | #if !defined(GL_ES_VERSION_2_0) |
692613e5 | 244 | case Image_PixMap::ImgGray: |
245 | thePixelFormat = GL_DEPTH_COMPONENT; | |
246 | theDataType = GL_UNSIGNED_BYTE; | |
247 | return true; | |
ca3c13d1 | 248 | case Image_PixMap::ImgGrayF: |
249 | thePixelFormat = GL_DEPTH_COMPONENT; | |
250 | theDataType = GL_FLOAT; | |
692613e5 | 251 | return true; |
252 | case Image_PixMap::ImgBGR: | |
253 | thePixelFormat = GL_BGR; | |
254 | theDataType = GL_UNSIGNED_BYTE; | |
255 | return true; | |
692613e5 | 256 | case Image_PixMap::ImgBGRA: |
257 | case Image_PixMap::ImgBGR32: | |
258 | thePixelFormat = GL_BGRA; | |
259 | theDataType = GL_UNSIGNED_BYTE; | |
260 | return true; | |
ca3c13d1 | 261 | case Image_PixMap::ImgBGRF: |
262 | thePixelFormat = GL_BGR; | |
692613e5 | 263 | theDataType = GL_FLOAT; |
264 | return true; | |
ca3c13d1 | 265 | case Image_PixMap::ImgBGRAF: |
266 | thePixelFormat = GL_BGRA; | |
692613e5 | 267 | theDataType = GL_FLOAT; |
268 | return true; | |
076ca35c | 269 | #else |
270 | case Image_PixMap::ImgGray: | |
271 | case Image_PixMap::ImgGrayF: | |
272 | case Image_PixMap::ImgBGR: | |
273 | case Image_PixMap::ImgBGRA: | |
274 | case Image_PixMap::ImgBGR32: | |
275 | case Image_PixMap::ImgBGRF: | |
276 | case Image_PixMap::ImgBGRAF: | |
277 | return false; | |
ca3c13d1 | 278 | #endif |
279 | case Image_PixMap::ImgRGB: | |
280 | thePixelFormat = GL_RGB; | |
281 | theDataType = GL_UNSIGNED_BYTE; | |
692613e5 | 282 | return true; |
ca3c13d1 | 283 | case Image_PixMap::ImgRGBA: |
284 | case Image_PixMap::ImgRGB32: | |
692613e5 | 285 | thePixelFormat = GL_RGBA; |
ca3c13d1 | 286 | theDataType = GL_UNSIGNED_BYTE; |
287 | return true; | |
288 | case Image_PixMap::ImgRGBF: | |
289 | thePixelFormat = GL_RGB; | |
692613e5 | 290 | theDataType = GL_FLOAT; |
291 | return true; | |
ca3c13d1 | 292 | case Image_PixMap::ImgRGBAF: |
293 | thePixelFormat = GL_RGBA; | |
692613e5 | 294 | theDataType = GL_FLOAT; |
295 | return true; | |
076ca35c | 296 | case Image_PixMap::ImgAlpha: |
297 | case Image_PixMap::ImgAlphaF: | |
298 | return false; // GL_ALPHA is no more supported in core context | |
299 | case Image_PixMap::ImgUNKNOWN: | |
692613e5 | 300 | return false; |
7fd59977 | 301 | } |
076ca35c | 302 | return false; |
7fd59977 | 303 | } |
304 | ||
692613e5 | 305 | Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView, |
306 | Image_PixMap& theImage, | |
307 | const Graphic3d_BufferType& theBufferType) | |
7fd59977 | 308 | { |
692613e5 | 309 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; |
310 | return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType); | |
2166f0fa SK |
311 | } |
312 | ||
f978241f | 313 | //! Compute aligned number greater or equal to specified one |
314 | inline Standard_Size getAligned (const Standard_Size theNumber, | |
315 | const Standard_Size theAlignment) | |
316 | { | |
317 | return theNumber + theAlignment - 1 - (theNumber - 1) % theAlignment; | |
318 | } | |
319 | ||
692613e5 | 320 | Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr, |
321 | Image_PixMap& theImage, | |
322 | const Graphic3d_BufferType& theBufferType) | |
7fd59977 | 323 | { |
692613e5 | 324 | GLenum aFormat, aType; |
325 | if (theImage.IsEmpty() | |
326 | || !getDataFormat (theImage, aFormat, aType) | |
692613e5 | 327 | || !Activate()) |
7fd59977 | 328 | { |
329 | return Standard_False; | |
330 | } | |
ca3c13d1 | 331 | #if !defined(GL_ES_VERSION_2_0) |
332 | GLint aReadBufferPrev = GL_BACK; | |
333 | if (theBufferType == Graphic3d_BT_Depth | |
334 | && aFormat != GL_DEPTH_COMPONENT) | |
335 | { | |
336 | return Standard_False; | |
337 | } | |
338 | #endif | |
7fd59977 | 339 | |
7fd59977 | 340 | // bind FBO if used |
692613e5 | 341 | if (theFBOPtr != NULL && theFBOPtr->IsValid()) |
7fd59977 | 342 | { |
692613e5 | 343 | theFBOPtr->BindBuffer (GetGlContext()); |
7fd59977 | 344 | } |
345 | else | |
346 | { | |
ca3c13d1 | 347 | #if !defined(GL_ES_VERSION_2_0) |
7fd59977 | 348 | glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev); |
349 | GLint aDrawBufferPrev = GL_BACK; | |
350 | glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev); | |
351 | glReadBuffer (aDrawBufferPrev); | |
ca3c13d1 | 352 | #endif |
7fd59977 | 353 | } |
354 | ||
74706083 | 355 | // setup alignment |
74706083 | 356 | const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL |
692613e5 | 357 | glPixelStorei (GL_PACK_ALIGNMENT, anAligment); |
f978241f | 358 | bool isBatchCopy = !theImage.IsTopDown(); |
692613e5 | 359 | |
f978241f | 360 | const GLint anExtraBytes = GLint(theImage.RowExtraBytes()); |
361 | GLint aPixelsWidth = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes()); | |
362 | Standard_Size aSizeRowBytesEstim = getAligned (theImage.SizePixelBytes() * aPixelsWidth, anAligment); | |
363 | if (anExtraBytes < anAligment) | |
364 | { | |
365 | aPixelsWidth = 0; | |
366 | } | |
367 | else if (aSizeRowBytesEstim != theImage.SizeRowBytes()) | |
368 | { | |
369 | aPixelsWidth = 0; | |
370 | isBatchCopy = false; | |
371 | } | |
ca3c13d1 | 372 | #if !defined(GL_ES_VERSION_2_0) |
f978241f | 373 | glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth); |
374 | #else | |
375 | if (aPixelsWidth != 0) | |
376 | { | |
377 | isBatchCopy = false; | |
378 | } | |
ca3c13d1 | 379 | #endif |
74706083 | 380 | |
f978241f | 381 | if (!isBatchCopy) |
692613e5 | 382 | { |
383 | // copy row by row | |
384 | for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) | |
385 | { | |
74706083 | 386 | // Image_PixMap rows indexation always starts from the upper corner |
387 | // while order in memory depends on the flag and processed by ChangeRow() method | |
388 | glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow)); | |
692613e5 | 389 | } |
390 | } | |
391 | else | |
7fd59977 | 392 | { |
692613e5 | 393 | glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData()); |
7fd59977 | 394 | } |
7fd59977 | 395 | |
74706083 | 396 | glPixelStorei (GL_PACK_ALIGNMENT, 1); |
ca3c13d1 | 397 | #if !defined(GL_ES_VERSION_2_0) |
74706083 | 398 | glPixelStorei (GL_PACK_ROW_LENGTH, 0); |
ca3c13d1 | 399 | #endif |
7fd59977 | 400 | |
692613e5 | 401 | if (theFBOPtr != NULL && theFBOPtr->IsValid()) |
7fd59977 | 402 | { |
692613e5 | 403 | theFBOPtr->UnbindBuffer (GetGlContext()); |
7fd59977 | 404 | } |
405 | else | |
406 | { | |
ca3c13d1 | 407 | #if !defined(GL_ES_VERSION_2_0) |
7fd59977 | 408 | glReadBuffer (aReadBufferPrev); |
ca3c13d1 | 409 | #endif |
7fd59977 | 410 | } |
411 | return Standard_True; | |
412 | } | |
413 | ||
dd8a4ce9 | 414 | void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView) |
2166f0fa | 415 | { |
a272ed94 | 416 | Handle(OpenGl_Context) aCtx = GetSharedContext(); |
417 | OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; | |
418 | if (aCView == NULL | |
419 | || aCView->View.IsNull() | |
420 | || aCView->WS.IsNull()) | |
fd4a6963 | 421 | { |
a272ed94 | 422 | return; |
fd4a6963 | 423 | } |
a272ed94 | 424 | |
425 | Handle(OpenGl_View) aView = aCView->View; | |
426 | Handle(OpenGl_Workspace) aWindow = aCView->WS; | |
427 | if (!myMapOfWS .Remove (aWindow) | |
428 | || !myMapOfView.Remove (aView)) | |
fd4a6963 | 429 | { |
a272ed94 | 430 | return; |
fd4a6963 | 431 | } |
a272ed94 | 432 | |
433 | if (aWindow->GetGlContext()->MakeCurrent()) | |
fd4a6963 | 434 | { |
a272ed94 | 435 | aCtx = aWindow->GetGlContext(); |
436 | } | |
437 | else | |
438 | { | |
439 | // try to hijack another context if any | |
440 | const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext(); | |
441 | if (!anOtherCtx.IsNull() | |
442 | && anOtherCtx != aWindow->GetGlContext()) | |
443 | { | |
444 | aCtx = anOtherCtx; | |
445 | aCtx->MakeCurrent(); | |
446 | } | |
fd4a6963 | 447 | } |
7fd59977 | 448 | |
a272ed94 | 449 | aView->ReleaseGlResources (aCtx); |
fd4a6963 | 450 | if (myMapOfWS.IsEmpty()) |
dd8a4ce9 | 451 | { |
452 | // The last view removed but some objects still present. | |
453 | // Release GL resources now without object destruction. | |
454 | for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure); | |
455 | aStructIt.More (); aStructIt.Next()) | |
456 | { | |
457 | OpenGl_Structure* aStruct = aStructIt.ChangeValue(); | |
fd4a6963 | 458 | aStruct->ReleaseGlResources (aCtx); |
dd8a4ce9 | 459 | } |
10b9c7df | 460 | myTempText->Release (aCtx.operator->()); |
fd4a6963 | 461 | myDeviceLostFlag = !myMapOfStructure.IsEmpty(); |
dd8a4ce9 | 462 | } |
463 | ||
2166f0fa | 464 | delete aCView; |
dd8a4ce9 | 465 | ((Graphic3d_CView *)&theCView)->ptrView = NULL; |
fd4a6963 | 466 | |
467 | aCtx.Nullify(); | |
468 | aView.Nullify(); | |
469 | aWindow.Nullify(); | |
7fd59977 | 470 | } |
471 | ||
2166f0fa SK |
472 | void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView) |
473 | { | |
474 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
475 | if (aCView) | |
476 | aCView->View->SetLights(ACView.Context); | |
7fd59977 | 477 | } |
478 | ||
4269bd1b | 479 | void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView) |
2166f0fa | 480 | { |
4269bd1b | 481 | const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; |
2166f0fa | 482 | if (aCView) |
4269bd1b | 483 | { |
484 | aCView->View->SetClipPlanes (theCView.Context.ClipPlanes); | |
485 | } | |
486 | } | |
487 | ||
b5ac8292 | 488 | //======================================================================= |
489 | //function : SetCamera | |
490 | //purpose : | |
491 | //======================================================================= | |
492 | void OpenGl_GraphicDriver::SetCamera (const Graphic3d_CView& theCView) | |
493 | { | |
494 | const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; | |
495 | if (aCView) | |
496 | { | |
497 | aCView->View->SetCamera (theCView.Context.Camera); | |
498 | } | |
499 | } | |
500 | ||
2166f0fa SK |
501 | void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView) |
502 | { | |
503 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
504 | if (aCView) | |
505 | { | |
506 | aCView->View->SetVisualisation(ACView.Context); | |
7fd59977 | 507 | } |
7fd59977 | 508 | } |
509 | ||
b7cd4ba7 | 510 | // ======================================================================= |
511 | // function : InvalidateBVHData | |
512 | // purpose : | |
513 | // ======================================================================= | |
514 | void OpenGl_GraphicDriver::InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId) | |
515 | { | |
516 | OpenGl_CView *aCView = (OpenGl_CView *)theCView.ptrView; | |
517 | if(aCView) | |
518 | { | |
519 | aCView->View->InvalidateBVHData (theLayerId); | |
520 | } | |
521 | } | |
522 | ||
5e27df78 | 523 | Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView) |
2166f0fa | 524 | { |
05e2200b | 525 | Handle(OpenGl_Context) aShareCtx = GetSharedContext(); |
a272ed94 | 526 | OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; |
527 | if (aCView != NULL | |
528 | && myMapOfView.Contains (aCView->View)) | |
2166f0fa | 529 | { |
a272ed94 | 530 | Handle(OpenGl_Workspace) anOldWS = aCView->WS; |
531 | Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); | |
05e2200b | 532 | aCView->WS = aWS; |
a272ed94 | 533 | aWS->SetActiveView (aCView->View, theCView.ViewId); |
05e2200b | 534 | |
a272ed94 | 535 | myMapOfWS.Remove (anOldWS); |
536 | myMapOfWS.Add (aWS); | |
05e2200b | 537 | return Standard_True; |
7fd59977 | 538 | } |
539 | ||
25b97fac | 540 | Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); |
392ac980 | 541 | Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context, &myStateCounter); |
a272ed94 | 542 | myMapOfWS .Add (aWS); |
543 | myMapOfView.Add (aView); | |
7fd59977 | 544 | |
a272ed94 | 545 | aCView = new OpenGl_CView(); |
2166f0fa | 546 | aCView->View = aView; |
fd4a6963 | 547 | aCView->WS = aWS; |
5e27df78 | 548 | theCView.ptrView = aCView; |
a272ed94 | 549 | aWS->SetActiveView (aCView->View, theCView.ViewId); |
7fd59977 | 550 | |
2166f0fa SK |
551 | return Standard_True; |
552 | } | |
7fd59977 | 553 | |
2166f0fa SK |
554 | void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView) |
555 | { | |
556 | const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; | |
557 | if (aCView) | |
558 | aCView->View->SetBackfacing(ACView.Backfacing); | |
559 | } | |
59f45b7c | 560 | |
561 | //======================================================================= | |
562 | //function : AddZLayer | |
bf75be98 | 563 | //purpose : |
59f45b7c | 564 | //======================================================================= |
565 | ||
a1954302 | 566 | void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView, |
567 | const Graphic3d_ZLayerId theLayerId) | |
59f45b7c | 568 | { |
569 | const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; | |
570 | if (aCView) | |
571 | aCView->View->AddZLayer (theLayerId); | |
572 | } | |
573 | ||
574 | //======================================================================= | |
575 | //function : RemoveZLayer | |
576 | //purpose : | |
577 | //======================================================================= | |
a1954302 | 578 | void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView, |
579 | const Graphic3d_ZLayerId theLayerId) | |
59f45b7c | 580 | { |
581 | const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView; | |
582 | if (aCView) | |
583 | aCView->View->RemoveZLayer (theLayerId); | |
584 | } | |
c5751993 | 585 | |
586 | //======================================================================= | |
587 | //function : SetZLayerSettings | |
588 | //purpose : | |
589 | //======================================================================= | |
a1954302 | 590 | Standard_EXPORT void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_CView& theCView, |
591 | const Graphic3d_ZLayerId theLayerId, | |
c5751993 | 592 | const Graphic3d_ZLayerSettings& theSettings) |
593 | { | |
594 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
595 | if (aCView) | |
596 | aCView->View->SetZLayerSettings (theLayerId, theSettings); | |
597 | } |