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> |
5f8b738e | 32 | |
cbf18624 | 33 | #include <Message_Messenger.hxx> |
30f0ad28 | 34 | |
a174a3c5 | 35 | #include <NCollection_Vector.hxx> |
36 | ||
2bd4c032 | 37 | #include <Standard_ProgramError.hxx> |
38 | ||
da8bb41d | 39 | #if defined(HAVE_EGL) |
40 | #include <EGL/egl.h> | |
41 | #ifdef _MSC_VER | |
42 | #pragma comment(lib, "libEGL.lib") | |
43 | #endif | |
44 | #elif defined(_WIN32) | |
5f8b738e | 45 | // |
46 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
47 | #include <dlfcn.h> | |
48 | #else | |
49 | #include <GL/glx.h> // glXGetProcAddress() | |
50 | #endif | |
51 | ||
2166f0fa SK |
52 | IMPLEMENT_STANDARD_HANDLE (OpenGl_Context, Standard_Transient) |
53 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient) | |
54 | ||
5e27df78 | 55 | namespace |
56 | { | |
57 | static const Handle(OpenGl_Resource) NULL_GL_RESOURCE; | |
01ca42b2 | 58 | } |
5e27df78 | 59 | |
2166f0fa SK |
60 | // ======================================================================= |
61 | // function : OpenGl_Context | |
62 | // purpose : | |
63 | // ======================================================================= | |
58655684 | 64 | OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps) |
01ca42b2 | 65 | : core11 (NULL), |
66 | core11fwd (NULL), | |
67 | core15 (NULL), | |
68 | core15fwd (NULL), | |
69 | core20 (NULL), | |
70 | core20fwd (NULL), | |
71 | core32 (NULL), | |
72 | core32back (NULL), | |
25ef750e | 73 | core33 (NULL), |
74 | core33back (NULL), | |
01ca42b2 | 75 | core41 (NULL), |
76 | core41back (NULL), | |
77 | core42 (NULL), | |
78 | core42back (NULL), | |
79 | core43 (NULL), | |
80 | core43back (NULL), | |
81 | core44 (NULL), | |
82 | core44back (NULL), | |
58655684 | 83 | caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()), |
ca3c13d1 | 84 | #if defined(GL_ES_VERSION_2_0) |
85 | hasHighp (Standard_False), | |
86 | hasTexRGBA8(Standard_False), | |
87 | #else | |
88 | hasHighp (Standard_True), | |
89 | hasTexRGBA8(Standard_True), | |
90 | #endif | |
25ef750e | 91 | arbNPTW (Standard_False), |
92 | arbTexRG (Standard_False), | |
93 | arbTexBindless (NULL), | |
5e27df78 | 94 | arbTBO (NULL), |
25ef750e | 95 | arbTboRGB32 (Standard_False), |
5e27df78 | 96 | arbIns (NULL), |
58655684 | 97 | arbDbg (NULL), |
01ca42b2 | 98 | arbFBO (NULL), |
b86bb3df | 99 | arbFBOBlit (NULL), |
37eb4787 | 100 | extGS (NULL), |
bf75be98 | 101 | extBgra(Standard_False), |
102 | extAnis(Standard_False), | |
30f0ad28 | 103 | extPDS (Standard_False), |
f0430952 | 104 | atiMem (Standard_False), |
105 | nvxMem (Standard_False), | |
5e27df78 | 106 | mySharedResources (new OpenGl_ResourcesMap()), |
a174a3c5 | 107 | myDelayed (new OpenGl_DelayReleaseMap()), |
3125ebb6 | 108 | myUnusedResources (new OpenGl_ResourcesStack()), |
4269bd1b | 109 | myClippingState (), |
5f8b738e | 110 | myGlLibHandle (NULL), |
01ca42b2 | 111 | myFuncs (new OpenGl_GlFunctions()), |
2f6cb3ac | 112 | myAnisoMax (1), |
ca3c13d1 | 113 | myTexClamp (GL_CLAMP_TO_EDGE), |
eafb234b | 114 | myMaxTexDim (1024), |
4269bd1b | 115 | myMaxClipPlanes (6), |
5f8b738e | 116 | myGlVerMajor (0), |
117 | myGlVerMinor (0), | |
b5ac8292 | 118 | myIsInitialized (Standard_False), |
119 | myIsStereoBuffers (Standard_False), | |
7d9e854b | 120 | myIsGlNormalizeEnabled (Standard_False), |
ca3c13d1 | 121 | #if !defined(GL_ES_VERSION_2_0) |
7d3e64ef | 122 | myRenderMode (GL_RENDER), |
ca3c13d1 | 123 | #else |
124 | myRenderMode (0), | |
125 | #endif | |
38a0206f | 126 | myReadBuffer (0), |
4e1523ef | 127 | myDrawBuffer (0), |
128 | myDefaultVao (0), | |
129 | myIsGlDebugCtx (Standard_False) | |
2166f0fa | 130 | { |
4e1523ef | 131 | // system-dependent fields |
132 | #if defined(HAVE_EGL) | |
133 | myDisplay = (Aspect_Display )EGL_NO_DISPLAY; | |
134 | myWindow = (Aspect_Drawable )EGL_NO_SURFACE; | |
458c2c58 | 135 | myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT; |
4e1523ef | 136 | #elif defined(_WIN32) |
137 | myWindow = NULL; | |
138 | myWindowDC = NULL; | |
139 | myGContext = NULL; | |
140 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
5f8b738e | 141 | // Vendors can not extend functionality on this system |
142 | // and developers are limited to OpenGL support provided by Mac OS X SDK. | |
143 | // We retrieve function pointers from system library | |
144 | // to generalize extensions support on all platforms. | |
145 | // In this way we also reach binary compatibility benefit between OS releases | |
146 | // if some newest functionality is optionally used. | |
147 | // Notice that GL version / extension availability checks are required | |
148 | // because function pointers may be available but not functionality itself | |
149 | // (depends on renderer). | |
a2e4f780 | 150 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE |
151 | myGContext = NULL; | |
152 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY); | |
153 | #else | |
4e1523ef | 154 | myGContext = NULL; |
5f8b738e | 155 | myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY); |
a2e4f780 | 156 | #endif |
4e1523ef | 157 | #else |
158 | myDisplay = NULL; | |
159 | myWindow = 0; | |
160 | myGContext = 0; | |
5f8b738e | 161 | #endif |
a2e4f780 | 162 | |
01ca42b2 | 163 | memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions)); |
30f0ad28 | 164 | myShaderManager = new OpenGl_ShaderManager (this); |
2166f0fa SK |
165 | } |
166 | ||
167 | // ======================================================================= | |
168 | // function : ~OpenGl_Context | |
169 | // purpose : | |
170 | // ======================================================================= | |
171 | OpenGl_Context::~OpenGl_Context() | |
172 | { | |
5e27df78 | 173 | // release clean up queue |
174 | ReleaseDelayed(); | |
175 | ||
4e1523ef | 176 | #if !defined(GL_ES_VERSION_2_0) |
177 | // release default VAO | |
178 | if (myDefaultVao != 0 | |
179 | && IsValid() | |
180 | && core32 != NULL) | |
181 | { | |
182 | core32->glDeleteVertexArrays (1, &myDefaultVao); | |
183 | } | |
184 | myDefaultVao = 0; | |
185 | #endif | |
186 | ||
a2e4f780 | 187 | // release default FBO |
188 | if (!myDefaultFbo.IsNull()) | |
189 | { | |
190 | myDefaultFbo->Release (this); | |
191 | myDefaultFbo.Nullify(); | |
192 | } | |
193 | ||
5e27df78 | 194 | // release shared resources if any |
195 | if (((const Handle(Standard_Transient)& )mySharedResources)->GetRefCount() <= 1) | |
196 | { | |
392ac980 | 197 | myShaderManager.Nullify(); |
5e27df78 | 198 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); |
199 | anIter.More(); anIter.Next()) | |
200 | { | |
201 | anIter.Value()->Release (this); | |
202 | } | |
e1c659da | 203 | |
204 | // release delayed resources added during deletion of shared resources | |
205 | while (!myUnusedResources->IsEmpty()) | |
206 | { | |
207 | myUnusedResources->First()->Release (this); | |
208 | myUnusedResources->RemoveFirst(); | |
209 | } | |
5e27df78 | 210 | } |
392ac980 | 211 | else |
212 | { | |
213 | myShaderManager->SetContext (NULL); | |
214 | } | |
5e27df78 | 215 | mySharedResources.Nullify(); |
a174a3c5 | 216 | myDelayed.Nullify(); |
5e27df78 | 217 | |
25ef750e | 218 | // release sampler object |
219 | if (!myTexSampler.IsNull()) | |
220 | { | |
221 | myTexSampler->Release (this); | |
222 | } | |
223 | ||
ca3c13d1 | 224 | #if !defined(GL_ES_VERSION_2_0) |
cbf18624 | 225 | if (arbDbg != NULL |
4e1523ef | 226 | && myIsGlDebugCtx |
f8c8ba7a | 227 | && IsValid()) |
cbf18624 | 228 | { |
229 | // reset callback | |
230 | void* aPtr = NULL; | |
231 | glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM_ARB, &aPtr); | |
232 | if (aPtr == this) | |
233 | { | |
234 | arbDbg->glDebugMessageCallbackARB (NULL, NULL); | |
235 | } | |
4e1523ef | 236 | myIsGlDebugCtx = Standard_False; |
cbf18624 | 237 | } |
ca3c13d1 | 238 | #endif |
5f8b738e | 239 | } |
240 | ||
05e2200b | 241 | // ======================================================================= |
242 | // function : forcedRelease | |
243 | // purpose : | |
244 | // ======================================================================= | |
245 | void OpenGl_Context::forcedRelease() | |
246 | { | |
247 | ReleaseDelayed(); | |
248 | for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources); | |
249 | anIter.More(); anIter.Next()) | |
250 | { | |
251 | anIter.Value()->Release (this); | |
252 | } | |
253 | mySharedResources->Clear(); | |
254 | myShaderManager->clear(); | |
255 | myShaderManager->SetContext (NULL); | |
e1c659da | 256 | |
257 | // release delayed resources added during deletion of shared resources | |
258 | while (!myUnusedResources->IsEmpty()) | |
259 | { | |
260 | myUnusedResources->First()->Release (this); | |
261 | myUnusedResources->RemoveFirst(); | |
262 | } | |
05e2200b | 263 | } |
264 | ||
bf75be98 | 265 | // ======================================================================= |
266 | // function : MaxDegreeOfAnisotropy | |
267 | // purpose : | |
268 | // ======================================================================= | |
269 | Standard_Integer OpenGl_Context::MaxDegreeOfAnisotropy() const | |
270 | { | |
271 | return myAnisoMax; | |
272 | } | |
273 | ||
274 | // ======================================================================= | |
275 | // function : MaxTextureSize | |
276 | // purpose : | |
277 | // ======================================================================= | |
278 | Standard_Integer OpenGl_Context::MaxTextureSize() const | |
279 | { | |
280 | return myMaxTexDim; | |
281 | } | |
282 | ||
4269bd1b | 283 | // ======================================================================= |
284 | // function : MaxClipPlanes | |
285 | // purpose : | |
286 | // ======================================================================= | |
287 | Standard_Integer OpenGl_Context::MaxClipPlanes() const | |
288 | { | |
289 | return myMaxClipPlanes; | |
290 | } | |
291 | ||
ca3c13d1 | 292 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 293 | inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer) |
294 | { | |
295 | switch (theBuffer) | |
b5ac8292 | 296 | { |
38a0206f | 297 | case GL_BACK_LEFT: |
298 | case GL_BACK_RIGHT: | |
299 | return GL_BACK; | |
300 | case GL_FRONT_LEFT: | |
301 | case GL_FRONT_RIGHT: | |
302 | return GL_FRONT; | |
303 | default: | |
304 | return theBuffer; | |
b5ac8292 | 305 | } |
306 | } | |
38a0206f | 307 | #endif |
b5ac8292 | 308 | |
309 | // ======================================================================= | |
38a0206f | 310 | // function : SetReadBuffer |
b5ac8292 | 311 | // purpose : |
312 | // ======================================================================= | |
38a0206f | 313 | void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer) |
b5ac8292 | 314 | { |
ca3c13d1 | 315 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 316 | myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer; |
317 | if (myReadBuffer < GL_COLOR_ATTACHMENT0 | |
318 | && arbFBO != NULL) | |
b5ac8292 | 319 | { |
38a0206f | 320 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 321 | } |
38a0206f | 322 | ::glReadBuffer (myReadBuffer); |
323 | #else | |
324 | (void )theReadBuffer; | |
ca3c13d1 | 325 | #endif |
b5ac8292 | 326 | } |
327 | ||
328 | // ======================================================================= | |
38a0206f | 329 | // function : SetDrawBuffer |
b5ac8292 | 330 | // purpose : |
331 | // ======================================================================= | |
38a0206f | 332 | void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer) |
b5ac8292 | 333 | { |
ca3c13d1 | 334 | #if !defined(GL_ES_VERSION_2_0) |
38a0206f | 335 | myDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer; |
336 | if (myDrawBuffer < GL_COLOR_ATTACHMENT0 | |
337 | && arbFBO != NULL) | |
b5ac8292 | 338 | { |
38a0206f | 339 | arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); |
b5ac8292 | 340 | } |
38a0206f | 341 | ::glDrawBuffer (myDrawBuffer); |
342 | #else | |
343 | (void )theDrawBuffer; | |
ca3c13d1 | 344 | #endif |
b5ac8292 | 345 | } |
346 | ||
347 | // ======================================================================= | |
348 | // function : FetchState | |
349 | // purpose : | |
350 | // ======================================================================= | |
351 | void OpenGl_Context::FetchState() | |
352 | { | |
ca3c13d1 | 353 | #if !defined(GL_ES_VERSION_2_0) |
b5ac8292 | 354 | // cache feedback mode state |
4e1523ef | 355 | if (core11 != NULL) |
356 | { | |
357 | ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode); | |
358 | } | |
b5ac8292 | 359 | |
38a0206f | 360 | // cache buffers state |
361 | ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer); | |
362 | ::glGetIntegerv (GL_DRAW_BUFFER, &myDrawBuffer); | |
ca3c13d1 | 363 | #endif |
b5ac8292 | 364 | } |
365 | ||
5e27df78 | 366 | // ======================================================================= |
367 | // function : Share | |
368 | // purpose : | |
369 | // ======================================================================= | |
370 | void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx) | |
371 | { | |
372 | if (!theShareCtx.IsNull()) | |
373 | { | |
374 | mySharedResources = theShareCtx->mySharedResources; | |
a174a3c5 | 375 | myDelayed = theShareCtx->myDelayed; |
3125ebb6 | 376 | myUnusedResources = theShareCtx->myUnusedResources; |
392ac980 | 377 | myShaderManager = theShareCtx->myShaderManager; |
5e27df78 | 378 | } |
379 | } | |
380 | ||
4fe56619 | 381 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
382 | ||
86fa64d9 | 383 | // ======================================================================= |
384 | // function : IsCurrent | |
385 | // purpose : | |
386 | // ======================================================================= | |
387 | Standard_Boolean OpenGl_Context::IsCurrent() const | |
388 | { | |
da8bb41d | 389 | #if defined(HAVE_EGL) |
390 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
391 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
392 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
393 | { | |
394 | return Standard_False; | |
395 | } | |
396 | ||
397 | return (((EGLDisplay )myDisplay == eglGetCurrentDisplay()) | |
398 | && ((EGLContext )myGContext == eglGetCurrentContext()) | |
399 | && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW))); | |
400 | #elif defined(_WIN32) | |
86fa64d9 | 401 | if (myWindowDC == NULL || myGContext == NULL) |
402 | { | |
403 | return Standard_False; | |
404 | } | |
405 | return (( (HDC )myWindowDC == wglGetCurrentDC()) | |
406 | && ((HGLRC )myGContext == wglGetCurrentContext())); | |
407 | #else | |
408 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) | |
409 | { | |
410 | return Standard_False; | |
411 | } | |
412 | ||
413 | return ( ((Display* )myDisplay == glXGetCurrentDisplay()) | |
414 | && ((GLXContext )myGContext == glXGetCurrentContext()) | |
415 | && ((GLXDrawable )myWindow == glXGetCurrentDrawable())); | |
416 | #endif | |
417 | } | |
418 | ||
2bd4c032 | 419 | // ======================================================================= |
420 | // function : MakeCurrent | |
421 | // purpose : | |
422 | // ======================================================================= | |
423 | Standard_Boolean OpenGl_Context::MakeCurrent() | |
424 | { | |
da8bb41d | 425 | #if defined(HAVE_EGL) |
426 | if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY | |
427 | || (EGLSurface )myWindow == EGL_NO_SURFACE | |
428 | || (EGLContext )myGContext == EGL_NO_CONTEXT) | |
429 | { | |
430 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
431 | return Standard_False; | |
432 | } | |
433 | ||
434 | if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE) | |
435 | { | |
436 | // if there is no current context it might be impossible to use glGetError() correctly | |
437 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, | |
438 | "eglMakeCurrent() has failed!"); | |
439 | myIsInitialized = Standard_False; | |
440 | return Standard_False; | |
441 | } | |
442 | #elif defined(_WIN32) | |
86fa64d9 | 443 | if (myWindowDC == NULL || myGContext == NULL) |
2bd4c032 | 444 | { |
86fa64d9 | 445 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); |
446 | return Standard_False; | |
447 | } | |
448 | ||
449 | // technically it should be safe to activate already bound GL context | |
450 | // however some drivers (Intel etc.) may FAIL doing this for unknown reason | |
451 | if (IsCurrent()) | |
452 | { | |
392ac980 | 453 | myShaderManager->SetContext (this); |
86fa64d9 | 454 | return Standard_True; |
455 | } | |
456 | else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE) | |
457 | { | |
458 | // notice that glGetError() couldn't be used here! | |
459 | wchar_t* aMsgBuff = NULL; | |
460 | DWORD anErrorCode = GetLastError(); | |
461 | FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | |
462 | NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL); | |
cbf18624 | 463 | TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. "); |
86fa64d9 | 464 | if (aMsgBuff != NULL) |
465 | { | |
cbf18624 | 466 | aMsg += (Standard_ExtString )aMsgBuff; |
86fa64d9 | 467 | LocalFree (aMsgBuff); |
468 | } | |
cbf18624 | 469 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg); |
fd4a6963 | 470 | myIsInitialized = Standard_False; |
2bd4c032 | 471 | return Standard_False; |
472 | } | |
473 | #else | |
86fa64d9 | 474 | if (myDisplay == NULL || myWindow == 0 || myGContext == 0) |
475 | { | |
476 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!"); | |
477 | return Standard_False; | |
478 | } | |
479 | ||
480 | if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext)) | |
2bd4c032 | 481 | { |
482 | // if there is no current context it might be impossible to use glGetError() correctly | |
cbf18624 | 483 | PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, |
484 | "glXMakeCurrent() has failed!"); | |
fd4a6963 | 485 | myIsInitialized = Standard_False; |
2bd4c032 | 486 | return Standard_False; |
487 | } | |
488 | #endif | |
392ac980 | 489 | myShaderManager->SetContext (this); |
2bd4c032 | 490 | return Standard_True; |
491 | } | |
492 | ||
5e27df78 | 493 | // ======================================================================= |
494 | // function : SwapBuffers | |
495 | // purpose : | |
496 | // ======================================================================= | |
497 | void OpenGl_Context::SwapBuffers() | |
498 | { | |
da8bb41d | 499 | #if defined(HAVE_EGL) |
500 | if ((EGLSurface )myWindow != EGL_NO_SURFACE) | |
501 | { | |
502 | eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow); | |
503 | } | |
504 | #elif defined(_WIN32) | |
5e27df78 | 505 | if ((HDC )myWindowDC != NULL) |
506 | { | |
507 | ::SwapBuffers ((HDC )myWindowDC); | |
508 | glFlush(); | |
509 | } | |
510 | #else | |
511 | if ((Display* )myDisplay != NULL) | |
512 | { | |
513 | glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow); | |
514 | } | |
515 | #endif | |
516 | } | |
517 | ||
4fe56619 | 518 | #endif // __APPLE__ |
519 | ||
5f8b738e | 520 | // ======================================================================= |
521 | // function : findProc | |
522 | // purpose : | |
523 | // ======================================================================= | |
524 | void* OpenGl_Context::findProc (const char* theFuncName) | |
525 | { | |
da8bb41d | 526 | #if defined(HAVE_EGL) |
527 | return (void* )eglGetProcAddress (theFuncName); | |
528 | #elif defined(_WIN32) | |
5f8b738e | 529 | return wglGetProcAddress (theFuncName); |
530 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) | |
531 | return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL; | |
532 | #else | |
533 | return (void* )glXGetProcAddress ((const GLubyte* )theFuncName); | |
534 | #endif | |
2166f0fa SK |
535 | } |
536 | ||
537 | // ======================================================================= | |
538 | // function : CheckExtension | |
539 | // purpose : | |
540 | // ======================================================================= | |
2bd4c032 | 541 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const |
2166f0fa | 542 | { |
5f8b738e | 543 | if (theExtName == NULL) |
544 | { | |
0797d9d3 | 545 | #ifdef OCCT_DEBUG |
5f8b738e | 546 | std::cerr << "CheckExtension called with NULL string!\n"; |
63c629aa | 547 | #endif |
5f8b738e | 548 | return Standard_False; |
549 | } | |
5f8b738e | 550 | |
4e1523ef | 551 | #if !defined(GL_ES_VERSION_2_0) |
5f8b738e | 552 | // available since OpenGL 3.0 |
553 | // and the ONLY way to check extensions with OpenGL 3.1+ core profile | |
4e1523ef | 554 | if (IsGlGreaterEqual (3, 0) |
555 | && myFuncs->glGetStringi != NULL) | |
5f8b738e | 556 | { |
557 | GLint anExtNb = 0; | |
4e1523ef | 558 | ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb); |
559 | const size_t anExtNameLen = strlen (theExtName); | |
5f8b738e | 560 | for (GLint anIter = 0; anIter < anExtNb; ++anIter) |
561 | { | |
4e1523ef | 562 | const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter); |
563 | const size_t aTestExtNameLen = strlen (anExtension); | |
564 | if (aTestExtNameLen == anExtNameLen | |
565 | && strncmp (anExtension, theExtName, anExtNameLen) == 0) | |
5f8b738e | 566 | { |
567 | return Standard_True; | |
568 | } | |
569 | } | |
570 | return Standard_False; | |
4e1523ef | 571 | } |
572 | #endif | |
5f8b738e | 573 | |
574 | // use old way with huge string for all extensions | |
575 | const char* anExtString = (const char* )glGetString (GL_EXTENSIONS); | |
576 | if (anExtString == NULL) | |
577 | { | |
7e7c2f0b | 578 | Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning); |
2166f0fa SK |
579 | return Standard_False; |
580 | } | |
58655684 | 581 | return CheckExtension (anExtString, theExtName); |
582 | } | |
583 | ||
584 | // ======================================================================= | |
585 | // function : CheckExtension | |
586 | // purpose : | |
587 | // ======================================================================= | |
588 | Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString, | |
589 | const char* theExtName) | |
590 | { | |
591 | if (theExtString == NULL) | |
592 | { | |
593 | return Standard_False; | |
594 | } | |
2166f0fa SK |
595 | |
596 | // Search for theExtName in the extensions string. | |
597 | // Use of strstr() is not sufficient because extension names can be prefixes of other extension names. | |
58655684 | 598 | char* aPtrIter = (char* )theExtString; |
599 | const char* aPtrEnd = aPtrIter + strlen (theExtString); | |
600 | const size_t anExtNameLen = strlen (theExtName); | |
2166f0fa SK |
601 | while (aPtrIter < aPtrEnd) |
602 | { | |
6a7d83c4 | 603 | const size_t n = strcspn (aPtrIter, " "); |
5f8b738e | 604 | if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0)) |
605 | { | |
2166f0fa | 606 | return Standard_True; |
5f8b738e | 607 | } |
2166f0fa SK |
608 | aPtrIter += (n + 1); |
609 | } | |
610 | return Standard_False; | |
611 | } | |
612 | ||
4fe56619 | 613 | #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) |
614 | ||
2166f0fa SK |
615 | // ======================================================================= |
616 | // function : Init | |
617 | // purpose : | |
618 | // ======================================================================= | |
4e1523ef | 619 | Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile) |
2166f0fa | 620 | { |
2bd4c032 | 621 | if (myIsInitialized) |
5f8b738e | 622 | { |
f0430952 | 623 | return Standard_True; |
5f8b738e | 624 | } |
2bd4c032 | 625 | |
da8bb41d | 626 | #if defined(HAVE_EGL) |
627 | myDisplay = (Aspect_Display )eglGetCurrentDisplay(); | |
628 | myGContext = (Aspect_RenderingContext )eglGetCurrentContext(); | |
629 | myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW); | |
630 | #elif defined(_WIN32) | |
2bd4c032 | 631 | myWindowDC = (Aspect_Handle )wglGetCurrentDC(); |
632 | myGContext = (Aspect_RenderingContext )wglGetCurrentContext(); | |
633 | #else | |
634 | myDisplay = (Aspect_Display )glXGetCurrentDisplay(); | |
635 | myGContext = (Aspect_RenderingContext )glXGetCurrentContext(); | |
636 | myWindow = (Aspect_Drawable )glXGetCurrentDrawable(); | |
637 | #endif | |
f0430952 | 638 | if (myGContext == NULL) |
639 | { | |
640 | return Standard_False; | |
641 | } | |
2bd4c032 | 642 | |
4e1523ef | 643 | init (theIsCoreProfile); |
2bd4c032 | 644 | myIsInitialized = Standard_True; |
f0430952 | 645 | return Standard_True; |
2bd4c032 | 646 | } |
647 | ||
4fe56619 | 648 | #endif // __APPLE__ |
649 | ||
2bd4c032 | 650 | // ======================================================================= |
651 | // function : Init | |
652 | // purpose : | |
653 | // ======================================================================= | |
da8bb41d | 654 | #if defined(HAVE_EGL) |
655 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface, | |
656 | const Aspect_Display theEglDisplay, | |
4e1523ef | 657 | const Aspect_RenderingContext theEglContext, |
658 | const Standard_Boolean theIsCoreProfile) | |
da8bb41d | 659 | #elif defined(_WIN32) |
f0430952 | 660 | Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow, |
661 | const Aspect_Handle theWindowDC, | |
4e1523ef | 662 | const Aspect_RenderingContext theGContext, |
663 | const Standard_Boolean theIsCoreProfile) | |
4fe56619 | 664 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 665 | |
666 | #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE | |
667 | Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext, | |
4e1523ef | 668 | const Standard_Boolean theIsCoreProfile) |
a2e4f780 | 669 | #else |
670 | Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext, | |
671 | const Standard_Boolean theIsCoreProfile) | |
672 | #endif | |
673 | ||
2bd4c032 | 674 | #else |
f0430952 | 675 | Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, |
676 | const Aspect_Display theDisplay, | |
4e1523ef | 677 | const Aspect_RenderingContext theGContext, |
678 | const Standard_Boolean theIsCoreProfile) | |
2bd4c032 | 679 | #endif |
680 | { | |
681 | Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!"); | |
da8bb41d | 682 | #if defined(HAVE_EGL) |
683 | myWindow = theEglSurface; | |
684 | myGContext = theEglContext; | |
685 | myDisplay = theEglDisplay; | |
686 | #elif defined(_WIN32) | |
2bd4c032 | 687 | myWindow = theWindow; |
688 | myGContext = theGContext; | |
2bd4c032 | 689 | myWindowDC = theWindowDC; |
4fe56619 | 690 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
a2e4f780 | 691 | myGContext = theGContext; |
2bd4c032 | 692 | #else |
4fe56619 | 693 | myWindow = theWindow; |
694 | myGContext = theGContext; | |
2bd4c032 | 695 | myDisplay = theDisplay; |
696 | #endif | |
86fa64d9 | 697 | if (myGContext == NULL || !MakeCurrent()) |
f0430952 | 698 | { |
699 | return Standard_False; | |
700 | } | |
2bd4c032 | 701 | |
4e1523ef | 702 | init (theIsCoreProfile); |
2bd4c032 | 703 | myIsInitialized = Standard_True; |
f0430952 | 704 | return Standard_True; |
5f8b738e | 705 | } |
706 | ||
707 | // ======================================================================= | |
708 | // function : ResetErrors | |
709 | // purpose : | |
710 | // ======================================================================= | |
711 | void OpenGl_Context::ResetErrors() | |
712 | { | |
713 | while (glGetError() != GL_NO_ERROR) | |
714 | { | |
715 | // | |
716 | } | |
717 | } | |
718 | ||
719 | // ======================================================================= | |
4e1523ef | 720 | // function : ReadGlVersion |
5f8b738e | 721 | // purpose : |
722 | // ======================================================================= | |
4e1523ef | 723 | void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor, |
724 | Standard_Integer& theGlVerMinor) | |
5f8b738e | 725 | { |
726 | // reset values | |
4e1523ef | 727 | theGlVerMajor = 0; |
728 | theGlVerMinor = 0; | |
5f8b738e | 729 | |
ca3c13d1 | 730 | #ifdef GL_MAJOR_VERSION |
731 | // available since OpenGL 3.0 and OpenGL 3.0 ES | |
86325709 | 732 | GLint aMajor = 0, aMinor = 0; |
5f8b738e | 733 | glGetIntegerv (GL_MAJOR_VERSION, &aMajor); |
734 | glGetIntegerv (GL_MINOR_VERSION, &aMinor); | |
30f0ad28 | 735 | // glGetError() sometimes does not report an error here even if |
86325709 | 736 | // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants. |
ca3c13d1 | 737 | // This happens on some renderers like e.g. Cygwin MESA. |
86325709 | 738 | // Thus checking additionally if GL has put anything to |
739 | // the output variables. | |
4e1523ef | 740 | if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0) |
5f8b738e | 741 | { |
4e1523ef | 742 | theGlVerMajor = aMajor; |
743 | theGlVerMinor = aMinor; | |
5f8b738e | 744 | return; |
745 | } | |
4e1523ef | 746 | for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError()) |
747 | { | |
748 | if (anErr == GL_NO_ERROR | |
749 | || anErr == aPrevErr) | |
750 | { | |
751 | break; | |
752 | } | |
753 | } | |
ca3c13d1 | 754 | #endif |
5f8b738e | 755 | |
756 | // Read version string. | |
ca3c13d1 | 757 | // Notice that only first two numbers split by point '2.1 XXXXX' are significant. |
5f8b738e | 758 | // Following trash (after space) is vendor-specific. |
759 | // New drivers also returns micro version of GL like '3.3.0' which has no meaning | |
760 | // and should be considered as vendor-specific too. | |
761 | const char* aVerStr = (const char* )glGetString (GL_VERSION); | |
762 | if (aVerStr == NULL || *aVerStr == '\0') | |
763 | { | |
764 | // invalid GL context | |
765 | return; | |
766 | } | |
767 | ||
ca3c13d1 | 768 | //#if defined(GL_ES_VERSION_2_0) |
769 | // skip "OpenGL ES-** " section | |
770 | for (; *aVerStr != '\0'; ++aVerStr) | |
771 | { | |
772 | if (*aVerStr >= '0' && *aVerStr <= '9') | |
773 | { | |
774 | break; | |
775 | } | |
776 | } | |
777 | //#endif | |
778 | ||
5f8b738e | 779 | // parse string for major number |
780 | char aMajorStr[32]; | |
781 | char aMinorStr[32]; | |
782 | size_t aMajIter = 0; | |
783 | while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9') | |
784 | { | |
785 | ++aMajIter; | |
786 | } | |
787 | if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr)) | |
788 | { | |
789 | return; | |
790 | } | |
791 | memcpy (aMajorStr, aVerStr, aMajIter); | |
792 | aMajorStr[aMajIter] = '\0'; | |
793 | ||
794 | // parse string for minor number | |
86325709 | 795 | aVerStr += aMajIter + 1; |
796 | size_t aMinIter = 0; | |
5f8b738e | 797 | while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9') |
798 | { | |
799 | ++aMinIter; | |
800 | } | |
86325709 | 801 | if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr)) |
5f8b738e | 802 | { |
803 | return; | |
804 | } | |
86325709 | 805 | memcpy (aMinorStr, aVerStr, aMinIter); |
806 | aMinorStr[aMinIter] = '\0'; | |
5f8b738e | 807 | |
808 | // read numbers | |
4e1523ef | 809 | theGlVerMajor = atoi (aMajorStr); |
810 | theGlVerMinor = atoi (aMinorStr); | |
5f8b738e | 811 | |
4e1523ef | 812 | if (theGlVerMajor <= 0) |
5f8b738e | 813 | { |
4e1523ef | 814 | theGlVerMajor = 0; |
815 | theGlVerMinor = 0; | |
5f8b738e | 816 | } |
817 | } | |
818 | ||
58655684 | 819 | static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN"; |
820 | static Standard_CString THE_DBGMSG_SOURCES[] = | |
821 | { | |
cbf18624 | 822 | ".OpenGL", // GL_DEBUG_SOURCE_API_ARB |
823 | ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB | |
824 | ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB | |
825 | ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY_ARB | |
826 | "", // GL_DEBUG_SOURCE_APPLICATION_ARB | |
827 | ".Other" // GL_DEBUG_SOURCE_OTHER_ARB | |
58655684 | 828 | }; |
829 | ||
830 | static Standard_CString THE_DBGMSG_TYPES[] = | |
831 | { | |
cbf18624 | 832 | "Error", // GL_DEBUG_TYPE_ERROR_ARB |
833 | "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB | |
834 | "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB | |
835 | "Portability", // GL_DEBUG_TYPE_PORTABILITY_ARB | |
836 | "Performance", // GL_DEBUG_TYPE_PERFORMANCE_ARB | |
837 | "Other" // GL_DEBUG_TYPE_OTHER_ARB | |
58655684 | 838 | }; |
839 | ||
840 | static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH_ARB | |
841 | static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM_ARB | |
842 | static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW_ARB | |
843 | ||
ca3c13d1 | 844 | #if !defined(GL_ES_VERSION_2_0) |
cbf18624 | 845 | //! Callback for GL_ARB_debug_output extension |
58655684 | 846 | static void APIENTRY debugCallbackWrap(unsigned int theSource, |
847 | unsigned int theType, | |
848 | unsigned int theId, | |
849 | unsigned int theSeverity, | |
850 | int /*theLength*/, | |
851 | const char* theMessage, | |
9293178b | 852 | const void* theUserParam) |
cbf18624 | 853 | { |
854 | OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam; | |
855 | aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage); | |
856 | } | |
ca3c13d1 | 857 | #endif |
cbf18624 | 858 | |
859 | // ======================================================================= | |
860 | // function : PushMessage | |
861 | // purpose : | |
862 | // ======================================================================= | |
863 | void OpenGl_Context::PushMessage (const unsigned int theSource, | |
864 | const unsigned int theType, | |
865 | const unsigned int theId, | |
866 | const unsigned int theSeverity, | |
867 | const TCollection_ExtendedString& theMessage) | |
58655684 | 868 | { |
c87535af | 869 | if (caps->suppressExtraMsg |
870 | && theSource >= GL_DEBUG_SOURCE_API_ARB | |
871 | && theSource <= GL_DEBUG_SOURCE_OTHER_ARB | |
872 | && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Contains (theId)) | |
873 | { | |
874 | return; | |
875 | } | |
876 | ||
58655684 | 877 | Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB |
01ca42b2 | 878 | && theSource <= GL_DEBUG_SOURCE_OTHER_ARB) |
58655684 | 879 | ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API_ARB] |
880 | : THE_DBGMSG_UNKNOWN; | |
881 | Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR_ARB | |
01ca42b2 | 882 | && theType <= GL_DEBUG_TYPE_OTHER_ARB) |
58655684 | 883 | ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR_ARB] |
884 | : THE_DBGMSG_UNKNOWN; | |
885 | Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB | |
886 | ? THE_DBGMSG_SEV_HIGH | |
887 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB | |
888 | ? THE_DBGMSG_SEV_MEDIUM | |
889 | : THE_DBGMSG_SEV_LOW); | |
cbf18624 | 890 | Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB |
891 | ? Message_Alarm | |
892 | : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB | |
893 | ? Message_Warning | |
894 | : Message_Info); | |
895 | ||
896 | TCollection_ExtendedString aMsg; | |
897 | aMsg += "TKOpenGl"; aMsg += aSrc; | |
898 | aMsg += " | Type: "; aMsg += aType; | |
899 | aMsg += " | ID: "; aMsg += (Standard_Integer )theId; | |
900 | aMsg += " | Severity: "; aMsg += aSev; | |
901 | aMsg += " | Message:\n "; | |
902 | aMsg += theMessage; | |
7e7c2f0b | 903 | Messenger()->Send (aMsg, aGrav); |
58655684 | 904 | } |
905 | ||
c87535af | 906 | // ======================================================================= |
907 | // function : ExcludeMessage | |
908 | // purpose : | |
909 | // ====================================================================== | |
910 | Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource, | |
911 | const unsigned int theId) | |
912 | { | |
913 | return theSource >= GL_DEBUG_SOURCE_API_ARB | |
914 | && theSource <= GL_DEBUG_SOURCE_OTHER_ARB | |
915 | && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Add (theId); | |
916 | } | |
917 | ||
918 | // ======================================================================= | |
919 | // function : IncludeMessage | |
920 | // purpose : | |
921 | // ====================================================================== | |
922 | Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource, | |
923 | const unsigned int theId) | |
924 | { | |
925 | return theSource >= GL_DEBUG_SOURCE_API_ARB | |
926 | && theSource <= GL_DEBUG_SOURCE_OTHER_ARB | |
927 | && myFilters[theSource - GL_DEBUG_SOURCE_API_ARB].Remove (theId); | |
928 | } | |
929 | ||
ee51a9fe | 930 | // ======================================================================= |
931 | // function : checkWrongVersion | |
932 | // purpose : | |
933 | // ====================================================================== | |
934 | void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor, | |
935 | const Standard_Integer theGlVerMinor) | |
936 | { | |
937 | if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor)) | |
938 | { | |
939 | return; | |
940 | } | |
941 | ||
942 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
943 | + "Error! OpenGL context reports version " | |
944 | + myGlVerMajor + "." + myGlVerMinor | |
945 | + " but does not export required functions for " | |
946 | + theGlVerMajor + "." + theGlVerMinor; | |
947 | PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, | |
948 | GL_DEBUG_TYPE_ERROR_ARB, | |
949 | 0, | |
950 | GL_DEBUG_SEVERITY_HIGH_ARB, | |
951 | aMsg); | |
952 | } | |
953 | ||
5f8b738e | 954 | // ======================================================================= |
955 | // function : init | |
956 | // purpose : | |
957 | // ======================================================================= | |
4e1523ef | 958 | void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile) |
5f8b738e | 959 | { |
960 | // read version | |
4e1523ef | 961 | myGlVerMajor = 0; |
962 | myGlVerMinor = 0; | |
963 | ReadGlVersion (myGlVerMajor, myGlVerMinor); | |
c87535af | 964 | myVendor = (const char* )::glGetString (GL_VENDOR); |
4e1523ef | 965 | |
966 | #if defined(GL_ES_VERSION_2_0) | |
967 | (void )theIsCoreProfile; | |
968 | const bool isCoreProfile = false; | |
969 | #else | |
c87535af | 970 | |
971 | if (myVendor.Search ("NVIDIA") != -1) | |
972 | { | |
973 | // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) | |
974 | // will use VIDEO memory as the source for buffer object operations. | |
975 | ExcludeMessage (GL_DEBUG_SOURCE_API_ARB, 131185); | |
976 | } | |
4e1523ef | 977 | if (IsGlGreaterEqual (3, 0)) |
978 | { | |
979 | // retrieve auxiliary function in advance | |
980 | FindProc ("glGetStringi", myFuncs->glGetStringi); | |
981 | } | |
982 | ||
d4271fe5 | 983 | bool isCoreProfile = false; |
4e1523ef | 984 | if (IsGlGreaterEqual (3, 2)) |
985 | { | |
d4271fe5 | 986 | isCoreProfile = (theIsCoreProfile == Standard_True); |
4e1523ef | 987 | |
d4271fe5 | 988 | // detect Core profile |
989 | if (isCoreProfile) | |
4e1523ef | 990 | { |
d4271fe5 | 991 | GLint aProfile = 0; |
992 | ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile); | |
993 | isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0; | |
4e1523ef | 994 | } |
995 | } | |
4e1523ef | 996 | #endif |
997 | ||
998 | core11 = NULL; | |
999 | if (!isCoreProfile) | |
1000 | { | |
1001 | core11 = (OpenGl_GlCore11* )(&(*myFuncs)); | |
1002 | } | |
01ca42b2 | 1003 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); |
1004 | core15 = NULL; | |
1005 | core15fwd = NULL; | |
1006 | core20 = NULL; | |
1007 | core20fwd = NULL; | |
1008 | core32 = NULL; | |
1009 | core32back = NULL; | |
25ef750e | 1010 | core33 = NULL; |
1011 | core33back = NULL; | |
01ca42b2 | 1012 | core41 = NULL; |
1013 | core41back = NULL; | |
1014 | core42 = NULL; | |
1015 | core42back = NULL; | |
1016 | core43 = NULL; | |
1017 | core43back = NULL; | |
1018 | core44 = NULL; | |
1019 | core44back = NULL; | |
1020 | arbTBO = NULL; | |
25ef750e | 1021 | arbTboRGB32 = Standard_False; |
01ca42b2 | 1022 | arbIns = NULL; |
1023 | arbDbg = NULL; | |
1024 | arbFBO = NULL; | |
b86bb3df | 1025 | arbFBOBlit = NULL; |
01ca42b2 | 1026 | extGS = NULL; |
4e1523ef | 1027 | myDefaultVao = 0; |
01ca42b2 | 1028 | |
ca3c13d1 | 1029 | #if defined(GL_ES_VERSION_2_0) |
1030 | ||
1031 | hasTexRGBA8 = IsGlGreaterEqual (3, 0) | |
1032 | || CheckExtension ("GL_OES_rgb8_rgba8"); | |
05e2200b | 1033 | // NPOT textures has limited support within OpenGL ES 2.0 |
1034 | // which are relaxed by OpenGL ES 3.0 or some extensions | |
1035 | //arbNPTW = IsGlGreaterEqual (3, 0) | |
1036 | // || CheckExtension ("GL_OES_texture_npot") | |
1037 | // || CheckExtension ("GL_NV_texture_npot_2D_mipmap"); | |
1038 | arbNPTW = Standard_True; | |
ca3c13d1 | 1039 | arbTexRG = IsGlGreaterEqual (3, 0) |
1040 | || CheckExtension ("GL_EXT_texture_rg"); | |
1041 | extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888"); | |
1042 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
1043 | extPDS = CheckExtension ("GL_OES_packed_depth_stencil"); | |
1044 | ||
1045 | core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs)); | |
1046 | if (IsGlGreaterEqual (2, 0)) | |
1047 | { | |
1048 | // enable compatible functions | |
1049 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
1050 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); | |
1051 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); | |
b86bb3df | 1052 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
1053 | } | |
1054 | if (IsGlGreaterEqual (3, 0) | |
1055 | && FindProc ("glBlitFramebuffer", myFuncs->glBlitFramebuffer)) | |
1056 | { | |
1057 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
ca3c13d1 | 1058 | } |
1059 | ||
447c4115 | 1060 | hasHighp = CheckExtension ("GL_OES_fragment_precision_high"); |
ca3c13d1 | 1061 | GLint aRange[2] = {0, 0}; |
447c4115 | 1062 | GLint aPrec = 0; |
1063 | ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec); | |
1064 | if (aPrec != 0) | |
ca3c13d1 | 1065 | { |
1066 | hasHighp = Standard_True; | |
1067 | } | |
1068 | #else | |
1069 | ||
1070 | myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP; | |
1071 | ||
1072 | hasTexRGBA8 = Standard_True; | |
bf75be98 | 1073 | arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two"); |
1074 | extBgra = CheckExtension ("GL_EXT_bgra"); | |
1075 | extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic"); | |
b859a34d | 1076 | extPDS = CheckExtension ("GL_EXT_packed_depth_stencil"); |
bf75be98 | 1077 | atiMem = CheckExtension ("GL_ATI_meminfo"); |
1078 | nvxMem = CheckExtension ("GL_NVX_gpu_memory_info"); | |
1079 | ||
ca3c13d1 | 1080 | GLint aStereo = GL_FALSE; |
b5ac8292 | 1081 | glGetIntegerv (GL_STEREO, &aStereo); |
1082 | myIsStereoBuffers = aStereo == 1; | |
1083 | ||
ca3c13d1 | 1084 | // get number of maximum clipping planes |
1085 | glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes); | |
1086 | #endif | |
1087 | ||
1088 | glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim); | |
1089 | ||
bf75be98 | 1090 | if (extAnis) |
1091 | { | |
1092 | glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax); | |
1093 | } | |
f0430952 | 1094 | |
4269bd1b | 1095 | myClippingState.Init (myMaxClipPlanes); |
1096 | ||
ca3c13d1 | 1097 | #if !defined(GL_ES_VERSION_2_0) |
1098 | ||
01ca42b2 | 1099 | bool has12 = false; |
1100 | bool has13 = false; | |
1101 | bool has14 = false; | |
1102 | bool has15 = false; | |
1103 | bool has20 = false; | |
1104 | bool has21 = false; | |
1105 | bool has30 = false; | |
1106 | bool has31 = false; | |
1107 | bool has32 = false; | |
1108 | bool has33 = false; | |
1109 | bool has40 = false; | |
1110 | bool has41 = false; | |
1111 | bool has42 = false; | |
1112 | bool has43 = false; | |
1113 | bool has44 = false; | |
1114 | ||
1115 | //! Make record shorter to retrieve function pointer using variable with same name | |
1116 | #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc) | |
1117 | ||
4e1523ef | 1118 | // retrieve platform-dependent extensions |
da8bb41d | 1119 | #if defined(_WIN32) && !defined(HAVE_EGL) |
01ca42b2 | 1120 | if (FindProcShort (wglGetExtensionsStringARB)) |
1121 | { | |
1122 | const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC()); | |
1123 | if (CheckExtension (aWglExts, "WGL_EXT_swap_control")) | |
1124 | { | |
1125 | FindProcShort (wglSwapIntervalEXT); | |
1126 | } | |
1127 | if (CheckExtension (aWglExts, "WGL_ARB_pixel_format")) | |
1128 | { | |
1129 | FindProcShort (wglChoosePixelFormatARB); | |
1130 | } | |
1131 | if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile")) | |
1132 | { | |
1133 | FindProcShort (wglCreateContextAttribsARB); | |
1134 | } | |
1135 | if (CheckExtension (aWglExts, "WGL_NV_DX_interop")) | |
1136 | { | |
1137 | FindProcShort (wglDXSetResourceShareHandleNV); | |
1138 | FindProcShort (wglDXOpenDeviceNV); | |
1139 | FindProcShort (wglDXCloseDeviceNV); | |
1140 | FindProcShort (wglDXRegisterObjectNV); | |
1141 | FindProcShort (wglDXUnregisterObjectNV); | |
1142 | FindProcShort (wglDXObjectAccessNV); | |
1143 | FindProcShort (wglDXLockObjectsNV); | |
1144 | FindProcShort (wglDXUnlockObjectsNV); | |
1145 | } | |
1146 | } | |
1147 | #endif | |
1148 | ||
58655684 | 1149 | // initialize debug context extension |
1150 | if (CheckExtension ("GL_ARB_debug_output")) | |
1151 | { | |
01ca42b2 | 1152 | arbDbg = NULL; |
1153 | if (FindProcShort (glDebugMessageControlARB) | |
1154 | && FindProcShort (glDebugMessageInsertARB) | |
1155 | && FindProcShort (glDebugMessageCallbackARB) | |
1156 | && FindProcShort (glGetDebugMessageLogARB)) | |
58655684 | 1157 | { |
01ca42b2 | 1158 | arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs)); |
58655684 | 1159 | } |
1160 | if (arbDbg != NULL | |
1161 | && caps->contextDebug) | |
1162 | { | |
1163 | // setup default callback | |
4e1523ef | 1164 | myIsGlDebugCtx = Standard_True; |
58655684 | 1165 | arbDbg->glDebugMessageCallbackARB (debugCallbackWrap, this); |
c87535af | 1166 | if (caps->contextSyncDebug) |
1167 | { | |
1168 | ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); | |
1169 | } | |
58655684 | 1170 | } |
1171 | } | |
1172 | ||
01ca42b2 | 1173 | // load OpenGL 1.2 new functions |
1174 | has12 = IsGlGreaterEqual (1, 2) | |
1175 | && FindProcShort (glBlendColor) | |
1176 | && FindProcShort (glBlendEquation) | |
1177 | && FindProcShort (glDrawRangeElements) | |
1178 | && FindProcShort (glTexImage3D) | |
1179 | && FindProcShort (glTexSubImage3D) | |
1180 | && FindProcShort (glCopyTexSubImage3D); | |
1181 | ||
1182 | // load OpenGL 1.3 new functions | |
1183 | has13 = IsGlGreaterEqual (1, 3) | |
1184 | && FindProcShort (glActiveTexture) | |
1185 | && FindProcShort (glSampleCoverage) | |
1186 | && FindProcShort (glCompressedTexImage3D) | |
1187 | && FindProcShort (glCompressedTexImage2D) | |
1188 | && FindProcShort (glCompressedTexImage1D) | |
1189 | && FindProcShort (glCompressedTexSubImage3D) | |
1190 | && FindProcShort (glCompressedTexSubImage2D) | |
1191 | && FindProcShort (glCompressedTexSubImage1D) | |
4e1523ef | 1192 | && FindProcShort (glGetCompressedTexImage); |
1193 | ||
1194 | if (!isCoreProfile) | |
1195 | { | |
1196 | has13 = has13 | |
01ca42b2 | 1197 | && FindProcShort (glClientActiveTexture) |
1198 | && FindProcShort (glMultiTexCoord1d) | |
1199 | && FindProcShort (glMultiTexCoord1dv) | |
1200 | && FindProcShort (glMultiTexCoord1f) | |
1201 | && FindProcShort (glMultiTexCoord1fv) | |
1202 | && FindProcShort (glMultiTexCoord1i) | |
1203 | && FindProcShort (glMultiTexCoord1iv) | |
1204 | && FindProcShort (glMultiTexCoord1s) | |
1205 | && FindProcShort (glMultiTexCoord1sv) | |
1206 | && FindProcShort (glMultiTexCoord2d) | |
1207 | && FindProcShort (glMultiTexCoord2dv) | |
1208 | && FindProcShort (glMultiTexCoord2f) | |
1209 | && FindProcShort (glMultiTexCoord2fv) | |
1210 | && FindProcShort (glMultiTexCoord2i) | |
1211 | && FindProcShort (glMultiTexCoord2iv) | |
1212 | && FindProcShort (glMultiTexCoord2s) | |
1213 | && FindProcShort (glMultiTexCoord2sv) | |
1214 | && FindProcShort (glMultiTexCoord3d) | |
1215 | && FindProcShort (glMultiTexCoord3dv) | |
1216 | && FindProcShort (glMultiTexCoord3f) | |
1217 | && FindProcShort (glMultiTexCoord3fv) | |
1218 | && FindProcShort (glMultiTexCoord3i) | |
1219 | && FindProcShort (glMultiTexCoord3iv) | |
1220 | && FindProcShort (glMultiTexCoord3s) | |
1221 | && FindProcShort (glMultiTexCoord3sv) | |
1222 | && FindProcShort (glMultiTexCoord4d) | |
1223 | && FindProcShort (glMultiTexCoord4dv) | |
1224 | && FindProcShort (glMultiTexCoord4f) | |
1225 | && FindProcShort (glMultiTexCoord4fv) | |
1226 | && FindProcShort (glMultiTexCoord4i) | |
1227 | && FindProcShort (glMultiTexCoord4iv) | |
1228 | && FindProcShort (glMultiTexCoord4s) | |
1229 | && FindProcShort (glMultiTexCoord4sv) | |
1230 | && FindProcShort (glLoadTransposeMatrixf) | |
1231 | && FindProcShort (glLoadTransposeMatrixd) | |
1232 | && FindProcShort (glMultTransposeMatrixf) | |
1233 | && FindProcShort (glMultTransposeMatrixd); | |
4e1523ef | 1234 | } |
01ca42b2 | 1235 | |
1236 | // load OpenGL 1.4 new functions | |
1237 | has14 = IsGlGreaterEqual (1, 4) | |
1238 | && FindProcShort (glBlendFuncSeparate) | |
1239 | && FindProcShort (glMultiDrawArrays) | |
1240 | && FindProcShort (glMultiDrawElements) | |
1241 | && FindProcShort (glPointParameterf) | |
1242 | && FindProcShort (glPointParameterfv) | |
1243 | && FindProcShort (glPointParameteri) | |
1244 | && FindProcShort (glPointParameteriv); | |
1245 | ||
1246 | // load OpenGL 1.5 new functions | |
1247 | has15 = IsGlGreaterEqual (1, 5) | |
1248 | && FindProcShort (glGenQueries) | |
1249 | && FindProcShort (glDeleteQueries) | |
1250 | && FindProcShort (glIsQuery) | |
1251 | && FindProcShort (glBeginQuery) | |
1252 | && FindProcShort (glEndQuery) | |
1253 | && FindProcShort (glGetQueryiv) | |
1254 | && FindProcShort (glGetQueryObjectiv) | |
1255 | && FindProcShort (glGetQueryObjectuiv) | |
1256 | && FindProcShort (glBindBuffer) | |
1257 | && FindProcShort (glDeleteBuffers) | |
1258 | && FindProcShort (glGenBuffers) | |
1259 | && FindProcShort (glIsBuffer) | |
1260 | && FindProcShort (glBufferData) | |
1261 | && FindProcShort (glBufferSubData) | |
1262 | && FindProcShort (glGetBufferSubData) | |
1263 | && FindProcShort (glMapBuffer) | |
1264 | && FindProcShort (glUnmapBuffer) | |
1265 | && FindProcShort (glGetBufferParameteriv) | |
1266 | && FindProcShort (glGetBufferPointerv); | |
1267 | ||
1268 | // load OpenGL 2.0 new functions | |
1269 | has20 = IsGlGreaterEqual (2, 0) | |
1270 | && FindProcShort (glBlendEquationSeparate) | |
1271 | && FindProcShort (glDrawBuffers) | |
1272 | && FindProcShort (glStencilOpSeparate) | |
1273 | && FindProcShort (glStencilFuncSeparate) | |
1274 | && FindProcShort (glStencilMaskSeparate) | |
1275 | && FindProcShort (glAttachShader) | |
1276 | && FindProcShort (glBindAttribLocation) | |
1277 | && FindProcShort (glCompileShader) | |
1278 | && FindProcShort (glCreateProgram) | |
1279 | && FindProcShort (glCreateShader) | |
1280 | && FindProcShort (glDeleteProgram) | |
1281 | && FindProcShort (glDeleteShader) | |
1282 | && FindProcShort (glDetachShader) | |
1283 | && FindProcShort (glDisableVertexAttribArray) | |
1284 | && FindProcShort (glEnableVertexAttribArray) | |
1285 | && FindProcShort (glGetActiveAttrib) | |
1286 | && FindProcShort (glGetActiveUniform) | |
1287 | && FindProcShort (glGetAttachedShaders) | |
1288 | && FindProcShort (glGetAttribLocation) | |
1289 | && FindProcShort (glGetProgramiv) | |
1290 | && FindProcShort (glGetProgramInfoLog) | |
1291 | && FindProcShort (glGetShaderiv) | |
1292 | && FindProcShort (glGetShaderInfoLog) | |
1293 | && FindProcShort (glGetShaderSource) | |
1294 | && FindProcShort (glGetUniformLocation) | |
1295 | && FindProcShort (glGetUniformfv) | |
1296 | && FindProcShort (glGetUniformiv) | |
1297 | && FindProcShort (glGetVertexAttribdv) | |
1298 | && FindProcShort (glGetVertexAttribfv) | |
1299 | && FindProcShort (glGetVertexAttribiv) | |
1300 | && FindProcShort (glGetVertexAttribPointerv) | |
1301 | && FindProcShort (glIsProgram) | |
1302 | && FindProcShort (glIsShader) | |
1303 | && FindProcShort (glLinkProgram) | |
1304 | && FindProcShort (glShaderSource) | |
1305 | && FindProcShort (glUseProgram) | |
1306 | && FindProcShort (glUniform1f) | |
1307 | && FindProcShort (glUniform2f) | |
1308 | && FindProcShort (glUniform3f) | |
1309 | && FindProcShort (glUniform4f) | |
1310 | && FindProcShort (glUniform1i) | |
1311 | && FindProcShort (glUniform2i) | |
1312 | && FindProcShort (glUniform3i) | |
1313 | && FindProcShort (glUniform4i) | |
1314 | && FindProcShort (glUniform1fv) | |
1315 | && FindProcShort (glUniform2fv) | |
1316 | && FindProcShort (glUniform3fv) | |
1317 | && FindProcShort (glUniform4fv) | |
1318 | && FindProcShort (glUniform1iv) | |
1319 | && FindProcShort (glUniform2iv) | |
1320 | && FindProcShort (glUniform3iv) | |
1321 | && FindProcShort (glUniform4iv) | |
1322 | && FindProcShort (glUniformMatrix2fv) | |
1323 | && FindProcShort (glUniformMatrix3fv) | |
1324 | && FindProcShort (glUniformMatrix4fv) | |
1325 | && FindProcShort (glValidateProgram) | |
1326 | && FindProcShort (glVertexAttrib1d) | |
1327 | && FindProcShort (glVertexAttrib1dv) | |
1328 | && FindProcShort (glVertexAttrib1f) | |
1329 | && FindProcShort (glVertexAttrib1fv) | |
1330 | && FindProcShort (glVertexAttrib1s) | |
1331 | && FindProcShort (glVertexAttrib1sv) | |
1332 | && FindProcShort (glVertexAttrib2d) | |
1333 | && FindProcShort (glVertexAttrib2dv) | |
1334 | && FindProcShort (glVertexAttrib2f) | |
1335 | && FindProcShort (glVertexAttrib2fv) | |
1336 | && FindProcShort (glVertexAttrib2s) | |
1337 | && FindProcShort (glVertexAttrib2sv) | |
1338 | && FindProcShort (glVertexAttrib3d) | |
1339 | && FindProcShort (glVertexAttrib3dv) | |
1340 | && FindProcShort (glVertexAttrib3f) | |
1341 | && FindProcShort (glVertexAttrib3fv) | |
1342 | && FindProcShort (glVertexAttrib3s) | |
1343 | && FindProcShort (glVertexAttrib3sv) | |
1344 | && FindProcShort (glVertexAttrib4Nbv) | |
1345 | && FindProcShort (glVertexAttrib4Niv) | |
1346 | && FindProcShort (glVertexAttrib4Nsv) | |
1347 | && FindProcShort (glVertexAttrib4Nub) | |
1348 | && FindProcShort (glVertexAttrib4Nubv) | |
1349 | && FindProcShort (glVertexAttrib4Nuiv) | |
1350 | && FindProcShort (glVertexAttrib4Nusv) | |
1351 | && FindProcShort (glVertexAttrib4bv) | |
1352 | && FindProcShort (glVertexAttrib4d) | |
1353 | && FindProcShort (glVertexAttrib4dv) | |
1354 | && FindProcShort (glVertexAttrib4f) | |
1355 | && FindProcShort (glVertexAttrib4fv) | |
1356 | && FindProcShort (glVertexAttrib4iv) | |
1357 | && FindProcShort (glVertexAttrib4s) | |
1358 | && FindProcShort (glVertexAttrib4sv) | |
1359 | && FindProcShort (glVertexAttrib4ubv) | |
1360 | && FindProcShort (glVertexAttrib4uiv) | |
1361 | && FindProcShort (glVertexAttrib4usv) | |
1362 | && FindProcShort (glVertexAttribPointer); | |
1363 | ||
1364 | // load OpenGL 2.1 new functions | |
1365 | has21 = IsGlGreaterEqual (2, 1) | |
1366 | && FindProcShort (glUniformMatrix2x3fv) | |
1367 | && FindProcShort (glUniformMatrix3x2fv) | |
1368 | && FindProcShort (glUniformMatrix2x4fv) | |
1369 | && FindProcShort (glUniformMatrix4x2fv) | |
1370 | && FindProcShort (glUniformMatrix3x4fv) | |
1371 | && FindProcShort (glUniformMatrix4x3fv); | |
1372 | ||
1373 | // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core) | |
1374 | const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object")) | |
1375 | && FindProcShort (glIsRenderbuffer) | |
1376 | && FindProcShort (glBindRenderbuffer) | |
1377 | && FindProcShort (glDeleteRenderbuffers) | |
1378 | && FindProcShort (glGenRenderbuffers) | |
1379 | && FindProcShort (glRenderbufferStorage) | |
1380 | && FindProcShort (glGetRenderbufferParameteriv) | |
1381 | && FindProcShort (glIsFramebuffer) | |
1382 | && FindProcShort (glBindFramebuffer) | |
1383 | && FindProcShort (glDeleteFramebuffers) | |
1384 | && FindProcShort (glGenFramebuffers) | |
1385 | && FindProcShort (glCheckFramebufferStatus) | |
1386 | && FindProcShort (glFramebufferTexture1D) | |
1387 | && FindProcShort (glFramebufferTexture2D) | |
1388 | && FindProcShort (glFramebufferTexture3D) | |
1389 | && FindProcShort (glFramebufferRenderbuffer) | |
1390 | && FindProcShort (glGetFramebufferAttachmentParameteriv) | |
1391 | && FindProcShort (glGenerateMipmap) | |
1392 | && FindProcShort (glBlitFramebuffer) | |
1393 | && FindProcShort (glRenderbufferStorageMultisample) | |
1394 | && FindProcShort (glFramebufferTextureLayer); | |
1395 | ||
1396 | // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core) | |
1397 | const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object")) | |
1398 | && FindProcShort (glBindVertexArray) | |
1399 | && FindProcShort (glDeleteVertexArrays) | |
1400 | && FindProcShort (glGenVertexArrays) | |
1401 | && FindProcShort (glIsVertexArray); | |
1402 | ||
1403 | // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core) | |
1404 | const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range")) | |
1405 | && FindProcShort (glMapBufferRange) | |
1406 | && FindProcShort (glFlushMappedBufferRange); | |
1407 | ||
1408 | // load OpenGL 3.0 new functions | |
1409 | has30 = IsGlGreaterEqual (3, 0) | |
1410 | && hasFBO | |
1411 | && hasVAO | |
1412 | && hasMapBufferRange | |
1413 | && FindProcShort (glColorMaski) | |
1414 | && FindProcShort (glGetBooleani_v) | |
1415 | && FindProcShort (glGetIntegeri_v) | |
1416 | && FindProcShort (glEnablei) | |
1417 | && FindProcShort (glDisablei) | |
1418 | && FindProcShort (glIsEnabledi) | |
1419 | && FindProcShort (glBeginTransformFeedback) | |
1420 | && FindProcShort (glEndTransformFeedback) | |
1421 | && FindProcShort (glBindBufferRange) | |
1422 | && FindProcShort (glBindBufferBase) | |
1423 | && FindProcShort (glTransformFeedbackVaryings) | |
1424 | && FindProcShort (glGetTransformFeedbackVarying) | |
1425 | && FindProcShort (glClampColor) | |
1426 | && FindProcShort (glBeginConditionalRender) | |
1427 | && FindProcShort (glEndConditionalRender) | |
1428 | && FindProcShort (glVertexAttribIPointer) | |
1429 | && FindProcShort (glGetVertexAttribIiv) | |
1430 | && FindProcShort (glGetVertexAttribIuiv) | |
1431 | && FindProcShort (glVertexAttribI1i) | |
1432 | && FindProcShort (glVertexAttribI2i) | |
1433 | && FindProcShort (glVertexAttribI3i) | |
1434 | && FindProcShort (glVertexAttribI4i) | |
1435 | && FindProcShort (glVertexAttribI1ui) | |
1436 | && FindProcShort (glVertexAttribI2ui) | |
1437 | && FindProcShort (glVertexAttribI3ui) | |
1438 | && FindProcShort (glVertexAttribI4ui) | |
1439 | && FindProcShort (glVertexAttribI1iv) | |
1440 | && FindProcShort (glVertexAttribI2iv) | |
1441 | && FindProcShort (glVertexAttribI3iv) | |
1442 | && FindProcShort (glVertexAttribI4iv) | |
1443 | && FindProcShort (glVertexAttribI1uiv) | |
1444 | && FindProcShort (glVertexAttribI2uiv) | |
1445 | && FindProcShort (glVertexAttribI3uiv) | |
1446 | && FindProcShort (glVertexAttribI4uiv) | |
1447 | && FindProcShort (glVertexAttribI4bv) | |
1448 | && FindProcShort (glVertexAttribI4sv) | |
1449 | && FindProcShort (glVertexAttribI4ubv) | |
1450 | && FindProcShort (glVertexAttribI4usv) | |
1451 | && FindProcShort (glGetUniformuiv) | |
1452 | && FindProcShort (glBindFragDataLocation) | |
1453 | && FindProcShort (glGetFragDataLocation) | |
1454 | && FindProcShort (glUniform1ui) | |
1455 | && FindProcShort (glUniform2ui) | |
1456 | && FindProcShort (glUniform3ui) | |
1457 | && FindProcShort (glUniform4ui) | |
1458 | && FindProcShort (glUniform1uiv) | |
1459 | && FindProcShort (glUniform2uiv) | |
1460 | && FindProcShort (glUniform3uiv) | |
1461 | && FindProcShort (glUniform4uiv) | |
1462 | && FindProcShort (glTexParameterIiv) | |
1463 | && FindProcShort (glTexParameterIuiv) | |
1464 | && FindProcShort (glGetTexParameterIiv) | |
1465 | && FindProcShort (glGetTexParameterIuiv) | |
1466 | && FindProcShort (glClearBufferiv) | |
1467 | && FindProcShort (glClearBufferuiv) | |
1468 | && FindProcShort (glClearBufferfv) | |
1469 | && FindProcShort (glClearBufferfi) | |
1470 | && FindProcShort (glGetStringi); | |
1471 | ||
1472 | // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core) | |
1473 | const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object")) | |
1474 | && FindProcShort (glGetUniformIndices) | |
1475 | && FindProcShort (glGetActiveUniformsiv) | |
1476 | && FindProcShort (glGetActiveUniformName) | |
1477 | && FindProcShort (glGetUniformBlockIndex) | |
1478 | && FindProcShort (glGetActiveUniformBlockiv) | |
1479 | && FindProcShort (glGetActiveUniformBlockName) | |
1480 | && FindProcShort (glUniformBlockBinding); | |
1481 | ||
1482 | // load GL_ARB_copy_buffer (added to OpenGL 3.1 core) | |
1483 | const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer")) | |
1484 | && FindProcShort (glCopyBufferSubData); | |
1485 | ||
1486 | if (has30) | |
2166f0fa | 1487 | { |
01ca42b2 | 1488 | // NPOT textures are required by OpenGL 2.0 specifications |
1489 | // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.) | |
1490 | arbNPTW = Standard_True; | |
1491 | arbTexRG = Standard_True; | |
2166f0fa SK |
1492 | } |
1493 | ||
01ca42b2 | 1494 | // load OpenGL 3.1 new functions |
1495 | has31 = IsGlGreaterEqual (3, 1) | |
1496 | && hasUBO | |
1497 | && hasCopyBufSubData | |
1498 | && FindProcShort (glDrawArraysInstanced) | |
1499 | && FindProcShort (glDrawElementsInstanced) | |
1500 | && FindProcShort (glTexBuffer) | |
1501 | && FindProcShort (glPrimitiveRestartIndex); | |
1502 | ||
1503 | // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core) | |
1504 | const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex")) | |
1505 | && FindProcShort (glDrawElementsBaseVertex) | |
1506 | && FindProcShort (glDrawRangeElementsBaseVertex) | |
1507 | && FindProcShort (glDrawElementsInstancedBaseVertex) | |
1508 | && FindProcShort (glMultiDrawElementsBaseVertex); | |
1509 | ||
1510 | // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core) | |
1511 | const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex")) | |
1512 | && FindProcShort (glProvokingVertex); | |
1513 | ||
1514 | // load GL_ARB_sync (added to OpenGL 3.2 core) | |
1515 | const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync")) | |
1516 | && FindProcShort (glFenceSync) | |
1517 | && FindProcShort (glIsSync) | |
1518 | && FindProcShort (glDeleteSync) | |
1519 | && FindProcShort (glClientWaitSync) | |
1520 | && FindProcShort (glWaitSync) | |
1521 | && FindProcShort (glGetInteger64v) | |
1522 | && FindProcShort (glGetSynciv); | |
1523 | ||
1524 | // load GL_ARB_texture_multisample (added to OpenGL 3.2 core) | |
1525 | const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample")) | |
1526 | && FindProcShort (glTexImage2DMultisample) | |
1527 | && FindProcShort (glTexImage3DMultisample) | |
1528 | && FindProcShort (glGetMultisamplefv) | |
1529 | && FindProcShort (glSampleMaski); | |
1530 | ||
1531 | // load OpenGL 3.2 new functions | |
1532 | has32 = IsGlGreaterEqual (3, 2) | |
1533 | && hasDrawElemsBaseVert | |
1534 | && hasProvokingVert | |
1535 | && hasSync | |
1536 | && hasTextureMultisample | |
1537 | && FindProcShort (glGetInteger64i_v) | |
1538 | && FindProcShort (glGetBufferParameteri64v) | |
1539 | && FindProcShort (glFramebufferTexture); | |
1540 | ||
1541 | // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core) | |
1542 | const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended")) | |
1543 | && FindProcShort (glBindFragDataLocationIndexed) | |
1544 | && FindProcShort (glGetFragDataIndex); | |
1545 | ||
1546 | // load GL_ARB_sampler_objects (added to OpenGL 3.3 core) | |
1547 | const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects")) | |
1548 | && FindProcShort (glGenSamplers) | |
1549 | && FindProcShort (glDeleteSamplers) | |
1550 | && FindProcShort (glIsSampler) | |
1551 | && FindProcShort (glBindSampler) | |
1552 | && FindProcShort (glSamplerParameteri) | |
1553 | && FindProcShort (glSamplerParameteriv) | |
1554 | && FindProcShort (glSamplerParameterf) | |
1555 | && FindProcShort (glSamplerParameterfv) | |
1556 | && FindProcShort (glSamplerParameterIiv) | |
1557 | && FindProcShort (glSamplerParameterIuiv) | |
1558 | && FindProcShort (glGetSamplerParameteriv) | |
1559 | && FindProcShort (glGetSamplerParameterIiv) | |
1560 | && FindProcShort (glGetSamplerParameterfv) | |
1561 | && FindProcShort (glGetSamplerParameterIuiv); | |
1562 | ||
1563 | // load GL_ARB_timer_query (added to OpenGL 3.3 core) | |
1564 | const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query")) | |
1565 | && FindProcShort (glQueryCounter) | |
1566 | && FindProcShort (glGetQueryObjecti64v) | |
1567 | && FindProcShort (glGetQueryObjectui64v); | |
1568 | ||
1569 | // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core) | |
1570 | const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev")) | |
1571 | && FindProcShort (glVertexP2ui) | |
1572 | && FindProcShort (glVertexP2uiv) | |
1573 | && FindProcShort (glVertexP3ui) | |
1574 | && FindProcShort (glVertexP3uiv) | |
1575 | && FindProcShort (glVertexP4ui) | |
1576 | && FindProcShort (glVertexP4uiv) | |
1577 | && FindProcShort (glTexCoordP1ui) | |
1578 | && FindProcShort (glTexCoordP1uiv) | |
1579 | && FindProcShort (glTexCoordP2ui) | |
1580 | && FindProcShort (glTexCoordP2uiv) | |
1581 | && FindProcShort (glTexCoordP3ui) | |
1582 | && FindProcShort (glTexCoordP3uiv) | |
1583 | && FindProcShort (glTexCoordP4ui) | |
1584 | && FindProcShort (glTexCoordP4uiv) | |
1585 | && FindProcShort (glMultiTexCoordP1ui) | |
1586 | && FindProcShort (glMultiTexCoordP1uiv) | |
1587 | && FindProcShort (glMultiTexCoordP2ui) | |
1588 | && FindProcShort (glMultiTexCoordP2uiv) | |
1589 | && FindProcShort (glMultiTexCoordP3ui) | |
1590 | && FindProcShort (glMultiTexCoordP3uiv) | |
1591 | && FindProcShort (glMultiTexCoordP4ui) | |
1592 | && FindProcShort (glMultiTexCoordP4uiv) | |
1593 | && FindProcShort (glNormalP3ui) | |
1594 | && FindProcShort (glNormalP3uiv) | |
1595 | && FindProcShort (glColorP3ui) | |
1596 | && FindProcShort (glColorP3uiv) | |
1597 | && FindProcShort (glColorP4ui) | |
1598 | && FindProcShort (glColorP4uiv) | |
1599 | && FindProcShort (glSecondaryColorP3ui) | |
1600 | && FindProcShort (glSecondaryColorP3uiv) | |
1601 | && FindProcShort (glVertexAttribP1ui) | |
1602 | && FindProcShort (glVertexAttribP1uiv) | |
1603 | && FindProcShort (glVertexAttribP2ui) | |
1604 | && FindProcShort (glVertexAttribP2uiv) | |
1605 | && FindProcShort (glVertexAttribP3ui) | |
1606 | && FindProcShort (glVertexAttribP3uiv) | |
1607 | && FindProcShort (glVertexAttribP4ui) | |
1608 | && FindProcShort (glVertexAttribP4uiv); | |
1609 | ||
1610 | // load OpenGL 3.3 extra functions | |
1611 | has33 = IsGlGreaterEqual (3, 3) | |
1612 | && hasBlendFuncExtended | |
1613 | && hasSamplerObjects | |
1614 | && hasTimerQuery | |
1615 | && hasVertType21010101rev | |
1616 | && FindProcShort (glVertexAttribDivisor); | |
1617 | ||
1618 | // load GL_ARB_draw_indirect (added to OpenGL 4.0 core) | |
1619 | const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect")) | |
1620 | && FindProcShort (glDrawArraysIndirect) | |
1621 | && FindProcShort (glDrawElementsIndirect); | |
1622 | ||
1623 | // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core) | |
1624 | const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64")) | |
1625 | && FindProcShort (glUniform1d) | |
1626 | && FindProcShort (glUniform2d) | |
1627 | && FindProcShort (glUniform3d) | |
1628 | && FindProcShort (glUniform4d) | |
1629 | && FindProcShort (glUniform1dv) | |
1630 | && FindProcShort (glUniform2dv) | |
1631 | && FindProcShort (glUniform3dv) | |
1632 | && FindProcShort (glUniform4dv) | |
1633 | && FindProcShort (glUniformMatrix2dv) | |
1634 | && FindProcShort (glUniformMatrix3dv) | |
1635 | && FindProcShort (glUniformMatrix4dv) | |
1636 | && FindProcShort (glUniformMatrix2x3dv) | |
1637 | && FindProcShort (glUniformMatrix2x4dv) | |
1638 | && FindProcShort (glUniformMatrix3x2dv) | |
1639 | && FindProcShort (glUniformMatrix3x4dv) | |
1640 | && FindProcShort (glUniformMatrix4x2dv) | |
1641 | && FindProcShort (glUniformMatrix4x3dv) | |
1642 | && FindProcShort (glGetUniformdv); | |
1643 | ||
1644 | // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core) | |
1645 | const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine")) | |
1646 | && FindProcShort (glGetSubroutineUniformLocation) | |
1647 | && FindProcShort (glGetSubroutineIndex) | |
1648 | && FindProcShort (glGetActiveSubroutineUniformiv) | |
1649 | && FindProcShort (glGetActiveSubroutineUniformName) | |
1650 | && FindProcShort (glGetActiveSubroutineName) | |
1651 | && FindProcShort (glUniformSubroutinesuiv) | |
1652 | && FindProcShort (glGetUniformSubroutineuiv) | |
1653 | && FindProcShort (glGetProgramStageiv); | |
1654 | ||
1655 | // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core) | |
1656 | const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader")) | |
1657 | && FindProcShort (glPatchParameteri) | |
1658 | && FindProcShort (glPatchParameterfv); | |
1659 | ||
1660 | // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core) | |
1661 | const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2")) | |
1662 | && FindProcShort (glBindTransformFeedback) | |
1663 | && FindProcShort (glDeleteTransformFeedbacks) | |
1664 | && FindProcShort (glGenTransformFeedbacks) | |
1665 | && FindProcShort (glIsTransformFeedback) | |
1666 | && FindProcShort (glPauseTransformFeedback) | |
1667 | && FindProcShort (glResumeTransformFeedback) | |
1668 | && FindProcShort (glDrawTransformFeedback); | |
1669 | ||
1670 | // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core) | |
1671 | const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3")) | |
1672 | && FindProcShort (glDrawTransformFeedbackStream) | |
1673 | && FindProcShort (glBeginQueryIndexed) | |
1674 | && FindProcShort (glEndQueryIndexed) | |
1675 | && FindProcShort (glGetQueryIndexediv); | |
1676 | ||
1677 | // load OpenGL 4.0 new functions | |
1678 | has40 = IsGlGreaterEqual (4, 0) | |
1679 | && hasDrawIndirect | |
1680 | && hasShaderFP64 | |
1681 | && hasShaderSubroutine | |
1682 | && hasTessellationShader | |
1683 | && hasTrsfFeedback2 | |
1684 | && hasTrsfFeedback3 | |
1685 | && FindProcShort (glMinSampleShading) | |
1686 | && FindProcShort (glBlendEquationi) | |
1687 | && FindProcShort (glBlendEquationSeparatei) | |
1688 | && FindProcShort (glBlendFunci) | |
1689 | && FindProcShort (glBlendFuncSeparatei); | |
1690 | ||
1691 | // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core) | |
1692 | const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility")) | |
1693 | && FindProcShort (glReleaseShaderCompiler) | |
1694 | && FindProcShort (glShaderBinary) | |
1695 | && FindProcShort (glGetShaderPrecisionFormat) | |
1696 | && FindProcShort (glDepthRangef) | |
1697 | && FindProcShort (glClearDepthf); | |
1698 | ||
1699 | // load GL_ARB_get_program_binary (added to OpenGL 4.1 core) | |
1700 | const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary")) | |
1701 | && FindProcShort (glGetProgramBinary) | |
1702 | && FindProcShort (glProgramBinary) | |
1703 | && FindProcShort (glProgramParameteri); | |
1704 | ||
1705 | ||
1706 | // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core) | |
1707 | const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects")) | |
1708 | && FindProcShort (glUseProgramStages) | |
1709 | && FindProcShort (glActiveShaderProgram) | |
1710 | && FindProcShort (glCreateShaderProgramv) | |
1711 | && FindProcShort (glBindProgramPipeline) | |
1712 | && FindProcShort (glDeleteProgramPipelines) | |
1713 | && FindProcShort (glGenProgramPipelines) | |
1714 | && FindProcShort (glIsProgramPipeline) | |
1715 | && FindProcShort (glGetProgramPipelineiv) | |
1716 | && FindProcShort (glProgramUniform1i) | |
1717 | && FindProcShort (glProgramUniform1iv) | |
1718 | && FindProcShort (glProgramUniform1f) | |
1719 | && FindProcShort (glProgramUniform1fv) | |
1720 | && FindProcShort (glProgramUniform1d) | |
1721 | && FindProcShort (glProgramUniform1dv) | |
1722 | && FindProcShort (glProgramUniform1ui) | |
1723 | && FindProcShort (glProgramUniform1uiv) | |
1724 | && FindProcShort (glProgramUniform2i) | |
1725 | && FindProcShort (glProgramUniform2iv) | |
1726 | && FindProcShort (glProgramUniform2f) | |
1727 | && FindProcShort (glProgramUniform2fv) | |
1728 | && FindProcShort (glProgramUniform2d) | |
1729 | && FindProcShort (glProgramUniform2dv) | |
1730 | && FindProcShort (glProgramUniform2ui) | |
1731 | && FindProcShort (glProgramUniform2uiv) | |
1732 | && FindProcShort (glProgramUniform3i) | |
1733 | && FindProcShort (glProgramUniform3iv) | |
1734 | && FindProcShort (glProgramUniform3f) | |
1735 | && FindProcShort (glProgramUniform3fv) | |
1736 | && FindProcShort (glProgramUniform3d) | |
1737 | && FindProcShort (glProgramUniform3dv) | |
1738 | && FindProcShort (glProgramUniform3ui) | |
1739 | && FindProcShort (glProgramUniform3uiv) | |
1740 | && FindProcShort (glProgramUniform4i) | |
1741 | && FindProcShort (glProgramUniform4iv) | |
1742 | && FindProcShort (glProgramUniform4f) | |
1743 | && FindProcShort (glProgramUniform4fv) | |
1744 | && FindProcShort (glProgramUniform4d) | |
1745 | && FindProcShort (glProgramUniform4dv) | |
1746 | && FindProcShort (glProgramUniform4ui) | |
1747 | && FindProcShort (glProgramUniform4uiv) | |
1748 | && FindProcShort (glProgramUniformMatrix2fv) | |
1749 | && FindProcShort (glProgramUniformMatrix3fv) | |
1750 | && FindProcShort (glProgramUniformMatrix4fv) | |
1751 | && FindProcShort (glProgramUniformMatrix2dv) | |
1752 | && FindProcShort (glProgramUniformMatrix3dv) | |
1753 | && FindProcShort (glProgramUniformMatrix4dv) | |
1754 | && FindProcShort (glProgramUniformMatrix2x3fv) | |
1755 | && FindProcShort (glProgramUniformMatrix3x2fv) | |
1756 | && FindProcShort (glProgramUniformMatrix2x4fv) | |
1757 | && FindProcShort (glProgramUniformMatrix4x2fv) | |
1758 | && FindProcShort (glProgramUniformMatrix3x4fv) | |
1759 | && FindProcShort (glProgramUniformMatrix4x3fv) | |
1760 | && FindProcShort (glProgramUniformMatrix2x3dv) | |
1761 | && FindProcShort (glProgramUniformMatrix3x2dv) | |
1762 | && FindProcShort (glProgramUniformMatrix2x4dv) | |
1763 | && FindProcShort (glProgramUniformMatrix4x2dv) | |
1764 | && FindProcShort (glProgramUniformMatrix3x4dv) | |
1765 | && FindProcShort (glProgramUniformMatrix4x3dv) | |
1766 | && FindProcShort (glValidateProgramPipeline) | |
1767 | && FindProcShort (glGetProgramPipelineInfoLog); | |
1768 | ||
1769 | // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core) | |
1770 | const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit")) | |
1771 | && FindProcShort (glVertexAttribL1d) | |
1772 | && FindProcShort (glVertexAttribL2d) | |
1773 | && FindProcShort (glVertexAttribL3d) | |
1774 | && FindProcShort (glVertexAttribL4d) | |
1775 | && FindProcShort (glVertexAttribL1dv) | |
1776 | && FindProcShort (glVertexAttribL2dv) | |
1777 | && FindProcShort (glVertexAttribL3dv) | |
1778 | && FindProcShort (glVertexAttribL4dv) | |
1779 | && FindProcShort (glVertexAttribLPointer) | |
1780 | && FindProcShort (glGetVertexAttribLdv); | |
1781 | ||
1782 | // load GL_ARB_viewport_array (added to OpenGL 4.1 core) | |
1783 | const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array")) | |
1784 | && FindProcShort (glViewportArrayv) | |
1785 | && FindProcShort (glViewportIndexedf) | |
1786 | && FindProcShort (glViewportIndexedfv) | |
1787 | && FindProcShort (glScissorArrayv) | |
1788 | && FindProcShort (glScissorIndexed) | |
1789 | && FindProcShort (glScissorIndexedv) | |
1790 | && FindProcShort (glDepthRangeArrayv) | |
1791 | && FindProcShort (glDepthRangeIndexed) | |
1792 | && FindProcShort (glGetFloati_v) | |
1793 | && FindProcShort (glGetDoublei_v); | |
1794 | ||
1795 | has41 = IsGlGreaterEqual (4, 1) | |
1796 | && hasES2Compatibility | |
1797 | && hasGetProgramBinary | |
1798 | && hasSeparateShaderObjects | |
1799 | && hasVertAttrib64bit | |
1800 | && hasViewportArray; | |
1801 | ||
1802 | // load GL_ARB_base_instance (added to OpenGL 4.2 core) | |
1803 | const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance")) | |
1804 | && FindProcShort (glDrawArraysInstancedBaseInstance) | |
1805 | && FindProcShort (glDrawElementsInstancedBaseInstance) | |
1806 | && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance); | |
1807 | ||
1808 | // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core) | |
1809 | const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced")) | |
1810 | && FindProcShort (glDrawTransformFeedbackInstanced) | |
1811 | && FindProcShort (glDrawTransformFeedbackStreamInstanced); | |
1812 | ||
1813 | // load GL_ARB_internalformat_query (added to OpenGL 4.2 core) | |
1814 | const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query")) | |
1815 | && FindProcShort (glGetInternalformativ); | |
1816 | ||
1817 | // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core) | |
1818 | const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters")) | |
1819 | && FindProcShort (glGetActiveAtomicCounterBufferiv); | |
1820 | ||
1821 | // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core) | |
1822 | const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store")) | |
1823 | && FindProcShort (glBindImageTexture) | |
1824 | && FindProcShort (glMemoryBarrier); | |
1825 | ||
1826 | // load GL_ARB_texture_storage (added to OpenGL 4.2 core) | |
1827 | const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage")) | |
1828 | && FindProcShort (glTexStorage1D) | |
1829 | && FindProcShort (glTexStorage2D) | |
c87535af | 1830 | && FindProcShort (glTexStorage3D); |
01ca42b2 | 1831 | |
1832 | has42 = IsGlGreaterEqual (4, 2) | |
1833 | && hasBaseInstance | |
1834 | && hasTrsfFeedbackInstanced | |
1835 | && hasInternalFormatQuery | |
1836 | && hasShaderAtomicCounters | |
1837 | && hasShaderImgLoadStore | |
1838 | && hasTextureStorage; | |
1839 | ||
1840 | has43 = IsGlGreaterEqual (4, 3) | |
1841 | && FindProcShort (glClearBufferData) | |
1842 | && FindProcShort (glClearBufferSubData) | |
1843 | && FindProcShort (glDispatchCompute) | |
1844 | && FindProcShort (glDispatchComputeIndirect) | |
1845 | && FindProcShort (glCopyImageSubData) | |
1846 | && FindProcShort (glFramebufferParameteri) | |
1847 | && FindProcShort (glGetFramebufferParameteriv) | |
1848 | && FindProcShort (glGetInternalformati64v) | |
1849 | && FindProcShort (glInvalidateTexSubImage) | |
1850 | && FindProcShort (glInvalidateTexImage) | |
1851 | && FindProcShort (glInvalidateBufferSubData) | |
1852 | && FindProcShort (glInvalidateBufferData) | |
1853 | && FindProcShort (glInvalidateFramebuffer) | |
1854 | && FindProcShort (glInvalidateSubFramebuffer) | |
1855 | && FindProcShort (glMultiDrawArraysIndirect) | |
1856 | && FindProcShort (glMultiDrawElementsIndirect) | |
1857 | && FindProcShort (glGetProgramInterfaceiv) | |
1858 | && FindProcShort (glGetProgramResourceIndex) | |
1859 | && FindProcShort (glGetProgramResourceName) | |
1860 | && FindProcShort (glGetProgramResourceiv) | |
1861 | && FindProcShort (glGetProgramResourceLocation) | |
1862 | && FindProcShort (glGetProgramResourceLocationIndex) | |
1863 | && FindProcShort (glShaderStorageBlockBinding) | |
1864 | && FindProcShort (glTexBufferRange) | |
1865 | && FindProcShort (glTexStorage2DMultisample) | |
1866 | && FindProcShort (glTexStorage3DMultisample) | |
1867 | && FindProcShort (glTextureView) | |
1868 | && FindProcShort (glBindVertexBuffer) | |
1869 | && FindProcShort (glVertexAttribFormat) | |
1870 | && FindProcShort (glVertexAttribIFormat) | |
1871 | && FindProcShort (glVertexAttribLFormat) | |
1872 | && FindProcShort (glVertexAttribBinding) | |
1873 | && FindProcShort (glVertexBindingDivisor) | |
1874 | && FindProcShort (glDebugMessageControl) | |
1875 | && FindProcShort (glDebugMessageInsert) | |
1876 | && FindProcShort (glDebugMessageCallback) | |
1877 | && FindProcShort (glGetDebugMessageLog) | |
1878 | && FindProcShort (glPushDebugGroup) | |
1879 | && FindProcShort (glPopDebugGroup) | |
1880 | && FindProcShort (glObjectLabel) | |
1881 | && FindProcShort (glGetObjectLabel) | |
1882 | && FindProcShort (glObjectPtrLabel) | |
1883 | && FindProcShort (glGetObjectPtrLabel); | |
1884 | ||
1885 | // load GL_ARB_clear_texture (added to OpenGL 4.4 core) | |
1886 | bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture")) | |
1887 | && FindProcShort (glClearTexImage) | |
1888 | && FindProcShort (glClearTexSubImage); | |
1889 | ||
1890 | has44 = IsGlGreaterEqual (4, 4) | |
1891 | && arbTexClear | |
1892 | && FindProcShort (glBufferStorage) | |
1893 | && FindProcShort (glBindBuffersBase) | |
1894 | && FindProcShort (glBindBuffersRange) | |
1895 | && FindProcShort (glBindTextures) | |
1896 | && FindProcShort (glBindSamplers) | |
1897 | && FindProcShort (glBindImageTextures) | |
1898 | && FindProcShort (glBindVertexBuffers); | |
1899 | ||
5e27df78 | 1900 | // initialize TBO extension (ARB) |
01ca42b2 | 1901 | if (!has31 |
1902 | && CheckExtension ("GL_ARB_texture_buffer_object") | |
1903 | && FindProc ("glTexBufferARB", myFuncs->glTexBuffer)) | |
5e27df78 | 1904 | { |
01ca42b2 | 1905 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); |
5e27df78 | 1906 | } |
25ef750e | 1907 | arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32"); |
5e27df78 | 1908 | |
1909 | // initialize hardware instancing extension (ARB) | |
01ca42b2 | 1910 | if (!has31 |
1911 | && CheckExtension ("GL_ARB_draw_instanced") | |
1912 | && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced) | |
1913 | && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced)) | |
5e27df78 | 1914 | { |
01ca42b2 | 1915 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); |
5e27df78 | 1916 | } |
1917 | ||
01ca42b2 | 1918 | // initialize FBO extension (ARB) |
1919 | if (hasFBO) | |
2166f0fa | 1920 | { |
b86bb3df | 1921 | arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs)); |
1922 | arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs)); | |
01ca42b2 | 1923 | extPDS = Standard_True; // extension for EXT, but part of ARB |
2166f0fa | 1924 | } |
5f8b738e | 1925 | |
37eb4787 | 1926 | // initialize GS extension (EXT) |
01ca42b2 | 1927 | if (CheckExtension ("GL_EXT_geometry_shader4") |
1928 | && FindProcShort (glProgramParameteriEXT)) | |
37eb4787 | 1929 | { |
01ca42b2 | 1930 | extGS = (OpenGl_ExtGS* )(&(*myFuncs)); |
37eb4787 | 1931 | } |
1932 | ||
25ef750e | 1933 | // initialize bindless texture extension (ARB) |
1934 | if (CheckExtension ("GL_ARB_bindless_texture") | |
1935 | && FindProcShort (glGetTextureHandleARB) | |
1936 | && FindProcShort (glGetTextureSamplerHandleARB) | |
1937 | && FindProcShort (glMakeTextureHandleResidentARB) | |
1938 | && FindProcShort (glMakeTextureHandleNonResidentARB) | |
1939 | && FindProcShort (glGetImageHandleARB) | |
1940 | && FindProcShort (glMakeImageHandleResidentARB) | |
1941 | && FindProcShort (glMakeImageHandleNonResidentARB) | |
1942 | && FindProcShort (glUniformHandleui64ARB) | |
1943 | && FindProcShort (glUniformHandleui64vARB) | |
1944 | && FindProcShort (glProgramUniformHandleui64ARB) | |
1945 | && FindProcShort (glProgramUniformHandleui64vARB) | |
1946 | && FindProcShort (glIsTextureHandleResidentARB) | |
1947 | && FindProcShort (glIsImageHandleResidentARB) | |
1948 | && FindProcShort (glVertexAttribL1ui64ARB) | |
1949 | && FindProcShort (glVertexAttribL1ui64vARB) | |
1950 | && FindProcShort (glGetVertexAttribLui64vARB)) | |
1951 | { | |
1952 | arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs)); | |
1953 | } | |
1954 | ||
01ca42b2 | 1955 | if (!has12) |
86325709 | 1956 | { |
ee51a9fe | 1957 | checkWrongVersion (1, 2); |
86325709 | 1958 | myGlVerMajor = 1; |
1959 | myGlVerMinor = 1; | |
1960 | return; | |
5f8b738e | 1961 | } |
01ca42b2 | 1962 | else if (!has13) |
5f8b738e | 1963 | { |
ee51a9fe | 1964 | checkWrongVersion (1, 3); |
01ca42b2 | 1965 | myGlVerMajor = 1; |
1966 | myGlVerMinor = 2; | |
1967 | return; | |
5f8b738e | 1968 | } |
01ca42b2 | 1969 | else if (!has14) |
5f8b738e | 1970 | { |
ee51a9fe | 1971 | checkWrongVersion (1, 4); |
86325709 | 1972 | myGlVerMajor = 1; |
01ca42b2 | 1973 | myGlVerMinor = 3; |
86325709 | 1974 | return; |
5f8b738e | 1975 | } |
01ca42b2 | 1976 | else if (!has15) |
86325709 | 1977 | { |
ee51a9fe | 1978 | checkWrongVersion (1, 5); |
01ca42b2 | 1979 | myGlVerMajor = 1; |
1980 | myGlVerMinor = 4; | |
1981 | return; | |
5f8b738e | 1982 | } |
4e1523ef | 1983 | if (!isCoreProfile) |
1984 | { | |
1985 | core15 = (OpenGl_GlCore15* )(&(*myFuncs)); | |
1986 | } | |
01ca42b2 | 1987 | core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs)); |
1988 | ||
1989 | if (!has20) | |
86325709 | 1990 | { |
ee51a9fe | 1991 | checkWrongVersion (2, 0); |
1992 | myGlVerMajor = 1; | |
1993 | myGlVerMinor = 5; | |
1994 | return; | |
1995 | } | |
1996 | ||
1997 | const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION); | |
1998 | if (aGlslVer == NULL | |
1999 | || *aGlslVer == '\0') | |
2000 | { | |
2001 | // broken context has been detected | |
2002 | TCollection_ExtendedString aMsg = TCollection_ExtendedString() | |
2003 | + "Error! OpenGL context reports version " | |
2004 | + myGlVerMajor + "." + myGlVerMinor | |
2005 | + " but reports wrong GLSL version"; | |
2006 | PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, | |
2007 | GL_DEBUG_TYPE_ERROR_ARB, | |
2008 | 0, | |
2009 | GL_DEBUG_SEVERITY_HIGH_ARB, | |
2010 | aMsg); | |
86325709 | 2011 | myGlVerMajor = 1; |
01ca42b2 | 2012 | myGlVerMinor = 5; |
86325709 | 2013 | return; |
5f8b738e | 2014 | } |
01ca42b2 | 2015 | |
4e1523ef | 2016 | if (!isCoreProfile) |
2017 | { | |
2018 | core20 = (OpenGl_GlCore20* )(&(*myFuncs)); | |
2019 | } | |
01ca42b2 | 2020 | core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs)); |
2021 | ||
2022 | if (!has21) | |
5f8b738e | 2023 | { |
ee51a9fe | 2024 | checkWrongVersion (2, 1); |
01ca42b2 | 2025 | myGlVerMajor = 2; |
2026 | myGlVerMinor = 0; | |
2027 | return; | |
86325709 | 2028 | } |
01ca42b2 | 2029 | |
2030 | if (!has30) | |
86325709 | 2031 | { |
ee51a9fe | 2032 | checkWrongVersion (3, 0); |
01ca42b2 | 2033 | myGlVerMajor = 2; |
2034 | myGlVerMinor = 1; | |
86325709 | 2035 | return; |
2036 | } | |
01ca42b2 | 2037 | |
2038 | if (!has31) | |
2039 | { | |
ee51a9fe | 2040 | checkWrongVersion (3, 1); |
01ca42b2 | 2041 | myGlVerMajor = 3; |
2042 | myGlVerMinor = 0; | |
2043 | return; | |
2044 | } | |
2045 | arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs)); | |
2046 | arbIns = (OpenGl_ArbIns* )(&(*myFuncs)); | |
2047 | ||
2048 | if (!has32) | |
86325709 | 2049 | { |
ee51a9fe | 2050 | checkWrongVersion (3, 2); |
01ca42b2 | 2051 | myGlVerMajor = 3; |
2052 | myGlVerMinor = 1; | |
2053 | return; | |
86325709 | 2054 | } |
4e1523ef | 2055 | core32 = (OpenGl_GlCore32* )(&(*myFuncs)); |
2056 | if (isCoreProfile) | |
2057 | { | |
2058 | core32->glGenVertexArrays (1, &myDefaultVao); | |
2059 | } | |
2060 | else | |
2061 | { | |
2062 | core32back = (OpenGl_GlCore32Back* )(&(*myFuncs)); | |
2063 | } | |
01ca42b2 | 2064 | |
2065 | if (!has33) | |
86325709 | 2066 | { |
ee51a9fe | 2067 | checkWrongVersion (3, 3); |
01ca42b2 | 2068 | myGlVerMajor = 3; |
2069 | myGlVerMinor = 2; | |
2070 | return; | |
86325709 | 2071 | } |
4e1523ef | 2072 | core33 = (OpenGl_GlCore33* )(&(*myFuncs)); |
2073 | if (!isCoreProfile) | |
2074 | { | |
2075 | core33back = (OpenGl_GlCore33Back* )(&(*myFuncs)); | |
2076 | } | |
25ef750e | 2077 | |
2078 | // initialize sampler object | |
2079 | myTexSampler = new OpenGl_Sampler(); | |
2080 | myTexSampler->Init (*this); | |
01ca42b2 | 2081 | |
2082 | if (!has40) | |
86325709 | 2083 | { |
ee51a9fe | 2084 | checkWrongVersion (4, 0); |
01ca42b2 | 2085 | myGlVerMajor = 3; |
2086 | myGlVerMinor = 3; | |
2087 | return; | |
2088 | } | |
25ef750e | 2089 | arbTboRGB32 = Standard_True; // in core since OpenGL 4.0 |
01ca42b2 | 2090 | |
2091 | if (!has41) | |
2092 | { | |
ee51a9fe | 2093 | checkWrongVersion (4, 1); |
01ca42b2 | 2094 | myGlVerMajor = 4; |
2095 | myGlVerMinor = 0; | |
2096 | return; | |
2097 | } | |
4e1523ef | 2098 | core41 = (OpenGl_GlCore41* )(&(*myFuncs)); |
2099 | if (!isCoreProfile) | |
2100 | { | |
2101 | core41back = (OpenGl_GlCore41Back* )(&(*myFuncs)); | |
2102 | } | |
01ca42b2 | 2103 | |
2104 | if(!has42) | |
2105 | { | |
ee51a9fe | 2106 | checkWrongVersion (4, 2); |
01ca42b2 | 2107 | myGlVerMajor = 4; |
2108 | myGlVerMinor = 1; | |
2109 | return; | |
2110 | } | |
4e1523ef | 2111 | core42 = (OpenGl_GlCore42* )(&(*myFuncs)); |
2112 | if (!isCoreProfile) | |
2113 | { | |
2114 | core42back = (OpenGl_GlCore42Back* )(&(*myFuncs)); | |
2115 | } | |
01ca42b2 | 2116 | |
4e1523ef | 2117 | if (!has43) |
01ca42b2 | 2118 | { |
ee51a9fe | 2119 | checkWrongVersion (4, 3); |
01ca42b2 | 2120 | myGlVerMajor = 4; |
2121 | myGlVerMinor = 2; | |
2122 | return; | |
2123 | } | |
4e1523ef | 2124 | core43 = (OpenGl_GlCore43* )(&(*myFuncs)); |
2125 | if (!isCoreProfile) | |
2126 | { | |
2127 | core43back = (OpenGl_GlCore43Back* )(&(*myFuncs)); | |
2128 | } | |
01ca42b2 | 2129 | |
2130 | if (!has44) | |
2131 | { | |
ee51a9fe | 2132 | checkWrongVersion (4, 4); |
01ca42b2 | 2133 | myGlVerMajor = 4; |
2134 | myGlVerMinor = 3; | |
2135 | return; | |
5f8b738e | 2136 | } |
4e1523ef | 2137 | core44 = (OpenGl_GlCore44* )(&(*myFuncs)); |
2138 | if (!isCoreProfile) | |
2139 | { | |
2140 | core44back = (OpenGl_GlCore44Back* )(&(*myFuncs)); | |
2141 | } | |
ca3c13d1 | 2142 | #endif |
2166f0fa | 2143 | } |
f0430952 | 2144 | |
2145 | // ======================================================================= | |
2146 | // function : MemoryInfo | |
2147 | // purpose : | |
2148 | // ======================================================================= | |
2149 | Standard_Size OpenGl_Context::AvailableMemory() const | |
2150 | { | |
ca3c13d1 | 2151 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2152 | if (atiMem) |
2153 | { | |
2154 | // this is actually information for VBO pool | |
2155 | // however because pools are mostly shared | |
2156 | // it can be used for total GPU memory estimations | |
2157 | GLint aMemInfo[4]; | |
2158 | aMemInfo[0] = 0; | |
2159 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo); | |
2160 | // returned value is in KiB, however this maybe changed in future | |
2161 | return Standard_Size(aMemInfo[0]) * 1024; | |
2162 | } | |
2163 | else if (nvxMem) | |
2164 | { | |
2165 | // current available dedicated video memory (in KiB), currently unused GPU memory | |
2166 | GLint aMemInfo = 0; | |
2167 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo); | |
2168 | return Standard_Size(aMemInfo) * 1024; | |
2169 | } | |
ca3c13d1 | 2170 | #endif |
f0430952 | 2171 | return 0; |
2172 | } | |
2173 | ||
2174 | // ======================================================================= | |
2175 | // function : MemoryInfo | |
2176 | // purpose : | |
2177 | // ======================================================================= | |
2178 | TCollection_AsciiString OpenGl_Context::MemoryInfo() const | |
2179 | { | |
2180 | TCollection_AsciiString anInfo; | |
ca3c13d1 | 2181 | #if !defined(GL_ES_VERSION_2_0) |
f0430952 | 2182 | if (atiMem) |
2183 | { | |
2184 | GLint aValues[4]; | |
2185 | memset (aValues, 0, sizeof(aValues)); | |
2186 | glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues); | |
2187 | ||
2188 | // total memory free in the pool | |
2189 | anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValues[0] / 1024) + " MiB\n"; | |
2190 | ||
2191 | // largest available free block in the pool | |
2192 | anInfo += TCollection_AsciiString (" Largest free block: ") + (aValues[1] / 1024) + " MiB\n"; | |
2193 | if (aValues[2] != aValues[0]) | |
2194 | { | |
2195 | // total auxiliary memory free | |
2196 | anInfo += TCollection_AsciiString (" Free memory: ") + (aValues[2] / 1024) + " MiB\n"; | |
2197 | } | |
2198 | } | |
2199 | else if (nvxMem) | |
2200 | { | |
2201 | //current available dedicated video memory (in KiB), currently unused GPU memory | |
2202 | GLint aValue = 0; | |
2203 | glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue); | |
2204 | anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValue / 1024) + " MiB\n"; | |
2205 | ||
2206 | // dedicated video memory, total size (in KiB) of the GPU memory | |
2207 | GLint aDedicated = 0; | |
2208 | glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated); | |
2209 | anInfo += TCollection_AsciiString (" GPU memory: ") + (aDedicated / 1024) + " MiB\n"; | |
2210 | ||
2211 | // total available memory, total size (in KiB) of the memory available for allocations | |
2212 | glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue); | |
2213 | if (aValue != aDedicated) | |
2214 | { | |
2215 | // different only for special configurations | |
2216 | anInfo += TCollection_AsciiString (" Total memory: ") + (aValue / 1024) + " MiB\n"; | |
2217 | } | |
2218 | } | |
ca3c13d1 | 2219 | #endif |
f0430952 | 2220 | return anInfo; |
2221 | } | |
5e27df78 | 2222 | |
2223 | ||
2224 | // ======================================================================= | |
2225 | // function : GetResource | |
2226 | // purpose : | |
2227 | // ======================================================================= | |
2228 | const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const | |
2229 | { | |
2230 | return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE; | |
2231 | } | |
2232 | ||
2233 | // ======================================================================= | |
2234 | // function : ShareResource | |
2235 | // purpose : | |
2236 | // ======================================================================= | |
2237 | Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey, | |
2238 | const Handle(OpenGl_Resource)& theResource) | |
2239 | { | |
2240 | if (theKey.IsEmpty() || theResource.IsNull()) | |
2241 | { | |
2242 | return Standard_False; | |
2243 | } | |
2244 | return mySharedResources->Bind (theKey, theResource); | |
2245 | } | |
2246 | ||
2247 | // ======================================================================= | |
2248 | // function : ReleaseResource | |
2249 | // purpose : | |
2250 | // ======================================================================= | |
a174a3c5 | 2251 | void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey, |
2252 | const Standard_Boolean theToDelay) | |
5e27df78 | 2253 | { |
2254 | if (!mySharedResources->IsBound (theKey)) | |
2255 | { | |
2256 | return; | |
2257 | } | |
2258 | const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey); | |
2259 | if (aRes->GetRefCount() > 1) | |
2260 | { | |
2261 | return; | |
2262 | } | |
2263 | ||
a174a3c5 | 2264 | if (theToDelay) |
2265 | { | |
2266 | myDelayed->Bind (theKey, 1); | |
2267 | } | |
2268 | else | |
2269 | { | |
2270 | aRes->Release (this); | |
2271 | mySharedResources->UnBind (theKey); | |
2272 | } | |
5e27df78 | 2273 | } |
2274 | ||
2275 | // ======================================================================= | |
2276 | // function : DelayedRelease | |
2277 | // purpose : | |
2278 | // ======================================================================= | |
2279 | void OpenGl_Context::DelayedRelease (Handle(OpenGl_Resource)& theResource) | |
2280 | { | |
3125ebb6 | 2281 | myUnusedResources->Prepend (theResource); |
5e27df78 | 2282 | theResource.Nullify(); |
2283 | } | |
2284 | ||
2285 | // ======================================================================= | |
2286 | // function : ReleaseDelayed | |
2287 | // purpose : | |
2288 | // ======================================================================= | |
2289 | void OpenGl_Context::ReleaseDelayed() | |
2290 | { | |
a174a3c5 | 2291 | // release queued elements |
3125ebb6 | 2292 | while (!myUnusedResources->IsEmpty()) |
5e27df78 | 2293 | { |
3125ebb6 | 2294 | myUnusedResources->First()->Release (this); |
2295 | myUnusedResources->RemoveFirst(); | |
5e27df78 | 2296 | } |
a174a3c5 | 2297 | |
265d4508 | 2298 | // release delayed shared resources |
a174a3c5 | 2299 | NCollection_Vector<TCollection_AsciiString> aDeadList; |
2300 | for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed); | |
2301 | anIter.More(); anIter.Next()) | |
2302 | { | |
2303 | if (++anIter.ChangeValue() <= 2) | |
2304 | { | |
2305 | continue; // postpone release one more frame to ensure noone use it periodically | |
2306 | } | |
2307 | ||
2308 | const TCollection_AsciiString& aKey = anIter.Key(); | |
2309 | if (!mySharedResources->IsBound (aKey)) | |
2310 | { | |
2311 | // mixed unshared strategy delayed/undelayed was used! | |
2312 | aDeadList.Append (aKey); | |
2313 | continue; | |
2314 | } | |
2315 | ||
2316 | Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey); | |
2317 | if (aRes->GetRefCount() > 1) | |
2318 | { | |
2319 | // should be only 1 instance in mySharedResources | |
2320 | // if not - resource was reused again | |
2321 | aDeadList.Append (aKey); | |
2322 | continue; | |
2323 | } | |
2324 | ||
2325 | // release resource if no one requiested it more than 2 redraw calls | |
2326 | aRes->Release (this); | |
2327 | mySharedResources->UnBind (aKey); | |
2328 | aDeadList.Append (aKey); | |
2329 | } | |
2330 | ||
2331 | for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter) | |
2332 | { | |
2333 | myDelayed->UnBind (aDeadList.Value (anIter)); | |
2334 | } | |
5e27df78 | 2335 | } |
7d3e64ef | 2336 | |
2337 | // ======================================================================= | |
2338 | // function : BindProgram | |
2339 | // purpose : | |
2340 | // ======================================================================= | |
8625ef7e | 2341 | Standard_Boolean OpenGl_Context::BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram) |
7d3e64ef | 2342 | { |
8625ef7e | 2343 | if (core20fwd == NULL) |
2344 | { | |
2345 | return Standard_False; | |
2346 | } | |
2347 | ||
7d3e64ef | 2348 | if (theProgram.IsNull() |
2349 | || !theProgram->IsValid()) | |
2350 | { | |
2351 | if (!myActiveProgram.IsNull()) | |
2352 | { | |
2353 | core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM); | |
2354 | myActiveProgram.Nullify(); | |
2355 | } | |
8625ef7e | 2356 | return Standard_False; |
7d3e64ef | 2357 | } |
2358 | ||
2359 | myActiveProgram = theProgram; | |
2360 | core20fwd->glUseProgram (theProgram->ProgramId()); | |
8625ef7e | 2361 | return Standard_True; |
2362 | } | |
2363 | ||
4e1523ef | 2364 | // ======================================================================= |
2365 | // function : BindDefaultVao | |
2366 | // purpose : | |
2367 | // ======================================================================= | |
2368 | void OpenGl_Context::BindDefaultVao() | |
2369 | { | |
2370 | #if !defined(GL_ES_VERSION_2_0) | |
2371 | if (myDefaultVao == 0 | |
2372 | || core32 == NULL) | |
2373 | { | |
2374 | return; | |
2375 | } | |
2376 | ||
2377 | core32->glBindVertexArray (myDefaultVao); | |
2378 | #endif | |
2379 | } | |
2380 | ||
a2e4f780 | 2381 | // ======================================================================= |
2382 | // function : SetDefaultFrameBuffer | |
2383 | // purpose : | |
2384 | // ======================================================================= | |
2385 | Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo) | |
2386 | { | |
2387 | Handle(OpenGl_FrameBuffer) aFbo = myDefaultFbo; | |
2388 | myDefaultFbo = theFbo; | |
2389 | return aFbo; | |
2390 | } | |
2391 | ||
8625ef7e | 2392 | // ======================================================================= |
2393 | // function : SetColor4fv | |
2394 | // purpose : | |
2395 | // ======================================================================= | |
2396 | void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor) | |
2397 | { | |
2398 | if (!myActiveProgram.IsNull()) | |
2399 | { | |
2400 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR), theColor); | |
2401 | } | |
2402 | #if !defined(GL_ES_VERSION_2_0) | |
2403 | else if (core11 != NULL) | |
2404 | { | |
2405 | core11->glColor4fv (theColor.GetData()); | |
2406 | } | |
2407 | #endif | |
2408 | } | |
2409 | ||
2410 | // ======================================================================= | |
2411 | // function : SetPointSize | |
2412 | // purpose : | |
2413 | // ======================================================================= | |
2414 | void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize) | |
2415 | { | |
2416 | if (!myActiveProgram.IsNull()) | |
2417 | { | |
2418 | myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize); | |
2419 | #if !defined(GL_ES_VERSION_2_0) | |
2420 | //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
2421 | #endif | |
2422 | } | |
2423 | #if !defined(GL_ES_VERSION_2_0) | |
2424 | //else | |
2425 | { | |
2426 | core11fwd->glPointSize (theSize); | |
2427 | if (core20fwd != NULL) | |
2428 | { | |
2429 | //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE); | |
2430 | } | |
2431 | } | |
2432 | #endif | |
7d3e64ef | 2433 | } |
7d9e854b | 2434 | |
2435 | // ======================================================================= | |
2436 | // function : SetGlNormalizeEnabled | |
2437 | // purpose : | |
2438 | // ======================================================================= | |
2439 | Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled) | |
2440 | { | |
2441 | if (isEnabled == myIsGlNormalizeEnabled) | |
2442 | { | |
2443 | return myIsGlNormalizeEnabled; | |
2444 | } | |
2445 | ||
2446 | Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled; | |
2447 | ||
2448 | myIsGlNormalizeEnabled = isEnabled; | |
2449 | ||
2450 | #if !defined(GL_ES_VERSION_2_0) | |
2451 | if (isEnabled) | |
2452 | { | |
2453 | glEnable (GL_NORMALIZE); | |
2454 | } | |
2455 | else | |
2456 | { | |
2457 | glDisable (GL_NORMALIZE); | |
2458 | } | |
2459 | #endif | |
2460 | ||
2461 | return anOldGlNormalize; | |
2462 | } | |
c827ea3a | 2463 | |
2464 | // ======================================================================= | |
2465 | // function : ApplyModelWorldMatrix | |
2466 | // purpose : | |
2467 | // ======================================================================= | |
2468 | void OpenGl_Context::ApplyModelWorldMatrix() | |
2469 | { | |
2470 | #if !defined(GL_ES_VERSION_2_0) | |
2471 | if (core11 != NULL) | |
2472 | { | |
2473 | core11->glMatrixMode (GL_MODELVIEW); | |
2474 | core11->glLoadMatrixf (ModelWorldState.Current()); | |
2475 | } | |
2476 | #endif | |
2477 | ||
2478 | if (!myShaderManager->IsEmpty()) | |
2479 | { | |
2480 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
2481 | } | |
2482 | } | |
2483 | ||
2484 | // ======================================================================= | |
2485 | // function : ApplyWorldViewMatrix | |
2486 | // purpose : | |
2487 | // ======================================================================= | |
2488 | void OpenGl_Context::ApplyWorldViewMatrix() | |
2489 | { | |
2490 | #if !defined(GL_ES_VERSION_2_0) | |
2491 | if (core11 != NULL) | |
2492 | { | |
2493 | core11->glMatrixMode (GL_MODELVIEW); | |
2494 | core11->glLoadMatrixf (WorldViewState.Current()); | |
2495 | } | |
2496 | #endif | |
2497 | ||
2498 | if (!myShaderManager->IsEmpty()) | |
2499 | { | |
2500 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); | |
2501 | } | |
2502 | } | |
2503 | ||
2504 | // ======================================================================= | |
2505 | // function : ApplyModelViewMatrix | |
2506 | // purpose : | |
2507 | // ======================================================================= | |
2508 | void OpenGl_Context::ApplyModelViewMatrix() | |
2509 | { | |
2510 | #if !defined(GL_ES_VERSION_2_0) | |
2511 | if (core11 != NULL) | |
2512 | { | |
2513 | OpenGl_Mat4 aModelView = WorldViewState.Current() * ModelWorldState.Current(); | |
2514 | core11->glMatrixMode (GL_MODELVIEW); | |
2515 | core11->glLoadMatrixf (aModelView.GetData()); | |
2516 | } | |
2517 | #endif | |
2518 | ||
2519 | if (!myShaderManager->IsEmpty()) | |
2520 | { | |
2521 | myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current()); | |
2522 | myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current()); | |
2523 | } | |
2524 | } | |
2525 | ||
2526 | // ======================================================================= | |
2527 | // function : ApplyProjectionMatrix | |
2528 | // purpose : | |
2529 | // ======================================================================= | |
2530 | void OpenGl_Context::ApplyProjectionMatrix() | |
2531 | { | |
2532 | #if !defined(GL_ES_VERSION_2_0) | |
2533 | if (core11 != NULL) | |
2534 | { | |
2535 | core11->glMatrixMode (GL_PROJECTION); | |
2536 | core11->glLoadMatrixf (ProjectionState.Current().GetData()); | |
2537 | } | |
2538 | #endif | |
2539 | ||
2540 | if (!myShaderManager->IsEmpty()) | |
2541 | { | |
2542 | myShaderManager->UpdateProjectionStateTo (ProjectionState.Current()); | |
2543 | } | |
2544 | } |