0024742: Remove rarely used collection classes
[occt.git] / src / OpenGl / OpenGl_Context.cxx
CommitLineData
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>
5f8b738e 27#include <OpenGl_GlCore20.hxx>
30f0ad28 28#include <OpenGl_ShaderManager.hxx>
5f8b738e 29
cbf18624 30#include <Message_Messenger.hxx>
30f0ad28 31
a174a3c5 32#include <NCollection_Vector.hxx>
33
2bd4c032 34#include <Standard_ProgramError.hxx>
35
58655684 36#if defined(_WIN32)
5f8b738e 37 //
38#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
39 #include <dlfcn.h>
40#else
41 #include <GL/glx.h> // glXGetProcAddress()
42#endif
43
f0430952 44// GL_NVX_gpu_memory_info
45#ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
46 enum
47 {
48 GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX = 0x9047,
49 GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX = 0x9048,
50 GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX = 0x9049,
51 GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX = 0x904A,
52 GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX = 0x904B
53 };
54#endif
55
2166f0fa
SK
56IMPLEMENT_STANDARD_HANDLE (OpenGl_Context, Standard_Transient)
57IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient)
58
5e27df78 59namespace
60{
61 static const Handle(OpenGl_Resource) NULL_GL_RESOURCE;
01ca42b2 62}
5e27df78 63
2166f0fa
SK
64// =======================================================================
65// function : OpenGl_Context
66// purpose :
67// =======================================================================
58655684 68OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
01ca42b2 69: core11 (NULL),
70 core11fwd (NULL),
71 core15 (NULL),
72 core15fwd (NULL),
73 core20 (NULL),
74 core20fwd (NULL),
75 core32 (NULL),
76 core32back (NULL),
77 core41 (NULL),
78 core41back (NULL),
79 core42 (NULL),
80 core42back (NULL),
81 core43 (NULL),
82 core43back (NULL),
83 core44 (NULL),
84 core44back (NULL),
58655684 85 caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()),
bf75be98 86 arbNPTW(Standard_False),
5e27df78 87 arbTBO (NULL),
88 arbIns (NULL),
58655684 89 arbDbg (NULL),
01ca42b2 90 arbFBO (NULL),
37eb4787 91 extGS (NULL),
bf75be98 92 extBgra(Standard_False),
93 extAnis(Standard_False),
30f0ad28 94 extPDS (Standard_False),
f0430952 95 atiMem (Standard_False),
96 nvxMem (Standard_False),
5e27df78 97 mySharedResources (new OpenGl_ResourcesMap()),
a174a3c5 98 myDelayed (new OpenGl_DelayReleaseMap()),
99 myReleaseQueue (new OpenGl_ResourcesQueue()),
4269bd1b 100 myClippingState (),
5f8b738e 101 myGlLibHandle (NULL),
01ca42b2 102 myFuncs (new OpenGl_GlFunctions()),
2f6cb3ac 103 myAnisoMax (1),
eafb234b 104 myMaxTexDim (1024),
4269bd1b 105 myMaxClipPlanes (6),
5f8b738e 106 myGlVerMajor (0),
107 myGlVerMinor (0),
b5ac8292 108 myRenderMode (GL_RENDER),
109 myIsInitialized (Standard_False),
110 myIsStereoBuffers (Standard_False),
111 myDrawBuffer (0)
2166f0fa 112{
5f8b738e 113#if defined(MAC_OS_X_VERSION_10_3) && !defined(MACOSX_USE_GLX)
114 // Vendors can not extend functionality on this system
115 // and developers are limited to OpenGL support provided by Mac OS X SDK.
116 // We retrieve function pointers from system library
117 // to generalize extensions support on all platforms.
118 // In this way we also reach binary compatibility benefit between OS releases
119 // if some newest functionality is optionally used.
120 // Notice that GL version / extension availability checks are required
121 // because function pointers may be available but not functionality itself
122 // (depends on renderer).
123 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
124#endif
01ca42b2 125 memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions));
30f0ad28 126 myShaderManager = new OpenGl_ShaderManager (this);
2166f0fa
SK
127}
128
129// =======================================================================
130// function : ~OpenGl_Context
131// purpose :
132// =======================================================================
133OpenGl_Context::~OpenGl_Context()
134{
5e27df78 135 // release clean up queue
136 ReleaseDelayed();
137
138 // release shared resources if any
139 if (((const Handle(Standard_Transient)& )mySharedResources)->GetRefCount() <= 1)
140 {
392ac980 141 myShaderManager.Nullify();
5e27df78 142 for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
143 anIter.More(); anIter.Next())
144 {
145 anIter.Value()->Release (this);
146 }
147 }
392ac980 148 else
149 {
150 myShaderManager->SetContext (NULL);
151 }
5e27df78 152 mySharedResources.Nullify();
a174a3c5 153 myDelayed.Nullify();
5e27df78 154
cbf18624 155 if (arbDbg != NULL
f8c8ba7a 156 && caps->contextDebug
157 && IsValid())
cbf18624 158 {
159 // reset callback
160 void* aPtr = NULL;
161 glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM_ARB, &aPtr);
162 if (aPtr == this)
163 {
164 arbDbg->glDebugMessageCallbackARB (NULL, NULL);
165 }
166 }
5f8b738e 167}
168
169// =======================================================================
bf75be98 170// function : MaxDegreeOfAnisotropy
171// purpose :
172// =======================================================================
173Standard_Integer OpenGl_Context::MaxDegreeOfAnisotropy() const
174{
175 return myAnisoMax;
176}
177
178// =======================================================================
179// function : MaxTextureSize
180// purpose :
181// =======================================================================
182Standard_Integer OpenGl_Context::MaxTextureSize() const
183{
184 return myMaxTexDim;
185}
186
187// =======================================================================
4269bd1b 188// function : MaxClipPlanes
189// purpose :
190// =======================================================================
191Standard_Integer OpenGl_Context::MaxClipPlanes() const
192{
193 return myMaxClipPlanes;
194}
195
196// =======================================================================
b5ac8292 197// function : SetDrawBufferLeft
198// purpose :
199// =======================================================================
200void OpenGl_Context::SetDrawBufferLeft()
201{
202 switch (myDrawBuffer)
203 {
204 case GL_BACK_RIGHT :
205 case GL_BACK :
206 glDrawBuffer (GL_BACK_LEFT);
207 myDrawBuffer = GL_BACK_LEFT;
208 break;
209
210 case GL_FRONT_RIGHT :
211 case GL_FRONT :
212 glDrawBuffer (GL_FRONT_LEFT);
213 myDrawBuffer = GL_FRONT_LEFT;
214 break;
215
216 case GL_FRONT_AND_BACK :
217 case GL_RIGHT :
218 glDrawBuffer (GL_LEFT);
219 myDrawBuffer = GL_LEFT;
220 break;
221 }
222}
223
224// =======================================================================
225// function : SetDrawBufferRight
226// purpose :
227// =======================================================================
228void OpenGl_Context::SetDrawBufferRight()
229{
230 switch (myDrawBuffer)
231 {
232 case GL_BACK_LEFT :
233 case GL_BACK :
234 glDrawBuffer (GL_BACK_RIGHT);
235 myDrawBuffer = GL_BACK_RIGHT;
236 break;
237
238 case GL_FRONT_LEFT :
239 case GL_FRONT :
240 glDrawBuffer (GL_FRONT_RIGHT);
241 myDrawBuffer = GL_FRONT_RIGHT;
242 break;
243
244 case GL_FRONT_AND_BACK :
245 case GL_LEFT :
246 glDrawBuffer (GL_RIGHT);
247 myDrawBuffer = GL_RIGHT;
248 break;
249 }
250}
251
252// =======================================================================
253// function : SetDrawBufferMono
254// purpose :
255// =======================================================================
256void OpenGl_Context::SetDrawBufferMono()
257{
258 switch (myDrawBuffer)
259 {
260 case GL_BACK_LEFT :
261 case GL_BACK_RIGHT :
262 glDrawBuffer (GL_BACK);
263 myDrawBuffer = GL_BACK;
264 break;
265
266 case GL_FRONT_LEFT :
267 case GL_FRONT_RIGHT :
268 glDrawBuffer (GL_FRONT);
269 myDrawBuffer = GL_FRONT;
270 break;
271
272 case GL_LEFT :
273 case GL_RIGHT :
274 glDrawBuffer (GL_FRONT_AND_BACK);
275 myDrawBuffer = GL_FRONT_AND_BACK;
276 break;
277 }
278}
279
280// =======================================================================
281// function : FetchState
282// purpose :
283// =======================================================================
284void OpenGl_Context::FetchState()
285{
286 // cache feedback mode state
287 glGetIntegerv (GL_RENDER_MODE, &myRenderMode);
288
289 // cache draw buffer state
290 glGetIntegerv (GL_DRAW_BUFFER, &myDrawBuffer);
291}
292
293// =======================================================================
5e27df78 294// function : Share
295// purpose :
296// =======================================================================
297void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx)
298{
299 if (!theShareCtx.IsNull())
300 {
301 mySharedResources = theShareCtx->mySharedResources;
a174a3c5 302 myDelayed = theShareCtx->myDelayed;
5e27df78 303 myReleaseQueue = theShareCtx->myReleaseQueue;
392ac980 304 myShaderManager = theShareCtx->myShaderManager;
5e27df78 305 }
306}
307
4fe56619 308#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
309
5e27df78 310// =======================================================================
86fa64d9 311// function : IsCurrent
312// purpose :
313// =======================================================================
314Standard_Boolean OpenGl_Context::IsCurrent() const
315{
58655684 316#if defined(_WIN32)
86fa64d9 317 if (myWindowDC == NULL || myGContext == NULL)
318 {
319 return Standard_False;
320 }
321 return (( (HDC )myWindowDC == wglGetCurrentDC())
322 && ((HGLRC )myGContext == wglGetCurrentContext()));
323#else
324 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
325 {
326 return Standard_False;
327 }
328
329 return ( ((Display* )myDisplay == glXGetCurrentDisplay())
330 && ((GLXContext )myGContext == glXGetCurrentContext())
331 && ((GLXDrawable )myWindow == glXGetCurrentDrawable()));
332#endif
333}
334
335// =======================================================================
2bd4c032 336// function : MakeCurrent
337// purpose :
338// =======================================================================
339Standard_Boolean OpenGl_Context::MakeCurrent()
340{
58655684 341#if defined(_WIN32)
86fa64d9 342 if (myWindowDC == NULL || myGContext == NULL)
2bd4c032 343 {
86fa64d9 344 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
345 return Standard_False;
346 }
347
348 // technically it should be safe to activate already bound GL context
349 // however some drivers (Intel etc.) may FAIL doing this for unknown reason
350 if (IsCurrent())
351 {
392ac980 352 myShaderManager->SetContext (this);
86fa64d9 353 return Standard_True;
354 }
355 else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
356 {
357 // notice that glGetError() couldn't be used here!
358 wchar_t* aMsgBuff = NULL;
359 DWORD anErrorCode = GetLastError();
360 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
361 NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
cbf18624 362 TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. ");
86fa64d9 363 if (aMsgBuff != NULL)
364 {
cbf18624 365 aMsg += (Standard_ExtString )aMsgBuff;
86fa64d9 366 LocalFree (aMsgBuff);
367 }
cbf18624 368 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg);
fd4a6963 369 myIsInitialized = Standard_False;
2bd4c032 370 return Standard_False;
371 }
372#else
86fa64d9 373 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
374 {
375 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
376 return Standard_False;
377 }
378
379 if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
2bd4c032 380 {
381 // if there is no current context it might be impossible to use glGetError() correctly
cbf18624 382 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB,
383 "glXMakeCurrent() has failed!");
fd4a6963 384 myIsInitialized = Standard_False;
2bd4c032 385 return Standard_False;
386 }
387#endif
392ac980 388 myShaderManager->SetContext (this);
2bd4c032 389 return Standard_True;
390}
391
392// =======================================================================
5e27df78 393// function : SwapBuffers
394// purpose :
395// =======================================================================
396void OpenGl_Context::SwapBuffers()
397{
58655684 398#if defined(_WIN32)
5e27df78 399 if ((HDC )myWindowDC != NULL)
400 {
401 ::SwapBuffers ((HDC )myWindowDC);
402 glFlush();
403 }
404#else
405 if ((Display* )myDisplay != NULL)
406 {
407 glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow);
408 }
409#endif
410}
411
4fe56619 412#endif // __APPLE__
413
5e27df78 414// =======================================================================
5f8b738e 415// function : findProc
416// purpose :
417// =======================================================================
418void* OpenGl_Context::findProc (const char* theFuncName)
419{
58655684 420#if defined(_WIN32)
5f8b738e 421 return wglGetProcAddress (theFuncName);
422#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
423 return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
424#else
425 return (void* )glXGetProcAddress ((const GLubyte* )theFuncName);
426#endif
2166f0fa
SK
427}
428
429// =======================================================================
430// function : CheckExtension
431// purpose :
432// =======================================================================
2bd4c032 433Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
2166f0fa 434{
5f8b738e 435 if (theExtName == NULL)
436 {
437 std::cerr << "CheckExtension called with NULL string!\n";
438 return Standard_False;
439 }
5f8b738e 440
441 // available since OpenGL 3.0
442 // and the ONLY way to check extensions with OpenGL 3.1+ core profile
2bd4c032 443 /**if (IsGlGreaterEqual (3, 0))
5f8b738e 444 {
445 GLint anExtNb = 0;
446 glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
447 for (GLint anIter = 0; anIter < anExtNb; ++anIter)
448 {
449 const char* anExtension = (const char* )core30->glGetStringi (GL_EXTENSIONS, (GLuint )anIter);
450 if (anExtension[anExtNameLen] == '\0' &&
451 strncmp (anExtension, theExtName, anExtNameLen) == 0)
452 {
453 return Standard_True;
454 }
455 }
456 return Standard_False;
457 }*/
458
459 // use old way with huge string for all extensions
460 const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
461 if (anExtString == NULL)
462 {
7e7c2f0b 463 Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning);
2166f0fa
SK
464 return Standard_False;
465 }
58655684 466 return CheckExtension (anExtString, theExtName);
467}
468
469// =======================================================================
470// function : CheckExtension
471// purpose :
472// =======================================================================
473Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString,
474 const char* theExtName)
475{
476 if (theExtString == NULL)
477 {
478 return Standard_False;
479 }
2166f0fa
SK
480
481 // Search for theExtName in the extensions string.
482 // Use of strstr() is not sufficient because extension names can be prefixes of other extension names.
58655684 483 char* aPtrIter = (char* )theExtString;
484 const char* aPtrEnd = aPtrIter + strlen (theExtString);
485 const size_t anExtNameLen = strlen (theExtName);
2166f0fa
SK
486 while (aPtrIter < aPtrEnd)
487 {
6a7d83c4 488 const size_t n = strcspn (aPtrIter, " ");
5f8b738e 489 if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0))
490 {
2166f0fa 491 return Standard_True;
5f8b738e 492 }
2166f0fa
SK
493 aPtrIter += (n + 1);
494 }
495 return Standard_False;
496}
497
4fe56619 498#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
499
2166f0fa
SK
500// =======================================================================
501// function : Init
502// purpose :
503// =======================================================================
f0430952 504Standard_Boolean OpenGl_Context::Init()
2166f0fa 505{
2bd4c032 506 if (myIsInitialized)
5f8b738e 507 {
f0430952 508 return Standard_True;
5f8b738e 509 }
2bd4c032 510
58655684 511#if defined(_WIN32)
2bd4c032 512 myWindowDC = (Aspect_Handle )wglGetCurrentDC();
513 myGContext = (Aspect_RenderingContext )wglGetCurrentContext();
514#else
515 myDisplay = (Aspect_Display )glXGetCurrentDisplay();
516 myGContext = (Aspect_RenderingContext )glXGetCurrentContext();
517 myWindow = (Aspect_Drawable )glXGetCurrentDrawable();
518#endif
f0430952 519 if (myGContext == NULL)
520 {
521 return Standard_False;
522 }
2bd4c032 523
524 init();
525 myIsInitialized = Standard_True;
f0430952 526 return Standard_True;
2bd4c032 527}
528
4fe56619 529#endif // __APPLE__
530
2bd4c032 531// =======================================================================
532// function : Init
533// purpose :
534// =======================================================================
58655684 535#if defined(_WIN32)
f0430952 536Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
537 const Aspect_Handle theWindowDC,
538 const Aspect_RenderingContext theGContext)
4fe56619 539#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
540Standard_Boolean OpenGl_Context::Init (const void* theGContext)
2bd4c032 541#else
f0430952 542Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
543 const Aspect_Display theDisplay,
544 const Aspect_RenderingContext theGContext)
2bd4c032 545#endif
546{
547 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
58655684 548#if defined(_WIN32)
2bd4c032 549 myWindow = theWindow;
550 myGContext = theGContext;
2bd4c032 551 myWindowDC = theWindowDC;
4fe56619 552#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
553 myGContext = (void* )theGContext;
2bd4c032 554#else
4fe56619 555 myWindow = theWindow;
556 myGContext = theGContext;
2bd4c032 557 myDisplay = theDisplay;
558#endif
86fa64d9 559 if (myGContext == NULL || !MakeCurrent())
f0430952 560 {
561 return Standard_False;
562 }
2bd4c032 563
564 init();
565 myIsInitialized = Standard_True;
f0430952 566 return Standard_True;
5f8b738e 567}
568
569// =======================================================================
570// function : ResetErrors
571// purpose :
572// =======================================================================
573void OpenGl_Context::ResetErrors()
574{
575 while (glGetError() != GL_NO_ERROR)
576 {
577 //
578 }
579}
580
581// =======================================================================
582// function : readGlVersion
583// purpose :
584// =======================================================================
585void OpenGl_Context::readGlVersion()
586{
587 // reset values
588 myGlVerMajor = 0;
589 myGlVerMinor = 0;
590
591 // available since OpenGL 3.0
86325709 592 GLint aMajor = 0, aMinor = 0;
5f8b738e 593 glGetIntegerv (GL_MAJOR_VERSION, &aMajor);
594 glGetIntegerv (GL_MINOR_VERSION, &aMinor);
30f0ad28 595 // glGetError() sometimes does not report an error here even if
86325709 596 // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants.
597 // This happens on some rendereres like e.g. Cygwin MESA.
598 // Thus checking additionally if GL has put anything to
599 // the output variables.
600 if (glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0)
5f8b738e 601 {
602 myGlVerMajor = aMajor;
603 myGlVerMinor = aMinor;
604 return;
605 }
606 ResetErrors();
607
608 // Read version string.
609 // Notice that only first two numbers splitted by point '2.1 XXXXX' are significant.
610 // Following trash (after space) is vendor-specific.
611 // New drivers also returns micro version of GL like '3.3.0' which has no meaning
612 // and should be considered as vendor-specific too.
613 const char* aVerStr = (const char* )glGetString (GL_VERSION);
614 if (aVerStr == NULL || *aVerStr == '\0')
615 {
616 // invalid GL context
617 return;
618 }
619
620 // parse string for major number
621 char aMajorStr[32];
622 char aMinorStr[32];
623 size_t aMajIter = 0;
624 while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9')
625 {
626 ++aMajIter;
627 }
628 if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr))
629 {
630 return;
631 }
632 memcpy (aMajorStr, aVerStr, aMajIter);
633 aMajorStr[aMajIter] = '\0';
634
635 // parse string for minor number
86325709 636 aVerStr += aMajIter + 1;
637 size_t aMinIter = 0;
5f8b738e 638 while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9')
639 {
640 ++aMinIter;
641 }
86325709 642 if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr))
5f8b738e 643 {
644 return;
645 }
86325709 646 memcpy (aMinorStr, aVerStr, aMinIter);
647 aMinorStr[aMinIter] = '\0';
5f8b738e 648
649 // read numbers
650 myGlVerMajor = atoi (aMajorStr);
651 myGlVerMinor = atoi (aMinorStr);
652
653 if (myGlVerMajor <= 0)
654 {
655 myGlVerMajor = 0;
656 myGlVerMinor = 0;
657 }
658}
659
58655684 660static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
661static Standard_CString THE_DBGMSG_SOURCES[] =
662{
cbf18624 663 ".OpenGL", // GL_DEBUG_SOURCE_API_ARB
664 ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
665 ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
666 ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY_ARB
667 "", // GL_DEBUG_SOURCE_APPLICATION_ARB
668 ".Other" // GL_DEBUG_SOURCE_OTHER_ARB
58655684 669};
670
671static Standard_CString THE_DBGMSG_TYPES[] =
672{
cbf18624 673 "Error", // GL_DEBUG_TYPE_ERROR_ARB
674 "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
675 "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
676 "Portability", // GL_DEBUG_TYPE_PORTABILITY_ARB
677 "Performance", // GL_DEBUG_TYPE_PERFORMANCE_ARB
678 "Other" // GL_DEBUG_TYPE_OTHER_ARB
58655684 679};
680
681static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH_ARB
682static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM_ARB
683static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW_ARB
684
cbf18624 685//! Callback for GL_ARB_debug_output extension
58655684 686static void APIENTRY debugCallbackWrap(unsigned int theSource,
687 unsigned int theType,
688 unsigned int theId,
689 unsigned int theSeverity,
690 int /*theLength*/,
691 const char* theMessage,
9293178b 692 const void* theUserParam)
cbf18624 693{
694 OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
695 aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage);
696}
697
698// =======================================================================
699// function : PushMessage
700// purpose :
701// =======================================================================
702void OpenGl_Context::PushMessage (const unsigned int theSource,
703 const unsigned int theType,
704 const unsigned int theId,
705 const unsigned int theSeverity,
706 const TCollection_ExtendedString& theMessage)
58655684 707{
708 //OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
709 Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API_ARB
01ca42b2 710 && theSource <= GL_DEBUG_SOURCE_OTHER_ARB)
58655684 711 ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API_ARB]
712 : THE_DBGMSG_UNKNOWN;
713 Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR_ARB
01ca42b2 714 && theType <= GL_DEBUG_TYPE_OTHER_ARB)
58655684 715 ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR_ARB]
716 : THE_DBGMSG_UNKNOWN;
717 Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
718 ? THE_DBGMSG_SEV_HIGH
719 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
720 ? THE_DBGMSG_SEV_MEDIUM
721 : THE_DBGMSG_SEV_LOW);
cbf18624 722 Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH_ARB
723 ? Message_Alarm
724 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM_ARB
725 ? Message_Warning
726 : Message_Info);
727
728 TCollection_ExtendedString aMsg;
729 aMsg += "TKOpenGl"; aMsg += aSrc;
730 aMsg += " | Type: "; aMsg += aType;
731 aMsg += " | ID: "; aMsg += (Standard_Integer )theId;
732 aMsg += " | Severity: "; aMsg += aSev;
733 aMsg += " | Message:\n ";
734 aMsg += theMessage;
735
7e7c2f0b 736 Messenger()->Send (aMsg, aGrav);
58655684 737}
738
5f8b738e 739// =======================================================================
740// function : init
741// purpose :
742// =======================================================================
743void OpenGl_Context::init()
744{
745 // read version
746 readGlVersion();
747
01ca42b2 748 core11 = (OpenGl_GlCore11* )(&(*myFuncs));
749 core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
750 core15 = NULL;
751 core15fwd = NULL;
752 core20 = NULL;
753 core20fwd = NULL;
754 core32 = NULL;
755 core32back = NULL;
756 core41 = NULL;
757 core41back = NULL;
758 core42 = NULL;
759 core42back = NULL;
760 core43 = NULL;
761 core43back = NULL;
762 core44 = NULL;
763 core44back = NULL;
764 arbTBO = NULL;
765 arbIns = NULL;
766 arbDbg = NULL;
767 arbFBO = NULL;
768 extGS = NULL;
769
bf75be98 770 arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
771 extBgra = CheckExtension ("GL_EXT_bgra");
772 extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
b859a34d 773 extPDS = CheckExtension ("GL_EXT_packed_depth_stencil");
bf75be98 774 atiMem = CheckExtension ("GL_ATI_meminfo");
775 nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
776
4269bd1b 777 // get number of maximum clipping planes
778 glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes);
bf75be98 779 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);
b5ac8292 780
781 GLint aStereo;
782 glGetIntegerv (GL_STEREO, &aStereo);
783 myIsStereoBuffers = aStereo == 1;
784
bf75be98 785 if (extAnis)
786 {
787 glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax);
788 }
f0430952 789
4269bd1b 790 myClippingState.Init (myMaxClipPlanes);
791
01ca42b2 792 bool has12 = false;
793 bool has13 = false;
794 bool has14 = false;
795 bool has15 = false;
796 bool has20 = false;
797 bool has21 = false;
798 bool has30 = false;
799 bool has31 = false;
800 bool has32 = false;
801 bool has33 = false;
802 bool has40 = false;
803 bool has41 = false;
804 bool has42 = false;
805 bool has43 = false;
806 bool has44 = false;
807
808 //! Make record shorter to retrieve function pointer using variable with same name
809 #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc)
810
811 // retrieve platform-dependent extensions
812#ifdef _WIN32
813 if (FindProcShort (wglGetExtensionsStringARB))
814 {
815 const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC());
816 if (CheckExtension (aWglExts, "WGL_EXT_swap_control"))
817 {
818 FindProcShort (wglSwapIntervalEXT);
819 }
820 if (CheckExtension (aWglExts, "WGL_ARB_pixel_format"))
821 {
822 FindProcShort (wglChoosePixelFormatARB);
823 }
824 if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile"))
825 {
826 FindProcShort (wglCreateContextAttribsARB);
827 }
828 if (CheckExtension (aWglExts, "WGL_NV_DX_interop"))
829 {
830 FindProcShort (wglDXSetResourceShareHandleNV);
831 FindProcShort (wglDXOpenDeviceNV);
832 FindProcShort (wglDXCloseDeviceNV);
833 FindProcShort (wglDXRegisterObjectNV);
834 FindProcShort (wglDXUnregisterObjectNV);
835 FindProcShort (wglDXObjectAccessNV);
836 FindProcShort (wglDXLockObjectsNV);
837 FindProcShort (wglDXUnlockObjectsNV);
838 }
839 }
840#endif
841
58655684 842 // initialize debug context extension
843 if (CheckExtension ("GL_ARB_debug_output"))
844 {
01ca42b2 845 arbDbg = NULL;
846 if (FindProcShort (glDebugMessageControlARB)
847 && FindProcShort (glDebugMessageInsertARB)
848 && FindProcShort (glDebugMessageCallbackARB)
849 && FindProcShort (glGetDebugMessageLogARB))
58655684 850 {
01ca42b2 851 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
58655684 852 }
853 if (arbDbg != NULL
854 && caps->contextDebug)
855 {
856 // setup default callback
857 arbDbg->glDebugMessageCallbackARB (debugCallbackWrap, this);
fcdbe201 858 #ifdef DEB
58655684 859 glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
fcdbe201 860 #endif
58655684 861 }
862 }
863
01ca42b2 864 // load OpenGL 1.2 new functions
865 has12 = IsGlGreaterEqual (1, 2)
866 && FindProcShort (glBlendColor)
867 && FindProcShort (glBlendEquation)
868 && FindProcShort (glDrawRangeElements)
869 && FindProcShort (glTexImage3D)
870 && FindProcShort (glTexSubImage3D)
871 && FindProcShort (glCopyTexSubImage3D);
872
873 // load OpenGL 1.3 new functions
874 has13 = IsGlGreaterEqual (1, 3)
875 && FindProcShort (glActiveTexture)
876 && FindProcShort (glSampleCoverage)
877 && FindProcShort (glCompressedTexImage3D)
878 && FindProcShort (glCompressedTexImage2D)
879 && FindProcShort (glCompressedTexImage1D)
880 && FindProcShort (glCompressedTexSubImage3D)
881 && FindProcShort (glCompressedTexSubImage2D)
882 && FindProcShort (glCompressedTexSubImage1D)
883 && FindProcShort (glGetCompressedTexImage)
884 && FindProcShort (glClientActiveTexture)
885 && FindProcShort (glMultiTexCoord1d)
886 && FindProcShort (glMultiTexCoord1dv)
887 && FindProcShort (glMultiTexCoord1f)
888 && FindProcShort (glMultiTexCoord1fv)
889 && FindProcShort (glMultiTexCoord1i)
890 && FindProcShort (glMultiTexCoord1iv)
891 && FindProcShort (glMultiTexCoord1s)
892 && FindProcShort (glMultiTexCoord1sv)
893 && FindProcShort (glMultiTexCoord2d)
894 && FindProcShort (glMultiTexCoord2dv)
895 && FindProcShort (glMultiTexCoord2f)
896 && FindProcShort (glMultiTexCoord2fv)
897 && FindProcShort (glMultiTexCoord2i)
898 && FindProcShort (glMultiTexCoord2iv)
899 && FindProcShort (glMultiTexCoord2s)
900 && FindProcShort (glMultiTexCoord2sv)
901 && FindProcShort (glMultiTexCoord3d)
902 && FindProcShort (glMultiTexCoord3dv)
903 && FindProcShort (glMultiTexCoord3f)
904 && FindProcShort (glMultiTexCoord3fv)
905 && FindProcShort (glMultiTexCoord3i)
906 && FindProcShort (glMultiTexCoord3iv)
907 && FindProcShort (glMultiTexCoord3s)
908 && FindProcShort (glMultiTexCoord3sv)
909 && FindProcShort (glMultiTexCoord4d)
910 && FindProcShort (glMultiTexCoord4dv)
911 && FindProcShort (glMultiTexCoord4f)
912 && FindProcShort (glMultiTexCoord4fv)
913 && FindProcShort (glMultiTexCoord4i)
914 && FindProcShort (glMultiTexCoord4iv)
915 && FindProcShort (glMultiTexCoord4s)
916 && FindProcShort (glMultiTexCoord4sv)
917 && FindProcShort (glLoadTransposeMatrixf)
918 && FindProcShort (glLoadTransposeMatrixd)
919 && FindProcShort (glMultTransposeMatrixf)
920 && FindProcShort (glMultTransposeMatrixd);
921
922 // load OpenGL 1.4 new functions
923 has14 = IsGlGreaterEqual (1, 4)
924 && FindProcShort (glBlendFuncSeparate)
925 && FindProcShort (glMultiDrawArrays)
926 && FindProcShort (glMultiDrawElements)
927 && FindProcShort (glPointParameterf)
928 && FindProcShort (glPointParameterfv)
929 && FindProcShort (glPointParameteri)
930 && FindProcShort (glPointParameteriv);
931
932 // load OpenGL 1.5 new functions
933 has15 = IsGlGreaterEqual (1, 5)
934 && FindProcShort (glGenQueries)
935 && FindProcShort (glDeleteQueries)
936 && FindProcShort (glIsQuery)
937 && FindProcShort (glBeginQuery)
938 && FindProcShort (glEndQuery)
939 && FindProcShort (glGetQueryiv)
940 && FindProcShort (glGetQueryObjectiv)
941 && FindProcShort (glGetQueryObjectuiv)
942 && FindProcShort (glBindBuffer)
943 && FindProcShort (glDeleteBuffers)
944 && FindProcShort (glGenBuffers)
945 && FindProcShort (glIsBuffer)
946 && FindProcShort (glBufferData)
947 && FindProcShort (glBufferSubData)
948 && FindProcShort (glGetBufferSubData)
949 && FindProcShort (glMapBuffer)
950 && FindProcShort (glUnmapBuffer)
951 && FindProcShort (glGetBufferParameteriv)
952 && FindProcShort (glGetBufferPointerv);
953
954 // load OpenGL 2.0 new functions
955 has20 = IsGlGreaterEqual (2, 0)
956 && FindProcShort (glBlendEquationSeparate)
957 && FindProcShort (glDrawBuffers)
958 && FindProcShort (glStencilOpSeparate)
959 && FindProcShort (glStencilFuncSeparate)
960 && FindProcShort (glStencilMaskSeparate)
961 && FindProcShort (glAttachShader)
962 && FindProcShort (glBindAttribLocation)
963 && FindProcShort (glCompileShader)
964 && FindProcShort (glCreateProgram)
965 && FindProcShort (glCreateShader)
966 && FindProcShort (glDeleteProgram)
967 && FindProcShort (glDeleteShader)
968 && FindProcShort (glDetachShader)
969 && FindProcShort (glDisableVertexAttribArray)
970 && FindProcShort (glEnableVertexAttribArray)
971 && FindProcShort (glGetActiveAttrib)
972 && FindProcShort (glGetActiveUniform)
973 && FindProcShort (glGetAttachedShaders)
974 && FindProcShort (glGetAttribLocation)
975 && FindProcShort (glGetProgramiv)
976 && FindProcShort (glGetProgramInfoLog)
977 && FindProcShort (glGetShaderiv)
978 && FindProcShort (glGetShaderInfoLog)
979 && FindProcShort (glGetShaderSource)
980 && FindProcShort (glGetUniformLocation)
981 && FindProcShort (glGetUniformfv)
982 && FindProcShort (glGetUniformiv)
983 && FindProcShort (glGetVertexAttribdv)
984 && FindProcShort (glGetVertexAttribfv)
985 && FindProcShort (glGetVertexAttribiv)
986 && FindProcShort (glGetVertexAttribPointerv)
987 && FindProcShort (glIsProgram)
988 && FindProcShort (glIsShader)
989 && FindProcShort (glLinkProgram)
990 && FindProcShort (glShaderSource)
991 && FindProcShort (glUseProgram)
992 && FindProcShort (glUniform1f)
993 && FindProcShort (glUniform2f)
994 && FindProcShort (glUniform3f)
995 && FindProcShort (glUniform4f)
996 && FindProcShort (glUniform1i)
997 && FindProcShort (glUniform2i)
998 && FindProcShort (glUniform3i)
999 && FindProcShort (glUniform4i)
1000 && FindProcShort (glUniform1fv)
1001 && FindProcShort (glUniform2fv)
1002 && FindProcShort (glUniform3fv)
1003 && FindProcShort (glUniform4fv)
1004 && FindProcShort (glUniform1iv)
1005 && FindProcShort (glUniform2iv)
1006 && FindProcShort (glUniform3iv)
1007 && FindProcShort (glUniform4iv)
1008 && FindProcShort (glUniformMatrix2fv)
1009 && FindProcShort (glUniformMatrix3fv)
1010 && FindProcShort (glUniformMatrix4fv)
1011 && FindProcShort (glValidateProgram)
1012 && FindProcShort (glVertexAttrib1d)
1013 && FindProcShort (glVertexAttrib1dv)
1014 && FindProcShort (glVertexAttrib1f)
1015 && FindProcShort (glVertexAttrib1fv)
1016 && FindProcShort (glVertexAttrib1s)
1017 && FindProcShort (glVertexAttrib1sv)
1018 && FindProcShort (glVertexAttrib2d)
1019 && FindProcShort (glVertexAttrib2dv)
1020 && FindProcShort (glVertexAttrib2f)
1021 && FindProcShort (glVertexAttrib2fv)
1022 && FindProcShort (glVertexAttrib2s)
1023 && FindProcShort (glVertexAttrib2sv)
1024 && FindProcShort (glVertexAttrib3d)
1025 && FindProcShort (glVertexAttrib3dv)
1026 && FindProcShort (glVertexAttrib3f)
1027 && FindProcShort (glVertexAttrib3fv)
1028 && FindProcShort (glVertexAttrib3s)
1029 && FindProcShort (glVertexAttrib3sv)
1030 && FindProcShort (glVertexAttrib4Nbv)
1031 && FindProcShort (glVertexAttrib4Niv)
1032 && FindProcShort (glVertexAttrib4Nsv)
1033 && FindProcShort (glVertexAttrib4Nub)
1034 && FindProcShort (glVertexAttrib4Nubv)
1035 && FindProcShort (glVertexAttrib4Nuiv)
1036 && FindProcShort (glVertexAttrib4Nusv)
1037 && FindProcShort (glVertexAttrib4bv)
1038 && FindProcShort (glVertexAttrib4d)
1039 && FindProcShort (glVertexAttrib4dv)
1040 && FindProcShort (glVertexAttrib4f)
1041 && FindProcShort (glVertexAttrib4fv)
1042 && FindProcShort (glVertexAttrib4iv)
1043 && FindProcShort (glVertexAttrib4s)
1044 && FindProcShort (glVertexAttrib4sv)
1045 && FindProcShort (glVertexAttrib4ubv)
1046 && FindProcShort (glVertexAttrib4uiv)
1047 && FindProcShort (glVertexAttrib4usv)
1048 && FindProcShort (glVertexAttribPointer);
1049
1050 // load OpenGL 2.1 new functions
1051 has21 = IsGlGreaterEqual (2, 1)
1052 && FindProcShort (glUniformMatrix2x3fv)
1053 && FindProcShort (glUniformMatrix3x2fv)
1054 && FindProcShort (glUniformMatrix2x4fv)
1055 && FindProcShort (glUniformMatrix4x2fv)
1056 && FindProcShort (glUniformMatrix3x4fv)
1057 && FindProcShort (glUniformMatrix4x3fv);
1058
1059 // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core)
1060 const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object"))
1061 && FindProcShort (glIsRenderbuffer)
1062 && FindProcShort (glBindRenderbuffer)
1063 && FindProcShort (glDeleteRenderbuffers)
1064 && FindProcShort (glGenRenderbuffers)
1065 && FindProcShort (glRenderbufferStorage)
1066 && FindProcShort (glGetRenderbufferParameteriv)
1067 && FindProcShort (glIsFramebuffer)
1068 && FindProcShort (glBindFramebuffer)
1069 && FindProcShort (glDeleteFramebuffers)
1070 && FindProcShort (glGenFramebuffers)
1071 && FindProcShort (glCheckFramebufferStatus)
1072 && FindProcShort (glFramebufferTexture1D)
1073 && FindProcShort (glFramebufferTexture2D)
1074 && FindProcShort (glFramebufferTexture3D)
1075 && FindProcShort (glFramebufferRenderbuffer)
1076 && FindProcShort (glGetFramebufferAttachmentParameteriv)
1077 && FindProcShort (glGenerateMipmap)
1078 && FindProcShort (glBlitFramebuffer)
1079 && FindProcShort (glRenderbufferStorageMultisample)
1080 && FindProcShort (glFramebufferTextureLayer);
1081
1082 // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core)
1083 const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object"))
1084 && FindProcShort (glBindVertexArray)
1085 && FindProcShort (glDeleteVertexArrays)
1086 && FindProcShort (glGenVertexArrays)
1087 && FindProcShort (glIsVertexArray);
1088
1089 // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core)
1090 const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range"))
1091 && FindProcShort (glMapBufferRange)
1092 && FindProcShort (glFlushMappedBufferRange);
1093
1094 // load OpenGL 3.0 new functions
1095 has30 = IsGlGreaterEqual (3, 0)
1096 && hasFBO
1097 && hasVAO
1098 && hasMapBufferRange
1099 && FindProcShort (glColorMaski)
1100 && FindProcShort (glGetBooleani_v)
1101 && FindProcShort (glGetIntegeri_v)
1102 && FindProcShort (glEnablei)
1103 && FindProcShort (glDisablei)
1104 && FindProcShort (glIsEnabledi)
1105 && FindProcShort (glBeginTransformFeedback)
1106 && FindProcShort (glEndTransformFeedback)
1107 && FindProcShort (glBindBufferRange)
1108 && FindProcShort (glBindBufferBase)
1109 && FindProcShort (glTransformFeedbackVaryings)
1110 && FindProcShort (glGetTransformFeedbackVarying)
1111 && FindProcShort (glClampColor)
1112 && FindProcShort (glBeginConditionalRender)
1113 && FindProcShort (glEndConditionalRender)
1114 && FindProcShort (glVertexAttribIPointer)
1115 && FindProcShort (glGetVertexAttribIiv)
1116 && FindProcShort (glGetVertexAttribIuiv)
1117 && FindProcShort (glVertexAttribI1i)
1118 && FindProcShort (glVertexAttribI2i)
1119 && FindProcShort (glVertexAttribI3i)
1120 && FindProcShort (glVertexAttribI4i)
1121 && FindProcShort (glVertexAttribI1ui)
1122 && FindProcShort (glVertexAttribI2ui)
1123 && FindProcShort (glVertexAttribI3ui)
1124 && FindProcShort (glVertexAttribI4ui)
1125 && FindProcShort (glVertexAttribI1iv)
1126 && FindProcShort (glVertexAttribI2iv)
1127 && FindProcShort (glVertexAttribI3iv)
1128 && FindProcShort (glVertexAttribI4iv)
1129 && FindProcShort (glVertexAttribI1uiv)
1130 && FindProcShort (glVertexAttribI2uiv)
1131 && FindProcShort (glVertexAttribI3uiv)
1132 && FindProcShort (glVertexAttribI4uiv)
1133 && FindProcShort (glVertexAttribI4bv)
1134 && FindProcShort (glVertexAttribI4sv)
1135 && FindProcShort (glVertexAttribI4ubv)
1136 && FindProcShort (glVertexAttribI4usv)
1137 && FindProcShort (glGetUniformuiv)
1138 && FindProcShort (glBindFragDataLocation)
1139 && FindProcShort (glGetFragDataLocation)
1140 && FindProcShort (glUniform1ui)
1141 && FindProcShort (glUniform2ui)
1142 && FindProcShort (glUniform3ui)
1143 && FindProcShort (glUniform4ui)
1144 && FindProcShort (glUniform1uiv)
1145 && FindProcShort (glUniform2uiv)
1146 && FindProcShort (glUniform3uiv)
1147 && FindProcShort (glUniform4uiv)
1148 && FindProcShort (glTexParameterIiv)
1149 && FindProcShort (glTexParameterIuiv)
1150 && FindProcShort (glGetTexParameterIiv)
1151 && FindProcShort (glGetTexParameterIuiv)
1152 && FindProcShort (glClearBufferiv)
1153 && FindProcShort (glClearBufferuiv)
1154 && FindProcShort (glClearBufferfv)
1155 && FindProcShort (glClearBufferfi)
1156 && FindProcShort (glGetStringi);
1157
1158 // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core)
1159 const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object"))
1160 && FindProcShort (glGetUniformIndices)
1161 && FindProcShort (glGetActiveUniformsiv)
1162 && FindProcShort (glGetActiveUniformName)
1163 && FindProcShort (glGetUniformBlockIndex)
1164 && FindProcShort (glGetActiveUniformBlockiv)
1165 && FindProcShort (glGetActiveUniformBlockName)
1166 && FindProcShort (glUniformBlockBinding);
1167
1168 // load GL_ARB_copy_buffer (added to OpenGL 3.1 core)
1169 const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer"))
1170 && FindProcShort (glCopyBufferSubData);
1171
1172 if (has30)
2166f0fa 1173 {
01ca42b2 1174 // NPOT textures are required by OpenGL 2.0 specifications
1175 // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.)
1176 arbNPTW = Standard_True;
1177 arbTexRG = Standard_True;
2166f0fa
SK
1178 }
1179
01ca42b2 1180 // load OpenGL 3.1 new functions
1181 has31 = IsGlGreaterEqual (3, 1)
1182 && hasUBO
1183 && hasCopyBufSubData
1184 && FindProcShort (glDrawArraysInstanced)
1185 && FindProcShort (glDrawElementsInstanced)
1186 && FindProcShort (glTexBuffer)
1187 && FindProcShort (glPrimitiveRestartIndex);
1188
1189 // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core)
1190 const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex"))
1191 && FindProcShort (glDrawElementsBaseVertex)
1192 && FindProcShort (glDrawRangeElementsBaseVertex)
1193 && FindProcShort (glDrawElementsInstancedBaseVertex)
1194 && FindProcShort (glMultiDrawElementsBaseVertex);
1195
1196 // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core)
1197 const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex"))
1198 && FindProcShort (glProvokingVertex);
1199
1200 // load GL_ARB_sync (added to OpenGL 3.2 core)
1201 const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync"))
1202 && FindProcShort (glFenceSync)
1203 && FindProcShort (glIsSync)
1204 && FindProcShort (glDeleteSync)
1205 && FindProcShort (glClientWaitSync)
1206 && FindProcShort (glWaitSync)
1207 && FindProcShort (glGetInteger64v)
1208 && FindProcShort (glGetSynciv);
1209
1210 // load GL_ARB_texture_multisample (added to OpenGL 3.2 core)
1211 const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample"))
1212 && FindProcShort (glTexImage2DMultisample)
1213 && FindProcShort (glTexImage3DMultisample)
1214 && FindProcShort (glGetMultisamplefv)
1215 && FindProcShort (glSampleMaski);
1216
1217 // load OpenGL 3.2 new functions
1218 has32 = IsGlGreaterEqual (3, 2)
1219 && hasDrawElemsBaseVert
1220 && hasProvokingVert
1221 && hasSync
1222 && hasTextureMultisample
1223 && FindProcShort (glGetInteger64i_v)
1224 && FindProcShort (glGetBufferParameteri64v)
1225 && FindProcShort (glFramebufferTexture);
1226
1227 // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core)
1228 const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended"))
1229 && FindProcShort (glBindFragDataLocationIndexed)
1230 && FindProcShort (glGetFragDataIndex);
1231
1232 // load GL_ARB_sampler_objects (added to OpenGL 3.3 core)
1233 const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects"))
1234 && FindProcShort (glGenSamplers)
1235 && FindProcShort (glDeleteSamplers)
1236 && FindProcShort (glIsSampler)
1237 && FindProcShort (glBindSampler)
1238 && FindProcShort (glSamplerParameteri)
1239 && FindProcShort (glSamplerParameteriv)
1240 && FindProcShort (glSamplerParameterf)
1241 && FindProcShort (glSamplerParameterfv)
1242 && FindProcShort (glSamplerParameterIiv)
1243 && FindProcShort (glSamplerParameterIuiv)
1244 && FindProcShort (glGetSamplerParameteriv)
1245 && FindProcShort (glGetSamplerParameterIiv)
1246 && FindProcShort (glGetSamplerParameterfv)
1247 && FindProcShort (glGetSamplerParameterIuiv);
1248
1249 // load GL_ARB_timer_query (added to OpenGL 3.3 core)
1250 const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query"))
1251 && FindProcShort (glQueryCounter)
1252 && FindProcShort (glGetQueryObjecti64v)
1253 && FindProcShort (glGetQueryObjectui64v);
1254
1255 // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core)
1256 const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev"))
1257 && FindProcShort (glVertexP2ui)
1258 && FindProcShort (glVertexP2uiv)
1259 && FindProcShort (glVertexP3ui)
1260 && FindProcShort (glVertexP3uiv)
1261 && FindProcShort (glVertexP4ui)
1262 && FindProcShort (glVertexP4uiv)
1263 && FindProcShort (glTexCoordP1ui)
1264 && FindProcShort (glTexCoordP1uiv)
1265 && FindProcShort (glTexCoordP2ui)
1266 && FindProcShort (glTexCoordP2uiv)
1267 && FindProcShort (glTexCoordP3ui)
1268 && FindProcShort (glTexCoordP3uiv)
1269 && FindProcShort (glTexCoordP4ui)
1270 && FindProcShort (glTexCoordP4uiv)
1271 && FindProcShort (glMultiTexCoordP1ui)
1272 && FindProcShort (glMultiTexCoordP1uiv)
1273 && FindProcShort (glMultiTexCoordP2ui)
1274 && FindProcShort (glMultiTexCoordP2uiv)
1275 && FindProcShort (glMultiTexCoordP3ui)
1276 && FindProcShort (glMultiTexCoordP3uiv)
1277 && FindProcShort (glMultiTexCoordP4ui)
1278 && FindProcShort (glMultiTexCoordP4uiv)
1279 && FindProcShort (glNormalP3ui)
1280 && FindProcShort (glNormalP3uiv)
1281 && FindProcShort (glColorP3ui)
1282 && FindProcShort (glColorP3uiv)
1283 && FindProcShort (glColorP4ui)
1284 && FindProcShort (glColorP4uiv)
1285 && FindProcShort (glSecondaryColorP3ui)
1286 && FindProcShort (glSecondaryColorP3uiv)
1287 && FindProcShort (glVertexAttribP1ui)
1288 && FindProcShort (glVertexAttribP1uiv)
1289 && FindProcShort (glVertexAttribP2ui)
1290 && FindProcShort (glVertexAttribP2uiv)
1291 && FindProcShort (glVertexAttribP3ui)
1292 && FindProcShort (glVertexAttribP3uiv)
1293 && FindProcShort (glVertexAttribP4ui)
1294 && FindProcShort (glVertexAttribP4uiv);
1295
1296 // load OpenGL 3.3 extra functions
1297 has33 = IsGlGreaterEqual (3, 3)
1298 && hasBlendFuncExtended
1299 && hasSamplerObjects
1300 && hasTimerQuery
1301 && hasVertType21010101rev
1302 && FindProcShort (glVertexAttribDivisor);
1303
1304 // load GL_ARB_draw_indirect (added to OpenGL 4.0 core)
1305 const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect"))
1306 && FindProcShort (glDrawArraysIndirect)
1307 && FindProcShort (glDrawElementsIndirect);
1308
1309 // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core)
1310 const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64"))
1311 && FindProcShort (glUniform1d)
1312 && FindProcShort (glUniform2d)
1313 && FindProcShort (glUniform3d)
1314 && FindProcShort (glUniform4d)
1315 && FindProcShort (glUniform1dv)
1316 && FindProcShort (glUniform2dv)
1317 && FindProcShort (glUniform3dv)
1318 && FindProcShort (glUniform4dv)
1319 && FindProcShort (glUniformMatrix2dv)
1320 && FindProcShort (glUniformMatrix3dv)
1321 && FindProcShort (glUniformMatrix4dv)
1322 && FindProcShort (glUniformMatrix2x3dv)
1323 && FindProcShort (glUniformMatrix2x4dv)
1324 && FindProcShort (glUniformMatrix3x2dv)
1325 && FindProcShort (glUniformMatrix3x4dv)
1326 && FindProcShort (glUniformMatrix4x2dv)
1327 && FindProcShort (glUniformMatrix4x3dv)
1328 && FindProcShort (glGetUniformdv);
1329
1330 // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core)
1331 const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine"))
1332 && FindProcShort (glGetSubroutineUniformLocation)
1333 && FindProcShort (glGetSubroutineIndex)
1334 && FindProcShort (glGetActiveSubroutineUniformiv)
1335 && FindProcShort (glGetActiveSubroutineUniformName)
1336 && FindProcShort (glGetActiveSubroutineName)
1337 && FindProcShort (glUniformSubroutinesuiv)
1338 && FindProcShort (glGetUniformSubroutineuiv)
1339 && FindProcShort (glGetProgramStageiv);
1340
1341 // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core)
1342 const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader"))
1343 && FindProcShort (glPatchParameteri)
1344 && FindProcShort (glPatchParameterfv);
1345
1346 // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core)
1347 const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2"))
1348 && FindProcShort (glBindTransformFeedback)
1349 && FindProcShort (glDeleteTransformFeedbacks)
1350 && FindProcShort (glGenTransformFeedbacks)
1351 && FindProcShort (glIsTransformFeedback)
1352 && FindProcShort (glPauseTransformFeedback)
1353 && FindProcShort (glResumeTransformFeedback)
1354 && FindProcShort (glDrawTransformFeedback);
1355
1356 // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core)
1357 const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3"))
1358 && FindProcShort (glDrawTransformFeedbackStream)
1359 && FindProcShort (glBeginQueryIndexed)
1360 && FindProcShort (glEndQueryIndexed)
1361 && FindProcShort (glGetQueryIndexediv);
1362
1363 // load OpenGL 4.0 new functions
1364 has40 = IsGlGreaterEqual (4, 0)
1365 && hasDrawIndirect
1366 && hasShaderFP64
1367 && hasShaderSubroutine
1368 && hasTessellationShader
1369 && hasTrsfFeedback2
1370 && hasTrsfFeedback3
1371 && FindProcShort (glMinSampleShading)
1372 && FindProcShort (glBlendEquationi)
1373 && FindProcShort (glBlendEquationSeparatei)
1374 && FindProcShort (glBlendFunci)
1375 && FindProcShort (glBlendFuncSeparatei);
1376
1377 // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core)
1378 const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility"))
1379 && FindProcShort (glReleaseShaderCompiler)
1380 && FindProcShort (glShaderBinary)
1381 && FindProcShort (glGetShaderPrecisionFormat)
1382 && FindProcShort (glDepthRangef)
1383 && FindProcShort (glClearDepthf);
1384
1385 // load GL_ARB_get_program_binary (added to OpenGL 4.1 core)
1386 const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary"))
1387 && FindProcShort (glGetProgramBinary)
1388 && FindProcShort (glProgramBinary)
1389 && FindProcShort (glProgramParameteri);
1390
1391
1392 // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core)
1393 const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects"))
1394 && FindProcShort (glUseProgramStages)
1395 && FindProcShort (glActiveShaderProgram)
1396 && FindProcShort (glCreateShaderProgramv)
1397 && FindProcShort (glBindProgramPipeline)
1398 && FindProcShort (glDeleteProgramPipelines)
1399 && FindProcShort (glGenProgramPipelines)
1400 && FindProcShort (glIsProgramPipeline)
1401 && FindProcShort (glGetProgramPipelineiv)
1402 && FindProcShort (glProgramUniform1i)
1403 && FindProcShort (glProgramUniform1iv)
1404 && FindProcShort (glProgramUniform1f)
1405 && FindProcShort (glProgramUniform1fv)
1406 && FindProcShort (glProgramUniform1d)
1407 && FindProcShort (glProgramUniform1dv)
1408 && FindProcShort (glProgramUniform1ui)
1409 && FindProcShort (glProgramUniform1uiv)
1410 && FindProcShort (glProgramUniform2i)
1411 && FindProcShort (glProgramUniform2iv)
1412 && FindProcShort (glProgramUniform2f)
1413 && FindProcShort (glProgramUniform2fv)
1414 && FindProcShort (glProgramUniform2d)
1415 && FindProcShort (glProgramUniform2dv)
1416 && FindProcShort (glProgramUniform2ui)
1417 && FindProcShort (glProgramUniform2uiv)
1418 && FindProcShort (glProgramUniform3i)
1419 && FindProcShort (glProgramUniform3iv)
1420 && FindProcShort (glProgramUniform3f)
1421 && FindProcShort (glProgramUniform3fv)
1422 && FindProcShort (glProgramUniform3d)
1423 && FindProcShort (glProgramUniform3dv)
1424 && FindProcShort (glProgramUniform3ui)
1425 && FindProcShort (glProgramUniform3uiv)
1426 && FindProcShort (glProgramUniform4i)
1427 && FindProcShort (glProgramUniform4iv)
1428 && FindProcShort (glProgramUniform4f)
1429 && FindProcShort (glProgramUniform4fv)
1430 && FindProcShort (glProgramUniform4d)
1431 && FindProcShort (glProgramUniform4dv)
1432 && FindProcShort (glProgramUniform4ui)
1433 && FindProcShort (glProgramUniform4uiv)
1434 && FindProcShort (glProgramUniformMatrix2fv)
1435 && FindProcShort (glProgramUniformMatrix3fv)
1436 && FindProcShort (glProgramUniformMatrix4fv)
1437 && FindProcShort (glProgramUniformMatrix2dv)
1438 && FindProcShort (glProgramUniformMatrix3dv)
1439 && FindProcShort (glProgramUniformMatrix4dv)
1440 && FindProcShort (glProgramUniformMatrix2x3fv)
1441 && FindProcShort (glProgramUniformMatrix3x2fv)
1442 && FindProcShort (glProgramUniformMatrix2x4fv)
1443 && FindProcShort (glProgramUniformMatrix4x2fv)
1444 && FindProcShort (glProgramUniformMatrix3x4fv)
1445 && FindProcShort (glProgramUniformMatrix4x3fv)
1446 && FindProcShort (glProgramUniformMatrix2x3dv)
1447 && FindProcShort (glProgramUniformMatrix3x2dv)
1448 && FindProcShort (glProgramUniformMatrix2x4dv)
1449 && FindProcShort (glProgramUniformMatrix4x2dv)
1450 && FindProcShort (glProgramUniformMatrix3x4dv)
1451 && FindProcShort (glProgramUniformMatrix4x3dv)
1452 && FindProcShort (glValidateProgramPipeline)
1453 && FindProcShort (glGetProgramPipelineInfoLog);
1454
1455 // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core)
1456 const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit"))
1457 && FindProcShort (glVertexAttribL1d)
1458 && FindProcShort (glVertexAttribL2d)
1459 && FindProcShort (glVertexAttribL3d)
1460 && FindProcShort (glVertexAttribL4d)
1461 && FindProcShort (glVertexAttribL1dv)
1462 && FindProcShort (glVertexAttribL2dv)
1463 && FindProcShort (glVertexAttribL3dv)
1464 && FindProcShort (glVertexAttribL4dv)
1465 && FindProcShort (glVertexAttribLPointer)
1466 && FindProcShort (glGetVertexAttribLdv);
1467
1468 // load GL_ARB_viewport_array (added to OpenGL 4.1 core)
1469 const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array"))
1470 && FindProcShort (glViewportArrayv)
1471 && FindProcShort (glViewportIndexedf)
1472 && FindProcShort (glViewportIndexedfv)
1473 && FindProcShort (glScissorArrayv)
1474 && FindProcShort (glScissorIndexed)
1475 && FindProcShort (glScissorIndexedv)
1476 && FindProcShort (glDepthRangeArrayv)
1477 && FindProcShort (glDepthRangeIndexed)
1478 && FindProcShort (glGetFloati_v)
1479 && FindProcShort (glGetDoublei_v);
1480
1481 has41 = IsGlGreaterEqual (4, 1)
1482 && hasES2Compatibility
1483 && hasGetProgramBinary
1484 && hasSeparateShaderObjects
1485 && hasVertAttrib64bit
1486 && hasViewportArray;
1487
1488 // load GL_ARB_base_instance (added to OpenGL 4.2 core)
1489 const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance"))
1490 && FindProcShort (glDrawArraysInstancedBaseInstance)
1491 && FindProcShort (glDrawElementsInstancedBaseInstance)
1492 && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance);
1493
1494 // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core)
1495 const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced"))
1496 && FindProcShort (glDrawTransformFeedbackInstanced)
1497 && FindProcShort (glDrawTransformFeedbackStreamInstanced);
1498
1499 // load GL_ARB_internalformat_query (added to OpenGL 4.2 core)
1500 const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query"))
1501 && FindProcShort (glGetInternalformativ);
1502
1503 // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core)
1504 const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters"))
1505 && FindProcShort (glGetActiveAtomicCounterBufferiv);
1506
1507 // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core)
1508 const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store"))
1509 && FindProcShort (glBindImageTexture)
1510 && FindProcShort (glMemoryBarrier);
1511
1512 // load GL_ARB_texture_storage (added to OpenGL 4.2 core)
1513 const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage"))
1514 && FindProcShort (glTexStorage1D)
1515 && FindProcShort (glTexStorage2D)
1516 && FindProcShort (glTexStorage3D)
1517 && FindProcShort (glTextureStorage1DEXT)
1518 && FindProcShort (glTextureStorage2DEXT)
1519 && FindProcShort (glTextureStorage3DEXT);
1520
1521 has42 = IsGlGreaterEqual (4, 2)
1522 && hasBaseInstance
1523 && hasTrsfFeedbackInstanced
1524 && hasInternalFormatQuery
1525 && hasShaderAtomicCounters
1526 && hasShaderImgLoadStore
1527 && hasTextureStorage;
1528
1529 has43 = IsGlGreaterEqual (4, 3)
1530 && FindProcShort (glClearBufferData)
1531 && FindProcShort (glClearBufferSubData)
1532 && FindProcShort (glDispatchCompute)
1533 && FindProcShort (glDispatchComputeIndirect)
1534 && FindProcShort (glCopyImageSubData)
1535 && FindProcShort (glFramebufferParameteri)
1536 && FindProcShort (glGetFramebufferParameteriv)
1537 && FindProcShort (glGetInternalformati64v)
1538 && FindProcShort (glInvalidateTexSubImage)
1539 && FindProcShort (glInvalidateTexImage)
1540 && FindProcShort (glInvalidateBufferSubData)
1541 && FindProcShort (glInvalidateBufferData)
1542 && FindProcShort (glInvalidateFramebuffer)
1543 && FindProcShort (glInvalidateSubFramebuffer)
1544 && FindProcShort (glMultiDrawArraysIndirect)
1545 && FindProcShort (glMultiDrawElementsIndirect)
1546 && FindProcShort (glGetProgramInterfaceiv)
1547 && FindProcShort (glGetProgramResourceIndex)
1548 && FindProcShort (glGetProgramResourceName)
1549 && FindProcShort (glGetProgramResourceiv)
1550 && FindProcShort (glGetProgramResourceLocation)
1551 && FindProcShort (glGetProgramResourceLocationIndex)
1552 && FindProcShort (glShaderStorageBlockBinding)
1553 && FindProcShort (glTexBufferRange)
1554 && FindProcShort (glTexStorage2DMultisample)
1555 && FindProcShort (glTexStorage3DMultisample)
1556 && FindProcShort (glTextureView)
1557 && FindProcShort (glBindVertexBuffer)
1558 && FindProcShort (glVertexAttribFormat)
1559 && FindProcShort (glVertexAttribIFormat)
1560 && FindProcShort (glVertexAttribLFormat)
1561 && FindProcShort (glVertexAttribBinding)
1562 && FindProcShort (glVertexBindingDivisor)
1563 && FindProcShort (glDebugMessageControl)
1564 && FindProcShort (glDebugMessageInsert)
1565 && FindProcShort (glDebugMessageCallback)
1566 && FindProcShort (glGetDebugMessageLog)
1567 && FindProcShort (glPushDebugGroup)
1568 && FindProcShort (glPopDebugGroup)
1569 && FindProcShort (glObjectLabel)
1570 && FindProcShort (glGetObjectLabel)
1571 && FindProcShort (glObjectPtrLabel)
1572 && FindProcShort (glGetObjectPtrLabel);
1573
1574 // load GL_ARB_clear_texture (added to OpenGL 4.4 core)
1575 bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture"))
1576 && FindProcShort (glClearTexImage)
1577 && FindProcShort (glClearTexSubImage);
1578
1579 has44 = IsGlGreaterEqual (4, 4)
1580 && arbTexClear
1581 && FindProcShort (glBufferStorage)
1582 && FindProcShort (glBindBuffersBase)
1583 && FindProcShort (glBindBuffersRange)
1584 && FindProcShort (glBindTextures)
1585 && FindProcShort (glBindSamplers)
1586 && FindProcShort (glBindImageTextures)
1587 && FindProcShort (glBindVertexBuffers);
1588
5e27df78 1589 // initialize TBO extension (ARB)
01ca42b2 1590 if (!has31
1591 && CheckExtension ("GL_ARB_texture_buffer_object")
1592 && FindProc ("glTexBufferARB", myFuncs->glTexBuffer))
5e27df78 1593 {
01ca42b2 1594 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
5e27df78 1595 }
1596
1597 // initialize hardware instancing extension (ARB)
01ca42b2 1598 if (!has31
1599 && CheckExtension ("GL_ARB_draw_instanced")
1600 && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced)
1601 && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced))
5e27df78 1602 {
01ca42b2 1603 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
5e27df78 1604 }
1605
01ca42b2 1606 // initialize FBO extension (ARB)
1607 if (hasFBO)
2166f0fa 1608 {
01ca42b2 1609 arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
1610 extPDS = Standard_True; // extension for EXT, but part of ARB
2166f0fa 1611 }
5f8b738e 1612
37eb4787 1613 // initialize GS extension (EXT)
01ca42b2 1614 if (CheckExtension ("GL_EXT_geometry_shader4")
1615 && FindProcShort (glProgramParameteriEXT))
37eb4787 1616 {
01ca42b2 1617 extGS = (OpenGl_ExtGS* )(&(*myFuncs));
37eb4787 1618 }
1619
01ca42b2 1620 if (!has12)
86325709 1621 {
1622 myGlVerMajor = 1;
1623 myGlVerMinor = 1;
1624 return;
5f8b738e 1625 }
01ca42b2 1626 else if (!has13)
5f8b738e 1627 {
01ca42b2 1628 myGlVerMajor = 1;
1629 myGlVerMinor = 2;
1630 return;
5f8b738e 1631 }
01ca42b2 1632 else if (!has14)
5f8b738e 1633 {
86325709 1634 myGlVerMajor = 1;
01ca42b2 1635 myGlVerMinor = 3;
86325709 1636 return;
5f8b738e 1637 }
01ca42b2 1638 else if (!has15)
86325709 1639 {
01ca42b2 1640 myGlVerMajor = 1;
1641 myGlVerMinor = 4;
1642 return;
5f8b738e 1643 }
01ca42b2 1644 core15 = (OpenGl_GlCore15* )(&(*myFuncs));
1645 core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
1646
1647 if (!has20)
86325709 1648 {
1649 myGlVerMajor = 1;
01ca42b2 1650 myGlVerMinor = 5;
86325709 1651 return;
5f8b738e 1652 }
01ca42b2 1653
1654 core20 = (OpenGl_GlCore20* )(&(*myFuncs));
1655 core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
1656
1657 if (!has21)
5f8b738e 1658 {
01ca42b2 1659 myGlVerMajor = 2;
1660 myGlVerMinor = 0;
1661 return;
86325709 1662 }
01ca42b2 1663
1664 if (!has30)
86325709 1665 {
01ca42b2 1666 myGlVerMajor = 2;
1667 myGlVerMinor = 1;
86325709 1668 return;
1669 }
01ca42b2 1670
1671 if (!has31)
1672 {
1673 myGlVerMajor = 3;
1674 myGlVerMinor = 0;
1675 return;
1676 }
1677 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
1678 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
1679
1680 if (!has32)
86325709 1681 {
01ca42b2 1682 myGlVerMajor = 3;
1683 myGlVerMinor = 1;
1684 return;
86325709 1685 }
01ca42b2 1686 core32 = (OpenGl_GlCore32* )(&(*myFuncs));
1687 core32back = (OpenGl_GlCore32Back* )(&(*myFuncs));
1688
1689 if (!has33)
86325709 1690 {
01ca42b2 1691 myGlVerMajor = 3;
1692 myGlVerMinor = 2;
1693 return;
86325709 1694 }
01ca42b2 1695
1696 if (!has40)
86325709 1697 {
01ca42b2 1698 myGlVerMajor = 3;
1699 myGlVerMinor = 3;
1700 return;
1701 }
1702
1703 if (!has41)
1704 {
1705 myGlVerMajor = 4;
1706 myGlVerMinor = 0;
1707 return;
1708 }
1709 core41 = (OpenGl_GlCore41* )(&(*myFuncs));
1710 core41back = (OpenGl_GlCore41Back* )(&(*myFuncs));
1711
1712 if(!has42)
1713 {
1714 myGlVerMajor = 4;
1715 myGlVerMinor = 1;
1716 return;
1717 }
1718 core42 = (OpenGl_GlCore42* )(&(*myFuncs));
1719 core42back = (OpenGl_GlCore42Back* )(&(*myFuncs));
1720
1721 if(!has43)
1722 {
1723 myGlVerMajor = 4;
1724 myGlVerMinor = 2;
1725 return;
1726 }
1727 core43 = (OpenGl_GlCore43* )(&(*myFuncs));
1728 core43back = (OpenGl_GlCore43Back* )(&(*myFuncs));
1729
1730 if (!has44)
1731 {
1732 myGlVerMajor = 4;
1733 myGlVerMinor = 3;
1734 return;
5f8b738e 1735 }
01ca42b2 1736 core44 = (OpenGl_GlCore44* )(&(*myFuncs));
1737 core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
2166f0fa 1738}
f0430952 1739
1740// =======================================================================
1741// function : MemoryInfo
1742// purpose :
1743// =======================================================================
1744Standard_Size OpenGl_Context::AvailableMemory() const
1745{
1746 if (atiMem)
1747 {
1748 // this is actually information for VBO pool
1749 // however because pools are mostly shared
1750 // it can be used for total GPU memory estimations
1751 GLint aMemInfo[4];
1752 aMemInfo[0] = 0;
1753 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo);
1754 // returned value is in KiB, however this maybe changed in future
1755 return Standard_Size(aMemInfo[0]) * 1024;
1756 }
1757 else if (nvxMem)
1758 {
1759 // current available dedicated video memory (in KiB), currently unused GPU memory
1760 GLint aMemInfo = 0;
1761 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo);
1762 return Standard_Size(aMemInfo) * 1024;
1763 }
1764 return 0;
1765}
1766
1767// =======================================================================
1768// function : MemoryInfo
1769// purpose :
1770// =======================================================================
1771TCollection_AsciiString OpenGl_Context::MemoryInfo() const
1772{
1773 TCollection_AsciiString anInfo;
1774 if (atiMem)
1775 {
1776 GLint aValues[4];
1777 memset (aValues, 0, sizeof(aValues));
1778 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues);
1779
1780 // total memory free in the pool
1781 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValues[0] / 1024) + " MiB\n";
1782
1783 // largest available free block in the pool
1784 anInfo += TCollection_AsciiString (" Largest free block: ") + (aValues[1] / 1024) + " MiB\n";
1785 if (aValues[2] != aValues[0])
1786 {
1787 // total auxiliary memory free
1788 anInfo += TCollection_AsciiString (" Free memory: ") + (aValues[2] / 1024) + " MiB\n";
1789 }
1790 }
1791 else if (nvxMem)
1792 {
1793 //current available dedicated video memory (in KiB), currently unused GPU memory
1794 GLint aValue = 0;
1795 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue);
1796 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValue / 1024) + " MiB\n";
1797
1798 // dedicated video memory, total size (in KiB) of the GPU memory
1799 GLint aDedicated = 0;
1800 glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated);
1801 anInfo += TCollection_AsciiString (" GPU memory: ") + (aDedicated / 1024) + " MiB\n";
1802
1803 // total available memory, total size (in KiB) of the memory available for allocations
1804 glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue);
1805 if (aValue != aDedicated)
1806 {
1807 // different only for special configurations
1808 anInfo += TCollection_AsciiString (" Total memory: ") + (aValue / 1024) + " MiB\n";
1809 }
1810 }
1811 return anInfo;
1812}
5e27df78 1813
1814
1815// =======================================================================
1816// function : GetResource
1817// purpose :
1818// =======================================================================
1819const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const
1820{
1821 return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE;
1822}
1823
1824// =======================================================================
1825// function : ShareResource
1826// purpose :
1827// =======================================================================
1828Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey,
1829 const Handle(OpenGl_Resource)& theResource)
1830{
1831 if (theKey.IsEmpty() || theResource.IsNull())
1832 {
1833 return Standard_False;
1834 }
1835 return mySharedResources->Bind (theKey, theResource);
1836}
1837
1838// =======================================================================
1839// function : ReleaseResource
1840// purpose :
1841// =======================================================================
a174a3c5 1842void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey,
1843 const Standard_Boolean theToDelay)
5e27df78 1844{
1845 if (!mySharedResources->IsBound (theKey))
1846 {
1847 return;
1848 }
1849 const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey);
1850 if (aRes->GetRefCount() > 1)
1851 {
1852 return;
1853 }
1854
a174a3c5 1855 if (theToDelay)
1856 {
1857 myDelayed->Bind (theKey, 1);
1858 }
1859 else
1860 {
1861 aRes->Release (this);
1862 mySharedResources->UnBind (theKey);
1863 }
5e27df78 1864}
1865
1866// =======================================================================
1867// function : DelayedRelease
1868// purpose :
1869// =======================================================================
1870void OpenGl_Context::DelayedRelease (Handle(OpenGl_Resource)& theResource)
1871{
1872 myReleaseQueue->Push (theResource);
1873 theResource.Nullify();
1874}
1875
1876// =======================================================================
1877// function : ReleaseDelayed
1878// purpose :
1879// =======================================================================
1880void OpenGl_Context::ReleaseDelayed()
1881{
a174a3c5 1882 // release queued elements
5e27df78 1883 while (!myReleaseQueue->IsEmpty())
1884 {
1885 myReleaseQueue->Front()->Release (this);
1886 myReleaseQueue->Pop();
1887 }
a174a3c5 1888
265d4508 1889 // release delayed shared resources
a174a3c5 1890 NCollection_Vector<TCollection_AsciiString> aDeadList;
1891 for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed);
1892 anIter.More(); anIter.Next())
1893 {
1894 if (++anIter.ChangeValue() <= 2)
1895 {
1896 continue; // postpone release one more frame to ensure noone use it periodically
1897 }
1898
1899 const TCollection_AsciiString& aKey = anIter.Key();
1900 if (!mySharedResources->IsBound (aKey))
1901 {
1902 // mixed unshared strategy delayed/undelayed was used!
1903 aDeadList.Append (aKey);
1904 continue;
1905 }
1906
1907 Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey);
1908 if (aRes->GetRefCount() > 1)
1909 {
1910 // should be only 1 instance in mySharedResources
1911 // if not - resource was reused again
1912 aDeadList.Append (aKey);
1913 continue;
1914 }
1915
1916 // release resource if no one requiested it more than 2 redraw calls
1917 aRes->Release (this);
1918 mySharedResources->UnBind (aKey);
1919 aDeadList.Append (aKey);
1920 }
1921
1922 for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter)
1923 {
1924 myDelayed->UnBind (aDeadList.Value (anIter));
1925 }
5e27df78 1926}