Commit | Line | Data |
---|---|---|
6aca4d39 | 1 | // Created on: 2012-01-26 |
b311480e | 2 | // Created by: Kirill GAVRILOV |
6aca4d39 | 3 | // Copyright (c) 2012-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. | |
b311480e | 15 | |
58655684 | 16 | #if defined(_WIN32) |
5f8b738e | 17 | #include <windows.h> |
18 | #endif | |
19 | ||
2166f0fa SK |
20 | #include <OpenGl_Context.hxx> |
21 | ||
5e27df78 | 22 | #include <OpenGl_ArbTBO.hxx> |
23 | #include <OpenGl_ArbIns.hxx> | |
58655684 | 24 | #include <OpenGl_ArbDbg.hxx> |
01ca42b2 | 25 | #include <OpenGl_ArbFBO.hxx> |
37eb4787 | 26 | #include <OpenGl_ExtGS.hxx> |
25ef750e | 27 | #include <OpenGl_ArbTexBindless.hxx> |
4e1523ef | 28 | #include <OpenGl_GlCore44.hxx> |
a2e4f780 | 29 | #include <OpenGl_FrameBuffer.hxx> |
25ef750e | 30 | #include <OpenGl_Sampler.hxx> |
30f0ad28 | 31 | #include <OpenGl_ShaderManager.hxx> |
299e0ab9 | 32 | #include <OpenGl_Workspace.hxx> |
33 | #include <OpenGl_AspectFace.hxx> | |
79f4f036 | 34 | #include <Graphic3d_TransformUtils.hxx> |
5f8b738e | 35 | |
cbf18624 | 36 | #include <Message_Messenger.hxx> |
30f0ad28 | 37 | |
a174a3c5 | 38 | #include <NCollection_Vector.hxx> |
39 | ||
2bd4c032 | 40 | #include <Standard_ProgramError.hxx> |
41 | ||
f5f4ebd0 | 42 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient) |
43 | ||
da8bb41d | 44 | #if defined(HAVE_EGL) |
45 | #include <EGL/egl.h> | |
46 | #ifdef _MSC_VER | |
47 | #pragma comment(lib, "libEGL.lib") | |
48 | #endif | |
49 | #elif defined(_WIN32) | |
5f8b738e | 50 | // |
51 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
52 | #include <dlfcn.h> | |
f978241f | 53 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
54 | // | |
55 | #else | |
56 | #include <OpenGL/OpenGL.h> | |
26d9c835 | 57 | #include <CoreGraphics/CoreGraphics.h> |
f978241f | 58 | #endif |
5f8b738e | 59 | #else |
60 | #include <GL/glx.h> // glXGetProcAddress() | |
61 | #endif | |
62 | ||
ac116c22 | 63 | #ifdef HAVE_GL2PS |
64 | #include <gl2ps.h> | |
65 | #ifdef _MSC_VER | |
66 | #pragma comment (lib, "gl2ps.lib") | |
67 | #endif | |
68 | #endif | |
69 | ||
2166f0fa | 70 | |
5e27df78 | 71 | namespace |
72 | { | |
73 | static const Handle(OpenGl_Resource) NULL_GL_RESOURCE; | |
458e3c0d | 74 | static const OpenGl_Mat4 THE_IDENTITY_MATRIX; |
26d9c835 | 75 | |
76 | //! Add key-value pair to the dictionary. | |
77 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
78 | const TCollection_AsciiString& theKey, | |
79 | const TCollection_AsciiString& theValue) | |
80 | { | |
81 | theDict.ChangeFromIndex (theDict.Add (theKey, theValue)) = theValue; | |
82 | } | |
83 | ||
84 | //! Add key-value pair to the dictionary. | |
85 | static void addInfo (TColStd_IndexedDataMapOfStringString& theDict, | |
86 | const TCollection_AsciiString& theKey, | |
87 | const char* theValue) | |
88 | { | |
89 | TCollection_AsciiString aValue (theValue != NULL ? theValue : ""); | |
90 | theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue; | |
91 | } | |
01ca42b2 | 92 | } |
5e27df78 | 93 | |
2166f0fa SK |
94 | // ======================================================================= |
95 | // function : OpenGl_Context | |
96 | // purpose : | |
97 | // ======================================================================= | |
58655684 | 98 | OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) |
01ca42b2 | 99 | : core11 (NULL), |
100 | core11fwd (NULL), | |
101 | core15 (NULL), | |
102 | core15fwd (NULL), | |
103 | core20 (NULL), | |
104 | core20fwd (NULL), | |
105 | core32 (NULL), | |
106 | core32back (NULL), | |
25ef750e | 107 | core33 (NULL), |
108 | core33back (NULL), | |
01ca42b2 | 109 | core41 (NULL), |
110 | core41back (NULL), | |
111 | core42 (NULL), | |
112 | core42back (NULL), | |
113 | core43 (NULL), | |
114 | core43back (NULL), | |
115 | core44 (NULL), | |
116 | core44back (NULL), | |
58655684 | 117 | caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()), |
ca3c13d1 | 118 | #if defined(GL_ES_VERSION_2_0) |
119 | hasHighp (Standard_False), | |
e99a2f7c | 120 | hasUintIndex(Standard_False), |
ca3c13d1 | 121 | hasTexRGBA8(Standard_False), |
122 | #else | |
123 | hasHighp (Standard_True), | |
e99a2f7c | 124 | hasUintIndex(Standard_True), |
ca3c13d1 | 125 | hasTexRGBA8(Standard_True), |
126 | #endif | |
25ef750e | 127 | arbNPTW (Standard_False), |
128 | arbTexRG (Standard_False), | |
74fb257d | 129 | arbTexFloat (Standard_False), |
25ef750e | 130 | arbTexBindless (NULL), |
5e27df78 | 131 | arbTBO (NULL), |
25ef750e | 132 | arbTboRGB32 (Standard_False), |
5e27df78 | 133 | arbIns (NULL), |
58655684 | 134 | arbDbg (NULL), |
01ca42b2 | 135 | arbFBO (NULL), |
b86bb3df | 136 | arbFBOBlit (NULL), |
1ce0716b | 137 | extFragDepth (Standard_False), |
37eb4787 | 138 | extGS (NULL), |
bf75be98 | 139 | extBgra(Standard_False), |
140 | extAnis(Standard_False), | |
30f0ad28 | 141 | extPDS (Standard_False), |
f0430952 | 142 | atiMem (Standard_False), |
143 | nvxMem (Standard_False), | |
5e27df78 | 144 | mySharedResources (new OpenGl_ResourcesMap()), |
a174a3c5 | 145 | myDelayed (new OpenGl_DelayReleaseMap()), |
3125ebb6 | 146 | myUnusedResources (new OpenGl_ResourcesStack()), |
4269bd1b | 147 | myClippingState (), |
5f8b738e | 148 | myGlLibHandle (NULL), |
01ca42b2 | 149 | myFuncs (new OpenGl_GlFunctions()), |
2f6cb3ac | 150 | myAnisoMax (1), |
ca3c13d1 | 151 | myTexClamp (GL_CLAMP_TO_EDGE), |
eafb234b | 152 | myMaxTexDim (1024), |
4269bd1b | 153 | myMaxClipPlanes (6), |
3c4b62a4 | 154 | myMaxMsaaSamples(0), |
5f8b738e | 155 | myGlVerMajor (0), |
156 | myGlVerMinor (0), | |
b5ac8292 | 157 | myIsInitialized (Standard_False), |
158 | myIsStereoBuffers (Standard_False), | |
7d9e854b | 159 | myIsGlNormalizeEnabled (Standard_False), |
ca3c13d1 | 160 | #if !defined(GL_ES_VERSION_2_0) |
fd59283a | 161 | myPointSpriteOrig (GL_UPPER_LEFT), |
7d3e64ef | 162 | myRenderMode (GL_RENDER), |
6d0e6be5 | 163 | myPolygonMode (GL_FILL), |
ca3c13d1 | 164 | #else |
fd59283a | 165 | myPointSpriteOrig (0), |
ca3c13d1 | 166 | myRenderMode (0), |
6d0e6be5 | 167 | myPolygonMode (0), |
ca3c13d1 | 168 | #endif |
b6472664 | 169 | myToCullBackFaces (false), |
38a0206f | 170 | myReadBuffer (0), |
4e1523ef | 171 | myDrawBuffer (0), |
172 | myDefaultVao (0), | |
75c262a9 | 173 | myIsGlDebugCtx (Standard_False), |
174 | myResolutionRatio (1.0f) | |
2166f0fa | 175 | { |
3bffef55 | 176 | myViewport[0] = 0; |
177 | myViewport[1] = 0; | |
178 | myViewport[2] = 0; | |
179 | myViewport[3] = 0; | |
180 | ||
4e1523ef | 181 | // system-dependent fields |
182 | #if defined(HAVE_EGL) | |
183 | myDisplay = (Aspect_Display )EGL_NO_DISPLAY; | |
184 | myWindow = (Aspect_Drawable )EGL_NO_SURFACE; | |
458c2c58 | 185 | myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT; |
4e1523ef | 186 | #elif defined(_WIN32) |
187 | myWindow = NULL; | |
188 | myWindowDC = NULL; | |
189 | myGContext = NULL; | |
190 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
5f8b738e | 191 | // Vendors can not extend functionality on this system |
192 | // and developers are limited to OpenGL support provided by Mac OS X SDK. | |
193 | // We retrieve function pointers from system library | |
194 | // to generalize extensions support on all platforms. | |
195 | // In this way we also reach binary compatibility benefit between OS releases | |
196 | // if some newest functionality is optionally used. | |
197 | // Notice that GL version / extension availability checks are required | |
198 | // because function pointers may be available but not functionality itself | |
199 | // (depends on renderer). | |
a2e4f780 | 200 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
201 | myGContext = NULL; | |
202 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY); | |
203 | #else | |
4e1523ef | 204 | myGContext = NULL; |
5f8b738e | 205 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY); |
a2e4f780 | 206 | #endif |
4e1523ef | 207 | #else |
208 | myDisplay = NULL; | |
209 | myWindow = 0; | |
210 | myGContext = 0; | |
5f8b738e | 211 | #endif |
a2e4f780 | 212 | |
01ca42b2 | 213 | memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions)); |
30f0ad28 | 214 | myShaderManager = new OpenGl_ShaderManager (this); |
2166f0fa SK |
215 | } |
216 | ||
217 | // ======================================================================= | |
218 | // function : ~OpenGl_Context | |
219 | // purpose : | |
220 | // ======================================================================= | |
221 | OpenGl_Context::~OpenGl_Context() | |
222 | { | |
5e27df78 | 223 | // release clean up queue |
224 | ReleaseDelayed(); | |
225 | ||
4e1523ef | 226 | #if !defined(GL_ES_VERSION_2_0) |
227 | // release default VAO | |
228 | if (myDefaultVao != 0 | |
229 | && IsValid() | |
230 | && core32 != NULL) | |
231 | { | |
232 | core32->glDeleteVertexArrays (1, &myDefaultVao); | |
233 | } | |
234 | myDefaultVao = 0; | |
235 | #endif | |
236 | ||
a2e4f780 | 237 | // release default FBO |
238 | if (!myDefaultFbo.IsNull()) | |
239 | { | |
240 | myDefaultFbo->Release (this); | |
241 | myDefaultFbo.Nullify(); | |
242 | } | |
243 | ||
5e27df78 | 244 | // release shared resources if any |
4796758e | 245 | if (mySharedResources->GetRefCount() <= 1) |
5e27df78 | 246 | { |
392ac980 | 247 | myShaderManager.Nullify(); |
5e27df78 | 248 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); |
249 | anIter.More(); anIter.Next()) | |
250 | { | |
251 | anIter.Value()->Release (this); | |
252 | } | |
e1c659da | 253 | |
254 | // release delayed resources added during deletion of shared resources | |
255 | while (!myUnusedResources->IsEmpty()) | |
256 | { | |
257 | myUnusedResources->First()->Release (this); | |
258 | myUnusedResources->RemoveFirst(); | |
259 | } | |
5e27df78 | 260 | } |
c357e426 | 261 | else if (myShaderManager->IsSameContext (this)) |
392ac980 | 262 | { |
263 | myShaderManager->SetContext (NULL); | |
264 | } | |
5e27df78 | 265 | mySharedResources.Nullify(); |
a174a3c5 | 266 | myDelayed.Nullify(); |
5e27df78 | 267 | |
25ef750e | 268 | // release sampler object |
269 | if (!myTexSampler.IsNull()) | |
270 | { | |
271 | myTexSampler->Release (this); | |
272 | } | |
273 | ||
cbf18624 | 274 | if (arbDbg != NULL |
4e1523ef | 275 | && myIsGlDebugCtx |
f8c8ba7a | 276 | && IsValid()) |
cbf18624 | 277 | { |
278 | // reset callback | |
0deb6f04 | 279 | #if !defined(GL_ES_VERSION_2_0) |
cbf18624 | 280 | void* aPtr = NULL; |
3b523c4c | 281 | glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr); |
cbf18624 | 282 | if (aPtr == this) |
0deb6f04 | 283 | #endif |
cbf18624 | 284 | { |
0deb6f04 | 285 | arbDbg->glDebugMessageCallback (NULL, NULL); |
cbf18624 | 286 | } |
4e1523ef | 287 | myIsGlDebugCtx = Standard_False; |
cbf18624 | 288 | } |
5f8b738e | 289 | } |
290 | ||
05e2200b | 291 | // ======================================================================= |
292 | // function : forcedRelease | |
293 | // purpose : | |
294 | // ======================================================================= | |
295 | void OpenGl_Context::forcedRelease() | |
296 | { | |
297 | ReleaseDelayed(); | |
298 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); | |
299 | anIter.More(); anIter.Next()) | |
300 | { | |
301 | anIter.Value()->Release (this); | |
302 | } | |
303 | mySharedResources->Clear(); | |
304 | myShaderManager->clear(); | |
305 | myShaderManager->SetContext (NULL); | |
e1c659da | 306 | |
307 | // release delayed resources added during deletion of shared resources | |
308 | while (!myUnusedResources->IsEmpty()) | |
309 | { | |
310 | myUnusedResources->First()->Release (this); | |
311 | myUnusedResources->RemoveFirst(); | |
312 | } | |
05e2200b | 313 | } |
314 | ||
3bffef55 | 315 | // ======================================================================= |
316 | // function : ResizeViewport | |
317 | // purpose : | |
318 | // ======================================================================= | |
319 | void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect) | |
320 | { | |
321 | core11fwd->glViewport (theRect[0], theRect[1], theRect[2], theRect[3]); | |
322 | myViewport[0] = theRect[0]; | |
323 | myViewport[1] = theRect[1]; | |
324 | myViewport[2] = theRect[2]; | |
325 | myViewport[3] = theRect[3]; | |
326 | } | |
327 | ||
ca3c13d1 | 328 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 329 | inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer) |
330 | { | |
331 | switch (theBuffer) | |
b5ac8292 | 332 | { |
38a0206f | 333 | case GL_BACK_LEFT: |
334 | case GL_BACK_RIGHT: | |
335 | return GL_BACK; | |
336 | case GL_FRONT_LEFT: | |
337 | case GL_FRONT_RIGHT: | |
338 | return GL_FRONT; | |
339 | default: | |
340 | return theBuffer; | |
b5ac8292 | 341 | } |
342 | } | |
38a0206f | 343 | #endif |
b5ac8292 | 344 | |
345 | // ======================================================================= | |
38a0206f | 346 | // function : SetReadBuffer |
b5ac8292 | 347 | // purpose : |
348 | // ======================================================================= | |
38a0206f | 349 | void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer) |
b5ac8292 | 350 | { |
ca3c13d1 | 351 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 352 | myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer; |
353 | if (myReadBuffer < GL_COLOR_ATTACHMENT0 | |
354 | && arbFBO != NULL) | |
b5ac8292 | 355 | { |
38a0206f | 356 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 357 | } |
38a0206f | 358 | ::glReadBuffer (myReadBuffer); |
359 | #else | |
360 | (void )theReadBuffer; | |
ca3c13d1 | 361 | #endif |
b5ac8292 | 362 | } |
363 | ||
364 | // ======================================================================= | |
38a0206f | 365 | // function : SetDrawBuffer |
b5ac8292 | 366 | // purpose : |
367 | // ======================================================================= | |
38a0206f | 368 | void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer) |
b5ac8292 | 369 | { |
ca3c13d1 | 370 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 371 | myDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer; |
372 | if (myDrawBuffer < GL_COLOR_ATTACHMENT0 | |
373 | && arbFBO != NULL) | |
b5ac8292 | 374 | { |
38a0206f | 375 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 376 | } |
38a0206f | 377 | ::glDrawBuffer (myDrawBuffer); |
378 | #else | |
379 | (void )theDrawBuffer; | |
ca3c13d1 | 380 | #endif |
b5ac8292 | 381 | } |
382 | ||
b6472664 | 383 | // ======================================================================= |
384 | // function : SetCullBackFaces | |
385 | // purpose : | |
386 | // ======================================================================= | |
387 | void OpenGl_Context::SetCullBackFaces (bool theToEnable) | |
388 | { | |
389 | if (myToCullBackFaces == theToEnable) | |
390 | { | |
391 | return; | |
392 | } | |
393 | ||
394 | myToCullBackFaces = theToEnable; | |
395 | if (theToEnable) | |
396 | { | |
397 | //glCullFace (GL_BACK); GL_BACK by default | |
398 | core11fwd->glEnable (GL_CULL_FACE); | |
399 | } | |
400 | else | |
401 | { | |
402 | core11fwd->glDisable (GL_CULL_FACE); | |
403 | } | |
404 | } | |
405 | ||
b5ac8292 | 406 | // ======================================================================= |
407 | // function : FetchState | |
408 | // purpose : | |
409 | // ======================================================================= | |
410 | void OpenGl_Context::FetchState() | |
411 | { | |
ca3c13d1 | 412 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 413 | // cache feedback mode state |
4e1523ef | 414 | if (core11 != NULL) |
415 | { | |
416 | ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode); | |
417 | } | |
b5ac8292 | 418 | |
38a0206f | 419 | // cache buffers state |
420 | ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); | |
421 | ::glGetIntegerv (GL_DRAW_BUFFER, &myDrawBuffer); | |
ca3c13d1 | 422 | #endif |
b5ac8292 | 423 | } |
424 | ||
5e27df78 | 425 | // ======================================================================= |
426 | // function : Share | |
427 | // purpose : | |
428 | // ======================================================================= | |
429 | void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx) | |
430 | { | |
431 | if (!theShareCtx.IsNull()) | |
432 | { | |
433 | mySharedResources = theShareCtx->mySharedResources; | |
a174a3c5 | 434 | myDelayed = theShareCtx->myDelayed; |
3125ebb6 | 435 | myUnusedResources = theShareCtx->myUnusedResources; |
392ac980 | 436 | myShaderManager = theShareCtx->myShaderManager; |
5e27df78 | 437 | } |
438 | } | |
439 | ||
4fe56619 | 440 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
441 | ||
86fa64d9 | 442 | // ======================================================================= |
443 | // function : IsCurrent | |
444 | // purpose : | |
445 | // ======================================================================= | |
446 | Standard_Boolean OpenGl_Context::IsCurrent() const | |
447 | { | |
da8bb41d | 448 | #if defined(HAVE_EGL) |
449 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
450 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
451 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
452 | { | |
453 | return Standard_False; | |
454 | } | |
455 | ||
456 | return (((EGLDisplay )myDisplay == eglGetCurrentDisplay()) | |
457 | && ((EGLContext )myGContext == eglGetCurrentContext()) | |
458 | && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW))); | |
459 | #elif defined(_WIN32) | |
86fa64d9 | 460 | if (myWindowDC == NULL || myGContext == NULL) |
461 | { | |
462 | return Standard_False; | |
463 | } | |
464 | return (( (HDC )myWindowDC == wglGetCurrentDC()) | |
465 | && ((HGLRC )myGContext == wglGetCurrentContext())); | |
466 | #else | |
467 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) | |
468 | { | |
469 | return Standard_False; | |
470 | } | |
471 | ||
472 | return ( ((Display* )myDisplay == glXGetCurrentDisplay()) | |
473 | && ((GLXContext )myGContext == glXGetCurrentContext()) | |
474 | && ((GLXDrawable )myWindow == glXGetCurrentDrawable())); | |
475 | #endif | |
476 | } | |
477 | ||
2bd4c032 | 478 | // ======================================================================= |
479 | // function : MakeCurrent | |
480 | // purpose : | |
481 | // ======================================================================= | |
482 | Standard_Boolean OpenGl_Context::MakeCurrent() | |
483 | { | |
da8bb41d | 484 | #if defined(HAVE_EGL) |
485 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
486 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
487 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
488 | { | |
489 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
490 | return Standard_False; | |
491 | } | |
492 | ||
493 | if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE) | |
494 | { | |
495 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 496 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
da8bb41d | 497 | "eglMakeCurrent() has failed!"); |
498 | myIsInitialized = Standard_False; | |
499 | return Standard_False; | |
500 | } | |
501 | #elif defined(_WIN32) | |
86fa64d9 | 502 | if (myWindowDC == NULL || myGContext == NULL) |
2bd4c032 | 503 | { |
86fa64d9 | 504 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); |
505 | return Standard_False; | |
506 | } | |
507 | ||
508 | // technically it should be safe to activate already bound GL context | |
509 | // however some drivers (Intel etc.) may FAIL doing this for unknown reason | |
510 | if (IsCurrent()) | |
511 | { | |
392ac980 | 512 | myShaderManager->SetContext (this); |
86fa64d9 | 513 | return Standard_True; |
514 | } | |
515 | else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE) | |
516 | { | |
517 | // notice that glGetError() couldn't be used here! | |
518 | wchar_t* aMsgBuff = NULL; | |
519 | DWORD anErrorCode = GetLastError(); | |
520 | FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
521 | NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL); | |
cbf18624 | 522 | TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. "); |
86fa64d9 | 523 | if (aMsgBuff != NULL) |
524 | { | |
cbf18624 | 525 | aMsg += (Standard_ExtString )aMsgBuff; |
86fa64d9 | 526 | LocalFree (aMsgBuff); |
527 | } | |
3b523c4c | 528 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg); |
fd4a6963 | 529 | myIsInitialized = Standard_False; |
2bd4c032 | 530 | return Standard_False; |
531 | } | |
532 | #else | |
86fa64d9 | 533 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) |
534 | { | |
535 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
536 | return Standard_False; | |
537 | } | |
538 | ||
539 | if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext)) | |
2bd4c032 | 540 | { |
541 | // if there is no current context it might be impossible to use glGetError() correctly | |
3b523c4c | 542 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH, |
cbf18624 | 543 | "glXMakeCurrent() has failed!"); |
fd4a6963 | 544 | myIsInitialized = Standard_False; |
2bd4c032 | 545 | return Standard_False; |
546 | } | |
547 | #endif | |
392ac980 | 548 | myShaderManager->SetContext (this); |
2bd4c032 | 549 | return Standard_True; |
550 | } | |
551 | ||
5e27df78 | 552 | // ======================================================================= |
553 | // function : SwapBuffers | |
554 | // purpose : | |
555 | // ======================================================================= | |
556 | void OpenGl_Context::SwapBuffers() | |
557 | { | |
da8bb41d | 558 | #if defined(HAVE_EGL) |
559 | if ((EGLSurface )myWindow != EGL_NO_SURFACE) | |
560 | { | |
561 | eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow); | |
562 | } | |
563 | #elif defined(_WIN32) | |
5e27df78 | 564 | if ((HDC )myWindowDC != NULL) |
565 | { | |
566 | ::SwapBuffers ((HDC )myWindowDC); | |
567 | glFlush(); | |
568 | } | |
569 | #else | |
570 | if ((Display* )myDisplay != NULL) | |
571 | { | |
572 | glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow); | |
573 | } | |
574 | #endif | |
575 | } | |
576 | ||
4fe56619 | 577 | #endif // __APPLE__ |
578 | ||
f978241f | 579 | // ======================================================================= |
580 | // function : SetSwapInterval | |
581 | // purpose : | |
582 | // ======================================================================= | |
583 | Standard_Boolean OpenGl_Context::SetSwapInterval (const Standard_Integer theInterval) | |
584 | { | |
585 | #if defined(HAVE_EGL) | |
586 | if (::eglSwapInterval ((EGLDisplay )myDisplay, theInterval) == EGL_TRUE) | |
587 | { | |
588 | return Standard_True; | |
589 | } | |
590 | #elif defined(_WIN32) | |
591 | if (myFuncs->wglSwapIntervalEXT != NULL) | |
592 | { | |
593 | myFuncs->wglSwapIntervalEXT (theInterval); | |
594 | return Standard_True; | |
595 | } | |
596 | #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
597 | // | |
598 | #elif defined(__APPLE__) | |
599 | if (::CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &theInterval) == kCGLNoError) | |
600 | { | |
601 | return Standard_True; | |
602 | } | |
603 | #else | |
604 | if (theInterval == -1 | |
605 | && myFuncs->glXSwapIntervalEXT != NULL) | |
606 | { | |
607 | typedef int (*glXSwapIntervalEXT_t_x)(Display* theDisplay, GLXDrawable theDrawable, int theInterval); | |
608 | glXSwapIntervalEXT_t_x aFuncPtr = (glXSwapIntervalEXT_t_x )myFuncs->glXSwapIntervalEXT; | |
609 | aFuncPtr ((Display* )myDisplay, (GLXDrawable )myWindow, theInterval); | |
610 | return Standard_True; | |
611 | } | |
612 | else if (myFuncs->glXSwapIntervalSGI != NULL) | |
613 | { | |
614 | myFuncs->glXSwapIntervalSGI (theInterval); | |
615 | return Standard_True; | |
616 | } | |
617 | #endif | |
618 | return Standard_False; | |
619 | } | |
620 | ||
5f8b738e | 621 | // ======================================================================= |
622 | // function : findProc | |
623 | // purpose : | |
624 | // ======================================================================= | |
625 | void* OpenGl_Context::findProc (const char* theFuncName) | |
626 | { | |
da8bb41d | 627 | #if defined(HAVE_EGL) |
628 | return (void* )eglGetProcAddress (theFuncName); | |
629 | #elif defined(_WIN32) | |
7c65581d | 630 | return (void* )wglGetProcAddress (theFuncName); |
5f8b738e | 631 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
632 | return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL; | |
633 | #else | |
634 | return (void* )glXGetProcAddress ((const GLubyte* )theFuncName); | |
635 | #endif | |
2166f0fa SK |
636 | } |
637 | ||
638 | // ======================================================================= | |
639 | // function : CheckExtension | |
640 | // purpose : | |
641 | // ======================================================================= | |
2bd4c032 | 642 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const |
2166f0fa | 643 | { |
5f8b738e | 644 | if (theExtName == NULL) |
645 | { | |
0797d9d3 | 646 | #ifdef OCCT_DEBUG |
5f8b738e | 647 | std::cerr << "CheckExtension called with NULL string!\n"; |
63c629aa | 648 | #endif |
5f8b738e | 649 | return Standard_False; |
650 | } | |
5f8b738e | 651 | |
4e1523ef | 652 | #if !defined(GL_ES_VERSION_2_0) |
5f8b738e | 653 | // available since OpenGL 3.0 |
654 | // and the ONLY way to check extensions with OpenGL 3.1+ core profile | |
4e1523ef | 655 | if (IsGlGreaterEqual (3, 0) |
656 | && myFuncs->glGetStringi != NULL) | |
5f8b738e | 657 | { |
658 | GLint anExtNb = 0; | |
4e1523ef | 659 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); |
660 | const size_t anExtNameLen = strlen (theExtName); | |
5f8b738e | 661 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) |
662 | { | |
4e1523ef | 663 | const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter); |
664 | const size_t aTestExtNameLen = strlen (anExtension); | |
665 | if (aTestExtNameLen == anExtNameLen | |
666 | && strncmp (anExtension, theExtName, anExtNameLen) == 0) | |
5f8b738e | 667 | { |
668 | return Standard_True; | |
669 | } | |
670 | } | |
671 | return Standard_False; | |
4e1523ef | 672 | } |
673 | #endif | |
5f8b738e | 674 | |
675 | // use old way with huge string for all extensions | |
676 | const char* anExtString = (const char* )glGetString (GL_EXTENSIONS); | |
677 | if (anExtString == NULL) | |
678 | { | |
7e7c2f0b | 679 | Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning); |
2166f0fa SK |
680 | return Standard_False; |
681 | } | |
58655684 | 682 | return CheckExtension (anExtString, theExtName); |
683 | } | |
684 | ||
685 | // ======================================================================= | |
686 | // function : CheckExtension | |
687 | // purpose : | |
688 | // ======================================================================= | |
689 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString, | |
690 | const char* theExtName) | |
691 | { | |
692 | if (theExtString == NULL) | |
693 | { | |
694 | return Standard_False; | |
695 | } | |
2166f0fa SK |
696 | |
697 | // Search for theExtName in the extensions string. | |
698 | // Use of strstr() is not sufficient because extension names can be prefixes of other extension names. | |
58655684 | 699 | char* aPtrIter = (char* )theExtString; |
700 | const char* aPtrEnd = aPtrIter + strlen (theExtString); | |
701 | const size_t anExtNameLen = strlen (theExtName); | |
2166f0fa SK |
702 | while (aPtrIter < aPtrEnd) |
703 | { | |
6a7d83c4 | 704 | const size_t n = strcspn (aPtrIter, " "); |
5f8b738e | 705 | if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0)) |
706 | { | |
2166f0fa | 707 | return Standard_True; |
5f8b738e | 708 | } |
2166f0fa SK |
709 | aPtrIter += (n + 1); |
710 | } | |
711 | return Standard_False; | |
712 | } | |
713 | ||
4fe56619 | 714 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
715 | ||
2166f0fa SK |
716 | // ======================================================================= |
717 | // function : Init | |
718 | // purpose : | |
719 | // ======================================================================= | |
4e1523ef | 720 | Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile) |
2166f0fa | 721 | { |
2bd4c032 | 722 | if (myIsInitialized) |
5f8b738e | 723 | { |
f0430952 | 724 | return Standard_True; |
5f8b738e | 725 | } |
2bd4c032 | 726 | |
da8bb41d | 727 | #if defined(HAVE_EGL) |
728 | myDisplay = (Aspect_Display )eglGetCurrentDisplay(); | |
729 | myGContext = (Aspect_RenderingContext )eglGetCurrentContext(); | |
730 | myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW); | |
731 | #elif defined(_WIN32) | |
2bd4c032 | 732 | myWindowDC = (Aspect_Handle )wglGetCurrentDC(); |
733 | myGContext = (Aspect_RenderingContext )wglGetCurrentContext(); | |
734 | #else | |
735 | myDisplay = (Aspect_Display )glXGetCurrentDisplay(); | |
736 | myGContext = (Aspect_RenderingContext )glXGetCurrentContext(); | |
737 | myWindow = (Aspect_Drawable )glXGetCurrentDrawable(); | |
738 | #endif | |
f0430952 | 739 | if (myGContext == NULL) |
740 | { | |
741 | return Standard_False; | |
742 | } | |
2bd4c032 | 743 | |
4e1523ef | 744 | init (theIsCoreProfile); |
2bd4c032 | 745 | myIsInitialized = Standard_True; |
f0430952 | 746 | return Standard_True; |
2bd4c032 | 747 | } |
748 | ||
4fe56619 | 749 | #endif // __APPLE__ |
750 | ||
2bd4c032 | 751 | // ======================================================================= |
752 | // function : Init | |
753 | // purpose : | |
754 | // ======================================================================= | |
da8bb41d | 755 | #if defined(HAVE_EGL) |
756 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface, | |
757 | const Aspect_Display theEglDisplay, | |
4e1523ef | 758 | const Aspect_RenderingContext theEglContext, |
759 | const Standard_Boolean theIsCoreProfile) | |
da8bb41d | 760 | #elif defined(_WIN32) |
f0430952 | 761 | Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow, |
762 | const Aspect_Handle theWindowDC, | |
4e1523ef | 763 | const Aspect_RenderingContext theGContext, |
764 | const Standard_Boolean theIsCoreProfile) | |
4fe56619 | 765 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 766 | |
767 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
768 | Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext, | |
4e1523ef | 769 | const Standard_Boolean theIsCoreProfile) |
a2e4f780 | 770 | #else |
771 | Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext, | |
772 | const Standard_Boolean theIsCoreProfile) | |
773 | #endif | |
774 | ||
2bd4c032 | 775 | #else |
f0430952 | 776 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, |
777 | const Aspect_Display theDisplay, | |
4e1523ef | 778 | const Aspect_RenderingContext theGContext, |
779 | const Standard_Boolean theIsCoreProfile) | |
2bd4c032 | 780 | #endif |
781 | { | |
782 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!"); | |
da8bb41d | 783 | #if defined(HAVE_EGL) |
784 | myWindow = theEglSurface; | |
785 | myGContext = theEglContext; | |
786 | myDisplay = theEglDisplay; | |
787 | #elif defined(_WIN32) | |
2bd4c032 | 788 | myWindow = theWindow; |
789 | myGContext = theGContext; | |
2bd4c032 | 790 | myWindowDC = theWindowDC; |
4fe56619 | 791 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 792 | myGContext = theGContext; |
2bd4c032 | 793 | #else |
4fe56619 | 794 | myWindow = theWindow; |
795 | myGContext = theGContext; | |
2bd4c032 | 796 | myDisplay = theDisplay; |
797 | #endif | |
86fa64d9 | 798 | if (myGContext == NULL || !MakeCurrent()) |
f0430952 | 799 | { |
800 | return Standard_False; | |
801 | } | |
2bd4c032 | 802 | |
4e1523ef | 803 | init (theIsCoreProfile); |
2bd4c032 | 804 | myIsInitialized = Standard_True; |
f0430952 | 805 | return Standard_True; |
5f8b738e | 806 | } |
807 | ||
808 | // ======================================================================= | |
809 | // function : ResetErrors | |
810 | // purpose : | |
811 | // ======================================================================= | |
3c4b62a4 | 812 | void OpenGl_Context::ResetErrors (const bool theToPrintErrors) |
5f8b738e | 813 | { |
3c4b62a4 | 814 | int aPrevErr = 0; |
815 | int anErr = ::glGetError(); | |
816 | if (!theToPrintErrors) | |
5f8b738e | 817 | { |
3c4b62a4 | 818 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) |
819 | { | |
820 | // | |
821 | } | |
822 | return; | |
823 | } | |
824 | ||
825 | for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError()) | |
826 | { | |
827 | TCollection_ExtendedString anErrId; | |
828 | switch (anErr) | |
829 | { | |
830 | case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break; | |
831 | case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break; | |
832 | case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break; | |
833 | #ifdef GL_STACK_OVERFLOW | |
834 | case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break; | |
835 | case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break; | |
836 | #endif | |
837 | case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break; | |
838 | case GL_INVALID_FRAMEBUFFER_OPERATION: | |
839 | anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION"; | |
840 | break; | |
841 | default: | |
842 | anErrId = TCollection_ExtendedString("#") + anErr; | |
843 | break; | |
844 | } | |
845 | ||
846 | const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId; | |
82f443b6 | 847 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg); |
5f8b738e | 848 | } |
849 | } | |
850 | ||
851 | // ======================================================================= | |
4e1523ef | 852 | // function : ReadGlVersion |
5f8b738e | 853 | // purpose : |
854 | // ======================================================================= | |
4e1523ef | 855 | void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor, |
856 | Standard_Integer& theGlVerMinor) | |
5f8b738e | 857 | { |
858 | // reset values | |
4e1523ef | 859 | theGlVerMajor = 0; |
860 | theGlVerMinor = 0; | |
5f8b738e | 861 | |
ca3c13d1 | 862 | #ifdef GL_MAJOR_VERSION |
863 | // available since OpenGL 3.0 and OpenGL 3.0 ES | |
86325709 | 864 | GLint aMajor = 0, aMinor = 0; |
5f8b738e | 865 | glGetIntegerv (GL_MAJOR_VERSION, &aMajor); |
866 | glGetIntegerv (GL_MINOR_VERSION, &aMinor); | |
30f0ad28 | 867 | // glGetError() sometimes does not report an error here even if |
86325709 | 868 | // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. |
ca3c13d1 | 869 | // This happens on some renderers like e.g. Cygwin MESA. |
86325709 | 870 | // Thus checking additionally if GL has put anything to |
871 | // the output variables. | |
4e1523ef | 872 | if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) |
5f8b738e | 873 | { |
4e1523ef | 874 | theGlVerMajor = aMajor; |
875 | theGlVerMinor = aMinor; | |
5f8b738e | 876 | return; |
877 | } | |
4e1523ef | 878 | for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) |
879 | { | |
880 | if (anErr == GL_NO_ERROR | |
881 | || anErr == aPrevErr) | |
882 | { | |
883 | break; | |
884 | } | |
885 | } | |
ca3c13d1 | 886 | #endif |
5f8b738e | 887 | |
888 | // Read version string. | |
ca3c13d1 | 889 | // Notice that only first two numbers split by point '2.1 XXXXX' are significant. |
5f8b738e | 890 | // Following trash (after space) is vendor-specific. |
891 | // New drivers also returns micro version of GL like '3.3.0' which has no meaning | |
892 | // and should be considered as vendor-specific too. | |
893 | const char* aVerStr = (const char* )glGetString (GL_VERSION); | |
894 | if (aVerStr == NULL || *aVerStr == '\0') | |
895 | { | |
896 | // invalid GL context | |
897 | return; | |
898 | } | |
899 | ||
ca3c13d1 | 900 | //#if defined(GL_ES_VERSION_2_0) |
901 | // skip "OpenGL ES-** " section | |
902 | for (; *aVerStr != '\0'; ++aVerStr) | |
903 | { | |
904 | if (*aVerStr >= '0' && *aVerStr <= '9') | |
905 | { | |
906 | break; | |
907 | } | |
908 | } | |
909 | //#endif | |
910 | ||
5f8b738e | 911 | // parse string for major number |
912 | char aMajorStr[32]; | |
913 | char aMinorStr[32]; | |
914 | size_t aMajIter = 0; | |
915 | while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9') | |
916 | { | |
917 | ++aMajIter; | |
918 | } | |
919 | if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr)) | |
920 | { | |
921 | return; | |
922 | } | |
923 | memcpy (aMajorStr, aVerStr, aMajIter); | |
924 | aMajorStr[aMajIter] = '\0'; | |
925 | ||
926 | // parse string for minor number | |
86325709 | 927 | aVerStr += aMajIter + 1; |
928 | size_t aMinIter = 0; | |
5f8b738e | 929 | while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9') |
930 | { | |
931 | ++aMinIter; | |
932 | } | |
86325709 | 933 | if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr)) |
5f8b738e | 934 | { |
935 | return; | |
936 | } | |
86325709 | 937 | memcpy (aMinorStr, aVerStr, aMinIter); |
938 | aMinorStr[aMinIter] = '\0'; | |
5f8b738e | 939 | |
940 | // read numbers | |
4e1523ef | 941 | theGlVerMajor = atoi (aMajorStr); |
942 | theGlVerMinor = atoi (aMinorStr); | |
5f8b738e | 943 | |
4e1523ef | 944 | if (theGlVerMajor <= 0) |
5f8b738e | 945 | { |
4e1523ef | 946 | theGlVerMajor = 0; |
947 | theGlVerMinor = 0; | |
5f8b738e | 948 | } |
949 | } | |
950 | ||
58655684 | 951 | static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN"; |
952 | static Standard_CString THE_DBGMSG_SOURCES[] = | |
953 | { | |
3b523c4c | 954 | ".OpenGL", // GL_DEBUG_SOURCE_API |
955 | ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM | |
956 | ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER | |
957 | ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY | |
958 | "", // GL_DEBUG_SOURCE_APPLICATION | |
959 | ".Other" // GL_DEBUG_SOURCE_OTHER | |
58655684 | 960 | }; |
961 | ||
962 | static Standard_CString THE_DBGMSG_TYPES[] = | |
963 | { | |
3b523c4c | 964 | "Error", // GL_DEBUG_TYPE_ERROR |
965 | "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR | |
966 | "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR | |
967 | "Portability", // GL_DEBUG_TYPE_PORTABILITY | |
968 | "Performance", // GL_DEBUG_TYPE_PERFORMANCE | |
969 | "Other" // GL_DEBUG_TYPE_OTHER | |
58655684 | 970 | }; |
971 | ||
3b523c4c | 972 | static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH |
973 | static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM | |
974 | static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW | |
58655684 | 975 | |
cbf18624 | 976 | //! Callback for GL_ARB_debug_output extension |
58655684 | 977 | static void APIENTRY debugCallbackWrap(unsigned int theSource, |
978 | unsigned int theType, | |
979 | unsigned int theId, | |
980 | unsigned int theSeverity, | |
981 | int /*theLength*/, | |
982 | const char* theMessage, | |
9293178b | 983 | const void* theUserParam) |
cbf18624 | 984 | { |
985 | OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam; | |
986 | aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage); | |
987 | } | |
988 | ||
989 | // ======================================================================= | |
990 | // function : PushMessage | |
991 | // purpose : | |
992 | // ======================================================================= | |
993 | void OpenGl_Context::PushMessage (const unsigned int theSource, | |
994 | const unsigned int theType, | |
995 | const unsigned int theId, | |
996 | const unsigned int theSeverity, | |
997 | const TCollection_ExtendedString& theMessage) | |
58655684 | 998 | { |
c87535af | 999 | if (caps->suppressExtraMsg |
3b523c4c | 1000 | && theSource >= GL_DEBUG_SOURCE_API |
1001 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1002 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId)) | |
c87535af | 1003 | { |
1004 | return; | |
1005 | } | |
1006 | ||
3b523c4c | 1007 | Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API |
1008 | && theSource <= GL_DEBUG_SOURCE_OTHER) | |
1009 | ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API] | |
58655684 | 1010 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1011 | Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR |
1012 | && theType <= GL_DEBUG_TYPE_OTHER) | |
1013 | ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR] | |
58655684 | 1014 | : THE_DBGMSG_UNKNOWN; |
3b523c4c | 1015 | Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH |
58655684 | 1016 | ? THE_DBGMSG_SEV_HIGH |
3b523c4c | 1017 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
58655684 | 1018 | ? THE_DBGMSG_SEV_MEDIUM |
1019 | : THE_DBGMSG_SEV_LOW); | |
3b523c4c | 1020 | Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH |
cbf18624 | 1021 | ? Message_Alarm |
3b523c4c | 1022 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM |
cbf18624 | 1023 | ? Message_Warning |
1024 | : Message_Info); | |
1025 | ||
1026 | TCollection_ExtendedString aMsg; | |
1027 | aMsg += "TKOpenGl"; aMsg += aSrc; | |
1028 | aMsg += " | Type: "; aMsg += aType; | |
1029 | aMsg += " | ID: "; aMsg += (Standard_Integer )theId; | |
1030 | aMsg += " | Severity: "; aMsg += aSev; | |
1031 | aMsg += " | Message:\n "; | |
1032 | aMsg += theMessage; | |
7e7c2f0b | 1033 | Messenger()->Send (aMsg, aGrav); |
58655684 | 1034 | } |
1035 | ||
c87535af | 1036 | // ======================================================================= |
1037 | // function : ExcludeMessage | |
1038 | // purpose : | |
1039 | // ====================================================================== | |
1040 | Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource, | |
1041 | const unsigned int theId) | |
1042 | { | |
3b523c4c | 1043 | return theSource >= GL_DEBUG_SOURCE_API |
1044 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1045 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId); | |
c87535af | 1046 | } |
1047 | ||
1048 | // ======================================================================= | |
1049 | // function : IncludeMessage | |
1050 | // purpose : | |
1051 | // ====================================================================== | |
1052 | Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource, | |
1053 | const unsigned int theId) | |
1054 | { | |
3b523c4c | 1055 | return theSource >= GL_DEBUG_SOURCE_API |
1056 | && theSource <= GL_DEBUG_SOURCE_OTHER | |
1057 | && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId); | |
c87535af | 1058 | } |
1059 | ||
ee51a9fe | 1060 | // ======================================================================= |
1061 | // function : checkWrongVersion | |
1062 | // purpose : | |
1063 | // ====================================================================== | |
1064 | void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor, | |
1065 | const Standard_Integer theGlVerMinor) | |
1066 | { | |
1067 | if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor)) | |
1068 | { | |
1069 | return; | |
1070 | } | |
1071 | ||
1072 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
1073 | + "Error! OpenGL context reports version " | |
1074 | + myGlVerMajor + "." + myGlVerMinor | |
1075 | + " but does not export required functions for " | |
1076 | + theGlVerMajor + "." + theGlVerMinor; | |
3b523c4c | 1077 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, |
1078 | GL_DEBUG_TYPE_ERROR, | |
ee51a9fe | 1079 | 0, |
3b523c4c | 1080 | GL_DEBUG_SEVERITY_HIGH, |
ee51a9fe | 1081 | aMsg); |
1082 | } | |
1083 | ||
5f8b738e | 1084 | // ======================================================================= |
1085 | // function : init | |
1086 | // purpose : | |
1087 | // ======================================================================= | |
4e1523ef | 1088 | void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) |
5f8b738e | 1089 | { |
1090 | // read version | |
4e1523ef | 1091 | myGlVerMajor = 0; |
1092 | myGlVerMinor = 0; | |
3c4b62a4 | 1093 | myMaxMsaaSamples = 0; |
4e1523ef | 1094 | ReadGlVersion (myGlVerMajor, myGlVerMinor); |
c87535af | 1095 | myVendor = (const char* )::glGetString (GL_VENDOR); |
be375252 | 1096 | if (!caps->ffpEnable |
1097 | && !IsGlGreaterEqual (2, 0)) | |
1098 | { | |
1099 | caps->ffpEnable = true; | |
1100 | TCollection_ExtendedString aMsg = | |
1101 | TCollection_ExtendedString("OpenGL driver is too old! Context info:\n") | |
1102 | + " Vendor: " + (const char* )::glGetString (GL_VENDOR) + "\n" | |
1103 | + " Renderer: " + (const char* )::glGetString (GL_RENDERER) + "\n" | |
1104 | + " Version: " + (const char* )::glGetString (GL_VERSION) + "\n" | |
1105 | + " Fallback using deprecated fixed-function pipeline.\n" | |
1106 | + " Visualization might work incorrectly.\n" | |
1107 | " Consider upgrading the graphics driver."; | |
1108 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aMsg); | |
1109 | } | |
4e1523ef | 1110 | |
1111 | #if defined(GL_ES_VERSION_2_0) | |
1112 | (void )theIsCoreProfile; | |
1113 | const bool isCoreProfile = false; | |
1114 | #else | |
c87535af | 1115 | |
1116 | if (myVendor.Search ("NVIDIA") != -1) | |
1117 | { | |
1118 | // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) | |
1119 | // will use VIDEO memory as the source for buffer object operations. | |
3b523c4c | 1120 | ExcludeMessage (GL_DEBUG_SOURCE_API, 131185); |
c87535af | 1121 | } |
4e1523ef | 1122 | if (IsGlGreaterEqual (3, 0)) |
1123 | { | |
1124 | // retrieve auxiliary function in advance | |
1125 | FindProc ("glGetStringi", myFuncs->glGetStringi); | |
1126 | } | |
1127 | ||
d4271fe5 | 1128 | bool isCoreProfile = false; |
4e1523ef | 1129 | if (IsGlGreaterEqual (3, 2)) |
1130 | { | |
d4271fe5 | 1131 | isCoreProfile = (theIsCoreProfile == Standard_True); |
4e1523ef | 1132 | |
d4271fe5 | 1133 | // detect Core profile |
c6ad5e5f | 1134 | if (!isCoreProfile) |
4e1523ef | 1135 | { |
d4271fe5 | 1136 | GLint aProfile = 0; |
1137 | ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile); | |
1138 | isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0; | |
4e1523ef | 1139 | } |
1140 | } | |
4e1523ef | 1141 | #endif |
1142 | ||
1143 | core11 = NULL; | |
1144 | if (!isCoreProfile) | |
1145 | { | |
1146 | core11 = (OpenGl_GlCore11* )(&(*myFuncs)); | |
1147 | } | |
01ca42b2 | 1148 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); |
1149 | core15 = NULL; | |
1150 | core15fwd = NULL; | |
1151 | core20 = NULL; | |
1152 | core20fwd = NULL; | |
1153 | core32 = NULL; | |
1154 | core32back = NULL; | |
25ef750e | 1155 | core33 = NULL; |
1156 | core33back = NULL; | |
01ca42b2 | 1157 | core41 = NULL; |
1158 | core41back = NULL; | |
1159 | core42 = NULL; | |
1160 | core42back = NULL; | |
1161 | core43 = NULL; | |
1162 | core43back = NULL; | |
1163 | core44 = NULL; | |
1164 | core44back = NULL; | |
1165 | arbTBO = NULL; | |
25ef750e | 1166 | arbTboRGB32 = Standard_False; |
01ca42b2 | 1167 | arbIns = NULL; |
1168 | arbDbg = NULL; | |
1169 | arbFBO = NULL; | |
b86bb3df | 1170 | arbFBOBlit = NULL; |
01ca42b2 | 1171 | extGS = NULL; |
4e1523ef | 1172 | myDefaultVao = 0; |
01ca42b2 | 1173 | |
ca3c13d1 | 1174 | #if defined(GL_ES_VERSION_2_0) |
1175 | ||
1176 | hasTexRGBA8 = IsGlGreaterEqual (3, 0) | |
1177 | || CheckExtension ("GL_OES_rgb8_rgba8"); | |
05e2200b | 1178 | // NPOT textures has limited support within OpenGL ES 2.0 |
1179 | // which are relaxed by OpenGL ES 3.0 or some extensions | |
1180 | //arbNPTW = IsGlGreaterEqual (3, 0) | |
1181 | // || CheckExtension ("GL_OES_texture_npot") | |
1182 | // || CheckExtension ("GL_NV_texture_npot_2D_mipmap"); | |
1183 | arbNPTW = Standard_True; | |
ca3c13d1 | 1184 | arbTexRG = IsGlGreaterEqual (3, 0) |
1185 | || CheckExtension ("GL_EXT_texture_rg"); | |
1186 | extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888"); | |
1187 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
1188 | extPDS = CheckExtension ("GL_OES_packed_depth_stencil"); | |
1189 | ||
1190 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); | |
1191 | if (IsGlGreaterEqual (2, 0)) | |
1192 | { | |
1193 | // enable compatible functions | |
1194 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
1195 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); | |
1196 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); | |
b86bb3df | 1197 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
1198 | } | |
1199 | if (IsGlGreaterEqual (3, 0) | |
1200 | && FindProc ("glBlitFramebuffer", myFuncs->glBlitFramebuffer)) | |
1201 | { | |
1202 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
ca3c13d1 | 1203 | } |
1ce0716b | 1204 | extFragDepth = !IsGlGreaterEqual(3, 0) |
1205 | && CheckExtension ("GL_EXT_frag_depth"); | |
3c4b62a4 | 1206 | if (IsGlGreaterEqual (3, 1) |
1207 | && FindProc ("glTexStorage2DMultisample", myFuncs->glTexStorage2DMultisample)) | |
1208 | { | |
1209 | // MSAA RenderBuffers have been defined in OpenGL ES 3.0, | |
1210 | // but MSAA Textures - only in OpenGL ES 3.1+ | |
1211 | ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples); | |
1212 | } | |
ca3c13d1 | 1213 | |
e99a2f7c | 1214 | hasUintIndex = IsGlGreaterEqual (3, 0) |
1215 | || CheckExtension ("GL_OES_element_index_uint"); | |
1216 | hasHighp = CheckExtension ("GL_OES_fragment_precision_high"); | |
ca3c13d1 | 1217 | GLint aRange[2] = {0, 0}; |
447c4115 | 1218 | GLint aPrec = 0; |
1219 | ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec); | |
1220 | if (aPrec != 0) | |
ca3c13d1 | 1221 | { |
1222 | hasHighp = Standard_True; | |
1223 | } | |
74fb257d | 1224 | |
1225 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1226 | && FindProc ("glTexImage3D", myFuncs->glTexImage3D); | |
20aeeb7b | 1227 | |
1228 | const Standard_Boolean hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProc ("glTexBuffer", myFuncs->glTexBuffer); | |
1229 | const Standard_Boolean hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer); | |
1230 | ||
1231 | if (hasTexBuffer32 || hasExtTexBuffer) | |
1232 | { | |
1233 | arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get()); | |
1234 | } | |
0deb6f04 | 1235 | |
1236 | // initialize debug context extension | |
1237 | if (CheckExtension ("GL_KHR_debug")) | |
1238 | { | |
1239 | // this functionality become a part of OpenGL ES 3.2 | |
1240 | arbDbg = NULL; | |
1241 | // According to GL_KHR_debug spec, all functions should have KHR suffix. | |
1242 | // However, some implementations can export these functions without suffix. | |
1243 | if (FindProc ("glDebugMessageControlKHR", myFuncs->glDebugMessageControl) | |
1244 | && FindProc ("glDebugMessageInsertKHR", myFuncs->glDebugMessageInsert) | |
1245 | && FindProc ("glDebugMessageCallbackKHR", myFuncs->glDebugMessageCallback) | |
1246 | && FindProc ("glGetDebugMessageLogKHR", myFuncs->glGetDebugMessageLog)) | |
1247 | { | |
1248 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
1249 | } | |
1250 | ||
1251 | if (arbDbg != NULL | |
1252 | && caps->contextDebug) | |
1253 | { | |
1254 | // setup default callback | |
1255 | myIsGlDebugCtx = Standard_True; | |
1256 | arbDbg->glDebugMessageCallback (debugCallbackWrap, this); | |
1257 | ::glEnable (GL_DEBUG_OUTPUT); | |
1258 | if (caps->contextSyncDebug) | |
1259 | { | |
1260 | // note that some broken implementations (e.g. simulators) might generate error message on this call | |
1261 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS); | |
1262 | } | |
1263 | } | |
1264 | } | |
1265 | ||
ca3c13d1 | 1266 | #else |
1267 | ||
1268 | myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP; | |
1269 | ||
1270 | hasTexRGBA8 = Standard_True; | |
74fb257d | 1271 | arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two"); |
1272 | arbTexFloat = IsGlGreaterEqual (3, 0) | |
1273 | || CheckExtension ("GL_ARB_texture_float"); | |
1274 | extBgra = CheckExtension ("GL_EXT_bgra"); | |
1275 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
1276 | extPDS = CheckExtension ("GL_EXT_packed_depth_stencil"); | |
1277 | atiMem = CheckExtension ("GL_ATI_meminfo"); | |
1278 | nvxMem = CheckExtension ("GL_NVX_gpu_memory_info"); | |
bf75be98 | 1279 | |
ca3c13d1 | 1280 | GLint aStereo = GL_FALSE; |
b5ac8292 | 1281 | glGetIntegerv (GL_STEREO, &aStereo); |
1282 | myIsStereoBuffers = aStereo == 1; | |
1283 | ||
ca3c13d1 | 1284 | // get number of maximum clipping planes |
1285 | glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes); | |
1286 | #endif | |
1287 | ||
1288 | glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); | |
1289 | ||
bf75be98 | 1290 | if (extAnis) |
1291 | { | |
1292 | glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax); | |
1293 | } | |
f0430952 | 1294 | |
4269bd1b | 1295 | myClippingState.Init (myMaxClipPlanes); |
1296 | ||
ca3c13d1 | 1297 | #if !defined(GL_ES_VERSION_2_0) |
1298 | ||
01ca42b2 | 1299 | bool has12 = false; |
1300 | bool has13 = false; | |
1301 | bool has14 = false; | |
1302 | bool has15 = false; | |
1303 | bool has20 = false; | |
1304 | bool has21 = false; | |
1305 | bool has30 = false; | |
1306 | bool has31 = false; | |
1307 | bool has32 = false; | |
1308 | bool has33 = false; | |
1309 | bool has40 = false; | |
1310 | bool has41 = false; | |
1311 | bool has42 = false; | |
1312 | bool has43 = false; | |
1313 | bool has44 = false; | |
1314 | ||
1315 | //! Make record shorter to retrieve function pointer using variable with same name | |
1316 | #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc) | |
1317 | ||
4e1523ef | 1318 | // retrieve platform-dependent extensions |
f978241f | 1319 | #if defined(HAVE_EGL) |
1320 | // | |
1321 | #elif defined(_WIN32) | |
01ca42b2 | 1322 | if (FindProcShort (wglGetExtensionsStringARB)) |
1323 | { | |
1324 | const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC()); | |
1325 | if (CheckExtension (aWglExts, "WGL_EXT_swap_control")) | |
1326 | { | |
1327 | FindProcShort (wglSwapIntervalEXT); | |
1328 | } | |
1329 | if (CheckExtension (aWglExts, "WGL_ARB_pixel_format")) | |
1330 | { | |
1331 | FindProcShort (wglChoosePixelFormatARB); | |
1332 | } | |
1333 | if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile")) | |
1334 | { | |
1335 | FindProcShort (wglCreateContextAttribsARB); | |
1336 | } | |
1337 | if (CheckExtension (aWglExts, "WGL_NV_DX_interop")) | |
1338 | { | |
1339 | FindProcShort (wglDXSetResourceShareHandleNV); | |
1340 | FindProcShort (wglDXOpenDeviceNV); | |
1341 | FindProcShort (wglDXCloseDeviceNV); | |
1342 | FindProcShort (wglDXRegisterObjectNV); | |
1343 | FindProcShort (wglDXUnregisterObjectNV); | |
1344 | FindProcShort (wglDXObjectAccessNV); | |
1345 | FindProcShort (wglDXLockObjectsNV); | |
1346 | FindProcShort (wglDXUnlockObjectsNV); | |
1347 | } | |
1348 | } | |
f978241f | 1349 | #elif defined(__APPLE__) |
1350 | // | |
1351 | #else | |
1352 | const char* aGlxExts = ::glXQueryExtensionsString ((Display* )myDisplay, DefaultScreen ((Display* )myDisplay)); | |
1353 | if (CheckExtension (aGlxExts, "GLX_EXT_swap_control")) | |
1354 | { | |
1355 | FindProcShort (glXSwapIntervalEXT); | |
1356 | } | |
1357 | if (CheckExtension (aGlxExts, "GLX_SGI_swap_control")) | |
1358 | { | |
1359 | FindProcShort (glXSwapIntervalSGI); | |
1360 | } | |
26d9c835 | 1361 | if (CheckExtension (aGlxExts, "GLX_MESA_query_renderer")) |
1362 | { | |
1363 | FindProcShort (glXQueryRendererIntegerMESA); | |
1364 | FindProcShort (glXQueryCurrentRendererIntegerMESA); | |
1365 | FindProcShort (glXQueryRendererStringMESA); | |
1366 | FindProcShort (glXQueryCurrentRendererStringMESA); | |
1367 | } | |
f978241f | 1368 | //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear"); |
01ca42b2 | 1369 | #endif |
1370 | ||
01ca42b2 | 1371 | // load OpenGL 1.2 new functions |
1372 | has12 = IsGlGreaterEqual (1, 2) | |
1373 | && FindProcShort (glBlendColor) | |
1374 | && FindProcShort (glBlendEquation) | |
1375 | && FindProcShort (glDrawRangeElements) | |
1376 | && FindProcShort (glTexImage3D) | |
1377 | && FindProcShort (glTexSubImage3D) | |
1378 | && FindProcShort (glCopyTexSubImage3D); | |
1379 | ||
1380 | // load OpenGL 1.3 new functions | |
1381 | has13 = IsGlGreaterEqual (1, 3) | |
1382 | && FindProcShort (glActiveTexture) | |
1383 | && FindProcShort (glSampleCoverage) | |
1384 | && FindProcShort (glCompressedTexImage3D) | |
1385 | && FindProcShort (glCompressedTexImage2D) | |
1386 | && FindProcShort (glCompressedTexImage1D) | |
1387 | && FindProcShort (glCompressedTexSubImage3D) | |
1388 | && FindProcShort (glCompressedTexSubImage2D) | |
1389 | && FindProcShort (glCompressedTexSubImage1D) | |
4e1523ef | 1390 | && FindProcShort (glGetCompressedTexImage); |
1391 | ||
1392 | if (!isCoreProfile) | |
1393 | { | |
1394 | has13 = has13 | |
01ca42b2 | 1395 | && FindProcShort (glClientActiveTexture) |
1396 | && FindProcShort (glMultiTexCoord1d) | |
1397 | && FindProcShort (glMultiTexCoord1dv) | |
1398 | && FindProcShort (glMultiTexCoord1f) | |
1399 | && FindProcShort (glMultiTexCoord1fv) | |
1400 | && FindProcShort (glMultiTexCoord1i) | |
1401 | && FindProcShort (glMultiTexCoord1iv) | |
1402 | && FindProcShort (glMultiTexCoord1s) | |
1403 | && FindProcShort (glMultiTexCoord1sv) | |
1404 | && FindProcShort (glMultiTexCoord2d) | |
1405 | && FindProcShort (glMultiTexCoord2dv) | |
1406 | && FindProcShort (glMultiTexCoord2f) | |
1407 | && FindProcShort (glMultiTexCoord2fv) | |
1408 | && FindProcShort (glMultiTexCoord2i) | |
1409 | && FindProcShort (glMultiTexCoord2iv) | |
1410 | && FindProcShort (glMultiTexCoord2s) | |
1411 | && FindProcShort (glMultiTexCoord2sv) | |
1412 | && FindProcShort (glMultiTexCoord3d) | |
1413 | && FindProcShort (glMultiTexCoord3dv) | |
1414 | && FindProcShort (glMultiTexCoord3f) | |
1415 | && FindProcShort (glMultiTexCoord3fv) | |
1416 | && FindProcShort (glMultiTexCoord3i) | |
1417 | && FindProcShort (glMultiTexCoord3iv) | |
1418 | && FindProcShort (glMultiTexCoord3s) | |
1419 | && FindProcShort (glMultiTexCoord3sv) | |
1420 | && FindProcShort (glMultiTexCoord4d) | |
1421 | && FindProcShort (glMultiTexCoord4dv) | |
1422 | && FindProcShort (glMultiTexCoord4f) | |
1423 | && FindProcShort (glMultiTexCoord4fv) | |
1424 | && FindProcShort (glMultiTexCoord4i) | |
1425 | && FindProcShort (glMultiTexCoord4iv) | |
1426 | && FindProcShort (glMultiTexCoord4s) | |
1427 | && FindProcShort (glMultiTexCoord4sv) | |
1428 | && FindProcShort (glLoadTransposeMatrixf) | |
1429 | && FindProcShort (glLoadTransposeMatrixd) | |
1430 | && FindProcShort (glMultTransposeMatrixf) | |
1431 | && FindProcShort (glMultTransposeMatrixd); | |
4e1523ef | 1432 | } |
01ca42b2 | 1433 | |
1434 | // load OpenGL 1.4 new functions | |
1435 | has14 = IsGlGreaterEqual (1, 4) | |
1436 | && FindProcShort (glBlendFuncSeparate) | |
1437 | && FindProcShort (glMultiDrawArrays) | |
1438 | && FindProcShort (glMultiDrawElements) | |
1439 | && FindProcShort (glPointParameterf) | |
1440 | && FindProcShort (glPointParameterfv) | |
1441 | && FindProcShort (glPointParameteri) | |
1442 | && FindProcShort (glPointParameteriv); | |
1443 | ||
1444 | // load OpenGL 1.5 new functions | |
1445 | has15 = IsGlGreaterEqual (1, 5) | |
1446 | && FindProcShort (glGenQueries) | |
1447 | && FindProcShort (glDeleteQueries) | |
1448 | && FindProcShort (glIsQuery) | |
1449 | && FindProcShort (glBeginQuery) | |
1450 | && FindProcShort (glEndQuery) | |
1451 | && FindProcShort (glGetQueryiv) | |
1452 | && FindProcShort (glGetQueryObjectiv) | |
1453 | && FindProcShort (glGetQueryObjectuiv) | |
1454 | && FindProcShort (glBindBuffer) | |
1455 | && FindProcShort (glDeleteBuffers) | |
1456 | && FindProcShort (glGenBuffers) | |
1457 | && FindProcShort (glIsBuffer) | |
1458 | && FindProcShort (glBufferData) | |
1459 | && FindProcShort (glBufferSubData) | |
1460 | && FindProcShort (glGetBufferSubData) | |
1461 | && FindProcShort (glMapBuffer) | |
1462 | && FindProcShort (glUnmapBuffer) | |
1463 | && FindProcShort (glGetBufferParameteriv) | |
1464 | && FindProcShort (glGetBufferPointerv); | |
1465 | ||
1466 | // load OpenGL 2.0 new functions | |
1467 | has20 = IsGlGreaterEqual (2, 0) | |
1468 | && FindProcShort (glBlendEquationSeparate) | |
1469 | && FindProcShort (glDrawBuffers) | |
1470 | && FindProcShort (glStencilOpSeparate) | |
1471 | && FindProcShort (glStencilFuncSeparate) | |
1472 | && FindProcShort (glStencilMaskSeparate) | |
1473 | && FindProcShort (glAttachShader) | |
1474 | && FindProcShort (glBindAttribLocation) | |
1475 | && FindProcShort (glCompileShader) | |
1476 | && FindProcShort (glCreateProgram) | |
1477 | && FindProcShort (glCreateShader) | |
1478 | && FindProcShort (glDeleteProgram) | |
1479 | && FindProcShort (glDeleteShader) | |
1480 | && FindProcShort (glDetachShader) | |
1481 | && FindProcShort (glDisableVertexAttribArray) | |
1482 | && FindProcShort (glEnableVertexAttribArray) | |
1483 | && FindProcShort (glGetActiveAttrib) | |
1484 | && FindProcShort (glGetActiveUniform) | |
1485 | && FindProcShort (glGetAttachedShaders) | |
1486 | && FindProcShort (glGetAttribLocation) | |
1487 | && FindProcShort (glGetProgramiv) | |
1488 | && FindProcShort (glGetProgramInfoLog) | |
1489 | && FindProcShort (glGetShaderiv) | |
1490 | && FindProcShort (glGetShaderInfoLog) | |
1491 | && FindProcShort (glGetShaderSource) | |
1492 | && FindProcShort (glGetUniformLocation) | |
1493 | && FindProcShort (glGetUniformfv) | |
1494 | && FindProcShort (glGetUniformiv) | |
1495 | && FindProcShort (glGetVertexAttribdv) | |
1496 | && FindProcShort (glGetVertexAttribfv) | |
1497 | && FindProcShort (glGetVertexAttribiv) | |
1498 | && FindProcShort (glGetVertexAttribPointerv) | |
1499 | && FindProcShort (glIsProgram) | |
1500 | && FindProcShort (glIsShader) | |
1501 | && FindProcShort (glLinkProgram) | |
1502 | && FindProcShort (glShaderSource) | |
1503 | && FindProcShort (glUseProgram) | |
1504 | && FindProcShort (glUniform1f) | |
1505 | && FindProcShort (glUniform2f) | |
1506 | && FindProcShort (glUniform3f) | |
1507 | && FindProcShort (glUniform4f) | |
1508 | && FindProcShort (glUniform1i) | |
1509 | && FindProcShort (glUniform2i) | |
1510 | && FindProcShort (glUniform3i) | |
1511 | && FindProcShort (glUniform4i) | |
1512 | && FindProcShort (glUniform1fv) | |
1513 | && FindProcShort (glUniform2fv) | |
1514 | && FindProcShort (glUniform3fv) | |
1515 | && FindProcShort (glUniform4fv) | |
1516 | && FindProcShort (glUniform1iv) | |
1517 | && FindProcShort (glUniform2iv) | |
1518 | && FindProcShort (glUniform3iv) | |
1519 | && FindProcShort (glUniform4iv) | |
1520 | && FindProcShort (glUniformMatrix2fv) | |
1521 | && FindProcShort (glUniformMatrix3fv) | |
1522 | && FindProcShort (glUniformMatrix4fv) | |
1523 | && FindProcShort (glValidateProgram) | |
1524 | && FindProcShort (glVertexAttrib1d) | |
1525 | && FindProcShort (glVertexAttrib1dv) | |
1526 | && FindProcShort (glVertexAttrib1f) | |
1527 | && FindProcShort (glVertexAttrib1fv) | |
1528 | && FindProcShort (glVertexAttrib1s) | |
1529 | && FindProcShort (glVertexAttrib1sv) | |
1530 | && FindProcShort (glVertexAttrib2d) | |
1531 | && FindProcShort (glVertexAttrib2dv) | |
1532 | && FindProcShort (glVertexAttrib2f) | |
1533 | && FindProcShort (glVertexAttrib2fv) | |
1534 | && FindProcShort (glVertexAttrib2s) | |
1535 | && FindProcShort (glVertexAttrib2sv) | |
1536 | && FindProcShort (glVertexAttrib3d) | |
1537 | && FindProcShort (glVertexAttrib3dv) | |
1538 | && FindProcShort (glVertexAttrib3f) | |
1539 | && FindProcShort (glVertexAttrib3fv) | |
1540 | && FindProcShort (glVertexAttrib3s) | |
1541 | && FindProcShort (glVertexAttrib3sv) | |
1542 | && FindProcShort (glVertexAttrib4Nbv) | |
1543 | && FindProcShort (glVertexAttrib4Niv) | |
1544 | && FindProcShort (glVertexAttrib4Nsv) | |
1545 | && FindProcShort (glVertexAttrib4Nub) | |
1546 | && FindProcShort (glVertexAttrib4Nubv) | |
1547 | && FindProcShort (glVertexAttrib4Nuiv) | |
1548 | && FindProcShort (glVertexAttrib4Nusv) | |
1549 | && FindProcShort (glVertexAttrib4bv) | |
1550 | && FindProcShort (glVertexAttrib4d) | |
1551 | && FindProcShort (glVertexAttrib4dv) | |
1552 | && FindProcShort (glVertexAttrib4f) | |
1553 | && FindProcShort (glVertexAttrib4fv) | |
1554 | && FindProcShort (glVertexAttrib4iv) | |
1555 | && FindProcShort (glVertexAttrib4s) | |
1556 | && FindProcShort (glVertexAttrib4sv) | |
1557 | && FindProcShort (glVertexAttrib4ubv) | |
1558 | && FindProcShort (glVertexAttrib4uiv) | |
1559 | && FindProcShort (glVertexAttrib4usv) | |
1560 | && FindProcShort (glVertexAttribPointer); | |
1561 | ||
1562 | // load OpenGL 2.1 new functions | |
1563 | has21 = IsGlGreaterEqual (2, 1) | |
1564 | && FindProcShort (glUniformMatrix2x3fv) | |
1565 | && FindProcShort (glUniformMatrix3x2fv) | |
1566 | && FindProcShort (glUniformMatrix2x4fv) | |
1567 | && FindProcShort (glUniformMatrix4x2fv) | |
1568 | && FindProcShort (glUniformMatrix3x4fv) | |
1569 | && FindProcShort (glUniformMatrix4x3fv); | |
1570 | ||
1571 | // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core) | |
1572 | const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object")) | |
1573 | && FindProcShort (glIsRenderbuffer) | |
1574 | && FindProcShort (glBindRenderbuffer) | |
1575 | && FindProcShort (glDeleteRenderbuffers) | |
1576 | && FindProcShort (glGenRenderbuffers) | |
1577 | && FindProcShort (glRenderbufferStorage) | |
1578 | && FindProcShort (glGetRenderbufferParameteriv) | |
1579 | && FindProcShort (glIsFramebuffer) | |
1580 | && FindProcShort (glBindFramebuffer) | |
1581 | && FindProcShort (glDeleteFramebuffers) | |
1582 | && FindProcShort (glGenFramebuffers) | |
1583 | && FindProcShort (glCheckFramebufferStatus) | |
1584 | && FindProcShort (glFramebufferTexture1D) | |
1585 | && FindProcShort (glFramebufferTexture2D) | |
1586 | && FindProcShort (glFramebufferTexture3D) | |
1587 | && FindProcShort (glFramebufferRenderbuffer) | |
1588 | && FindProcShort (glGetFramebufferAttachmentParameteriv) | |
1589 | && FindProcShort (glGenerateMipmap) | |
1590 | && FindProcShort (glBlitFramebuffer) | |
1591 | && FindProcShort (glRenderbufferStorageMultisample) | |
1592 | && FindProcShort (glFramebufferTextureLayer); | |
1593 | ||
1594 | // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core) | |
1595 | const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object")) | |
1596 | && FindProcShort (glBindVertexArray) | |
1597 | && FindProcShort (glDeleteVertexArrays) | |
1598 | && FindProcShort (glGenVertexArrays) | |
1599 | && FindProcShort (glIsVertexArray); | |
1600 | ||
1601 | // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core) | |
1602 | const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range")) | |
1603 | && FindProcShort (glMapBufferRange) | |
1604 | && FindProcShort (glFlushMappedBufferRange); | |
1605 | ||
1606 | // load OpenGL 3.0 new functions | |
1607 | has30 = IsGlGreaterEqual (3, 0) | |
1608 | && hasFBO | |
1609 | && hasVAO | |
1610 | && hasMapBufferRange | |
1611 | && FindProcShort (glColorMaski) | |
1612 | && FindProcShort (glGetBooleani_v) | |
1613 | && FindProcShort (glGetIntegeri_v) | |
1614 | && FindProcShort (glEnablei) | |
1615 | && FindProcShort (glDisablei) | |
1616 | && FindProcShort (glIsEnabledi) | |
1617 | && FindProcShort (glBeginTransformFeedback) | |
1618 | && FindProcShort (glEndTransformFeedback) | |
1619 | && FindProcShort (glBindBufferRange) | |
1620 | && FindProcShort (glBindBufferBase) | |
1621 | && FindProcShort (glTransformFeedbackVaryings) | |
1622 | && FindProcShort (glGetTransformFeedbackVarying) | |
1623 | && FindProcShort (glClampColor) | |
1624 | && FindProcShort (glBeginConditionalRender) | |
1625 | && FindProcShort (glEndConditionalRender) | |
1626 | && FindProcShort (glVertexAttribIPointer) | |
1627 | && FindProcShort (glGetVertexAttribIiv) | |
1628 | && FindProcShort (glGetVertexAttribIuiv) | |
1629 | && FindProcShort (glVertexAttribI1i) | |
1630 | && FindProcShort (glVertexAttribI2i) | |
1631 | && FindProcShort (glVertexAttribI3i) | |
1632 | && FindProcShort (glVertexAttribI4i) | |
1633 | && FindProcShort (glVertexAttribI1ui) | |
1634 | && FindProcShort (glVertexAttribI2ui) | |
1635 | && FindProcShort (glVertexAttribI3ui) | |
1636 | && FindProcShort (glVertexAttribI4ui) | |
1637 | && FindProcShort (glVertexAttribI1iv) | |
1638 | && FindProcShort (glVertexAttribI2iv) | |
1639 | && FindProcShort (glVertexAttribI3iv) | |
1640 | && FindProcShort (glVertexAttribI4iv) | |
1641 | && FindProcShort (glVertexAttribI1uiv) | |
1642 | && FindProcShort (glVertexAttribI2uiv) | |
1643 | && FindProcShort (glVertexAttribI3uiv) | |
1644 | && FindProcShort (glVertexAttribI4uiv) | |
1645 | && FindProcShort (glVertexAttribI4bv) | |
1646 | && FindProcShort (glVertexAttribI4sv) | |
1647 | && FindProcShort (glVertexAttribI4ubv) | |
1648 | && FindProcShort (glVertexAttribI4usv) | |
1649 | && FindProcShort (glGetUniformuiv) | |
1650 | && FindProcShort (glBindFragDataLocation) | |
1651 | && FindProcShort (glGetFragDataLocation) | |
1652 | && FindProcShort (glUniform1ui) | |
1653 | && FindProcShort (glUniform2ui) | |
1654 | && FindProcShort (glUniform3ui) | |
1655 | && FindProcShort (glUniform4ui) | |
1656 | && FindProcShort (glUniform1uiv) | |
1657 | && FindProcShort (glUniform2uiv) | |
1658 | && FindProcShort (glUniform3uiv) | |
1659 | && FindProcShort (glUniform4uiv) | |
1660 | && FindProcShort (glTexParameterIiv) | |
1661 | && FindProcShort (glTexParameterIuiv) | |
1662 | && FindProcShort (glGetTexParameterIiv) | |
1663 | && FindProcShort (glGetTexParameterIuiv) | |
1664 | && FindProcShort (glClearBufferiv) | |
1665 | && FindProcShort (glClearBufferuiv) | |
1666 | && FindProcShort (glClearBufferfv) | |
1667 | && FindProcShort (glClearBufferfi) | |
1668 | && FindProcShort (glGetStringi); | |
1669 | ||
1670 | // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core) | |
1671 | const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object")) | |
1672 | && FindProcShort (glGetUniformIndices) | |
1673 | && FindProcShort (glGetActiveUniformsiv) | |
1674 | && FindProcShort (glGetActiveUniformName) | |
1675 | && FindProcShort (glGetUniformBlockIndex) | |
1676 | && FindProcShort (glGetActiveUniformBlockiv) | |
1677 | && FindProcShort (glGetActiveUniformBlockName) | |
1678 | && FindProcShort (glUniformBlockBinding); | |
1679 | ||
1680 | // load GL_ARB_copy_buffer (added to OpenGL 3.1 core) | |
1681 | const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer")) | |
1682 | && FindProcShort (glCopyBufferSubData); | |
1683 | ||
1684 | if (has30) | |
2166f0fa | 1685 | { |
01ca42b2 | 1686 | // NPOT textures are required by OpenGL 2.0 specifications |
1687 | // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.) | |
1688 | arbNPTW = Standard_True; | |
1689 | arbTexRG = Standard_True; | |
2166f0fa SK |
1690 | } |
1691 | ||
01ca42b2 | 1692 | // load OpenGL 3.1 new functions |
1693 | has31 = IsGlGreaterEqual (3, 1) | |
1694 | && hasUBO | |
1695 | && hasCopyBufSubData | |
1696 | && FindProcShort (glDrawArraysInstanced) | |
1697 | && FindProcShort (glDrawElementsInstanced) | |
1698 | && FindProcShort (glTexBuffer) | |
1699 | && FindProcShort (glPrimitiveRestartIndex); | |
1700 | ||
1701 | // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core) | |
1702 | const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex")) | |
1703 | && FindProcShort (glDrawElementsBaseVertex) | |
1704 | && FindProcShort (glDrawRangeElementsBaseVertex) | |
1705 | && FindProcShort (glDrawElementsInstancedBaseVertex) | |
1706 | && FindProcShort (glMultiDrawElementsBaseVertex); | |
1707 | ||
1708 | // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core) | |
1709 | const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex")) | |
1710 | && FindProcShort (glProvokingVertex); | |
1711 | ||
1712 | // load GL_ARB_sync (added to OpenGL 3.2 core) | |
1713 | const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync")) | |
1714 | && FindProcShort (glFenceSync) | |
1715 | && FindProcShort (glIsSync) | |
1716 | && FindProcShort (glDeleteSync) | |
1717 | && FindProcShort (glClientWaitSync) | |
1718 | && FindProcShort (glWaitSync) | |
1719 | && FindProcShort (glGetInteger64v) | |
1720 | && FindProcShort (glGetSynciv); | |
1721 | ||
1722 | // load GL_ARB_texture_multisample (added to OpenGL 3.2 core) | |
1723 | const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample")) | |
1724 | && FindProcShort (glTexImage2DMultisample) | |
1725 | && FindProcShort (glTexImage3DMultisample) | |
1726 | && FindProcShort (glGetMultisamplefv) | |
1727 | && FindProcShort (glSampleMaski); | |
1728 | ||
1729 | // load OpenGL 3.2 new functions | |
1730 | has32 = IsGlGreaterEqual (3, 2) | |
1731 | && hasDrawElemsBaseVert | |
1732 | && hasProvokingVert | |
1733 | && hasSync | |
1734 | && hasTextureMultisample | |
1735 | && FindProcShort (glGetInteger64i_v) | |
1736 | && FindProcShort (glGetBufferParameteri64v) | |
1737 | && FindProcShort (glFramebufferTexture); | |
1738 | ||
1739 | // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core) | |
1740 | const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended")) | |
1741 | && FindProcShort (glBindFragDataLocationIndexed) | |
1742 | && FindProcShort (glGetFragDataIndex); | |
1743 | ||
1744 | // load GL_ARB_sampler_objects (added to OpenGL 3.3 core) | |
1745 | const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects")) | |
1746 | && FindProcShort (glGenSamplers) | |
1747 | && FindProcShort (glDeleteSamplers) | |
1748 | && FindProcShort (glIsSampler) | |
1749 | && FindProcShort (glBindSampler) | |
1750 | && FindProcShort (glSamplerParameteri) | |
1751 | && FindProcShort (glSamplerParameteriv) | |
1752 | && FindProcShort (glSamplerParameterf) | |
1753 | && FindProcShort (glSamplerParameterfv) | |
1754 | && FindProcShort (glSamplerParameterIiv) | |
1755 | && FindProcShort (glSamplerParameterIuiv) | |
1756 | && FindProcShort (glGetSamplerParameteriv) | |
1757 | && FindProcShort (glGetSamplerParameterIiv) | |
1758 | && FindProcShort (glGetSamplerParameterfv) | |
1759 | && FindProcShort (glGetSamplerParameterIuiv); | |
1760 | ||
1761 | // load GL_ARB_timer_query (added to OpenGL 3.3 core) | |
1762 | const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query")) | |
1763 | && FindProcShort (glQueryCounter) | |
1764 | && FindProcShort (glGetQueryObjecti64v) | |
1765 | && FindProcShort (glGetQueryObjectui64v); | |
1766 | ||
1767 | // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core) | |
1768 | const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev")) | |
0e628baf | 1769 | && FindProcShort (glVertexAttribP1ui) |
1770 | && FindProcShort (glVertexAttribP1uiv) | |
1771 | && FindProcShort (glVertexAttribP2ui) | |
1772 | && FindProcShort (glVertexAttribP2uiv) | |
1773 | && FindProcShort (glVertexAttribP3ui) | |
1774 | && FindProcShort (glVertexAttribP3uiv) | |
1775 | && FindProcShort (glVertexAttribP4ui) | |
1776 | && FindProcShort (glVertexAttribP4uiv); | |
1777 | ||
1778 | if ( hasVertType21010101rev | |
1779 | && !isCoreProfile) | |
1780 | { | |
1781 | // load deprecated functions | |
1782 | const bool hasVertType21010101revExt = | |
1783 | FindProcShort (glVertexP2ui) | |
01ca42b2 | 1784 | && FindProcShort (glVertexP2uiv) |
1785 | && FindProcShort (glVertexP3ui) | |
1786 | && FindProcShort (glVertexP3uiv) | |
1787 | && FindProcShort (glVertexP4ui) | |
1788 | && FindProcShort (glVertexP4uiv) | |
1789 | && FindProcShort (glTexCoordP1ui) | |
1790 | && FindProcShort (glTexCoordP1uiv) | |
1791 | && FindProcShort (glTexCoordP2ui) | |
1792 | && FindProcShort (glTexCoordP2uiv) | |
1793 | && FindProcShort (glTexCoordP3ui) | |
1794 | && FindProcShort (glTexCoordP3uiv) | |
1795 | && FindProcShort (glTexCoordP4ui) | |
1796 | && FindProcShort (glTexCoordP4uiv) | |
1797 | && FindProcShort (glMultiTexCoordP1ui) | |
1798 | && FindProcShort (glMultiTexCoordP1uiv) | |
1799 | && FindProcShort (glMultiTexCoordP2ui) | |
1800 | && FindProcShort (glMultiTexCoordP2uiv) | |
1801 | && FindProcShort (glMultiTexCoordP3ui) | |
1802 | && FindProcShort (glMultiTexCoordP3uiv) | |
1803 | && FindProcShort (glMultiTexCoordP4ui) | |
1804 | && FindProcShort (glMultiTexCoordP4uiv) | |
1805 | && FindProcShort (glNormalP3ui) | |
1806 | && FindProcShort (glNormalP3uiv) | |
1807 | && FindProcShort (glColorP3ui) | |
1808 | && FindProcShort (glColorP3uiv) | |
1809 | && FindProcShort (glColorP4ui) | |
1810 | && FindProcShort (glColorP4uiv) | |
1811 | && FindProcShort (glSecondaryColorP3ui) | |
0e628baf | 1812 | && FindProcShort (glSecondaryColorP3uiv); |
1813 | (void )hasVertType21010101revExt; | |
1814 | } | |
01ca42b2 | 1815 | |
1816 | // load OpenGL 3.3 extra functions | |
1817 | has33 = IsGlGreaterEqual (3, 3) | |
1818 | && hasBlendFuncExtended | |
1819 | && hasSamplerObjects | |
1820 | && hasTimerQuery | |
1821 | && hasVertType21010101rev | |
1822 | && FindProcShort (glVertexAttribDivisor); | |
1823 | ||
1824 | // load GL_ARB_draw_indirect (added to OpenGL 4.0 core) | |
1825 | const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect")) | |
1826 | && FindProcShort (glDrawArraysIndirect) | |
1827 | && FindProcShort (glDrawElementsIndirect); | |
1828 | ||
1829 | // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core) | |
1830 | const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64")) | |
1831 | && FindProcShort (glUniform1d) | |
1832 | && FindProcShort (glUniform2d) | |
1833 | && FindProcShort (glUniform3d) | |
1834 | && FindProcShort (glUniform4d) | |
1835 | && FindProcShort (glUniform1dv) | |
1836 | && FindProcShort (glUniform2dv) | |
1837 | && FindProcShort (glUniform3dv) | |
1838 | && FindProcShort (glUniform4dv) | |
1839 | && FindProcShort (glUniformMatrix2dv) | |
1840 | && FindProcShort (glUniformMatrix3dv) | |
1841 | && FindProcShort (glUniformMatrix4dv) | |
1842 | && FindProcShort (glUniformMatrix2x3dv) | |
1843 | && FindProcShort (glUniformMatrix2x4dv) | |
1844 | && FindProcShort (glUniformMatrix3x2dv) | |
1845 | && FindProcShort (glUniformMatrix3x4dv) | |
1846 | && FindProcShort (glUniformMatrix4x2dv) | |
1847 | && FindProcShort (glUniformMatrix4x3dv) | |
1848 | && FindProcShort (glGetUniformdv); | |
1849 | ||
1850 | // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core) | |
1851 | const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine")) | |
1852 | && FindProcShort (glGetSubroutineUniformLocation) | |
1853 | && FindProcShort (glGetSubroutineIndex) | |
1854 | && FindProcShort (glGetActiveSubroutineUniformiv) | |
1855 | && FindProcShort (glGetActiveSubroutineUniformName) | |
1856 | && FindProcShort (glGetActiveSubroutineName) | |
1857 | && FindProcShort (glUniformSubroutinesuiv) | |
1858 | && FindProcShort (glGetUniformSubroutineuiv) | |
1859 | && FindProcShort (glGetProgramStageiv); | |
1860 | ||
1861 | // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core) | |
1862 | const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader")) | |
1863 | && FindProcShort (glPatchParameteri) | |
1864 | && FindProcShort (glPatchParameterfv); | |
1865 | ||
1866 | // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core) | |
1867 | const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2")) | |
1868 | && FindProcShort (glBindTransformFeedback) | |
1869 | && FindProcShort (glDeleteTransformFeedbacks) | |
1870 | && FindProcShort (glGenTransformFeedbacks) | |
1871 | && FindProcShort (glIsTransformFeedback) | |
1872 | && FindProcShort (glPauseTransformFeedback) | |
1873 | && FindProcShort (glResumeTransformFeedback) | |
1874 | && FindProcShort (glDrawTransformFeedback); | |
1875 | ||
1876 | // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core) | |
1877 | const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3")) | |
1878 | && FindProcShort (glDrawTransformFeedbackStream) | |
1879 | && FindProcShort (glBeginQueryIndexed) | |
1880 | && FindProcShort (glEndQueryIndexed) | |
1881 | && FindProcShort (glGetQueryIndexediv); | |
1882 | ||
1883 | // load OpenGL 4.0 new functions | |
1884 | has40 = IsGlGreaterEqual (4, 0) | |
1885 | && hasDrawIndirect | |
1886 | && hasShaderFP64 | |
1887 | && hasShaderSubroutine | |
1888 | && hasTessellationShader | |
1889 | && hasTrsfFeedback2 | |
1890 | && hasTrsfFeedback3 | |
1891 | && FindProcShort (glMinSampleShading) | |
1892 | && FindProcShort (glBlendEquationi) | |
1893 | && FindProcShort (glBlendEquationSeparatei) | |
1894 | && FindProcShort (glBlendFunci) | |
1895 | && FindProcShort (glBlendFuncSeparatei); | |
1896 | ||
1897 | // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core) | |
1898 | const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility")) | |
1899 | && FindProcShort (glReleaseShaderCompiler) | |
1900 | && FindProcShort (glShaderBinary) | |
1901 | && FindProcShort (glGetShaderPrecisionFormat) | |
1902 | && FindProcShort (glDepthRangef) | |
1903 | && FindProcShort (glClearDepthf); | |
1904 | ||
1905 | // load GL_ARB_get_program_binary (added to OpenGL 4.1 core) | |
1906 | const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary")) | |
1907 | && FindProcShort (glGetProgramBinary) | |
1908 | && FindProcShort (glProgramBinary) | |
1909 | && FindProcShort (glProgramParameteri); | |
1910 | ||
1911 | ||
1912 | // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core) | |
1913 | const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects")) | |
1914 | && FindProcShort (glUseProgramStages) | |
1915 | && FindProcShort (glActiveShaderProgram) | |
1916 | && FindProcShort (glCreateShaderProgramv) | |
1917 | && FindProcShort (glBindProgramPipeline) | |
1918 | && FindProcShort (glDeleteProgramPipelines) | |
1919 | && FindProcShort (glGenProgramPipelines) | |
1920 | && FindProcShort (glIsProgramPipeline) | |
1921 | && FindProcShort (glGetProgramPipelineiv) | |
1922 | && FindProcShort (glProgramUniform1i) | |
1923 | && FindProcShort (glProgramUniform1iv) | |
1924 | && FindProcShort (glProgramUniform1f) | |
1925 | && FindProcShort (glProgramUniform1fv) | |
1926 | && FindProcShort (glProgramUniform1d) | |
1927 | && FindProcShort (glProgramUniform1dv) | |
1928 | && FindProcShort (glProgramUniform1ui) | |
1929 | && FindProcShort (glProgramUniform1uiv) | |
1930 | && FindProcShort (glProgramUniform2i) | |
1931 | && FindProcShort (glProgramUniform2iv) | |
1932 | && FindProcShort (glProgramUniform2f) | |
1933 | && FindProcShort (glProgramUniform2fv) | |
1934 | && FindProcShort (glProgramUniform2d) | |
1935 | && FindProcShort (glProgramUniform2dv) | |
1936 | && FindProcShort (glProgramUniform2ui) | |
1937 | && FindProcShort (glProgramUniform2uiv) | |
1938 | && FindProcShort (glProgramUniform3i) | |
1939 | && FindProcShort (glProgramUniform3iv) | |
1940 | && FindProcShort (glProgramUniform3f) | |
1941 | && FindProcShort (glProgramUniform3fv) | |
1942 | && FindProcShort (glProgramUniform3d) | |
1943 | && FindProcShort (glProgramUniform3dv) | |
1944 | && FindProcShort (glProgramUniform3ui) | |
1945 | && FindProcShort (glProgramUniform3uiv) | |
1946 | && FindProcShort (glProgramUniform4i) | |
1947 | && FindProcShort (glProgramUniform4iv) | |
1948 | && FindProcShort (glProgramUniform4f) | |
1949 | && FindProcShort (glProgramUniform4fv) | |
1950 | && FindProcShort (glProgramUniform4d) | |
1951 | && FindProcShort (glProgramUniform4dv) | |
1952 | && FindProcShort (glProgramUniform4ui) | |
1953 | && FindProcShort (glProgramUniform4uiv) | |
1954 | && FindProcShort (glProgramUniformMatrix2fv) | |
1955 | && FindProcShort (glProgramUniformMatrix3fv) | |
1956 | && FindProcShort (glProgramUniformMatrix4fv) | |
1957 | && FindProcShort (glProgramUniformMatrix2dv) | |
1958 | && FindProcShort (glProgramUniformMatrix3dv) | |
1959 | && FindProcShort (glProgramUniformMatrix4dv) | |
1960 | && FindProcShort (glProgramUniformMatrix2x3fv) | |
1961 | && FindProcShort (glProgramUniformMatrix3x2fv) | |
1962 | && FindProcShort (glProgramUniformMatrix2x4fv) | |
1963 | && FindProcShort (glProgramUniformMatrix4x2fv) | |
1964 | && FindProcShort (glProgramUniformMatrix3x4fv) | |
1965 | && FindProcShort (glProgramUniformMatrix4x3fv) | |
1966 | && FindProcShort (glProgramUniformMatrix2x3dv) | |
1967 | && FindProcShort (glProgramUniformMatrix3x2dv) | |
1968 | && FindProcShort (glProgramUniformMatrix2x4dv) | |
1969 | && FindProcShort (glProgramUniformMatrix4x2dv) | |
1970 | && FindProcShort (glProgramUniformMatrix3x4dv) | |
1971 | && FindProcShort (glProgramUniformMatrix4x3dv) | |
1972 | && FindProcShort (glValidateProgramPipeline) | |
1973 | && FindProcShort (glGetProgramPipelineInfoLog); | |
1974 | ||
1975 | // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core) | |
1976 | const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit")) | |
1977 | && FindProcShort (glVertexAttribL1d) | |
1978 | && FindProcShort (glVertexAttribL2d) | |
1979 | && FindProcShort (glVertexAttribL3d) | |
1980 | && FindProcShort (glVertexAttribL4d) | |
1981 | && FindProcShort (glVertexAttribL1dv) | |
1982 | && FindProcShort (glVertexAttribL2dv) | |
1983 | && FindProcShort (glVertexAttribL3dv) | |
1984 | && FindProcShort (glVertexAttribL4dv) | |
1985 | && FindProcShort (glVertexAttribLPointer) | |
1986 | && FindProcShort (glGetVertexAttribLdv); | |
1987 | ||
1988 | // load GL_ARB_viewport_array (added to OpenGL 4.1 core) | |
1989 | const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array")) | |
1990 | && FindProcShort (glViewportArrayv) | |
1991 | && FindProcShort (glViewportIndexedf) | |
1992 | && FindProcShort (glViewportIndexedfv) | |
1993 | && FindProcShort (glScissorArrayv) | |
1994 | && FindProcShort (glScissorIndexed) | |
1995 | && FindProcShort (glScissorIndexedv) | |
1996 | && FindProcShort (glDepthRangeArrayv) | |
1997 | && FindProcShort (glDepthRangeIndexed) | |
1998 | && FindProcShort (glGetFloati_v) | |
1999 | && FindProcShort (glGetDoublei_v); | |
2000 | ||
2001 | has41 = IsGlGreaterEqual (4, 1) | |
2002 | && hasES2Compatibility | |
2003 | && hasGetProgramBinary | |
2004 | && hasSeparateShaderObjects | |
2005 | && hasVertAttrib64bit | |
2006 | && hasViewportArray; | |
2007 | ||
2008 | // load GL_ARB_base_instance (added to OpenGL 4.2 core) | |
2009 | const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance")) | |
2010 | && FindProcShort (glDrawArraysInstancedBaseInstance) | |
2011 | && FindProcShort (glDrawElementsInstancedBaseInstance) | |
2012 | && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance); | |
2013 | ||
2014 | // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core) | |
2015 | const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced")) | |
2016 | && FindProcShort (glDrawTransformFeedbackInstanced) | |
2017 | && FindProcShort (glDrawTransformFeedbackStreamInstanced); | |
2018 | ||
2019 | // load GL_ARB_internalformat_query (added to OpenGL 4.2 core) | |
2020 | const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query")) | |
2021 | && FindProcShort (glGetInternalformativ); | |
2022 | ||
2023 | // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core) | |
2024 | const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters")) | |
2025 | && FindProcShort (glGetActiveAtomicCounterBufferiv); | |
2026 | ||
2027 | // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core) | |
2028 | const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store")) | |
2029 | && FindProcShort (glBindImageTexture) | |
2030 | && FindProcShort (glMemoryBarrier); | |
2031 | ||
2032 | // load GL_ARB_texture_storage (added to OpenGL 4.2 core) | |
2033 | const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage")) | |
2034 | && FindProcShort (glTexStorage1D) | |
2035 | && FindProcShort (glTexStorage2D) | |
c87535af | 2036 | && FindProcShort (glTexStorage3D); |
01ca42b2 | 2037 | |
2038 | has42 = IsGlGreaterEqual (4, 2) | |
2039 | && hasBaseInstance | |
2040 | && hasTrsfFeedbackInstanced | |
2041 | && hasInternalFormatQuery | |
2042 | && hasShaderAtomicCounters | |
2043 | && hasShaderImgLoadStore | |
2044 | && hasTextureStorage; | |
2045 | ||
2046 | has43 = IsGlGreaterEqual (4, 3) | |
2047 | && FindProcShort (glClearBufferData) | |
2048 | && FindProcShort (glClearBufferSubData) | |
2049 | && FindProcShort (glDispatchCompute) | |
2050 | && FindProcShort (glDispatchComputeIndirect) | |
2051 | && FindProcShort (glCopyImageSubData) | |
2052 | && FindProcShort (glFramebufferParameteri) | |
2053 | && FindProcShort (glGetFramebufferParameteriv) | |
2054 | && FindProcShort (glGetInternalformati64v) | |
2055 | && FindProcShort (glInvalidateTexSubImage) | |
2056 | && FindProcShort (glInvalidateTexImage) | |
2057 | && FindProcShort (glInvalidateBufferSubData) | |
2058 | && FindProcShort (glInvalidateBufferData) | |
2059 | && FindProcShort (glInvalidateFramebuffer) | |
2060 | && FindProcShort (glInvalidateSubFramebuffer) | |
2061 | && FindProcShort (glMultiDrawArraysIndirect) | |
2062 | && FindProcShort (glMultiDrawElementsIndirect) | |
2063 | && FindProcShort (glGetProgramInterfaceiv) | |
2064 | && FindProcShort (glGetProgramResourceIndex) | |
2065 | && FindProcShort (glGetProgramResourceName) | |
2066 | && FindProcShort (glGetProgramResourceiv) | |
2067 | && FindProcShort (glGetProgramResourceLocation) | |
2068 | && FindProcShort (glGetProgramResourceLocationIndex) | |
2069 | && FindProcShort (glShaderStorageBlockBinding) | |
2070 | && FindProcShort (glTexBufferRange) | |
2071 | && FindProcShort (glTexStorage2DMultisample) | |
2072 | && FindProcShort (glTexStorage3DMultisample) | |
2073 | && FindProcShort (glTextureView) | |
2074 | && FindProcShort (glBindVertexBuffer) | |
2075 | && FindProcShort (glVertexAttribFormat) | |
2076 | && FindProcShort (glVertexAttribIFormat) | |
2077 | && FindProcShort (glVertexAttribLFormat) | |
2078 | && FindProcShort (glVertexAttribBinding) | |
2079 | && FindProcShort (glVertexBindingDivisor) | |
2080 | && FindProcShort (glDebugMessageControl) | |
2081 | && FindProcShort (glDebugMessageInsert) | |
2082 | && FindProcShort (glDebugMessageCallback) | |
2083 | && FindProcShort (glGetDebugMessageLog) | |
2084 | && FindProcShort (glPushDebugGroup) | |
2085 | && FindProcShort (glPopDebugGroup) | |
2086 | && FindProcShort (glObjectLabel) | |
2087 | && FindProcShort (glGetObjectLabel) | |
2088 | && FindProcShort (glObjectPtrLabel) | |
2089 | && FindProcShort (glGetObjectPtrLabel); | |
2090 | ||
2091 | // load GL_ARB_clear_texture (added to OpenGL 4.4 core) | |
2092 | bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture")) | |
2093 | && FindProcShort (glClearTexImage) | |
2094 | && FindProcShort (glClearTexSubImage); | |
2095 | ||
2096 | has44 = IsGlGreaterEqual (4, 4) | |
2097 | && arbTexClear | |
2098 | && FindProcShort (glBufferStorage) | |
2099 | && FindProcShort (glBindBuffersBase) | |
2100 | && FindProcShort (glBindBuffersRange) | |
2101 | && FindProcShort (glBindTextures) | |
2102 | && FindProcShort (glBindSamplers) | |
2103 | && FindProcShort (glBindImageTextures) | |
2104 | && FindProcShort (glBindVertexBuffers); | |
2105 | ||
0deb6f04 | 2106 | // initialize debug context extension |
2107 | if (CheckExtension ("GL_ARB_debug_output")) | |
2108 | { | |
2109 | arbDbg = NULL; | |
2110 | if (has43) | |
2111 | { | |
2112 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
2113 | } | |
2114 | else if (FindProc ("glDebugMessageControlARB", myFuncs->glDebugMessageControl) | |
2115 | && FindProc ("glDebugMessageInsertARB", myFuncs->glDebugMessageInsert) | |
2116 | && FindProc ("glDebugMessageCallbackARB", myFuncs->glDebugMessageCallback) | |
2117 | && FindProc ("glGetDebugMessageLogARB", myFuncs->glGetDebugMessageLog)) | |
2118 | { | |
2119 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); | |
2120 | } | |
2121 | ||
2122 | if (arbDbg != NULL | |
2123 | && caps->contextDebug) | |
2124 | { | |
2125 | // setup default callback | |
2126 | myIsGlDebugCtx = Standard_True; | |
2127 | arbDbg->glDebugMessageCallback (debugCallbackWrap, this); | |
2128 | if (has43) | |
2129 | { | |
2130 | ::glEnable (GL_DEBUG_OUTPUT); | |
2131 | } | |
2132 | if (caps->contextSyncDebug) | |
2133 | { | |
2134 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS); | |
2135 | } | |
2136 | } | |
2137 | } | |
2138 | ||
5e27df78 | 2139 | // initialize TBO extension (ARB) |
01ca42b2 | 2140 | if (!has31 |
2141 | && CheckExtension ("GL_ARB_texture_buffer_object") | |
2142 | && FindProc ("glTexBufferARB", myFuncs->glTexBuffer)) | |
5e27df78 | 2143 | { |
01ca42b2 | 2144 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); |
5e27df78 | 2145 | } |
25ef750e | 2146 | arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32"); |
5e27df78 | 2147 | |
2148 | // initialize hardware instancing extension (ARB) | |
01ca42b2 | 2149 | if (!has31 |
2150 | && CheckExtension ("GL_ARB_draw_instanced") | |
2151 | && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced) | |
2152 | && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced)) | |
5e27df78 | 2153 | { |
01ca42b2 | 2154 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); |
5e27df78 | 2155 | } |
2156 | ||
01ca42b2 | 2157 | // initialize FBO extension (ARB) |
2158 | if (hasFBO) | |
2166f0fa | 2159 | { |
b86bb3df | 2160 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
2161 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
01ca42b2 | 2162 | extPDS = Standard_True; // extension for EXT, but part of ARB |
2166f0fa | 2163 | } |
5f8b738e | 2164 | |
37eb4787 | 2165 | // initialize GS extension (EXT) |
01ca42b2 | 2166 | if (CheckExtension ("GL_EXT_geometry_shader4") |
2167 | && FindProcShort (glProgramParameteriEXT)) | |
37eb4787 | 2168 | { |
01ca42b2 | 2169 | extGS = (OpenGl_ExtGS* )(&(*myFuncs)); |
37eb4787 | 2170 | } |
2171 | ||
25ef750e | 2172 | // initialize bindless texture extension (ARB) |
2173 | if (CheckExtension ("GL_ARB_bindless_texture") | |
2174 | && FindProcShort (glGetTextureHandleARB) | |
2175 | && FindProcShort (glGetTextureSamplerHandleARB) | |
2176 | && FindProcShort (glMakeTextureHandleResidentARB) | |
2177 | && FindProcShort (glMakeTextureHandleNonResidentARB) | |
2178 | && FindProcShort (glGetImageHandleARB) | |
2179 | && FindProcShort (glMakeImageHandleResidentARB) | |
2180 | && FindProcShort (glMakeImageHandleNonResidentARB) | |
2181 | && FindProcShort (glUniformHandleui64ARB) | |
2182 | && FindProcShort (glUniformHandleui64vARB) | |
2183 | && FindProcShort (glProgramUniformHandleui64ARB) | |
2184 | && FindProcShort (glProgramUniformHandleui64vARB) | |
2185 | && FindProcShort (glIsTextureHandleResidentARB) | |
2186 | && FindProcShort (glIsImageHandleResidentARB) | |
2187 | && FindProcShort (glVertexAttribL1ui64ARB) | |
2188 | && FindProcShort (glVertexAttribL1ui64vARB) | |
2189 | && FindProcShort (glGetVertexAttribLui64vARB)) | |
2190 | { | |
2191 | arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs)); | |
2192 | } | |
2193 | ||
01ca42b2 | 2194 | if (!has12) |
86325709 | 2195 | { |
ee51a9fe | 2196 | checkWrongVersion (1, 2); |
86325709 | 2197 | myGlVerMajor = 1; |
2198 | myGlVerMinor = 1; | |
2199 | return; | |
5f8b738e | 2200 | } |
01ca42b2 | 2201 | else if (!has13) |
5f8b738e | 2202 | { |
ee51a9fe | 2203 | checkWrongVersion (1, 3); |
01ca42b2 | 2204 | myGlVerMajor = 1; |
2205 | myGlVerMinor = 2; | |
2206 | return; | |
5f8b738e | 2207 | } |
01ca42b2 | 2208 | else if (!has14) |
5f8b738e | 2209 | { |
ee51a9fe | 2210 | checkWrongVersion (1, 4); |
86325709 | 2211 | myGlVerMajor = 1; |
01ca42b2 | 2212 | myGlVerMinor = 3; |
86325709 | 2213 | return; |
5f8b738e | 2214 | } |
01ca42b2 | 2215 | else if (!has15) |
86325709 | 2216 | { |
ee51a9fe | 2217 | checkWrongVersion (1, 5); |
01ca42b2 | 2218 | myGlVerMajor = 1; |
2219 | myGlVerMinor = 4; | |
2220 | return; | |
5f8b738e | 2221 | } |
4e1523ef | 2222 | if (!isCoreProfile) |
2223 | { | |
2224 | core15 = (OpenGl_GlCore15* )(&(*myFuncs)); | |
2225 | } | |
01ca42b2 | 2226 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); |
2227 | ||
2228 | if (!has20) | |
86325709 | 2229 | { |
ee51a9fe | 2230 | checkWrongVersion (2, 0); |
2231 | myGlVerMajor = 1; | |
2232 | myGlVerMinor = 5; | |
2233 | return; | |
2234 | } | |
2235 | ||
2236 | const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION); | |
2237 | if (aGlslVer == NULL | |
2238 | || *aGlslVer == '\0') | |
2239 | { | |
2240 | // broken context has been detected | |
2241 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
2242 | + "Error! OpenGL context reports version " | |
2243 | + myGlVerMajor + "." + myGlVerMinor | |
2244 | + " but reports wrong GLSL version"; | |
3b523c4c | 2245 | PushMessage (GL_DEBUG_SOURCE_APPLICATION, |
2246 | GL_DEBUG_TYPE_ERROR, | |
ee51a9fe | 2247 | 0, |
3b523c4c | 2248 | GL_DEBUG_SEVERITY_HIGH, |
ee51a9fe | 2249 | aMsg); |
86325709 | 2250 | myGlVerMajor = 1; |
01ca42b2 | 2251 | myGlVerMinor = 5; |
86325709 | 2252 | return; |
5f8b738e | 2253 | } |
01ca42b2 | 2254 | |
4e1523ef | 2255 | if (!isCoreProfile) |
2256 | { | |
2257 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
2258 | } | |
01ca42b2 | 2259 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); |
2260 | ||
2261 | if (!has21) | |
5f8b738e | 2262 | { |
ee51a9fe | 2263 | checkWrongVersion (2, 1); |
01ca42b2 | 2264 | myGlVerMajor = 2; |
2265 | myGlVerMinor = 0; | |
2266 | return; | |
86325709 | 2267 | } |
01ca42b2 | 2268 | |
2269 | if (!has30) | |
86325709 | 2270 | { |
ee51a9fe | 2271 | checkWrongVersion (3, 0); |
01ca42b2 | 2272 | myGlVerMajor = 2; |
2273 | myGlVerMinor = 1; | |
86325709 | 2274 | return; |
2275 | } | |
01ca42b2 | 2276 | |
3c4b62a4 | 2277 | // MSAA RenderBuffers have been defined in OpenGL 3.0, |
2278 | // but MSAA Textures - only in OpenGL 3.2+ | |
2279 | if (!has32 | |
2280 | && CheckExtension ("GL_ARB_texture_multisample") | |
2281 | && FindProcShort (glTexImage2DMultisample)) | |
2282 | { | |
2283 | GLint aNbColorSamples = 0, aNbDepthSamples = 0; | |
2284 | ::glGetIntegerv (GL_MAX_COLOR_TEXTURE_SAMPLES, &aNbColorSamples); | |
2285 | ::glGetIntegerv (GL_MAX_DEPTH_TEXTURE_SAMPLES, &aNbDepthSamples); | |
2286 | myMaxMsaaSamples = Min (aNbColorSamples, aNbDepthSamples); | |
2287 | } | |
2288 | if (!has43 | |
2289 | && CheckExtension ("GL_ARB_texture_storage_multisample") | |
2290 | && FindProcShort (glTexStorage2DMultisample)) | |
2291 | { | |
2292 | // | |
2293 | } | |
2294 | ||
01ca42b2 | 2295 | if (!has31) |
2296 | { | |
ee51a9fe | 2297 | checkWrongVersion (3, 1); |
01ca42b2 | 2298 | myGlVerMajor = 3; |
2299 | myGlVerMinor = 0; | |
2300 | return; | |
2301 | } | |
2302 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); | |
2303 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); | |
2304 | ||
2305 | if (!has32) | |
86325709 | 2306 | { |
ee51a9fe | 2307 | checkWrongVersion (3, 2); |
01ca42b2 | 2308 | myGlVerMajor = 3; |
2309 | myGlVerMinor = 1; | |
2310 | return; | |
86325709 | 2311 | } |
4e1523ef | 2312 | core32 = (OpenGl_GlCore32* )(&(*myFuncs)); |
2313 | if (isCoreProfile) | |
2314 | { | |
2315 | core32->glGenVertexArrays (1, &myDefaultVao); | |
2316 | } | |
2317 | else | |
2318 | { | |
2319 | core32back = (OpenGl_GlCore32Back* )(&(*myFuncs)); | |
2320 | } | |
3c4b62a4 | 2321 | ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples); |
01ca42b2 | 2322 | |
2323 | if (!has33) | |
86325709 | 2324 | { |
ee51a9fe | 2325 | checkWrongVersion (3, 3); |
01ca42b2 | 2326 | myGlVerMajor = 3; |
2327 | myGlVerMinor = 2; | |
2328 | return; | |
86325709 | 2329 | } |
4e1523ef | 2330 | core33 = (OpenGl_GlCore33* )(&(*myFuncs)); |
2331 | if (!isCoreProfile) | |
2332 | { | |
2333 | core33back = (OpenGl_GlCore33Back* )(&(*myFuncs)); | |
2334 | } | |
25ef750e | 2335 | |
2336 | // initialize sampler object | |
2337 | myTexSampler = new OpenGl_Sampler(); | |
2338 | myTexSampler->Init (*this); | |
01ca42b2 | 2339 | |
2340 | if (!has40) | |
86325709 | 2341 | { |
ee51a9fe | 2342 | checkWrongVersion (4, 0); |
01ca42b2 | 2343 | myGlVerMajor = 3; |
2344 | myGlVerMinor = 3; | |
2345 | return; | |
2346 | } | |
25ef750e | 2347 | arbTboRGB32 = Standard_True; // in core since OpenGL 4.0 |
01ca42b2 | 2348 | |
2349 | if (!has41) | |
2350 | { | |
ee51a9fe | 2351 | checkWrongVersion (4, 1); |
01ca42b2 | 2352 | myGlVerMajor = 4; |
2353 | myGlVerMinor = 0; | |
2354 | return; | |
2355 | } | |
4e1523ef | 2356 | core41 = (OpenGl_GlCore41* )(&(*myFuncs)); |
2357 | if (!isCoreProfile) | |
2358 | { | |
2359 | core41back = (OpenGl_GlCore41Back* )(&(*myFuncs)); | |
2360 | } | |
01ca42b2 | 2361 | |
2362 | if(!has42) | |
2363 | { | |
ee51a9fe | 2364 | checkWrongVersion (4, 2); |
01ca42b2 | 2365 | myGlVerMajor = 4; |
2366 | myGlVerMinor = 1; | |
2367 | return; | |
2368 | } | |
4e1523ef | 2369 | core42 = (OpenGl_GlCore42* )(&(*myFuncs)); |
2370 | if (!isCoreProfile) | |
2371 | { | |
2372 | core42back = (OpenGl_GlCore42Back* )(&(*myFuncs)); | |
2373 | } | |
01ca42b2 | 2374 | |
4e1523ef | 2375 | if (!has43) |
01ca42b2 | 2376 | { |
ee51a9fe | 2377 | checkWrongVersion (4, 3); |
01ca42b2 | 2378 | myGlVerMajor = 4; |
2379 | myGlVerMinor = 2; | |
2380 | return; | |
2381 | } | |
4e1523ef | 2382 | core43 = (OpenGl_GlCore43* )(&(*myFuncs)); |
2383 | if (!isCoreProfile) | |
2384 | { | |
2385 | core43back = (OpenGl_GlCore43Back* )(&(*myFuncs)); | |
2386 | } | |
01ca42b2 | 2387 | |
2388 | if (!has44) | |
2389 | { | |
ee51a9fe | 2390 | checkWrongVersion (4, 4); |
01ca42b2 | 2391 | myGlVerMajor = 4; |
2392 | myGlVerMinor = 3; | |
2393 | return; | |
5f8b738e | 2394 | } |
4e1523ef | 2395 | core44 = (OpenGl_GlCore44* )(&(*myFuncs)); |
2396 | if (!isCoreProfile) | |
2397 | { | |
2398 | core44back = (OpenGl_GlCore44Back* )(&(*myFuncs)); | |
2399 | } | |
ca3c13d1 | 2400 | #endif |
2166f0fa | 2401 | } |
f0430952 | 2402 | |
2403 | // ======================================================================= | |
2404 | // function : MemoryInfo | |
2405 | // purpose : | |
2406 | // ======================================================================= | |
2407 | Standard_Size OpenGl_Context::AvailableMemory() const | |
2408 | { | |
ca3c13d1 | 2409 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2410 | if (atiMem) |
2411 | { | |
2412 | // this is actually information for VBO pool | |
2413 | // however because pools are mostly shared | |
2414 | // it can be used for total GPU memory estimations | |
2415 | GLint aMemInfo[4]; | |
2416 | aMemInfo[0] = 0; | |
2417 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo); | |
2418 | // returned value is in KiB, however this maybe changed in future | |
2419 | return Standard_Size(aMemInfo[0]) * 1024; | |
2420 | } | |
2421 | else if (nvxMem) | |
2422 | { | |
2423 | // current available dedicated video memory (in KiB), currently unused GPU memory | |
2424 | GLint aMemInfo = 0; | |
2425 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo); | |
2426 | return Standard_Size(aMemInfo) * 1024; | |
2427 | } | |
ca3c13d1 | 2428 | #endif |
f0430952 | 2429 | return 0; |
2430 | } | |
2431 | ||
2432 | // ======================================================================= | |
2433 | // function : MemoryInfo | |
2434 | // purpose : | |
2435 | // ======================================================================= | |
2436 | TCollection_AsciiString OpenGl_Context::MemoryInfo() const | |
2437 | { | |
26d9c835 | 2438 | TColStd_IndexedDataMapOfStringString aDict; |
2439 | MemoryInfo (aDict); | |
2440 | ||
2441 | TCollection_AsciiString aText; | |
2442 | for (TColStd_IndexedDataMapOfStringString::Iterator anIter (aDict); anIter.More(); anIter.Next()) | |
2443 | { | |
2444 | if (!aText.IsEmpty()) | |
2445 | { | |
2446 | aText += "\n"; | |
2447 | } | |
2448 | aText += TCollection_AsciiString(" ") + anIter.Key() + ": " + anIter.Value(); | |
2449 | } | |
2450 | return aText; | |
2451 | } | |
2452 | ||
2453 | // ======================================================================= | |
2454 | // function : MemoryInfo | |
2455 | // purpose : | |
2456 | // ======================================================================= | |
2457 | void OpenGl_Context::MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const | |
2458 | { | |
2459 | #if defined(GL_ES_VERSION_2_0) | |
2460 | (void )theDict; | |
2461 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
2462 | GLint aGlRendId = 0; | |
2463 | CGLGetParameter (CGLGetCurrentContext(), kCGLCPCurrentRendererID, &aGlRendId); | |
2464 | ||
2465 | CGLRendererInfoObj aRendObj = NULL; | |
2466 | CGOpenGLDisplayMask aDispMask = CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay); | |
2467 | GLint aRendNb = 0; | |
2468 | CGLQueryRendererInfo (aDispMask, &aRendObj, &aRendNb); | |
2469 | for (GLint aRendIter = 0; aRendIter < aRendNb; ++aRendIter) | |
2470 | { | |
2471 | GLint aRendId = 0; | |
2472 | if (CGLDescribeRenderer (aRendObj, aRendIter, kCGLRPRendererID, &aRendId) != kCGLNoError | |
2473 | || aRendId != aGlRendId) | |
2474 | { | |
2475 | continue; | |
2476 | } | |
2477 | ||
2478 | //kCGLRPVideoMemoryMegabytes = 131; | |
2479 | //kCGLRPTextureMemoryMegabytes = 132; | |
2480 | GLint aVMem = 0; | |
2481 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 | |
2482 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemoryMegabytes, &aVMem) == kCGLNoError) | |
2483 | { | |
2484 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + aVMem + " MiB"); | |
2485 | } | |
2486 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemoryMegabytes, &aVMem) == kCGLNoError) | |
2487 | { | |
2488 | addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + aVMem + " MiB"); | |
2489 | } | |
2490 | #else | |
2491 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemory, &aVMem) == kCGLNoError) | |
2492 | { | |
2493 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB"); | |
2494 | } | |
2495 | if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemory, &aVMem) == kCGLNoError) | |
2496 | { | |
2497 | addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB"); | |
2498 | } | |
2499 | #endif | |
2500 | } | |
2501 | #endif | |
2502 | ||
ca3c13d1 | 2503 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2504 | if (atiMem) |
2505 | { | |
2506 | GLint aValues[4]; | |
2507 | memset (aValues, 0, sizeof(aValues)); | |
2508 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues); | |
2509 | ||
2510 | // total memory free in the pool | |
26d9c835 | 2511 | addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValues[0] / 1024) + " MiB"); |
f0430952 | 2512 | |
26d9c835 | 2513 | if (aValues[1] != aValues[0]) |
2514 | { | |
2515 | // largest available free block in the pool | |
2516 | addInfo (theDict, "Largest free block", TCollection_AsciiString() + (aValues[1] / 1024) + " MiB"); | |
2517 | } | |
f0430952 | 2518 | if (aValues[2] != aValues[0]) |
2519 | { | |
2520 | // total auxiliary memory free | |
26d9c835 | 2521 | addInfo (theDict, "Free auxiliary memory", TCollection_AsciiString() + (aValues[2] / 1024) + " MiB"); |
f0430952 | 2522 | } |
2523 | } | |
2524 | else if (nvxMem) | |
2525 | { | |
2526 | //current available dedicated video memory (in KiB), currently unused GPU memory | |
2527 | GLint aValue = 0; | |
2528 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue); | |
26d9c835 | 2529 | addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValue / 1024) + " MiB"); |
f0430952 | 2530 | |
2531 | // dedicated video memory, total size (in KiB) of the GPU memory | |
2532 | GLint aDedicated = 0; | |
2533 | glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated); | |
26d9c835 | 2534 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aDedicated / 1024) + " MiB"); |
f0430952 | 2535 | |
2536 | // total available memory, total size (in KiB) of the memory available for allocations | |
2537 | glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue); | |
2538 | if (aValue != aDedicated) | |
2539 | { | |
2540 | // different only for special configurations | |
26d9c835 | 2541 | addInfo (theDict, "Total memory", TCollection_AsciiString() + (aValue / 1024) + " MiB"); |
2542 | } | |
2543 | } | |
2544 | #endif | |
2545 | ||
2546 | #if !defined(GL_ES_VERSION_2_0) && !defined(__APPLE__) && !defined(_WIN32) | |
2547 | // GLX_RENDERER_VENDOR_ID_MESA | |
2548 | if (myFuncs->glXQueryCurrentRendererIntegerMESA != NULL) | |
2549 | { | |
2550 | unsigned int aVMemMiB = 0; | |
2551 | if (myFuncs->glXQueryCurrentRendererIntegerMESA (GLX_RENDERER_VIDEO_MEMORY_MESA, &aVMemMiB) != False) | |
2552 | { | |
2553 | addInfo (theDict, "GPU memory", TCollection_AsciiString() + int(aVMemMiB) + " MiB"); | |
f0430952 | 2554 | } |
2555 | } | |
ca3c13d1 | 2556 | #endif |
f0430952 | 2557 | } |
5e27df78 | 2558 | |
26d9c835 | 2559 | // ======================================================================= |
2560 | // function : DiagnosticInfo | |
2561 | // purpose : | |
2562 | // ======================================================================= | |
2563 | void OpenGl_Context::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict, | |
2564 | Graphic3d_DiagnosticInfo theFlags) const | |
2565 | { | |
2566 | if ((theFlags & Graphic3d_DiagnosticInfo_NativePlatform) != 0) | |
2567 | { | |
2568 | #if defined(HAVE_EGL) | |
2569 | addInfo (theDict, "EGLVersion", ::eglQueryString ((Aspect_Display)myDisplay, EGL_VERSION)); | |
2570 | addInfo (theDict, "EGLVendor", ::eglQueryString ((Aspect_Display)myDisplay, EGL_VENDOR)); | |
2571 | addInfo (theDict, "EGLClientAPIs", ::eglQueryString ((Aspect_Display)myDisplay, EGL_CLIENT_APIS)); | |
2572 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2573 | { | |
2574 | addInfo (theDict, "EGLExtensions", ::eglQueryString ((Aspect_Display)myDisplay, EGL_EXTENSIONS)); | |
2575 | } | |
2576 | #elif defined(_WIN32) | |
2577 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0 | |
2578 | && myFuncs->wglGetExtensionsStringARB != NULL) | |
2579 | { | |
2580 | const char* aWglExts = myFuncs->wglGetExtensionsStringARB ((HDC )myWindowDC); | |
2581 | addInfo (theDict, "WGLExtensions", aWglExts); | |
2582 | } | |
2583 | #elif defined(__APPLE__) | |
2584 | // | |
2585 | #else | |
2586 | Display* aDisplay = (Display*)myDisplay; | |
2587 | const int aScreen = DefaultScreen(aDisplay); | |
2588 | addInfo (theDict, "GLXDirectRendering", ::glXIsDirect (aDisplay, (GLXContext )myGContext) ? "Yes" : "No"); | |
2589 | addInfo (theDict, "GLXVendor", ::glXQueryServerString (aDisplay, aScreen, GLX_VENDOR)); | |
2590 | addInfo (theDict, "GLXVersion", ::glXQueryServerString (aDisplay, aScreen, GLX_VERSION)); | |
2591 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2592 | { | |
2593 | const char* aGlxExts = ::glXQueryExtensionsString (aDisplay, aScreen); | |
2594 | addInfo(theDict, "GLXExtensions", aGlxExts); | |
2595 | } | |
2596 | ||
2597 | addInfo (theDict, "GLXClientVendor", ::glXGetClientString (aDisplay, GLX_VENDOR)); | |
2598 | addInfo (theDict, "GLXClientVersion", ::glXGetClientString (aDisplay, GLX_VERSION)); | |
2599 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2600 | { | |
2601 | addInfo (theDict, "GLXClientExtensions", ::glXGetClientString (aDisplay, GLX_EXTENSIONS)); | |
2602 | } | |
2603 | #endif | |
2604 | } | |
2605 | ||
2606 | if ((theFlags & Graphic3d_DiagnosticInfo_Device) != 0) | |
2607 | { | |
2608 | addInfo (theDict, "GLvendor", (const char*)::glGetString (GL_VENDOR)); | |
2609 | addInfo (theDict, "GLdevice", (const char*)::glGetString (GL_RENDERER)); | |
2610 | addInfo (theDict, "GLversion", (const char*)::glGetString (GL_VERSION)); | |
2611 | addInfo (theDict, "GLSLversion", (const char*)::glGetString (GL_SHADING_LANGUAGE_VERSION)); | |
2612 | if (myIsGlDebugCtx) | |
2613 | { | |
2614 | addInfo (theDict, "GLdebug", "ON"); | |
2615 | } | |
2616 | } | |
2617 | ||
2618 | if ((theFlags & Graphic3d_DiagnosticInfo_Limits) != 0) | |
2619 | { | |
2620 | addInfo (theDict, "Max texture size", TCollection_AsciiString(myMaxTexDim)); | |
2621 | addInfo (theDict, "Max MSAA samples", TCollection_AsciiString(myMaxMsaaSamples)); | |
2622 | } | |
2623 | ||
2624 | if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0) | |
2625 | { | |
2626 | GLint aViewport[4] = {}; | |
2627 | ::glGetIntegerv (GL_VIEWPORT, aViewport); | |
2628 | addInfo (theDict, "Viewport", TCollection_AsciiString() + aViewport[2] + "x" + aViewport[3]); | |
2629 | } | |
2630 | ||
2631 | if ((theFlags & Graphic3d_DiagnosticInfo_Memory) != 0) | |
2632 | { | |
2633 | MemoryInfo (theDict); | |
2634 | } | |
2635 | ||
2636 | if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0) | |
2637 | { | |
2638 | #if !defined(GL_ES_VERSION_2_0) | |
2639 | if (IsGlGreaterEqual (3, 0) | |
2640 | && myFuncs->glGetStringi != NULL) | |
2641 | { | |
2642 | TCollection_AsciiString anExtList; | |
2643 | GLint anExtNb = 0; | |
2644 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); | |
2645 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) | |
2646 | { | |
2647 | const char* anExtension = (const char*)myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint)anIter); | |
2648 | if (!anExtList.IsEmpty()) | |
2649 | { | |
2650 | anExtList += " "; | |
2651 | } | |
2652 | anExtList += anExtension; | |
2653 | } | |
2654 | addInfo(theDict, "GLextensions", anExtList); | |
2655 | } | |
2656 | else | |
2657 | #endif | |
2658 | { | |
2659 | addInfo (theDict, "GLextensions", (const char*)::glGetString (GL_EXTENSIONS)); | |
2660 | } | |
2661 | } | |
2662 | } | |
5e27df78 | 2663 | |
2664 | // ======================================================================= | |
2665 | // function : GetResource | |
2666 | // purpose : | |
2667 | // ======================================================================= | |
2668 | const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const | |
2669 | { | |
2670 | return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE; | |
2671 | } | |
2672 | ||
2673 | // ======================================================================= | |
2674 | // function : ShareResource | |
2675 | // purpose : | |
2676 | // ======================================================================= | |
2677 | Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey, | |
2678 | const Handle(OpenGl_Resource)& theResource) | |
2679 | { | |
2680 | if (theKey.IsEmpty() || theResource.IsNull()) | |
2681 | { | |
2682 | return Standard_False; | |
2683 | } | |
2684 | return mySharedResources->Bind (theKey, theResource); | |
2685 | } | |
2686 | ||
2687 | // ======================================================================= | |
2688 | // function : ReleaseResource | |
2689 | // purpose : | |
2690 | // ======================================================================= | |
a174a3c5 | 2691 | void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey, |
2692 | const Standard_Boolean theToDelay) | |
5e27df78 | 2693 | { |
2694 | if (!mySharedResources->IsBound (theKey)) | |
2695 | { | |
2696 | return; | |
2697 | } | |
4796758e | 2698 | auto& aRes = mySharedResources->Find (theKey); |
5e27df78 | 2699 | if (aRes->GetRefCount() > 1) |
2700 | { | |
2701 | return; | |
2702 | } | |
2703 | ||
a174a3c5 | 2704 | if (theToDelay) |
2705 | { | |
2706 | myDelayed->Bind (theKey, 1); | |
2707 | } | |
2708 | else | |
2709 | { | |
2710 | aRes->Release (this); | |
2711 | mySharedResources->UnBind (theKey); | |
2712 | } | |
5e27df78 | 2713 | } |
2714 | ||
2715 | // ======================================================================= | |
5e27df78 | 2716 | // function : ReleaseDelayed |
2717 | // purpose : | |
2718 | // ======================================================================= | |
2719 | void OpenGl_Context::ReleaseDelayed() | |
2720 | { | |
a174a3c5 | 2721 | // release queued elements |
3125ebb6 | 2722 | while (!myUnusedResources->IsEmpty()) |
5e27df78 | 2723 | { |
3125ebb6 | 2724 | myUnusedResources->First()->Release (this); |
2725 | myUnusedResources->RemoveFirst(); | |
5e27df78 | 2726 | } |
a174a3c5 | 2727 | |
265d4508 | 2728 | // release delayed shared resources |
a174a3c5 | 2729 | NCollection_Vector<TCollection_AsciiString> aDeadList; |
2730 | for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed); | |
2731 | anIter.More(); anIter.Next()) | |
2732 | { | |
2733 | if (++anIter.ChangeValue() <= 2) | |
2734 | { | |
2735 | continue; // postpone release one more frame to ensure noone use it periodically | |
2736 | } | |
2737 | ||
2738 | const TCollection_AsciiString& aKey = anIter.Key(); | |
2739 | if (!mySharedResources->IsBound (aKey)) | |
2740 | { | |
2741 | // mixed unshared strategy delayed/undelayed was used! | |
2742 | aDeadList.Append (aKey); | |
2743 | continue; | |
2744 | } | |
2745 | ||
4796758e | 2746 | auto& aRes = mySharedResources->ChangeFind (aKey); |
a174a3c5 | 2747 | if (aRes->GetRefCount() > 1) |
2748 | { | |
2749 | // should be only 1 instance in mySharedResources | |
2750 | // if not - resource was reused again | |
2751 | aDeadList.Append (aKey); | |
2752 | continue; | |
2753 | } | |
2754 | ||
2755 | // release resource if no one requiested it more than 2 redraw calls | |
2756 | aRes->Release (this); | |
2757 | mySharedResources->UnBind (aKey); | |
2758 | aDeadList.Append (aKey); | |
2759 | } | |
2760 | ||
2761 | for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter) | |
2762 | { | |
2763 | myDelayed->UnBind (aDeadList.Value (anIter)); | |
2764 | } | |
5e27df78 | 2765 | } |
7d3e64ef | 2766 | |
2767 | // ======================================================================= | |
2768 | // function : BindProgram | |
2769 | // purpose : | |
2770 | // ======================================================================= | |
8625ef7e | 2771 | Standard_Boolean OpenGl_Context::BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram) |
7d3e64ef | 2772 | { |
8625ef7e | 2773 | if (core20fwd == NULL) |
2774 | { | |
2775 | return Standard_False; | |
2776 | } | |
2777 | ||
7d3e64ef | 2778 | if (theProgram.IsNull() |
2779 | || !theProgram->IsValid()) | |
2780 | { | |
2781 | if (!myActiveProgram.IsNull()) | |
2782 | { | |
2783 | core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM); | |
2784 | myActiveProgram.Nullify(); | |
2785 | } | |
8625ef7e | 2786 | return Standard_False; |
7d3e64ef | 2787 | } |
2788 | ||
2789 | myActiveProgram = theProgram; | |
2790 | core20fwd->glUseProgram (theProgram->ProgramId()); | |
8625ef7e | 2791 | return Standard_True; |
2792 | } | |
2793 | ||
4e1523ef | 2794 | // ======================================================================= |
2795 | // function : BindDefaultVao | |
2796 | // purpose : | |
2797 | // ======================================================================= | |
2798 | void OpenGl_Context::BindDefaultVao() | |
2799 | { | |
2800 | #if !defined(GL_ES_VERSION_2_0) | |
2801 | if (myDefaultVao == 0 | |
2802 | || core32 == NULL) | |
2803 | { | |
2804 | return; | |
2805 | } | |
2806 | ||
2807 | core32->glBindVertexArray (myDefaultVao); | |
2808 | #endif | |
2809 | } | |
2810 | ||
a2e4f780 | 2811 | // ======================================================================= |
2812 | // function : SetDefaultFrameBuffer | |
2813 | // purpose : | |
2814 | // ======================================================================= | |
2815 | Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo) | |
2816 | { | |
2817 | Handle(OpenGl_FrameBuffer) aFbo = myDefaultFbo; | |
2818 | myDefaultFbo = theFbo; | |
2819 | return aFbo; | |
2820 | } | |
2821 | ||
8625ef7e | 2822 | // ======================================================================= |
299e0ab9 | 2823 | // function : SetShadingMaterial |
2824 | // purpose : | |
2825 | // ======================================================================= | |
f9ba5c4d | 2826 | void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect, |
2827 | const OpenGl_Vec4* theHighlightColor) | |
299e0ab9 | 2828 | { |
2829 | if (!myActiveProgram.IsNull()) | |
2830 | { | |
2831 | myActiveProgram->SetUniform (this, | |
2832 | myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_ENABLE), | |
b6472664 | 2833 | theAspect->Aspect()->ToMapTexture() ? 1 : 0); |
299e0ab9 | 2834 | myActiveProgram->SetUniform (this, |
2835 | myActiveProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE), | |
b6472664 | 2836 | theAspect->Aspect()->Distinguish() ? 1 : 0); |
299e0ab9 | 2837 | |
2838 | OpenGl_Material aParams; | |
2839 | for (Standard_Integer anIndex = 0; anIndex < 2; ++anIndex) | |
2840 | { | |
2841 | const GLint aLoc = myActiveProgram->GetStateLocation (anIndex == 0 | |
2842 | ? OpenGl_OCCT_FRONT_MATERIAL | |
2843 | : OpenGl_OCCT_BACK_MATERIAL); | |
2844 | if (aLoc == OpenGl_ShaderProgram::INVALID_LOCATION) | |
2845 | { | |
2846 | continue; | |
2847 | } | |
2848 | ||
b6472664 | 2849 | if (anIndex == 0 || !theAspect->Aspect()->Distinguish()) |
2850 | { | |
2851 | const Graphic3d_MaterialAspect& aSrcMat = theAspect->Aspect()->FrontMaterial(); | |
2852 | const Quantity_Color& aSrcIntColor = theAspect->Aspect()->InteriorColor(); | |
2853 | aParams.Init (aSrcMat, aSrcIntColor); | |
2854 | aParams.Diffuse.a() = 1.0f - (float )aSrcMat.Transparency(); | |
2855 | } | |
2856 | else | |
2857 | { | |
2858 | const Graphic3d_MaterialAspect& aSrcMat = theAspect->Aspect()->BackMaterial(); | |
2859 | const Quantity_Color& aSrcIntColor = theAspect->Aspect()->BackInteriorColor(); | |
2860 | aParams.Init (aSrcMat, aSrcIntColor); | |
2861 | aParams.Diffuse.a() = 1.0f - (float )aSrcMat.Transparency(); | |
2862 | } | |
f9ba5c4d | 2863 | if (theHighlightColor != NULL) |
2864 | { | |
2865 | aParams.SetColor (*theHighlightColor); | |
2866 | } | |
2867 | ||
299e0ab9 | 2868 | myActiveProgram->SetUniform (this, aLoc, OpenGl_Material::NbOfVec4(), |
2869 | aParams.Packed()); | |
2870 | } | |
2871 | } | |
2872 | } | |
2873 | ||
2874 | // ======================================================================= | |
8625ef7e | 2875 | // function : SetColor4fv |
2876 | // purpose : | |
2877 | // ======================================================================= | |
2878 | void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor) | |
2879 | { | |
2880 | if (!myActiveProgram.IsNull()) | |
2881 | { | |
2882 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR), theColor); | |
2883 | } | |
2884 | #if !defined(GL_ES_VERSION_2_0) | |
2885 | else if (core11 != NULL) | |
2886 | { | |
2887 | core11->glColor4fv (theColor.GetData()); | |
2888 | } | |
2889 | #endif | |
2890 | } | |
2891 | ||
ac116c22 | 2892 | // ======================================================================= |
2893 | // function : SetTypeOfLine | |
2894 | // purpose : | |
2895 | // ======================================================================= | |
2896 | void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType, | |
2897 | const Standard_ShortReal theFactor) | |
2898 | { | |
2899 | Standard_Integer aPattern = 0xFFFF; | |
2900 | switch (theType) | |
2901 | { | |
2902 | case Aspect_TOL_DASH: | |
2903 | { | |
2904 | aPattern = 0xFFC0; | |
2905 | break; | |
2906 | } | |
2907 | case Aspect_TOL_DOT: | |
2908 | { | |
2909 | aPattern = 0xCCCC; | |
2910 | break; | |
2911 | } | |
2912 | case Aspect_TOL_DOTDASH: | |
2913 | { | |
2914 | aPattern = 0xFF18; | |
2915 | break; | |
2916 | } | |
2917 | case Aspect_TOL_SOLID: | |
2918 | { | |
2919 | aPattern = 0xFFFF; | |
2920 | break; | |
2921 | } | |
2922 | case Aspect_TOL_USERDEFINED: | |
2923 | { | |
2924 | aPattern = 0xFF24; | |
2925 | break; | |
2926 | } | |
2927 | } | |
2928 | ||
c04c30b3 | 2929 | if (!myActiveProgram.IsNull()) |
ac116c22 | 2930 | { |
2931 | myActiveProgram->SetUniform (this, "uPattern", aPattern); | |
2932 | myActiveProgram->SetUniform (this, "uFactor", theFactor); | |
2933 | return; | |
2934 | } | |
2935 | ||
2936 | #if !defined(GL_ES_VERSION_2_0) | |
2937 | if (theType != Aspect_TOL_SOLID) | |
2938 | { | |
2939 | #ifdef HAVE_GL2PS | |
2940 | if (IsFeedback()) | |
2941 | { | |
2942 | gl2psEnable (GL2PS_LINE_STIPPLE); | |
2943 | } | |
2944 | #endif | |
2945 | ||
2946 | if (core11 != NULL) | |
2947 | { | |
2948 | core11fwd->glEnable (GL_LINE_STIPPLE); | |
2949 | ||
2950 | core11->glLineStipple (static_cast<GLint> (theFactor), | |
2951 | static_cast<GLushort> (aPattern)); | |
2952 | } | |
2953 | } | |
2954 | else | |
2955 | { | |
2956 | if (core11 != NULL) | |
2957 | { | |
2958 | core11fwd->glDisable (GL_LINE_STIPPLE); | |
2959 | } | |
2960 | ||
2961 | #ifdef HAVE_GL2PS | |
2962 | if (IsFeedback()) | |
2963 | { | |
2964 | gl2psDisable (GL2PS_LINE_STIPPLE); | |
2965 | } | |
2966 | #endif | |
2967 | } | |
2968 | #endif | |
2969 | } | |
2970 | ||
2971 | // ======================================================================= | |
2972 | // function : SetLineWidth | |
2973 | // purpose : | |
2974 | // ======================================================================= | |
2975 | void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth) | |
2976 | { | |
2977 | if (core11 != NULL) | |
2978 | { | |
2979 | // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f | |
75c262a9 | 2980 | core11fwd->glLineWidth (theWidth * myResolutionRatio); |
ac116c22 | 2981 | } |
2982 | #ifdef HAVE_GL2PS | |
2983 | if (IsFeedback()) | |
2984 | { | |
2985 | gl2psLineWidth (theWidth); | |
2986 | } | |
2987 | #endif | |
2988 | } | |
2989 | ||
79f4f036 | 2990 | // ======================================================================= |
2991 | // function : SetTextureMatrix | |
2992 | // purpose : | |
2993 | // ======================================================================= | |
2994 | void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams) | |
2995 | { | |
2996 | if (theParams.IsNull()) | |
2997 | { | |
2998 | return; | |
2999 | } | |
3000 | else if (!myActiveProgram.IsNull()) | |
3001 | { | |
3002 | const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D); | |
3003 | if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION) | |
3004 | { | |
3005 | return; | |
3006 | } | |
3007 | ||
3008 | // pack transformation parameters | |
3009 | OpenGl_Vec4 aTrsf[2]; | |
3010 | aTrsf[0].xy() = theParams->Translation(); | |
3011 | aTrsf[0].zw() = theParams->Scale(); | |
3012 | aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); | |
3013 | aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0)); | |
3014 | myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf); | |
3015 | return; | |
3016 | } | |
3017 | ||
3018 | #if !defined(GL_ES_VERSION_2_0) | |
3019 | if (core11 != NULL) | |
3020 | { | |
3021 | GLint aMatrixMode = GL_TEXTURE; | |
3022 | ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode); | |
3023 | ||
3024 | core11->glMatrixMode (GL_TEXTURE); | |
3025 | OpenGl_Mat4 aTextureMat; | |
3026 | const Graphic3d_Vec2& aScale = theParams->Scale(); | |
3027 | const Graphic3d_Vec2& aTrans = theParams->Translation(); | |
3028 | Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f); | |
3029 | Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f); | |
3030 | Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f); | |
3031 | core11->glLoadMatrixf (aTextureMat); | |
3032 | core11->glMatrixMode (aMatrixMode); | |
3033 | } | |
3034 | #endif | |
3035 | } | |
3036 | ||
8625ef7e | 3037 | // ======================================================================= |
3038 | // function : SetPointSize | |
3039 | // purpose : | |
3040 | // ======================================================================= | |
3041 | void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize) | |
3042 | { | |
3043 | if (!myActiveProgram.IsNull()) | |
3044 | { | |
3045 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize); | |
3046 | #if !defined(GL_ES_VERSION_2_0) | |
3047 | //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3048 | #endif | |
3049 | } | |
3050 | #if !defined(GL_ES_VERSION_2_0) | |
3051 | //else | |
3052 | { | |
3053 | core11fwd->glPointSize (theSize); | |
3054 | if (core20fwd != NULL) | |
3055 | { | |
3056 | //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
3057 | } | |
3058 | } | |
3059 | #endif | |
7d3e64ef | 3060 | } |
7d9e854b | 3061 | |
fd59283a | 3062 | // ======================================================================= |
3063 | // function : SetPointSpriteOrigin | |
3064 | // purpose : | |
3065 | // ======================================================================= | |
3066 | void OpenGl_Context::SetPointSpriteOrigin() | |
3067 | { | |
3068 | #if !defined(GL_ES_VERSION_2_0) | |
3069 | if (core15fwd == NULL) | |
3070 | { | |
3071 | return; | |
3072 | } | |
3073 | ||
3074 | const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT; | |
3075 | if (myPointSpriteOrig != aNewState) | |
3076 | { | |
3077 | myPointSpriteOrig = aNewState; | |
3078 | core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState); | |
3079 | } | |
3080 | #endif | |
3081 | } | |
3082 | ||
7d9e854b | 3083 | // ======================================================================= |
3084 | // function : SetGlNormalizeEnabled | |
3085 | // purpose : | |
3086 | // ======================================================================= | |
3087 | Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled) | |
3088 | { | |
3089 | if (isEnabled == myIsGlNormalizeEnabled) | |
3090 | { | |
3091 | return myIsGlNormalizeEnabled; | |
3092 | } | |
3093 | ||
3094 | Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled; | |
3095 | ||
3096 | myIsGlNormalizeEnabled = isEnabled; | |
3097 | ||
3098 | #if !defined(GL_ES_VERSION_2_0) | |
39070532 | 3099 | if (core11 != NULL) |
7d9e854b | 3100 | { |
39070532 | 3101 | if (isEnabled) |
3102 | { | |
3103 | ::glEnable (GL_NORMALIZE); | |
3104 | } | |
3105 | else | |
3106 | { | |
3107 | ::glDisable (GL_NORMALIZE); | |
3108 | } | |
7d9e854b | 3109 | } |
3110 | #endif | |
3111 | ||
3112 | return anOldGlNormalize; | |
3113 | } | |
c827ea3a | 3114 | |
6d0e6be5 | 3115 | // ======================================================================= |
3116 | // function : SetPolygonMode | |
3117 | // purpose : | |
3118 | // ======================================================================= | |
3119 | Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode) | |
3120 | { | |
3121 | if (myPolygonMode == theMode) | |
3122 | { | |
3123 | return myPolygonMode; | |
3124 | } | |
3125 | ||
3126 | const Standard_Integer anOldPolygonMode = myPolygonMode; | |
3127 | ||
3128 | myPolygonMode = theMode; | |
3129 | ||
3130 | #if !defined(GL_ES_VERSION_2_0) | |
3131 | ::glPolygonMode (GL_FRONT_AND_BACK, (GLenum)theMode); | |
3132 | #endif | |
3133 | ||
3134 | return anOldPolygonMode; | |
3135 | } | |
3136 | ||
3137 | // ======================================================================= | |
3138 | // function : SetPolygonHatchEnabled | |
3139 | // purpose : | |
3140 | // ======================================================================= | |
3141 | bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled) | |
3142 | { | |
3143 | if (myHatchStyles.IsNull()) | |
3144 | { | |
3145 | return false; | |
3146 | } | |
3147 | else if (myHatchStyles->IsEnabled() == theIsEnabled) | |
3148 | { | |
3149 | return theIsEnabled; | |
3150 | } | |
3151 | ||
3152 | return myHatchStyles->SetEnabled (this, theIsEnabled); | |
3153 | } | |
3154 | ||
3155 | // ======================================================================= | |
3156 | // function : SetPolygonHatchStyle | |
3157 | // purpose : | |
3158 | // ======================================================================= | |
3159 | Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Standard_Integer theType) | |
3160 | { | |
3161 | if (myHatchStyles.IsNull()) | |
3162 | { | |
3163 | if (!GetResource ("OpenGl_LineAttributes", myHatchStyles)) | |
3164 | { | |
3165 | // share and register for release once the resource is no longer used | |
3166 | myHatchStyles = new OpenGl_LineAttributes(); | |
3167 | ShareResource ("OpenGl_LineAttributes", myHatchStyles); | |
3168 | myHatchStyles->Init (this); | |
3169 | } | |
3170 | } | |
3171 | if (myHatchStyles->TypeOfHatch() == theType) | |
3172 | { | |
3173 | return theType; | |
3174 | } | |
3175 | ||
3176 | return myHatchStyles->SetTypeOfHatch (this, theType); | |
3177 | } | |
3178 | ||
c827ea3a | 3179 | // ======================================================================= |
3180 | // function : ApplyModelWorldMatrix | |
3181 | // purpose : | |
3182 | // ======================================================================= | |
3183 | void OpenGl_Context::ApplyModelWorldMatrix() | |
3184 | { | |
3185 | #if !defined(GL_ES_VERSION_2_0) | |
3186 | if (core11 != NULL) | |
3187 | { | |
3188 | core11->glMatrixMode (GL_MODELVIEW); | |
3189 | core11->glLoadMatrixf (ModelWorldState.Current()); | |
3190 | } | |
3191 | #endif | |
3192 | ||
3193 | if (!myShaderManager->IsEmpty()) | |
3194 | { | |
3195 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
3196 | } | |
3197 | } | |
3198 | ||
3199 | // ======================================================================= | |
3200 | // function : ApplyWorldViewMatrix | |
3201 | // purpose : | |
3202 | // ======================================================================= | |
3203 | void OpenGl_Context::ApplyWorldViewMatrix() | |
3204 | { | |
3205 | #if !defined(GL_ES_VERSION_2_0) | |
3206 | if (core11 != NULL) | |
3207 | { | |
3208 | core11->glMatrixMode (GL_MODELVIEW); | |
3209 | core11->glLoadMatrixf (WorldViewState.Current()); | |
3210 | } | |
3211 | #endif | |
3212 | ||
3213 | if (!myShaderManager->IsEmpty()) | |
3214 | { | |
458e3c0d | 3215 | myShaderManager->UpdateModelWorldStateTo (THE_IDENTITY_MATRIX); |
c827ea3a | 3216 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); |
3217 | } | |
3218 | } | |
3219 | ||
3220 | // ======================================================================= | |
3221 | // function : ApplyModelViewMatrix | |
3222 | // purpose : | |
3223 | // ======================================================================= | |
3224 | void OpenGl_Context::ApplyModelViewMatrix() | |
3225 | { | |
3226 | #if !defined(GL_ES_VERSION_2_0) | |
3227 | if (core11 != NULL) | |
3228 | { | |
3229 | OpenGl_Mat4 aModelView = WorldViewState.Current() * ModelWorldState.Current(); | |
3230 | core11->glMatrixMode (GL_MODELVIEW); | |
3231 | core11->glLoadMatrixf (aModelView.GetData()); | |
3232 | } | |
3233 | #endif | |
3234 | ||
3235 | if (!myShaderManager->IsEmpty()) | |
3236 | { | |
3237 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
3238 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); | |
3239 | } | |
3240 | } | |
3241 | ||
3242 | // ======================================================================= | |
3243 | // function : ApplyProjectionMatrix | |
3244 | // purpose : | |
3245 | // ======================================================================= | |
3246 | void OpenGl_Context::ApplyProjectionMatrix() | |
3247 | { | |
3248 | #if !defined(GL_ES_VERSION_2_0) | |
3249 | if (core11 != NULL) | |
3250 | { | |
3251 | core11->glMatrixMode (GL_PROJECTION); | |
3252 | core11->glLoadMatrixf (ProjectionState.Current().GetData()); | |
3253 | } | |
3254 | #endif | |
3255 | ||
3256 | if (!myShaderManager->IsEmpty()) | |
3257 | { | |
3258 | myShaderManager->UpdateProjectionStateTo (ProjectionState.Current()); | |
3259 | } | |
3260 | } | |
c357e426 | 3261 | |
3262 | ||
3263 | // ======================================================================= | |
3264 | // function : EnableFeatures | |
3265 | // purpose : | |
3266 | // ======================================================================= | |
3267 | void OpenGl_Context::EnableFeatures() const | |
3268 | { | |
3269 | // | |
3270 | } | |
3271 | ||
3272 | // ======================================================================= | |
3273 | // function : DisableFeatures | |
3274 | // purpose : | |
3275 | // ======================================================================= | |
3276 | void OpenGl_Context::DisableFeatures() const | |
3277 | { | |
3278 | #if !defined(GL_ES_VERSION_2_0) | |
3279 | glPixelTransferi (GL_MAP_COLOR, GL_FALSE); | |
3280 | #endif | |
3281 | ||
3282 | /* | |
3283 | * Disable stuff that's likely to slow down glDrawPixels. | |
3284 | * (Omit as much of this as possible, when you know in advance | |
3285 | * that the OpenGL state will already be set correctly.) | |
3286 | */ | |
3287 | glDisable(GL_DITHER); | |
3288 | glDisable(GL_BLEND); | |
3289 | glDisable(GL_DEPTH_TEST); | |
3290 | glDisable(GL_TEXTURE_2D); | |
3291 | glDisable(GL_STENCIL_TEST); | |
3292 | ||
3293 | #if !defined(GL_ES_VERSION_2_0) | |
3294 | glDisable(GL_LIGHTING); | |
3295 | glDisable(GL_ALPHA_TEST); | |
3296 | glDisable(GL_FOG); | |
3297 | glDisable(GL_LOGIC_OP); | |
3298 | glDisable(GL_TEXTURE_1D); | |
3299 | ||
3300 | glPixelTransferi(GL_MAP_COLOR, GL_FALSE); | |
3301 | glPixelTransferi(GL_RED_SCALE, 1); | |
3302 | glPixelTransferi(GL_RED_BIAS, 0); | |
3303 | glPixelTransferi(GL_GREEN_SCALE, 1); | |
3304 | glPixelTransferi(GL_GREEN_BIAS, 0); | |
3305 | glPixelTransferi(GL_BLUE_SCALE, 1); | |
3306 | glPixelTransferi(GL_BLUE_BIAS, 0); | |
3307 | glPixelTransferi(GL_ALPHA_SCALE, 1); | |
3308 | glPixelTransferi(GL_ALPHA_BIAS, 0); | |
3309 | ||
3310 | /* | |
3311 | * Disable extensions that could slow down glDrawPixels. | |
3312 | * (Actually, you should check for the presence of the proper | |
3313 | * extension before making these calls. I've omitted that | |
3314 | * code for simplicity.) | |
3315 | */ | |
3316 | ||
3317 | if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2)) | |
3318 | { | |
3319 | #ifdef GL_EXT_convolution | |
3320 | if (CheckExtension ("GL_CONVOLUTION_1D_EXT")) | |
3321 | glDisable(GL_CONVOLUTION_1D_EXT); | |
3322 | ||
3323 | if (CheckExtension ("GL_CONVOLUTION_2D_EXT")) | |
3324 | glDisable(GL_CONVOLUTION_2D_EXT); | |
3325 | ||
3326 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) | |
3327 | glDisable(GL_SEPARABLE_2D_EXT); | |
3328 | #endif | |
3329 | ||
3330 | #ifdef GL_EXT_histogram | |
3331 | if (CheckExtension ("GL_SEPARABLE_2D_EXT")) | |
3332 | glDisable(GL_HISTOGRAM_EXT); | |
3333 | ||
3334 | if (CheckExtension ("GL_MINMAX_EXT")) | |
3335 | glDisable(GL_MINMAX_EXT); | |
3336 | #endif | |
3337 | ||
3338 | #ifdef GL_EXT_texture3D | |
3339 | if (CheckExtension ("GL_TEXTURE_3D_EXT")) | |
3340 | glDisable(GL_TEXTURE_3D_EXT); | |
3341 | #endif | |
3342 | } | |
3343 | #endif | |
3344 | } |