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