Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-10-20 |
2 | // Created by: Sergey ZERCHANINOV | |
1981cb22 | 3 | // Copyright (c) 2011-2013 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. | |
b311480e | 15 | |
2166f0fa | 16 | #include <OpenGl_GraphicDriver.hxx> |
f0430952 | 17 | #include <OpenGl_Context.hxx> |
938d4544 | 18 | #include <OpenGl_Flipper.hxx> |
a174a3c5 | 19 | #include <OpenGl_GraduatedTrihedron.hxx> |
20 | #include <OpenGl_Group.hxx> | |
1981cb22 | 21 | #include <OpenGl_CView.hxx> |
2166f0fa | 22 | #include <OpenGl_View.hxx> |
a6eb515f | 23 | #include <OpenGl_StencilTest.hxx> |
a174a3c5 | 24 | #include <OpenGl_Text.hxx> |
25 | #include <OpenGl_Trihedron.hxx> | |
2166f0fa | 26 | #include <OpenGl_Workspace.hxx> |
7fd59977 | 27 | |
25b97fac | 28 | #include <Aspect_GraphicDeviceDefinitionError.hxx> |
29 | #include <Message_Messenger.hxx> | |
73192b37 | 30 | #include <OSD_Environment.hxx> |
a174a3c5 | 31 | #include <Standard_NotImplemented.hxx> |
32 | ||
25b97fac | 33 | #if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
73192b37 | 34 | #include <X11/Xlib.h> // XOpenDisplay() |
35 | #endif | |
36 | ||
25b97fac | 37 | #if defined(HAVE_EGL) || defined(__ANDROID__) |
38 | #include <EGL/egl.h> | |
39 | #endif | |
40 | ||
7fd59977 | 41 | |
2166f0fa SK |
42 | namespace |
43 | { | |
5e27df78 | 44 | static const Handle(OpenGl_Context) TheNullGlCtx; |
7fd59977 | 45 | } |
46 | ||
65993a95 | 47 | // ======================================================================= |
48 | // function : OpenGl_GraphicDriver | |
49 | // purpose : | |
50 | // ======================================================================= | |
25b97fac | 51 | OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp, |
05e2200b | 52 | const Standard_Boolean theToInitialize) |
fe9fc669 | 53 | : Graphic3d_GraphicDriver (theDisp), |
05e2200b | 54 | myIsOwnContext (Standard_False), |
25b97fac | 55 | #if defined(HAVE_EGL) || defined(__ANDROID__) |
56 | myEglDisplay ((Aspect_Display )EGL_NO_DISPLAY), | |
57 | myEglContext ((Aspect_RenderingContext )EGL_NO_CONTEXT), | |
58 | myEglConfig (NULL), | |
59 | #endif | |
65993a95 | 60 | myCaps (new OpenGl_Caps()), |
61 | myMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator()), | |
62 | myMapOfWS (1, NCollection_BaseAllocator::CommonBaseAllocator()), | |
63 | myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator()), | |
64 | myUserDrawCallback (NULL), | |
65 | myTempText (new OpenGl_Text()) | |
66 | { | |
25b97fac | 67 | #if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
73192b37 | 68 | if (myDisplayConnection.IsNull()) |
69 | { | |
73192b37 | 70 | //Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: cannot connect to X server!"); |
fe9fc669 | 71 | return; |
73192b37 | 72 | } |
73 | ||
73192b37 | 74 | Display* aDisplay = myDisplayConnection->GetDisplay(); |
75 | Bool toSync = ::getenv ("CSF_GraphicSync") != NULL | |
76 | || ::getenv ("CALL_SYNCHRO_X") != NULL; | |
77 | XSynchronize (aDisplay, toSync); | |
78 | ||
25b97fac | 79 | #if !defined(HAVE_EGL) |
73192b37 | 80 | // does the server know about OpenGL & GLX? |
81 | int aDummy; | |
82 | if (!XQueryExtension (aDisplay, "GLX", &aDummy, &aDummy, &aDummy)) | |
83 | { | |
05e2200b | 84 | ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, this system doesn't appear to support OpenGL!", Message_Warning); |
73192b37 | 85 | } |
86 | #endif | |
25b97fac | 87 | #endif |
05e2200b | 88 | if (theToInitialize |
89 | && !InitContext()) | |
90 | { | |
91 | Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: default context can not be initialized!"); | |
92 | } | |
93 | } | |
25b97fac | 94 | |
05e2200b | 95 | // ======================================================================= |
96 | // function : ~OpenGl_GraphicDriver | |
97 | // purpose : | |
98 | // ======================================================================= | |
99 | OpenGl_GraphicDriver::~OpenGl_GraphicDriver() | |
100 | { | |
101 | ReleaseContext(); | |
102 | } | |
103 | ||
104 | // ======================================================================= | |
105 | // function : ReleaseContext | |
106 | // purpose : | |
107 | // ======================================================================= | |
108 | void OpenGl_GraphicDriver::ReleaseContext() | |
109 | { | |
110 | Handle(OpenGl_Context) aCtxShared; | |
a272ed94 | 111 | for (NCollection_Map<Handle(OpenGl_Workspace)>::Iterator aWindowIter (myMapOfWS); |
05e2200b | 112 | aWindowIter.More(); aWindowIter.Next()) |
25b97fac | 113 | { |
05e2200b | 114 | const Handle(OpenGl_Workspace)& aWindow = aWindowIter.ChangeValue(); |
115 | const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext(); | |
116 | if (aCtx->MakeCurrent() | |
117 | && aCtxShared.IsNull()) | |
25b97fac | 118 | { |
05e2200b | 119 | aCtxShared = aCtx; |
25b97fac | 120 | } |
05e2200b | 121 | } |
122 | ||
123 | if (!aCtxShared.IsNull()) | |
124 | { | |
125 | aCtxShared->MakeCurrent(); | |
126 | } | |
a272ed94 | 127 | for (NCollection_Map<Handle(OpenGl_View)>::Iterator aViewIter (myMapOfView); |
05e2200b | 128 | aViewIter.More(); aViewIter.Next()) |
129 | { | |
130 | const Handle(OpenGl_View)& aView = aViewIter.ChangeValue(); | |
131 | aView->ReleaseGlResources (aCtxShared); | |
132 | } | |
133 | ||
134 | for (NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure); | |
135 | aStructIt.More (); aStructIt.Next()) | |
136 | { | |
137 | OpenGl_Structure* aStruct = aStructIt.ChangeValue(); | |
138 | aStruct->ReleaseGlResources (aCtxShared); | |
139 | } | |
140 | myTempText->Release (aCtxShared.operator->()); | |
141 | myDeviceLostFlag = myDeviceLostFlag || !myMapOfStructure.IsEmpty(); | |
142 | ||
a272ed94 | 143 | for (NCollection_Map<Handle(OpenGl_Workspace)>::Iterator aWindowIter (myMapOfWS); |
05e2200b | 144 | aWindowIter.More(); aWindowIter.Next()) |
145 | { | |
146 | const Handle(OpenGl_Workspace)& aWindow = aWindowIter.ChangeValue(); | |
147 | const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext(); | |
148 | aCtx->forcedRelease(); | |
149 | } | |
25b97fac | 150 | |
05e2200b | 151 | #if defined(HAVE_EGL) || defined(__ANDROID__) |
152 | if (myIsOwnContext) | |
153 | { | |
154 | if (myEglContext != (Aspect_RenderingContext )EGL_NO_CONTEXT) | |
25b97fac | 155 | { |
05e2200b | 156 | if (eglMakeCurrent ((EGLDisplay )myEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) != EGL_TRUE) |
157 | { | |
158 | ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, FAILED to release OpenGL context!", Message_Warning); | |
159 | } | |
160 | eglDestroyContext ((EGLDisplay )myEglDisplay, (EGLContext )myEglContext); | |
161 | } | |
25b97fac | 162 | |
05e2200b | 163 | if (myEglDisplay != (Aspect_Display )EGL_NO_DISPLAY) |
25b97fac | 164 | { |
05e2200b | 165 | if (eglTerminate ((EGLDisplay )myEglDisplay) != EGL_TRUE) |
166 | { | |
167 | ::Message::DefaultMessenger()->Send ("OpenGl_GraphicDriver, EGL, eglTerminate FAILED!", Message_Warning); | |
168 | } | |
25b97fac | 169 | } |
25b97fac | 170 | } |
171 | ||
05e2200b | 172 | myEglDisplay = (Aspect_Display )EGL_NO_DISPLAY; |
173 | myEglContext = (Aspect_RenderingContext )EGL_NO_CONTEXT; | |
174 | myEglConfig = NULL; | |
175 | #endif | |
176 | myIsOwnContext = Standard_False; | |
177 | } | |
178 | ||
179 | // ======================================================================= | |
180 | // function : InitContext | |
181 | // purpose : | |
182 | // ======================================================================= | |
183 | Standard_Boolean OpenGl_GraphicDriver::InitContext() | |
184 | { | |
185 | ReleaseContext(); | |
186 | #if defined(HAVE_EGL) || defined(__ANDROID__) | |
187 | ||
25b97fac | 188 | #if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) |
05e2200b | 189 | if (myDisplayConnection.IsNull()) |
190 | { | |
191 | return Standard_False; | |
192 | } | |
193 | Display* aDisplay = myDisplayConnection->GetDisplay(); | |
25b97fac | 194 | myEglDisplay = (Aspect_Display )eglGetDisplay (aDisplay); |
195 | #else | |
196 | myEglDisplay = (Aspect_Display )eglGetDisplay (EGL_DEFAULT_DISPLAY); | |
197 | #endif | |
198 | if ((EGLDisplay )myEglDisplay == EGL_NO_DISPLAY) | |
199 | { | |
05e2200b | 200 | ::Message::DefaultMessenger()->Send ("Error: no EGL display!", Message_Fail); |
201 | return Standard_False; | |
25b97fac | 202 | } |
203 | ||
204 | EGLint aVerMajor = 0; EGLint aVerMinor = 0; | |
205 | if (eglInitialize ((EGLDisplay )myEglDisplay, &aVerMajor, &aVerMinor) != EGL_TRUE) | |
206 | { | |
05e2200b | 207 | ::Message::DefaultMessenger()->Send ("Error: EGL display is unavailable!", Message_Fail); |
208 | return Standard_False; | |
25b97fac | 209 | } |
210 | ||
05e2200b | 211 | EGLint aConfigAttribs[] = |
25b97fac | 212 | { |
213 | EGL_RED_SIZE, 8, | |
214 | EGL_GREEN_SIZE, 8, | |
215 | EGL_BLUE_SIZE, 8, | |
216 | EGL_ALPHA_SIZE, 0, | |
217 | EGL_DEPTH_SIZE, 24, | |
218 | EGL_STENCIL_SIZE, 8, | |
219 | #if defined(GL_ES_VERSION_2_0) | |
220 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
221 | #else | |
222 | EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, | |
223 | #endif | |
224 | EGL_NONE | |
225 | }; | |
226 | ||
227 | EGLint aNbConfigs = 0; | |
05e2200b | 228 | if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE |
229 | || myEglConfig == NULL) | |
25b97fac | 230 | { |
05e2200b | 231 | eglGetError(); |
232 | aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer | |
233 | if (eglChooseConfig ((EGLDisplay )myEglDisplay, aConfigAttribs, &myEglConfig, 1, &aNbConfigs) != EGL_TRUE | |
234 | || myEglConfig == NULL) | |
235 | { | |
236 | ::Message::DefaultMessenger()->Send ("Error: EGL does not provide compatible configurations!", Message_Fail); | |
237 | return Standard_False; | |
238 | } | |
25b97fac | 239 | } |
25b97fac | 240 | |
241 | #if defined(GL_ES_VERSION_2_0) | |
242 | EGLint anEglCtxAttribs[] = | |
243 | { | |
244 | EGL_CONTEXT_CLIENT_VERSION, 2, | |
245 | EGL_NONE | |
246 | }; | |
05e2200b | 247 | if (eglBindAPI (EGL_OPENGL_ES_API) != EGL_TRUE) |
248 | { | |
249 | ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL ES client!", Message_Fail); | |
250 | return Standard_False; | |
251 | } | |
25b97fac | 252 | #else |
253 | EGLint* anEglCtxAttribs = NULL; | |
05e2200b | 254 | if (eglBindAPI (EGL_OPENGL_API) != EGL_TRUE) |
255 | { | |
256 | ::Message::DefaultMessenger()->Send ("Error: EGL does not provide OpenGL client!", Message_Fail); | |
257 | return Standard_False; | |
258 | } | |
25b97fac | 259 | #endif |
260 | ||
261 | myEglContext = (Aspect_RenderingContext )eglCreateContext ((EGLDisplay )myEglDisplay, myEglConfig, EGL_NO_CONTEXT, anEglCtxAttribs); | |
262 | if ((EGLContext )myEglContext == EGL_NO_CONTEXT) | |
263 | { | |
05e2200b | 264 | ::Message::DefaultMessenger()->Send ("Error: EGL is unable to create OpenGL context!", Message_Fail); |
265 | return Standard_False; | |
25b97fac | 266 | } |
267 | if (eglMakeCurrent ((EGLDisplay )myEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, (EGLContext )myEglContext) != EGL_TRUE) | |
268 | { | |
05e2200b | 269 | ::Message::DefaultMessenger()->Send ("Error: EGL is unable bind OpenGL context!", Message_Fail); |
270 | return Standard_False; | |
25b97fac | 271 | } |
25b97fac | 272 | #endif |
05e2200b | 273 | myIsOwnContext = Standard_True; |
274 | return Standard_True; | |
73192b37 | 275 | } |
276 | ||
05e2200b | 277 | #if defined(HAVE_EGL) || defined(__ANDROID__) |
278 | // ======================================================================= | |
279 | // function : InitEglContext | |
280 | // purpose : | |
281 | // ======================================================================= | |
282 | Standard_Boolean OpenGl_GraphicDriver::InitEglContext (Aspect_Display theEglDisplay, | |
283 | Aspect_RenderingContext theEglContext, | |
284 | void* theEglConfig) | |
285 | { | |
286 | ReleaseContext(); | |
287 | #if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) | |
288 | if (myDisplayConnection.IsNull()) | |
289 | { | |
290 | return Standard_False; | |
291 | } | |
292 | #endif | |
293 | ||
294 | if ((EGLDisplay )theEglDisplay == EGL_NO_DISPLAY | |
295 | || (EGLContext )theEglContext == EGL_NO_CONTEXT | |
296 | || theEglConfig == NULL) | |
297 | { | |
298 | return Standard_False; | |
299 | } | |
300 | myEglDisplay = theEglDisplay; | |
301 | myEglContext = theEglContext; | |
302 | myEglConfig = theEglConfig; | |
303 | return Standard_True; | |
304 | } | |
305 | #endif | |
306 | ||
73192b37 | 307 | // ======================================================================= |
308 | // function : InquireLightLimit | |
309 | // purpose : | |
310 | // ======================================================================= | |
311 | Standard_Integer OpenGl_GraphicDriver::InquireLightLimit() | |
312 | { | |
313 | return OpenGLMaxLights; | |
314 | } | |
315 | ||
316 | // ======================================================================= | |
317 | // function : InquireViewLimit | |
318 | // purpose : | |
319 | // ======================================================================= | |
320 | Standard_Integer OpenGl_GraphicDriver::InquireViewLimit() | |
321 | { | |
322 | return 10000; | |
323 | } | |
324 | ||
325 | // ======================================================================= | |
326 | // function : InquirePlaneLimit | |
327 | // purpose : | |
328 | // ======================================================================= | |
329 | Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit() | |
330 | { | |
331 | // NOTE the 2 first planes are reserved for ZClipping | |
332 | const Handle(OpenGl_Context)& aCtx = GetSharedContext(); | |
333 | return aCtx.IsNull() ? 0 : Max (aCtx->MaxClipPlanes() - 2, 0); | |
334 | } | |
335 | ||
f0430952 | 336 | // ======================================================================= |
5e27df78 | 337 | // function : UserDrawCallback |
f0430952 | 338 | // purpose : |
339 | // ======================================================================= | |
5e27df78 | 340 | OpenGl_GraphicDriver::OpenGl_UserDrawCallback_t& OpenGl_GraphicDriver::UserDrawCallback() |
2166f0fa | 341 | { |
5e27df78 | 342 | return myUserDrawCallback; |
2166f0fa SK |
343 | } |
344 | ||
f0430952 | 345 | // ======================================================================= |
5e27df78 | 346 | // function : DefaultTextHeight |
f0430952 | 347 | // purpose : |
348 | // ======================================================================= | |
5e27df78 | 349 | Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const |
2166f0fa | 350 | { |
5e27df78 | 351 | return 16.; |
2166f0fa SK |
352 | } |
353 | ||
f0430952 | 354 | // ======================================================================= |
355 | // function : EnableVBO | |
356 | // purpose : | |
357 | // ======================================================================= | |
2166f0fa | 358 | void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn) |
7fd59977 | 359 | { |
58655684 | 360 | myCaps->vboDisable = !theToTurnOn; |
7fd59977 | 361 | } |
f0430952 | 362 | |
5e27df78 | 363 | // ======================================================================= |
364 | // function : GetSharedContext | |
365 | // purpose : | |
366 | // ======================================================================= | |
367 | const Handle(OpenGl_Context)& OpenGl_GraphicDriver::GetSharedContext() const | |
368 | { | |
369 | if (myMapOfWS.IsEmpty()) | |
370 | { | |
371 | return TheNullGlCtx; | |
372 | } | |
373 | ||
a272ed94 | 374 | NCollection_Map<Handle(OpenGl_Workspace)>::Iterator anIter (myMapOfWS); |
5e27df78 | 375 | return anIter.Value()->GetGlContext(); |
376 | } | |
377 | ||
f0430952 | 378 | // ======================================================================= |
379 | // function : MemoryInfo | |
380 | // purpose : | |
381 | // ======================================================================= | |
382 | Standard_Boolean OpenGl_GraphicDriver::MemoryInfo (Standard_Size& theFreeBytes, | |
383 | TCollection_AsciiString& theInfo) const | |
384 | { | |
385 | // this is extra work (for OpenGl_Context initialization)... | |
386 | OpenGl_Context aGlCtx; | |
387 | if (!aGlCtx.Init()) | |
388 | { | |
389 | return Standard_False; | |
390 | } | |
391 | theFreeBytes = aGlCtx.AvailableMemory(); | |
392 | theInfo = aGlCtx.MemoryInfo(); | |
393 | return !theInfo.IsEmpty(); | |
394 | } | |
1981cb22 | 395 | |
396 | // ======================================================================= | |
397 | // function : SetImmediateModeDrawToFront | |
398 | // purpose : | |
399 | // ======================================================================= | |
400 | Standard_Boolean OpenGl_GraphicDriver::SetImmediateModeDrawToFront (const Graphic3d_CView& theCView, | |
401 | const Standard_Boolean theDrawToFrontBuffer) | |
402 | { | |
403 | if (theCView.ViewId == -1) | |
404 | { | |
405 | return Standard_False; | |
406 | } | |
407 | ||
408 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
409 | if (aCView != NULL) | |
410 | { | |
411 | return aCView->WS->SetImmediateModeDrawToFront (theDrawToFrontBuffer); | |
412 | } | |
413 | return Standard_False; | |
414 | } | |
415 | ||
416 | // ======================================================================= | |
679ecdee | 417 | // function : DisplayImmediateStructure |
1981cb22 | 418 | // purpose : |
419 | // ======================================================================= | |
a1954302 | 420 | void OpenGl_GraphicDriver::DisplayImmediateStructure (const Graphic3d_CView& theCView, |
421 | const Handle(Graphic3d_Structure)& theStructure) | |
1981cb22 | 422 | { |
a1954302 | 423 | OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; |
679ecdee | 424 | if (aCView == NULL) |
1981cb22 | 425 | { |
679ecdee | 426 | return; |
1981cb22 | 427 | } |
428 | ||
a1954302 | 429 | aCView->View->DisplayImmediateStructure (theStructure); |
1981cb22 | 430 | } |
431 | ||
432 | // ======================================================================= | |
679ecdee | 433 | // function : EraseImmediateStructure |
1981cb22 | 434 | // purpose : |
435 | // ======================================================================= | |
679ecdee | 436 | void OpenGl_GraphicDriver::EraseImmediateStructure (const Graphic3d_CView& theCView, |
437 | const Graphic3d_CStructure& theCStructure) | |
1981cb22 | 438 | { |
679ecdee | 439 | OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; |
63bcc448 | 440 | OpenGl_Structure* aStructure = (OpenGl_Structure* )&theCStructure; |
679ecdee | 441 | if (aCView == NULL) |
1981cb22 | 442 | { |
679ecdee | 443 | return; |
1981cb22 | 444 | } |
1981cb22 | 445 | |
679ecdee | 446 | aCView->View->EraseImmediateStructure (aStructure); |
1981cb22 | 447 | } |
a174a3c5 | 448 | |
679ecdee | 449 | |
a174a3c5 | 450 | // ======================================================================= |
451 | // function : Print | |
452 | // purpose : | |
453 | // ======================================================================= | |
454 | Standard_Boolean OpenGl_GraphicDriver::Print (const Graphic3d_CView& theCView, | |
455 | const Aspect_CLayer2d& theCUnderLayer, | |
456 | const Aspect_CLayer2d& theCOverLayer, | |
457 | const Aspect_Handle thePrintDC, | |
458 | const Standard_Boolean theToShowBackground, | |
459 | const Standard_CString theFilename, | |
460 | const Aspect_PrintAlgo thePrintAlgorithm, | |
461 | const Standard_Real theScaleFactor) const | |
462 | { | |
463 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
464 | if (aCView == NULL | |
465 | || !myPrintContext.IsNull()) | |
466 | { | |
467 | return Standard_False; | |
468 | } | |
469 | ||
470 | Standard_Boolean isPrinted = Standard_False; | |
471 | myPrintContext = new OpenGl_PrinterContext(); | |
472 | #ifdef _WIN32 | |
473 | isPrinted = aCView->WS->Print (myPrintContext, | |
474 | theCView, | |
475 | theCUnderLayer, | |
476 | theCOverLayer, | |
477 | thePrintDC, | |
478 | theToShowBackground, | |
479 | theFilename, | |
480 | thePrintAlgorithm, | |
481 | theScaleFactor); | |
482 | #else | |
483 | Standard_NotImplemented::Raise ("OpenGl_GraphicDriver::Print is implemented only on Windows"); | |
484 | #endif | |
485 | myPrintContext.Nullify(); | |
486 | return isPrinted; | |
487 | } | |
488 | ||
a174a3c5 | 489 | // ======================================================================= |
490 | // function : ZBufferTriedronSetup | |
491 | // purpose : | |
492 | // ======================================================================= | |
536d98e2 | 493 | void OpenGl_GraphicDriver::ZBufferTriedronSetup (const Graphic3d_CView& theCView, |
494 | const Quantity_NameOfColor theXColor, | |
a174a3c5 | 495 | const Quantity_NameOfColor theYColor, |
496 | const Quantity_NameOfColor theZColor, | |
497 | const Standard_Real theSizeRatio, | |
498 | const Standard_Real theAxisDiametr, | |
536d98e2 | 499 | const Standard_Integer theNbFacets) |
a174a3c5 | 500 | { |
536d98e2 | 501 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; |
502 | if (aCView == NULL) | |
503 | { | |
504 | return; | |
505 | } | |
506 | ||
507 | OpenGl_Trihedron& aTrih = aCView->View->ChangeTrihedron(); | |
508 | aTrih.SetArrowsColors (theXColor, theYColor, theZColor); | |
509 | aTrih.SetSizeRatio (theSizeRatio); | |
510 | aTrih.SetNbFacets (theNbFacets); | |
511 | aTrih.SetArrowDiameter (theAxisDiametr); | |
a174a3c5 | 512 | } |
513 | ||
514 | // ======================================================================= | |
515 | // function : TriedronDisplay | |
516 | // purpose : | |
517 | // ======================================================================= | |
518 | void OpenGl_GraphicDriver::TriedronDisplay (const Graphic3d_CView& theCView, | |
519 | const Aspect_TypeOfTriedronPosition thePosition, | |
520 | const Quantity_NameOfColor theColor, | |
521 | const Standard_Real theScale, | |
522 | const Standard_Boolean theAsWireframe) | |
523 | { | |
524 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
525 | if (aCView != NULL) | |
526 | { | |
536d98e2 | 527 | aCView->View->TriedronDisplay (thePosition, theColor, theScale, theAsWireframe); |
a174a3c5 | 528 | } |
529 | } | |
530 | ||
531 | // ======================================================================= | |
532 | // function : TriedronErase | |
533 | // purpose : | |
534 | // ======================================================================= | |
535 | void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& theCView) | |
536 | { | |
537 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
538 | if (aCView != NULL) | |
539 | { | |
540 | aCView->View->TriedronErase (aCView->WS->GetGlContext()); | |
541 | } | |
542 | } | |
543 | ||
544 | // ======================================================================= | |
545 | // function : TriedronEcho | |
546 | // purpose : | |
547 | // ======================================================================= | |
548 | void OpenGl_GraphicDriver::TriedronEcho (const Graphic3d_CView& , | |
549 | const Aspect_TypeOfTriedronEcho ) | |
550 | { | |
551 | // do nothing | |
552 | } | |
553 | ||
554 | // ======================================================================= | |
555 | // function : Environment | |
556 | // purpose : | |
557 | // ======================================================================= | |
558 | void OpenGl_GraphicDriver::Environment (const Graphic3d_CView& theCView) | |
559 | { | |
560 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
561 | if (aCView == NULL) | |
562 | { | |
563 | return; | |
564 | } | |
565 | ||
566 | aCView->View->SetTextureEnv (aCView->WS->GetGlContext(), theCView.Context.TextureEnv); | |
567 | aCView->View->SetSurfaceDetail ((Visual3d_TypeOfSurfaceDetail)theCView.Context.SurfaceDetail); | |
568 | } | |
569 | ||
570 | // ======================================================================= | |
571 | // function : BackgroundImage | |
572 | // purpose : | |
573 | // ======================================================================= | |
574 | void OpenGl_GraphicDriver::BackgroundImage (const Standard_CString theFileName, | |
575 | const Graphic3d_CView& theCView, | |
576 | const Aspect_FillMethod theFillStyle) | |
577 | { | |
578 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
579 | if (aCView != NULL) | |
580 | { | |
581 | aCView->View->CreateBackgroundTexture (theFileName, theFillStyle); | |
582 | } | |
583 | } | |
584 | ||
585 | // ======================================================================= | |
586 | // function : SetBgImageStyle | |
587 | // purpose : | |
588 | // ======================================================================= | |
589 | void OpenGl_GraphicDriver::SetBgImageStyle (const Graphic3d_CView& theCView, | |
590 | const Aspect_FillMethod theFillStyle) | |
591 | { | |
592 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
593 | if (aCView != NULL) | |
594 | { | |
595 | aCView->View->SetBackgroundTextureStyle (theFillStyle); | |
596 | } | |
597 | } | |
598 | ||
599 | // ======================================================================= | |
600 | // function : SetBgGradientStyle | |
601 | // purpose : | |
602 | // ======================================================================= | |
603 | void OpenGl_GraphicDriver::SetBgGradientStyle (const Graphic3d_CView& theCView, | |
604 | const Aspect_GradientFillMethod theFillType) | |
605 | { | |
606 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
607 | if (aCView != NULL) | |
608 | { | |
609 | aCView->View->SetBackgroundGradientType (theFillType); | |
610 | } | |
611 | } | |
612 | ||
613 | // ======================================================================= | |
614 | // function : GraduatedTrihedronDisplay | |
615 | // purpose : | |
616 | // ======================================================================= | |
617 | void OpenGl_GraphicDriver::GraduatedTrihedronDisplay (const Graphic3d_CView& theCView, | |
a79f67f8 | 618 | const Graphic3d_GraduatedTrihedron& theCubic) |
a174a3c5 | 619 | { |
620 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
621 | if (aCView != NULL) | |
622 | { | |
623 | aCView->View->GraduatedTrihedronDisplay (aCView->WS->GetGlContext(), theCubic); | |
624 | } | |
625 | } | |
626 | ||
627 | // ======================================================================= | |
628 | // function : GraduatedTrihedronErase | |
629 | // purpose : | |
630 | // ======================================================================= | |
631 | void OpenGl_GraphicDriver::GraduatedTrihedronErase (const Graphic3d_CView& theCView) | |
632 | { | |
633 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
634 | if (aCView != NULL) | |
635 | { | |
636 | aCView->View->GraduatedTrihedronErase (aCView->WS->GetGlContext()); | |
637 | } | |
638 | } | |
639 | ||
640 | // ======================================================================= | |
641 | // function : GraduatedTrihedronMinMaxValues | |
642 | // purpose : | |
643 | // ======================================================================= | |
a79f67f8 | 644 | void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, |
536d98e2 | 645 | const Graphic3d_Vec3 theMin, |
646 | const Graphic3d_Vec3 theMax) | |
a174a3c5 | 647 | { |
a79f67f8 | 648 | const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; |
649 | if (aCView != NULL) | |
650 | { | |
536d98e2 | 651 | aCView->View->ChangeGraduatedTrihedron().SetMinMax (theMin, theMax); |
a79f67f8 | 652 | } |
a174a3c5 | 653 | } |
62e1beed | 654 | |
655 | // ======================================================================= | |
656 | // function : SetBuffersNoSwap | |
657 | // purpose : | |
658 | // ======================================================================= | |
659 | void OpenGl_GraphicDriver::SetBuffersNoSwap (const Standard_Boolean theIsNoSwap) | |
660 | { | |
661 | myCaps->buffersNoSwap = theIsNoSwap; | |
662 | } |