1 // Created on: 2012-01-26
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
20 #include <OpenGl_Context.hxx>
22 #include <OpenGl_ArbTBO.hxx>
23 #include <OpenGl_ArbIns.hxx>
24 #include <OpenGl_ArbDbg.hxx>
25 #include <OpenGl_ArbFBO.hxx>
26 #include <OpenGl_ExtGS.hxx>
27 #include <OpenGl_ArbTexBindless.hxx>
28 #include <OpenGl_GlCore44.hxx>
29 #include <OpenGl_FrameBuffer.hxx>
30 #include <OpenGl_Sampler.hxx>
31 #include <OpenGl_ShaderManager.hxx>
32 #include <OpenGl_Workspace.hxx>
33 #include <OpenGl_AspectFace.hxx>
34 #include <Graphic3d_TransformUtils.hxx>
36 #include <Message_Messenger.hxx>
38 #include <NCollection_Vector.hxx>
40 #include <Standard_ProgramError.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient)
47 #pragma comment(lib, "libEGL.lib")
51 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
53 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
56 #include <OpenGL/OpenGL.h>
59 #include <GL/glx.h> // glXGetProcAddress()
65 #pragma comment (lib, "gl2ps.lib")
72 static const Handle(OpenGl_Resource) NULL_GL_RESOURCE;
75 // =======================================================================
76 // function : OpenGl_Context
78 // =======================================================================
79 OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
98 caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()),
99 #if defined(GL_ES_VERSION_2_0)
100 hasHighp (Standard_False),
101 hasUintIndex(Standard_False),
102 hasTexRGBA8(Standard_False),
104 hasHighp (Standard_True),
105 hasUintIndex(Standard_True),
106 hasTexRGBA8(Standard_True),
108 arbNPTW (Standard_False),
109 arbTexRG (Standard_False),
110 arbTexFloat (Standard_False),
111 arbTexBindless (NULL),
113 arbTboRGB32 (Standard_False),
119 extBgra(Standard_False),
120 extAnis(Standard_False),
121 extPDS (Standard_False),
122 atiMem (Standard_False),
123 nvxMem (Standard_False),
124 mySharedResources (new OpenGl_ResourcesMap()),
125 myDelayed (new OpenGl_DelayReleaseMap()),
126 myUnusedResources (new OpenGl_ResourcesStack()),
128 myGlLibHandle (NULL),
129 myFuncs (new OpenGl_GlFunctions()),
131 myTexClamp (GL_CLAMP_TO_EDGE),
137 myIsInitialized (Standard_False),
138 myIsStereoBuffers (Standard_False),
139 myIsGlNormalizeEnabled (Standard_False),
140 #if !defined(GL_ES_VERSION_2_0)
141 myRenderMode (GL_RENDER),
148 myIsGlDebugCtx (Standard_False),
149 myResolutionRatio (1.0f)
151 // system-dependent fields
152 #if defined(HAVE_EGL)
153 myDisplay = (Aspect_Display )EGL_NO_DISPLAY;
154 myWindow = (Aspect_Drawable )EGL_NO_SURFACE;
155 myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT;
156 #elif defined(_WIN32)
160 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
161 // Vendors can not extend functionality on this system
162 // and developers are limited to OpenGL support provided by Mac OS X SDK.
163 // We retrieve function pointers from system library
164 // to generalize extensions support on all platforms.
165 // In this way we also reach binary compatibility benefit between OS releases
166 // if some newest functionality is optionally used.
167 // Notice that GL version / extension availability checks are required
168 // because function pointers may be available but not functionality itself
169 // (depends on renderer).
170 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
172 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY);
175 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
183 memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions));
184 myShaderManager = new OpenGl_ShaderManager (this);
187 // =======================================================================
188 // function : ~OpenGl_Context
190 // =======================================================================
191 OpenGl_Context::~OpenGl_Context()
193 // release clean up queue
196 #if !defined(GL_ES_VERSION_2_0)
197 // release default VAO
198 if (myDefaultVao != 0
202 core32->glDeleteVertexArrays (1, &myDefaultVao);
207 // release default FBO
208 if (!myDefaultFbo.IsNull())
210 myDefaultFbo->Release (this);
211 myDefaultFbo.Nullify();
214 // release shared resources if any
215 if (mySharedResources->GetRefCount() <= 1)
217 myShaderManager.Nullify();
218 for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
219 anIter.More(); anIter.Next())
221 anIter.Value()->Release (this);
224 // release delayed resources added during deletion of shared resources
225 while (!myUnusedResources->IsEmpty())
227 myUnusedResources->First()->Release (this);
228 myUnusedResources->RemoveFirst();
231 else if (myShaderManager->IsSameContext (this))
233 myShaderManager->SetContext (NULL);
235 mySharedResources.Nullify();
238 // release sampler object
239 if (!myTexSampler.IsNull())
241 myTexSampler->Release (this);
244 #if !defined(GL_ES_VERSION_2_0)
251 glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr);
254 arbDbg->glDebugMessageCallbackARB (NULL, NULL);
256 myIsGlDebugCtx = Standard_False;
261 // =======================================================================
262 // function : forcedRelease
264 // =======================================================================
265 void OpenGl_Context::forcedRelease()
268 for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
269 anIter.More(); anIter.Next())
271 anIter.Value()->Release (this);
273 mySharedResources->Clear();
274 myShaderManager->clear();
275 myShaderManager->SetContext (NULL);
277 // release delayed resources added during deletion of shared resources
278 while (!myUnusedResources->IsEmpty())
280 myUnusedResources->First()->Release (this);
281 myUnusedResources->RemoveFirst();
285 #if !defined(GL_ES_VERSION_2_0)
286 inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer)
302 // =======================================================================
303 // function : SetReadBuffer
305 // =======================================================================
306 void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer)
308 #if !defined(GL_ES_VERSION_2_0)
309 myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer;
310 if (myReadBuffer < GL_COLOR_ATTACHMENT0
313 arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
315 ::glReadBuffer (myReadBuffer);
317 (void )theReadBuffer;
321 // =======================================================================
322 // function : SetDrawBuffer
324 // =======================================================================
325 void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer)
327 #if !defined(GL_ES_VERSION_2_0)
328 myDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer;
329 if (myDrawBuffer < GL_COLOR_ATTACHMENT0
332 arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
334 ::glDrawBuffer (myDrawBuffer);
336 (void )theDrawBuffer;
340 // =======================================================================
341 // function : FetchState
343 // =======================================================================
344 void OpenGl_Context::FetchState()
346 #if !defined(GL_ES_VERSION_2_0)
347 // cache feedback mode state
350 ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode);
353 // cache buffers state
354 ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer);
355 ::glGetIntegerv (GL_DRAW_BUFFER, &myDrawBuffer);
359 // =======================================================================
362 // =======================================================================
363 void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx)
365 if (!theShareCtx.IsNull())
367 mySharedResources = theShareCtx->mySharedResources;
368 myDelayed = theShareCtx->myDelayed;
369 myUnusedResources = theShareCtx->myUnusedResources;
370 myShaderManager = theShareCtx->myShaderManager;
374 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
376 // =======================================================================
377 // function : IsCurrent
379 // =======================================================================
380 Standard_Boolean OpenGl_Context::IsCurrent() const
382 #if defined(HAVE_EGL)
383 if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
384 || (EGLSurface )myWindow == EGL_NO_SURFACE
385 || (EGLContext )myGContext == EGL_NO_CONTEXT)
387 return Standard_False;
390 return (((EGLDisplay )myDisplay == eglGetCurrentDisplay())
391 && ((EGLContext )myGContext == eglGetCurrentContext())
392 && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW)));
393 #elif defined(_WIN32)
394 if (myWindowDC == NULL || myGContext == NULL)
396 return Standard_False;
398 return (( (HDC )myWindowDC == wglGetCurrentDC())
399 && ((HGLRC )myGContext == wglGetCurrentContext()));
401 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
403 return Standard_False;
406 return ( ((Display* )myDisplay == glXGetCurrentDisplay())
407 && ((GLXContext )myGContext == glXGetCurrentContext())
408 && ((GLXDrawable )myWindow == glXGetCurrentDrawable()));
412 // =======================================================================
413 // function : MakeCurrent
415 // =======================================================================
416 Standard_Boolean OpenGl_Context::MakeCurrent()
418 #if defined(HAVE_EGL)
419 if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
420 || (EGLSurface )myWindow == EGL_NO_SURFACE
421 || (EGLContext )myGContext == EGL_NO_CONTEXT)
423 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
424 return Standard_False;
427 if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE)
429 // if there is no current context it might be impossible to use glGetError() correctly
430 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
431 "eglMakeCurrent() has failed!");
432 myIsInitialized = Standard_False;
433 return Standard_False;
435 #elif defined(_WIN32)
436 if (myWindowDC == NULL || myGContext == NULL)
438 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
439 return Standard_False;
442 // technically it should be safe to activate already bound GL context
443 // however some drivers (Intel etc.) may FAIL doing this for unknown reason
446 myShaderManager->SetContext (this);
447 return Standard_True;
449 else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
451 // notice that glGetError() couldn't be used here!
452 wchar_t* aMsgBuff = NULL;
453 DWORD anErrorCode = GetLastError();
454 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
455 NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
456 TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. ");
457 if (aMsgBuff != NULL)
459 aMsg += (Standard_ExtString )aMsgBuff;
460 LocalFree (aMsgBuff);
462 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg);
463 myIsInitialized = Standard_False;
464 return Standard_False;
467 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
469 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
470 return Standard_False;
473 if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
475 // if there is no current context it might be impossible to use glGetError() correctly
476 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
477 "glXMakeCurrent() has failed!");
478 myIsInitialized = Standard_False;
479 return Standard_False;
482 myShaderManager->SetContext (this);
483 return Standard_True;
486 // =======================================================================
487 // function : SwapBuffers
489 // =======================================================================
490 void OpenGl_Context::SwapBuffers()
492 #if defined(HAVE_EGL)
493 if ((EGLSurface )myWindow != EGL_NO_SURFACE)
495 eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow);
497 #elif defined(_WIN32)
498 if ((HDC )myWindowDC != NULL)
500 ::SwapBuffers ((HDC )myWindowDC);
504 if ((Display* )myDisplay != NULL)
506 glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow);
513 // =======================================================================
514 // function : SetSwapInterval
516 // =======================================================================
517 Standard_Boolean OpenGl_Context::SetSwapInterval (const Standard_Integer theInterval)
519 #if defined(HAVE_EGL)
520 if (::eglSwapInterval ((EGLDisplay )myDisplay, theInterval) == EGL_TRUE)
522 return Standard_True;
524 #elif defined(_WIN32)
525 if (myFuncs->wglSwapIntervalEXT != NULL)
527 myFuncs->wglSwapIntervalEXT (theInterval);
528 return Standard_True;
530 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
532 #elif defined(__APPLE__)
533 if (::CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &theInterval) == kCGLNoError)
535 return Standard_True;
538 if (theInterval == -1
539 && myFuncs->glXSwapIntervalEXT != NULL)
541 typedef int (*glXSwapIntervalEXT_t_x)(Display* theDisplay, GLXDrawable theDrawable, int theInterval);
542 glXSwapIntervalEXT_t_x aFuncPtr = (glXSwapIntervalEXT_t_x )myFuncs->glXSwapIntervalEXT;
543 aFuncPtr ((Display* )myDisplay, (GLXDrawable )myWindow, theInterval);
544 return Standard_True;
546 else if (myFuncs->glXSwapIntervalSGI != NULL)
548 myFuncs->glXSwapIntervalSGI (theInterval);
549 return Standard_True;
552 return Standard_False;
555 // =======================================================================
556 // function : findProc
558 // =======================================================================
559 void* OpenGl_Context::findProc (const char* theFuncName)
561 #if defined(HAVE_EGL)
562 return (void* )eglGetProcAddress (theFuncName);
563 #elif defined(_WIN32)
564 return (void* )wglGetProcAddress (theFuncName);
565 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
566 return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
568 return (void* )glXGetProcAddress ((const GLubyte* )theFuncName);
572 // =======================================================================
573 // function : CheckExtension
575 // =======================================================================
576 Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
578 if (theExtName == NULL)
581 std::cerr << "CheckExtension called with NULL string!\n";
583 return Standard_False;
586 #if !defined(GL_ES_VERSION_2_0)
587 // available since OpenGL 3.0
588 // and the ONLY way to check extensions with OpenGL 3.1+ core profile
589 if (IsGlGreaterEqual (3, 0)
590 && myFuncs->glGetStringi != NULL)
593 ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
594 const size_t anExtNameLen = strlen (theExtName);
595 for (GLint anIter = 0; anIter < anExtNb; ++anIter)
597 const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter);
598 const size_t aTestExtNameLen = strlen (anExtension);
599 if (aTestExtNameLen == anExtNameLen
600 && strncmp (anExtension, theExtName, anExtNameLen) == 0)
602 return Standard_True;
605 return Standard_False;
609 // use old way with huge string for all extensions
610 const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
611 if (anExtString == NULL)
613 Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning);
614 return Standard_False;
616 return CheckExtension (anExtString, theExtName);
619 // =======================================================================
620 // function : CheckExtension
622 // =======================================================================
623 Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString,
624 const char* theExtName)
626 if (theExtString == NULL)
628 return Standard_False;
631 // Search for theExtName in the extensions string.
632 // Use of strstr() is not sufficient because extension names can be prefixes of other extension names.
633 char* aPtrIter = (char* )theExtString;
634 const char* aPtrEnd = aPtrIter + strlen (theExtString);
635 const size_t anExtNameLen = strlen (theExtName);
636 while (aPtrIter < aPtrEnd)
638 const size_t n = strcspn (aPtrIter, " ");
639 if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0))
641 return Standard_True;
645 return Standard_False;
648 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
650 // =======================================================================
653 // =======================================================================
654 Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
658 return Standard_True;
661 #if defined(HAVE_EGL)
662 myDisplay = (Aspect_Display )eglGetCurrentDisplay();
663 myGContext = (Aspect_RenderingContext )eglGetCurrentContext();
664 myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW);
665 #elif defined(_WIN32)
666 myWindowDC = (Aspect_Handle )wglGetCurrentDC();
667 myGContext = (Aspect_RenderingContext )wglGetCurrentContext();
669 myDisplay = (Aspect_Display )glXGetCurrentDisplay();
670 myGContext = (Aspect_RenderingContext )glXGetCurrentContext();
671 myWindow = (Aspect_Drawable )glXGetCurrentDrawable();
673 if (myGContext == NULL)
675 return Standard_False;
678 init (theIsCoreProfile);
679 myIsInitialized = Standard_True;
680 return Standard_True;
685 // =======================================================================
688 // =======================================================================
689 #if defined(HAVE_EGL)
690 Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface,
691 const Aspect_Display theEglDisplay,
692 const Aspect_RenderingContext theEglContext,
693 const Standard_Boolean theIsCoreProfile)
694 #elif defined(_WIN32)
695 Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
696 const Aspect_Handle theWindowDC,
697 const Aspect_RenderingContext theGContext,
698 const Standard_Boolean theIsCoreProfile)
699 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
701 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
702 Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext,
703 const Standard_Boolean theIsCoreProfile)
705 Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext,
706 const Standard_Boolean theIsCoreProfile)
710 Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
711 const Aspect_Display theDisplay,
712 const Aspect_RenderingContext theGContext,
713 const Standard_Boolean theIsCoreProfile)
716 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
717 #if defined(HAVE_EGL)
718 myWindow = theEglSurface;
719 myGContext = theEglContext;
720 myDisplay = theEglDisplay;
721 #elif defined(_WIN32)
722 myWindow = theWindow;
723 myGContext = theGContext;
724 myWindowDC = theWindowDC;
725 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
726 myGContext = theGContext;
728 myWindow = theWindow;
729 myGContext = theGContext;
730 myDisplay = theDisplay;
732 if (myGContext == NULL || !MakeCurrent())
734 return Standard_False;
737 init (theIsCoreProfile);
738 myIsInitialized = Standard_True;
739 return Standard_True;
742 // =======================================================================
743 // function : ResetErrors
745 // =======================================================================
746 void OpenGl_Context::ResetErrors (const bool theToPrintErrors)
749 int anErr = ::glGetError();
750 if (!theToPrintErrors)
752 for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
759 for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
761 TCollection_ExtendedString anErrId;
764 case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break;
765 case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break;
766 case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break;
767 #ifdef GL_STACK_OVERFLOW
768 case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break;
769 case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break;
771 case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break;
772 case GL_INVALID_FRAMEBUFFER_OPERATION:
773 anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION";
776 anErrId = TCollection_ExtendedString("#") + anErr;
780 const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId;
781 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
785 // =======================================================================
786 // function : ReadGlVersion
788 // =======================================================================
789 void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor,
790 Standard_Integer& theGlVerMinor)
796 #ifdef GL_MAJOR_VERSION
797 // available since OpenGL 3.0 and OpenGL 3.0 ES
798 GLint aMajor = 0, aMinor = 0;
799 glGetIntegerv (GL_MAJOR_VERSION, &aMajor);
800 glGetIntegerv (GL_MINOR_VERSION, &aMinor);
801 // glGetError() sometimes does not report an error here even if
802 // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants.
803 // This happens on some renderers like e.g. Cygwin MESA.
804 // Thus checking additionally if GL has put anything to
805 // the output variables.
806 if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0)
808 theGlVerMajor = aMajor;
809 theGlVerMinor = aMinor;
812 for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError())
814 if (anErr == GL_NO_ERROR
815 || anErr == aPrevErr)
822 // Read version string.
823 // Notice that only first two numbers split by point '2.1 XXXXX' are significant.
824 // Following trash (after space) is vendor-specific.
825 // New drivers also returns micro version of GL like '3.3.0' which has no meaning
826 // and should be considered as vendor-specific too.
827 const char* aVerStr = (const char* )glGetString (GL_VERSION);
828 if (aVerStr == NULL || *aVerStr == '\0')
830 // invalid GL context
834 //#if defined(GL_ES_VERSION_2_0)
835 // skip "OpenGL ES-** " section
836 for (; *aVerStr != '\0'; ++aVerStr)
838 if (*aVerStr >= '0' && *aVerStr <= '9')
845 // parse string for major number
849 while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9')
853 if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr))
857 memcpy (aMajorStr, aVerStr, aMajIter);
858 aMajorStr[aMajIter] = '\0';
860 // parse string for minor number
861 aVerStr += aMajIter + 1;
863 while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9')
867 if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr))
871 memcpy (aMinorStr, aVerStr, aMinIter);
872 aMinorStr[aMinIter] = '\0';
875 theGlVerMajor = atoi (aMajorStr);
876 theGlVerMinor = atoi (aMinorStr);
878 if (theGlVerMajor <= 0)
885 static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
886 static Standard_CString THE_DBGMSG_SOURCES[] =
888 ".OpenGL", // GL_DEBUG_SOURCE_API
889 ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM
890 ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER
891 ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY
892 "", // GL_DEBUG_SOURCE_APPLICATION
893 ".Other" // GL_DEBUG_SOURCE_OTHER
896 static Standard_CString THE_DBGMSG_TYPES[] =
898 "Error", // GL_DEBUG_TYPE_ERROR
899 "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR
900 "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR
901 "Portability", // GL_DEBUG_TYPE_PORTABILITY
902 "Performance", // GL_DEBUG_TYPE_PERFORMANCE
903 "Other" // GL_DEBUG_TYPE_OTHER
906 static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH
907 static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM
908 static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW
910 #if !defined(GL_ES_VERSION_2_0)
911 //! Callback for GL_ARB_debug_output extension
912 static void APIENTRY debugCallbackWrap(unsigned int theSource,
913 unsigned int theType,
915 unsigned int theSeverity,
917 const char* theMessage,
918 const void* theUserParam)
920 OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
921 aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage);
925 // =======================================================================
926 // function : PushMessage
928 // =======================================================================
929 void OpenGl_Context::PushMessage (const unsigned int theSource,
930 const unsigned int theType,
931 const unsigned int theId,
932 const unsigned int theSeverity,
933 const TCollection_ExtendedString& theMessage)
935 if (caps->suppressExtraMsg
936 && theSource >= GL_DEBUG_SOURCE_API
937 && theSource <= GL_DEBUG_SOURCE_OTHER
938 && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId))
943 Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API
944 && theSource <= GL_DEBUG_SOURCE_OTHER)
945 ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API]
946 : THE_DBGMSG_UNKNOWN;
947 Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR
948 && theType <= GL_DEBUG_TYPE_OTHER)
949 ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR]
950 : THE_DBGMSG_UNKNOWN;
951 Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH
952 ? THE_DBGMSG_SEV_HIGH
953 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
954 ? THE_DBGMSG_SEV_MEDIUM
955 : THE_DBGMSG_SEV_LOW);
956 Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH
958 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
962 TCollection_ExtendedString aMsg;
963 aMsg += "TKOpenGl"; aMsg += aSrc;
964 aMsg += " | Type: "; aMsg += aType;
965 aMsg += " | ID: "; aMsg += (Standard_Integer )theId;
966 aMsg += " | Severity: "; aMsg += aSev;
967 aMsg += " | Message:\n ";
969 Messenger()->Send (aMsg, aGrav);
972 // =======================================================================
973 // function : ExcludeMessage
975 // ======================================================================
976 Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource,
977 const unsigned int theId)
979 return theSource >= GL_DEBUG_SOURCE_API
980 && theSource <= GL_DEBUG_SOURCE_OTHER
981 && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId);
984 // =======================================================================
985 // function : IncludeMessage
987 // ======================================================================
988 Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource,
989 const unsigned int theId)
991 return theSource >= GL_DEBUG_SOURCE_API
992 && theSource <= GL_DEBUG_SOURCE_OTHER
993 && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId);
996 // =======================================================================
997 // function : checkWrongVersion
999 // ======================================================================
1000 void OpenGl_Context::checkWrongVersion (const Standard_Integer theGlVerMajor,
1001 const Standard_Integer theGlVerMinor)
1003 if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor))
1008 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
1009 + "Error! OpenGL context reports version "
1010 + myGlVerMajor + "." + myGlVerMinor
1011 + " but does not export required functions for "
1012 + theGlVerMajor + "." + theGlVerMinor;
1013 PushMessage (GL_DEBUG_SOURCE_APPLICATION,
1014 GL_DEBUG_TYPE_ERROR,
1016 GL_DEBUG_SEVERITY_HIGH,
1020 // =======================================================================
1023 // =======================================================================
1024 void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
1029 myMaxMsaaSamples = 0;
1030 ReadGlVersion (myGlVerMajor, myGlVerMinor);
1031 myVendor = (const char* )::glGetString (GL_VENDOR);
1033 #if defined(GL_ES_VERSION_2_0)
1034 (void )theIsCoreProfile;
1035 const bool isCoreProfile = false;
1038 if (myVendor.Search ("NVIDIA") != -1)
1040 // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW)
1041 // will use VIDEO memory as the source for buffer object operations.
1042 ExcludeMessage (GL_DEBUG_SOURCE_API, 131185);
1044 if (IsGlGreaterEqual (3, 0))
1046 // retrieve auxiliary function in advance
1047 FindProc ("glGetStringi", myFuncs->glGetStringi);
1050 bool isCoreProfile = false;
1051 if (IsGlGreaterEqual (3, 2))
1053 isCoreProfile = (theIsCoreProfile == Standard_True);
1055 // detect Core profile
1059 ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile);
1060 isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0;
1068 core11 = (OpenGl_GlCore11* )(&(*myFuncs));
1070 core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
1088 arbTboRGB32 = Standard_False;
1096 #if defined(GL_ES_VERSION_2_0)
1098 hasTexRGBA8 = IsGlGreaterEqual (3, 0)
1099 || CheckExtension ("GL_OES_rgb8_rgba8");
1100 // NPOT textures has limited support within OpenGL ES 2.0
1101 // which are relaxed by OpenGL ES 3.0 or some extensions
1102 //arbNPTW = IsGlGreaterEqual (3, 0)
1103 // || CheckExtension ("GL_OES_texture_npot")
1104 // || CheckExtension ("GL_NV_texture_npot_2D_mipmap");
1105 arbNPTW = Standard_True;
1106 arbTexRG = IsGlGreaterEqual (3, 0)
1107 || CheckExtension ("GL_EXT_texture_rg");
1108 extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888");
1109 extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
1110 extPDS = CheckExtension ("GL_OES_packed_depth_stencil");
1112 core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
1113 if (IsGlGreaterEqual (2, 0))
1115 // enable compatible functions
1116 core20 = (OpenGl_GlCore20* )(&(*myFuncs));
1117 core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
1118 core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
1119 arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
1121 if (IsGlGreaterEqual (3, 0)
1122 && FindProc ("glBlitFramebuffer", myFuncs->glBlitFramebuffer))
1124 arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs));
1126 if (IsGlGreaterEqual (3, 1)
1127 && FindProc ("glTexStorage2DMultisample", myFuncs->glTexStorage2DMultisample))
1129 // MSAA RenderBuffers have been defined in OpenGL ES 3.0,
1130 // but MSAA Textures - only in OpenGL ES 3.1+
1131 ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
1134 hasUintIndex = IsGlGreaterEqual (3, 0)
1135 || CheckExtension ("GL_OES_element_index_uint");
1136 hasHighp = CheckExtension ("GL_OES_fragment_precision_high");
1137 GLint aRange[2] = {0, 0};
1139 ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec);
1142 hasHighp = Standard_True;
1145 arbTexFloat = IsGlGreaterEqual (3, 0)
1146 && FindProc ("glTexImage3D", myFuncs->glTexImage3D);
1148 const Standard_Boolean hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProc ("glTexBuffer", myFuncs->glTexBuffer);
1149 const Standard_Boolean hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer);
1151 if (hasTexBuffer32 || hasExtTexBuffer)
1153 arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get());
1157 myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP;
1159 hasTexRGBA8 = Standard_True;
1160 arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
1161 arbTexFloat = IsGlGreaterEqual (3, 0)
1162 || CheckExtension ("GL_ARB_texture_float");
1163 extBgra = CheckExtension ("GL_EXT_bgra");
1164 extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
1165 extPDS = CheckExtension ("GL_EXT_packed_depth_stencil");
1166 atiMem = CheckExtension ("GL_ATI_meminfo");
1167 nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
1169 GLint aStereo = GL_FALSE;
1170 glGetIntegerv (GL_STEREO, &aStereo);
1171 myIsStereoBuffers = aStereo == 1;
1173 // get number of maximum clipping planes
1174 glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes);
1177 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);
1181 glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax);
1184 myClippingState.Init (myMaxClipPlanes);
1186 #if !defined(GL_ES_VERSION_2_0)
1204 //! Make record shorter to retrieve function pointer using variable with same name
1205 #define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc)
1207 // retrieve platform-dependent extensions
1208 #if defined(HAVE_EGL)
1210 #elif defined(_WIN32)
1211 if (FindProcShort (wglGetExtensionsStringARB))
1213 const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC());
1214 if (CheckExtension (aWglExts, "WGL_EXT_swap_control"))
1216 FindProcShort (wglSwapIntervalEXT);
1218 if (CheckExtension (aWglExts, "WGL_ARB_pixel_format"))
1220 FindProcShort (wglChoosePixelFormatARB);
1222 if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile"))
1224 FindProcShort (wglCreateContextAttribsARB);
1226 if (CheckExtension (aWglExts, "WGL_NV_DX_interop"))
1228 FindProcShort (wglDXSetResourceShareHandleNV);
1229 FindProcShort (wglDXOpenDeviceNV);
1230 FindProcShort (wglDXCloseDeviceNV);
1231 FindProcShort (wglDXRegisterObjectNV);
1232 FindProcShort (wglDXUnregisterObjectNV);
1233 FindProcShort (wglDXObjectAccessNV);
1234 FindProcShort (wglDXLockObjectsNV);
1235 FindProcShort (wglDXUnlockObjectsNV);
1238 #elif defined(__APPLE__)
1241 const char* aGlxExts = ::glXQueryExtensionsString ((Display* )myDisplay, DefaultScreen ((Display* )myDisplay));
1242 if (CheckExtension (aGlxExts, "GLX_EXT_swap_control"))
1244 FindProcShort (glXSwapIntervalEXT);
1246 if (CheckExtension (aGlxExts, "GLX_SGI_swap_control"))
1248 FindProcShort (glXSwapIntervalSGI);
1250 //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear");
1253 // initialize debug context extension
1254 if (CheckExtension ("GL_ARB_debug_output"))
1257 if (FindProcShort (glDebugMessageControlARB)
1258 && FindProcShort (glDebugMessageInsertARB)
1259 && FindProcShort (glDebugMessageCallbackARB)
1260 && FindProcShort (glGetDebugMessageLogARB))
1262 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
1265 && caps->contextDebug)
1267 // setup default callback
1268 myIsGlDebugCtx = Standard_True;
1269 arbDbg->glDebugMessageCallbackARB (debugCallbackWrap, this);
1270 if (caps->contextSyncDebug)
1272 ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
1277 // load OpenGL 1.2 new functions
1278 has12 = IsGlGreaterEqual (1, 2)
1279 && FindProcShort (glBlendColor)
1280 && FindProcShort (glBlendEquation)
1281 && FindProcShort (glDrawRangeElements)
1282 && FindProcShort (glTexImage3D)
1283 && FindProcShort (glTexSubImage3D)
1284 && FindProcShort (glCopyTexSubImage3D);
1286 // load OpenGL 1.3 new functions
1287 has13 = IsGlGreaterEqual (1, 3)
1288 && FindProcShort (glActiveTexture)
1289 && FindProcShort (glSampleCoverage)
1290 && FindProcShort (glCompressedTexImage3D)
1291 && FindProcShort (glCompressedTexImage2D)
1292 && FindProcShort (glCompressedTexImage1D)
1293 && FindProcShort (glCompressedTexSubImage3D)
1294 && FindProcShort (glCompressedTexSubImage2D)
1295 && FindProcShort (glCompressedTexSubImage1D)
1296 && FindProcShort (glGetCompressedTexImage);
1301 && FindProcShort (glClientActiveTexture)
1302 && FindProcShort (glMultiTexCoord1d)
1303 && FindProcShort (glMultiTexCoord1dv)
1304 && FindProcShort (glMultiTexCoord1f)
1305 && FindProcShort (glMultiTexCoord1fv)
1306 && FindProcShort (glMultiTexCoord1i)
1307 && FindProcShort (glMultiTexCoord1iv)
1308 && FindProcShort (glMultiTexCoord1s)
1309 && FindProcShort (glMultiTexCoord1sv)
1310 && FindProcShort (glMultiTexCoord2d)
1311 && FindProcShort (glMultiTexCoord2dv)
1312 && FindProcShort (glMultiTexCoord2f)
1313 && FindProcShort (glMultiTexCoord2fv)
1314 && FindProcShort (glMultiTexCoord2i)
1315 && FindProcShort (glMultiTexCoord2iv)
1316 && FindProcShort (glMultiTexCoord2s)
1317 && FindProcShort (glMultiTexCoord2sv)
1318 && FindProcShort (glMultiTexCoord3d)
1319 && FindProcShort (glMultiTexCoord3dv)
1320 && FindProcShort (glMultiTexCoord3f)
1321 && FindProcShort (glMultiTexCoord3fv)
1322 && FindProcShort (glMultiTexCoord3i)
1323 && FindProcShort (glMultiTexCoord3iv)
1324 && FindProcShort (glMultiTexCoord3s)
1325 && FindProcShort (glMultiTexCoord3sv)
1326 && FindProcShort (glMultiTexCoord4d)
1327 && FindProcShort (glMultiTexCoord4dv)
1328 && FindProcShort (glMultiTexCoord4f)
1329 && FindProcShort (glMultiTexCoord4fv)
1330 && FindProcShort (glMultiTexCoord4i)
1331 && FindProcShort (glMultiTexCoord4iv)
1332 && FindProcShort (glMultiTexCoord4s)
1333 && FindProcShort (glMultiTexCoord4sv)
1334 && FindProcShort (glLoadTransposeMatrixf)
1335 && FindProcShort (glLoadTransposeMatrixd)
1336 && FindProcShort (glMultTransposeMatrixf)
1337 && FindProcShort (glMultTransposeMatrixd);
1340 // load OpenGL 1.4 new functions
1341 has14 = IsGlGreaterEqual (1, 4)
1342 && FindProcShort (glBlendFuncSeparate)
1343 && FindProcShort (glMultiDrawArrays)
1344 && FindProcShort (glMultiDrawElements)
1345 && FindProcShort (glPointParameterf)
1346 && FindProcShort (glPointParameterfv)
1347 && FindProcShort (glPointParameteri)
1348 && FindProcShort (glPointParameteriv);
1350 // load OpenGL 1.5 new functions
1351 has15 = IsGlGreaterEqual (1, 5)
1352 && FindProcShort (glGenQueries)
1353 && FindProcShort (glDeleteQueries)
1354 && FindProcShort (glIsQuery)
1355 && FindProcShort (glBeginQuery)
1356 && FindProcShort (glEndQuery)
1357 && FindProcShort (glGetQueryiv)
1358 && FindProcShort (glGetQueryObjectiv)
1359 && FindProcShort (glGetQueryObjectuiv)
1360 && FindProcShort (glBindBuffer)
1361 && FindProcShort (glDeleteBuffers)
1362 && FindProcShort (glGenBuffers)
1363 && FindProcShort (glIsBuffer)
1364 && FindProcShort (glBufferData)
1365 && FindProcShort (glBufferSubData)
1366 && FindProcShort (glGetBufferSubData)
1367 && FindProcShort (glMapBuffer)
1368 && FindProcShort (glUnmapBuffer)
1369 && FindProcShort (glGetBufferParameteriv)
1370 && FindProcShort (glGetBufferPointerv);
1372 // load OpenGL 2.0 new functions
1373 has20 = IsGlGreaterEqual (2, 0)
1374 && FindProcShort (glBlendEquationSeparate)
1375 && FindProcShort (glDrawBuffers)
1376 && FindProcShort (glStencilOpSeparate)
1377 && FindProcShort (glStencilFuncSeparate)
1378 && FindProcShort (glStencilMaskSeparate)
1379 && FindProcShort (glAttachShader)
1380 && FindProcShort (glBindAttribLocation)
1381 && FindProcShort (glCompileShader)
1382 && FindProcShort (glCreateProgram)
1383 && FindProcShort (glCreateShader)
1384 && FindProcShort (glDeleteProgram)
1385 && FindProcShort (glDeleteShader)
1386 && FindProcShort (glDetachShader)
1387 && FindProcShort (glDisableVertexAttribArray)
1388 && FindProcShort (glEnableVertexAttribArray)
1389 && FindProcShort (glGetActiveAttrib)
1390 && FindProcShort (glGetActiveUniform)
1391 && FindProcShort (glGetAttachedShaders)
1392 && FindProcShort (glGetAttribLocation)
1393 && FindProcShort (glGetProgramiv)
1394 && FindProcShort (glGetProgramInfoLog)
1395 && FindProcShort (glGetShaderiv)
1396 && FindProcShort (glGetShaderInfoLog)
1397 && FindProcShort (glGetShaderSource)
1398 && FindProcShort (glGetUniformLocation)
1399 && FindProcShort (glGetUniformfv)
1400 && FindProcShort (glGetUniformiv)
1401 && FindProcShort (glGetVertexAttribdv)
1402 && FindProcShort (glGetVertexAttribfv)
1403 && FindProcShort (glGetVertexAttribiv)
1404 && FindProcShort (glGetVertexAttribPointerv)
1405 && FindProcShort (glIsProgram)
1406 && FindProcShort (glIsShader)
1407 && FindProcShort (glLinkProgram)
1408 && FindProcShort (glShaderSource)
1409 && FindProcShort (glUseProgram)
1410 && FindProcShort (glUniform1f)
1411 && FindProcShort (glUniform2f)
1412 && FindProcShort (glUniform3f)
1413 && FindProcShort (glUniform4f)
1414 && FindProcShort (glUniform1i)
1415 && FindProcShort (glUniform2i)
1416 && FindProcShort (glUniform3i)
1417 && FindProcShort (glUniform4i)
1418 && FindProcShort (glUniform1fv)
1419 && FindProcShort (glUniform2fv)
1420 && FindProcShort (glUniform3fv)
1421 && FindProcShort (glUniform4fv)
1422 && FindProcShort (glUniform1iv)
1423 && FindProcShort (glUniform2iv)
1424 && FindProcShort (glUniform3iv)
1425 && FindProcShort (glUniform4iv)
1426 && FindProcShort (glUniformMatrix2fv)
1427 && FindProcShort (glUniformMatrix3fv)
1428 && FindProcShort (glUniformMatrix4fv)
1429 && FindProcShort (glValidateProgram)
1430 && FindProcShort (glVertexAttrib1d)
1431 && FindProcShort (glVertexAttrib1dv)
1432 && FindProcShort (glVertexAttrib1f)
1433 && FindProcShort (glVertexAttrib1fv)
1434 && FindProcShort (glVertexAttrib1s)
1435 && FindProcShort (glVertexAttrib1sv)
1436 && FindProcShort (glVertexAttrib2d)
1437 && FindProcShort (glVertexAttrib2dv)
1438 && FindProcShort (glVertexAttrib2f)
1439 && FindProcShort (glVertexAttrib2fv)
1440 && FindProcShort (glVertexAttrib2s)
1441 && FindProcShort (glVertexAttrib2sv)
1442 && FindProcShort (glVertexAttrib3d)
1443 && FindProcShort (glVertexAttrib3dv)
1444 && FindProcShort (glVertexAttrib3f)
1445 && FindProcShort (glVertexAttrib3fv)
1446 && FindProcShort (glVertexAttrib3s)
1447 && FindProcShort (glVertexAttrib3sv)
1448 && FindProcShort (glVertexAttrib4Nbv)
1449 && FindProcShort (glVertexAttrib4Niv)
1450 && FindProcShort (glVertexAttrib4Nsv)
1451 && FindProcShort (glVertexAttrib4Nub)
1452 && FindProcShort (glVertexAttrib4Nubv)
1453 && FindProcShort (glVertexAttrib4Nuiv)
1454 && FindProcShort (glVertexAttrib4Nusv)
1455 && FindProcShort (glVertexAttrib4bv)
1456 && FindProcShort (glVertexAttrib4d)
1457 && FindProcShort (glVertexAttrib4dv)
1458 && FindProcShort (glVertexAttrib4f)
1459 && FindProcShort (glVertexAttrib4fv)
1460 && FindProcShort (glVertexAttrib4iv)
1461 && FindProcShort (glVertexAttrib4s)
1462 && FindProcShort (glVertexAttrib4sv)
1463 && FindProcShort (glVertexAttrib4ubv)
1464 && FindProcShort (glVertexAttrib4uiv)
1465 && FindProcShort (glVertexAttrib4usv)
1466 && FindProcShort (glVertexAttribPointer);
1468 // load OpenGL 2.1 new functions
1469 has21 = IsGlGreaterEqual (2, 1)
1470 && FindProcShort (glUniformMatrix2x3fv)
1471 && FindProcShort (glUniformMatrix3x2fv)
1472 && FindProcShort (glUniformMatrix2x4fv)
1473 && FindProcShort (glUniformMatrix4x2fv)
1474 && FindProcShort (glUniformMatrix3x4fv)
1475 && FindProcShort (glUniformMatrix4x3fv);
1477 // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core)
1478 const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object"))
1479 && FindProcShort (glIsRenderbuffer)
1480 && FindProcShort (glBindRenderbuffer)
1481 && FindProcShort (glDeleteRenderbuffers)
1482 && FindProcShort (glGenRenderbuffers)
1483 && FindProcShort (glRenderbufferStorage)
1484 && FindProcShort (glGetRenderbufferParameteriv)
1485 && FindProcShort (glIsFramebuffer)
1486 && FindProcShort (glBindFramebuffer)
1487 && FindProcShort (glDeleteFramebuffers)
1488 && FindProcShort (glGenFramebuffers)
1489 && FindProcShort (glCheckFramebufferStatus)
1490 && FindProcShort (glFramebufferTexture1D)
1491 && FindProcShort (glFramebufferTexture2D)
1492 && FindProcShort (glFramebufferTexture3D)
1493 && FindProcShort (glFramebufferRenderbuffer)
1494 && FindProcShort (glGetFramebufferAttachmentParameteriv)
1495 && FindProcShort (glGenerateMipmap)
1496 && FindProcShort (glBlitFramebuffer)
1497 && FindProcShort (glRenderbufferStorageMultisample)
1498 && FindProcShort (glFramebufferTextureLayer);
1500 // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core)
1501 const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object"))
1502 && FindProcShort (glBindVertexArray)
1503 && FindProcShort (glDeleteVertexArrays)
1504 && FindProcShort (glGenVertexArrays)
1505 && FindProcShort (glIsVertexArray);
1507 // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core)
1508 const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range"))
1509 && FindProcShort (glMapBufferRange)
1510 && FindProcShort (glFlushMappedBufferRange);
1512 // load OpenGL 3.0 new functions
1513 has30 = IsGlGreaterEqual (3, 0)
1516 && hasMapBufferRange
1517 && FindProcShort (glColorMaski)
1518 && FindProcShort (glGetBooleani_v)
1519 && FindProcShort (glGetIntegeri_v)
1520 && FindProcShort (glEnablei)
1521 && FindProcShort (glDisablei)
1522 && FindProcShort (glIsEnabledi)
1523 && FindProcShort (glBeginTransformFeedback)
1524 && FindProcShort (glEndTransformFeedback)
1525 && FindProcShort (glBindBufferRange)
1526 && FindProcShort (glBindBufferBase)
1527 && FindProcShort (glTransformFeedbackVaryings)
1528 && FindProcShort (glGetTransformFeedbackVarying)
1529 && FindProcShort (glClampColor)
1530 && FindProcShort (glBeginConditionalRender)
1531 && FindProcShort (glEndConditionalRender)
1532 && FindProcShort (glVertexAttribIPointer)
1533 && FindProcShort (glGetVertexAttribIiv)
1534 && FindProcShort (glGetVertexAttribIuiv)
1535 && FindProcShort (glVertexAttribI1i)
1536 && FindProcShort (glVertexAttribI2i)
1537 && FindProcShort (glVertexAttribI3i)
1538 && FindProcShort (glVertexAttribI4i)
1539 && FindProcShort (glVertexAttribI1ui)
1540 && FindProcShort (glVertexAttribI2ui)
1541 && FindProcShort (glVertexAttribI3ui)
1542 && FindProcShort (glVertexAttribI4ui)
1543 && FindProcShort (glVertexAttribI1iv)
1544 && FindProcShort (glVertexAttribI2iv)
1545 && FindProcShort (glVertexAttribI3iv)
1546 && FindProcShort (glVertexAttribI4iv)
1547 && FindProcShort (glVertexAttribI1uiv)
1548 && FindProcShort (glVertexAttribI2uiv)
1549 && FindProcShort (glVertexAttribI3uiv)
1550 && FindProcShort (glVertexAttribI4uiv)
1551 && FindProcShort (glVertexAttribI4bv)
1552 && FindProcShort (glVertexAttribI4sv)
1553 && FindProcShort (glVertexAttribI4ubv)
1554 && FindProcShort (glVertexAttribI4usv)
1555 && FindProcShort (glGetUniformuiv)
1556 && FindProcShort (glBindFragDataLocation)
1557 && FindProcShort (glGetFragDataLocation)
1558 && FindProcShort (glUniform1ui)
1559 && FindProcShort (glUniform2ui)
1560 && FindProcShort (glUniform3ui)
1561 && FindProcShort (glUniform4ui)
1562 && FindProcShort (glUniform1uiv)
1563 && FindProcShort (glUniform2uiv)
1564 && FindProcShort (glUniform3uiv)
1565 && FindProcShort (glUniform4uiv)
1566 && FindProcShort (glTexParameterIiv)
1567 && FindProcShort (glTexParameterIuiv)
1568 && FindProcShort (glGetTexParameterIiv)
1569 && FindProcShort (glGetTexParameterIuiv)
1570 && FindProcShort (glClearBufferiv)
1571 && FindProcShort (glClearBufferuiv)
1572 && FindProcShort (glClearBufferfv)
1573 && FindProcShort (glClearBufferfi)
1574 && FindProcShort (glGetStringi);
1576 // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core)
1577 const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object"))
1578 && FindProcShort (glGetUniformIndices)
1579 && FindProcShort (glGetActiveUniformsiv)
1580 && FindProcShort (glGetActiveUniformName)
1581 && FindProcShort (glGetUniformBlockIndex)
1582 && FindProcShort (glGetActiveUniformBlockiv)
1583 && FindProcShort (glGetActiveUniformBlockName)
1584 && FindProcShort (glUniformBlockBinding);
1586 // load GL_ARB_copy_buffer (added to OpenGL 3.1 core)
1587 const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer"))
1588 && FindProcShort (glCopyBufferSubData);
1592 // NPOT textures are required by OpenGL 2.0 specifications
1593 // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.)
1594 arbNPTW = Standard_True;
1595 arbTexRG = Standard_True;
1598 // load OpenGL 3.1 new functions
1599 has31 = IsGlGreaterEqual (3, 1)
1601 && hasCopyBufSubData
1602 && FindProcShort (glDrawArraysInstanced)
1603 && FindProcShort (glDrawElementsInstanced)
1604 && FindProcShort (glTexBuffer)
1605 && FindProcShort (glPrimitiveRestartIndex);
1607 // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core)
1608 const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex"))
1609 && FindProcShort (glDrawElementsBaseVertex)
1610 && FindProcShort (glDrawRangeElementsBaseVertex)
1611 && FindProcShort (glDrawElementsInstancedBaseVertex)
1612 && FindProcShort (glMultiDrawElementsBaseVertex);
1614 // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core)
1615 const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex"))
1616 && FindProcShort (glProvokingVertex);
1618 // load GL_ARB_sync (added to OpenGL 3.2 core)
1619 const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync"))
1620 && FindProcShort (glFenceSync)
1621 && FindProcShort (glIsSync)
1622 && FindProcShort (glDeleteSync)
1623 && FindProcShort (glClientWaitSync)
1624 && FindProcShort (glWaitSync)
1625 && FindProcShort (glGetInteger64v)
1626 && FindProcShort (glGetSynciv);
1628 // load GL_ARB_texture_multisample (added to OpenGL 3.2 core)
1629 const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample"))
1630 && FindProcShort (glTexImage2DMultisample)
1631 && FindProcShort (glTexImage3DMultisample)
1632 && FindProcShort (glGetMultisamplefv)
1633 && FindProcShort (glSampleMaski);
1635 // load OpenGL 3.2 new functions
1636 has32 = IsGlGreaterEqual (3, 2)
1637 && hasDrawElemsBaseVert
1640 && hasTextureMultisample
1641 && FindProcShort (glGetInteger64i_v)
1642 && FindProcShort (glGetBufferParameteri64v)
1643 && FindProcShort (glFramebufferTexture);
1645 // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core)
1646 const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended"))
1647 && FindProcShort (glBindFragDataLocationIndexed)
1648 && FindProcShort (glGetFragDataIndex);
1650 // load GL_ARB_sampler_objects (added to OpenGL 3.3 core)
1651 const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects"))
1652 && FindProcShort (glGenSamplers)
1653 && FindProcShort (glDeleteSamplers)
1654 && FindProcShort (glIsSampler)
1655 && FindProcShort (glBindSampler)
1656 && FindProcShort (glSamplerParameteri)
1657 && FindProcShort (glSamplerParameteriv)
1658 && FindProcShort (glSamplerParameterf)
1659 && FindProcShort (glSamplerParameterfv)
1660 && FindProcShort (glSamplerParameterIiv)
1661 && FindProcShort (glSamplerParameterIuiv)
1662 && FindProcShort (glGetSamplerParameteriv)
1663 && FindProcShort (glGetSamplerParameterIiv)
1664 && FindProcShort (glGetSamplerParameterfv)
1665 && FindProcShort (glGetSamplerParameterIuiv);
1667 // load GL_ARB_timer_query (added to OpenGL 3.3 core)
1668 const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query"))
1669 && FindProcShort (glQueryCounter)
1670 && FindProcShort (glGetQueryObjecti64v)
1671 && FindProcShort (glGetQueryObjectui64v);
1673 // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core)
1674 const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev"))
1675 && FindProcShort (glVertexAttribP1ui)
1676 && FindProcShort (glVertexAttribP1uiv)
1677 && FindProcShort (glVertexAttribP2ui)
1678 && FindProcShort (glVertexAttribP2uiv)
1679 && FindProcShort (glVertexAttribP3ui)
1680 && FindProcShort (glVertexAttribP3uiv)
1681 && FindProcShort (glVertexAttribP4ui)
1682 && FindProcShort (glVertexAttribP4uiv);
1684 if ( hasVertType21010101rev
1687 // load deprecated functions
1688 const bool hasVertType21010101revExt =
1689 FindProcShort (glVertexP2ui)
1690 && FindProcShort (glVertexP2uiv)
1691 && FindProcShort (glVertexP3ui)
1692 && FindProcShort (glVertexP3uiv)
1693 && FindProcShort (glVertexP4ui)
1694 && FindProcShort (glVertexP4uiv)
1695 && FindProcShort (glTexCoordP1ui)
1696 && FindProcShort (glTexCoordP1uiv)
1697 && FindProcShort (glTexCoordP2ui)
1698 && FindProcShort (glTexCoordP2uiv)
1699 && FindProcShort (glTexCoordP3ui)
1700 && FindProcShort (glTexCoordP3uiv)
1701 && FindProcShort (glTexCoordP4ui)
1702 && FindProcShort (glTexCoordP4uiv)
1703 && FindProcShort (glMultiTexCoordP1ui)
1704 && FindProcShort (glMultiTexCoordP1uiv)
1705 && FindProcShort (glMultiTexCoordP2ui)
1706 && FindProcShort (glMultiTexCoordP2uiv)
1707 && FindProcShort (glMultiTexCoordP3ui)
1708 && FindProcShort (glMultiTexCoordP3uiv)
1709 && FindProcShort (glMultiTexCoordP4ui)
1710 && FindProcShort (glMultiTexCoordP4uiv)
1711 && FindProcShort (glNormalP3ui)
1712 && FindProcShort (glNormalP3uiv)
1713 && FindProcShort (glColorP3ui)
1714 && FindProcShort (glColorP3uiv)
1715 && FindProcShort (glColorP4ui)
1716 && FindProcShort (glColorP4uiv)
1717 && FindProcShort (glSecondaryColorP3ui)
1718 && FindProcShort (glSecondaryColorP3uiv);
1719 (void )hasVertType21010101revExt;
1722 // load OpenGL 3.3 extra functions
1723 has33 = IsGlGreaterEqual (3, 3)
1724 && hasBlendFuncExtended
1725 && hasSamplerObjects
1727 && hasVertType21010101rev
1728 && FindProcShort (glVertexAttribDivisor);
1730 // load GL_ARB_draw_indirect (added to OpenGL 4.0 core)
1731 const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect"))
1732 && FindProcShort (glDrawArraysIndirect)
1733 && FindProcShort (glDrawElementsIndirect);
1735 // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core)
1736 const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64"))
1737 && FindProcShort (glUniform1d)
1738 && FindProcShort (glUniform2d)
1739 && FindProcShort (glUniform3d)
1740 && FindProcShort (glUniform4d)
1741 && FindProcShort (glUniform1dv)
1742 && FindProcShort (glUniform2dv)
1743 && FindProcShort (glUniform3dv)
1744 && FindProcShort (glUniform4dv)
1745 && FindProcShort (glUniformMatrix2dv)
1746 && FindProcShort (glUniformMatrix3dv)
1747 && FindProcShort (glUniformMatrix4dv)
1748 && FindProcShort (glUniformMatrix2x3dv)
1749 && FindProcShort (glUniformMatrix2x4dv)
1750 && FindProcShort (glUniformMatrix3x2dv)
1751 && FindProcShort (glUniformMatrix3x4dv)
1752 && FindProcShort (glUniformMatrix4x2dv)
1753 && FindProcShort (glUniformMatrix4x3dv)
1754 && FindProcShort (glGetUniformdv);
1756 // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core)
1757 const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine"))
1758 && FindProcShort (glGetSubroutineUniformLocation)
1759 && FindProcShort (glGetSubroutineIndex)
1760 && FindProcShort (glGetActiveSubroutineUniformiv)
1761 && FindProcShort (glGetActiveSubroutineUniformName)
1762 && FindProcShort (glGetActiveSubroutineName)
1763 && FindProcShort (glUniformSubroutinesuiv)
1764 && FindProcShort (glGetUniformSubroutineuiv)
1765 && FindProcShort (glGetProgramStageiv);
1767 // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core)
1768 const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader"))
1769 && FindProcShort (glPatchParameteri)
1770 && FindProcShort (glPatchParameterfv);
1772 // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core)
1773 const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2"))
1774 && FindProcShort (glBindTransformFeedback)
1775 && FindProcShort (glDeleteTransformFeedbacks)
1776 && FindProcShort (glGenTransformFeedbacks)
1777 && FindProcShort (glIsTransformFeedback)
1778 && FindProcShort (glPauseTransformFeedback)
1779 && FindProcShort (glResumeTransformFeedback)
1780 && FindProcShort (glDrawTransformFeedback);
1782 // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core)
1783 const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3"))
1784 && FindProcShort (glDrawTransformFeedbackStream)
1785 && FindProcShort (glBeginQueryIndexed)
1786 && FindProcShort (glEndQueryIndexed)
1787 && FindProcShort (glGetQueryIndexediv);
1789 // load OpenGL 4.0 new functions
1790 has40 = IsGlGreaterEqual (4, 0)
1793 && hasShaderSubroutine
1794 && hasTessellationShader
1797 && FindProcShort (glMinSampleShading)
1798 && FindProcShort (glBlendEquationi)
1799 && FindProcShort (glBlendEquationSeparatei)
1800 && FindProcShort (glBlendFunci)
1801 && FindProcShort (glBlendFuncSeparatei);
1803 // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core)
1804 const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility"))
1805 && FindProcShort (glReleaseShaderCompiler)
1806 && FindProcShort (glShaderBinary)
1807 && FindProcShort (glGetShaderPrecisionFormat)
1808 && FindProcShort (glDepthRangef)
1809 && FindProcShort (glClearDepthf);
1811 // load GL_ARB_get_program_binary (added to OpenGL 4.1 core)
1812 const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary"))
1813 && FindProcShort (glGetProgramBinary)
1814 && FindProcShort (glProgramBinary)
1815 && FindProcShort (glProgramParameteri);
1818 // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core)
1819 const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects"))
1820 && FindProcShort (glUseProgramStages)
1821 && FindProcShort (glActiveShaderProgram)
1822 && FindProcShort (glCreateShaderProgramv)
1823 && FindProcShort (glBindProgramPipeline)
1824 && FindProcShort (glDeleteProgramPipelines)
1825 && FindProcShort (glGenProgramPipelines)
1826 && FindProcShort (glIsProgramPipeline)
1827 && FindProcShort (glGetProgramPipelineiv)
1828 && FindProcShort (glProgramUniform1i)
1829 && FindProcShort (glProgramUniform1iv)
1830 && FindProcShort (glProgramUniform1f)
1831 && FindProcShort (glProgramUniform1fv)
1832 && FindProcShort (glProgramUniform1d)
1833 && FindProcShort (glProgramUniform1dv)
1834 && FindProcShort (glProgramUniform1ui)
1835 && FindProcShort (glProgramUniform1uiv)
1836 && FindProcShort (glProgramUniform2i)
1837 && FindProcShort (glProgramUniform2iv)
1838 && FindProcShort (glProgramUniform2f)
1839 && FindProcShort (glProgramUniform2fv)
1840 && FindProcShort (glProgramUniform2d)
1841 && FindProcShort (glProgramUniform2dv)
1842 && FindProcShort (glProgramUniform2ui)
1843 && FindProcShort (glProgramUniform2uiv)
1844 && FindProcShort (glProgramUniform3i)
1845 && FindProcShort (glProgramUniform3iv)
1846 && FindProcShort (glProgramUniform3f)
1847 && FindProcShort (glProgramUniform3fv)
1848 && FindProcShort (glProgramUniform3d)
1849 && FindProcShort (glProgramUniform3dv)
1850 && FindProcShort (glProgramUniform3ui)
1851 && FindProcShort (glProgramUniform3uiv)
1852 && FindProcShort (glProgramUniform4i)
1853 && FindProcShort (glProgramUniform4iv)
1854 && FindProcShort (glProgramUniform4f)
1855 && FindProcShort (glProgramUniform4fv)
1856 && FindProcShort (glProgramUniform4d)
1857 && FindProcShort (glProgramUniform4dv)
1858 && FindProcShort (glProgramUniform4ui)
1859 && FindProcShort (glProgramUniform4uiv)
1860 && FindProcShort (glProgramUniformMatrix2fv)
1861 && FindProcShort (glProgramUniformMatrix3fv)
1862 && FindProcShort (glProgramUniformMatrix4fv)
1863 && FindProcShort (glProgramUniformMatrix2dv)
1864 && FindProcShort (glProgramUniformMatrix3dv)
1865 && FindProcShort (glProgramUniformMatrix4dv)
1866 && FindProcShort (glProgramUniformMatrix2x3fv)
1867 && FindProcShort (glProgramUniformMatrix3x2fv)
1868 && FindProcShort (glProgramUniformMatrix2x4fv)
1869 && FindProcShort (glProgramUniformMatrix4x2fv)
1870 && FindProcShort (glProgramUniformMatrix3x4fv)
1871 && FindProcShort (glProgramUniformMatrix4x3fv)
1872 && FindProcShort (glProgramUniformMatrix2x3dv)
1873 && FindProcShort (glProgramUniformMatrix3x2dv)
1874 && FindProcShort (glProgramUniformMatrix2x4dv)
1875 && FindProcShort (glProgramUniformMatrix4x2dv)
1876 && FindProcShort (glProgramUniformMatrix3x4dv)
1877 && FindProcShort (glProgramUniformMatrix4x3dv)
1878 && FindProcShort (glValidateProgramPipeline)
1879 && FindProcShort (glGetProgramPipelineInfoLog);
1881 // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core)
1882 const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit"))
1883 && FindProcShort (glVertexAttribL1d)
1884 && FindProcShort (glVertexAttribL2d)
1885 && FindProcShort (glVertexAttribL3d)
1886 && FindProcShort (glVertexAttribL4d)
1887 && FindProcShort (glVertexAttribL1dv)
1888 && FindProcShort (glVertexAttribL2dv)
1889 && FindProcShort (glVertexAttribL3dv)
1890 && FindProcShort (glVertexAttribL4dv)
1891 && FindProcShort (glVertexAttribLPointer)
1892 && FindProcShort (glGetVertexAttribLdv);
1894 // load GL_ARB_viewport_array (added to OpenGL 4.1 core)
1895 const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array"))
1896 && FindProcShort (glViewportArrayv)
1897 && FindProcShort (glViewportIndexedf)
1898 && FindProcShort (glViewportIndexedfv)
1899 && FindProcShort (glScissorArrayv)
1900 && FindProcShort (glScissorIndexed)
1901 && FindProcShort (glScissorIndexedv)
1902 && FindProcShort (glDepthRangeArrayv)
1903 && FindProcShort (glDepthRangeIndexed)
1904 && FindProcShort (glGetFloati_v)
1905 && FindProcShort (glGetDoublei_v);
1907 has41 = IsGlGreaterEqual (4, 1)
1908 && hasES2Compatibility
1909 && hasGetProgramBinary
1910 && hasSeparateShaderObjects
1911 && hasVertAttrib64bit
1912 && hasViewportArray;
1914 // load GL_ARB_base_instance (added to OpenGL 4.2 core)
1915 const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance"))
1916 && FindProcShort (glDrawArraysInstancedBaseInstance)
1917 && FindProcShort (glDrawElementsInstancedBaseInstance)
1918 && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance);
1920 // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core)
1921 const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced"))
1922 && FindProcShort (glDrawTransformFeedbackInstanced)
1923 && FindProcShort (glDrawTransformFeedbackStreamInstanced);
1925 // load GL_ARB_internalformat_query (added to OpenGL 4.2 core)
1926 const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query"))
1927 && FindProcShort (glGetInternalformativ);
1929 // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core)
1930 const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters"))
1931 && FindProcShort (glGetActiveAtomicCounterBufferiv);
1933 // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core)
1934 const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store"))
1935 && FindProcShort (glBindImageTexture)
1936 && FindProcShort (glMemoryBarrier);
1938 // load GL_ARB_texture_storage (added to OpenGL 4.2 core)
1939 const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage"))
1940 && FindProcShort (glTexStorage1D)
1941 && FindProcShort (glTexStorage2D)
1942 && FindProcShort (glTexStorage3D);
1944 has42 = IsGlGreaterEqual (4, 2)
1946 && hasTrsfFeedbackInstanced
1947 && hasInternalFormatQuery
1948 && hasShaderAtomicCounters
1949 && hasShaderImgLoadStore
1950 && hasTextureStorage;
1952 has43 = IsGlGreaterEqual (4, 3)
1953 && FindProcShort (glClearBufferData)
1954 && FindProcShort (glClearBufferSubData)
1955 && FindProcShort (glDispatchCompute)
1956 && FindProcShort (glDispatchComputeIndirect)
1957 && FindProcShort (glCopyImageSubData)
1958 && FindProcShort (glFramebufferParameteri)
1959 && FindProcShort (glGetFramebufferParameteriv)
1960 && FindProcShort (glGetInternalformati64v)
1961 && FindProcShort (glInvalidateTexSubImage)
1962 && FindProcShort (glInvalidateTexImage)
1963 && FindProcShort (glInvalidateBufferSubData)
1964 && FindProcShort (glInvalidateBufferData)
1965 && FindProcShort (glInvalidateFramebuffer)
1966 && FindProcShort (glInvalidateSubFramebuffer)
1967 && FindProcShort (glMultiDrawArraysIndirect)
1968 && FindProcShort (glMultiDrawElementsIndirect)
1969 && FindProcShort (glGetProgramInterfaceiv)
1970 && FindProcShort (glGetProgramResourceIndex)
1971 && FindProcShort (glGetProgramResourceName)
1972 && FindProcShort (glGetProgramResourceiv)
1973 && FindProcShort (glGetProgramResourceLocation)
1974 && FindProcShort (glGetProgramResourceLocationIndex)
1975 && FindProcShort (glShaderStorageBlockBinding)
1976 && FindProcShort (glTexBufferRange)
1977 && FindProcShort (glTexStorage2DMultisample)
1978 && FindProcShort (glTexStorage3DMultisample)
1979 && FindProcShort (glTextureView)
1980 && FindProcShort (glBindVertexBuffer)
1981 && FindProcShort (glVertexAttribFormat)
1982 && FindProcShort (glVertexAttribIFormat)
1983 && FindProcShort (glVertexAttribLFormat)
1984 && FindProcShort (glVertexAttribBinding)
1985 && FindProcShort (glVertexBindingDivisor)
1986 && FindProcShort (glDebugMessageControl)
1987 && FindProcShort (glDebugMessageInsert)
1988 && FindProcShort (glDebugMessageCallback)
1989 && FindProcShort (glGetDebugMessageLog)
1990 && FindProcShort (glPushDebugGroup)
1991 && FindProcShort (glPopDebugGroup)
1992 && FindProcShort (glObjectLabel)
1993 && FindProcShort (glGetObjectLabel)
1994 && FindProcShort (glObjectPtrLabel)
1995 && FindProcShort (glGetObjectPtrLabel);
1997 // load GL_ARB_clear_texture (added to OpenGL 4.4 core)
1998 bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture"))
1999 && FindProcShort (glClearTexImage)
2000 && FindProcShort (glClearTexSubImage);
2002 has44 = IsGlGreaterEqual (4, 4)
2004 && FindProcShort (glBufferStorage)
2005 && FindProcShort (glBindBuffersBase)
2006 && FindProcShort (glBindBuffersRange)
2007 && FindProcShort (glBindTextures)
2008 && FindProcShort (glBindSamplers)
2009 && FindProcShort (glBindImageTextures)
2010 && FindProcShort (glBindVertexBuffers);
2012 // initialize TBO extension (ARB)
2014 && CheckExtension ("GL_ARB_texture_buffer_object")
2015 && FindProc ("glTexBufferARB", myFuncs->glTexBuffer))
2017 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
2019 arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32");
2021 // initialize hardware instancing extension (ARB)
2023 && CheckExtension ("GL_ARB_draw_instanced")
2024 && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced)
2025 && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced))
2027 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
2030 // initialize FBO extension (ARB)
2033 arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
2034 arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs));
2035 extPDS = Standard_True; // extension for EXT, but part of ARB
2038 // initialize GS extension (EXT)
2039 if (CheckExtension ("GL_EXT_geometry_shader4")
2040 && FindProcShort (glProgramParameteriEXT))
2042 extGS = (OpenGl_ExtGS* )(&(*myFuncs));
2045 // initialize bindless texture extension (ARB)
2046 if (CheckExtension ("GL_ARB_bindless_texture")
2047 && FindProcShort (glGetTextureHandleARB)
2048 && FindProcShort (glGetTextureSamplerHandleARB)
2049 && FindProcShort (glMakeTextureHandleResidentARB)
2050 && FindProcShort (glMakeTextureHandleNonResidentARB)
2051 && FindProcShort (glGetImageHandleARB)
2052 && FindProcShort (glMakeImageHandleResidentARB)
2053 && FindProcShort (glMakeImageHandleNonResidentARB)
2054 && FindProcShort (glUniformHandleui64ARB)
2055 && FindProcShort (glUniformHandleui64vARB)
2056 && FindProcShort (glProgramUniformHandleui64ARB)
2057 && FindProcShort (glProgramUniformHandleui64vARB)
2058 && FindProcShort (glIsTextureHandleResidentARB)
2059 && FindProcShort (glIsImageHandleResidentARB)
2060 && FindProcShort (glVertexAttribL1ui64ARB)
2061 && FindProcShort (glVertexAttribL1ui64vARB)
2062 && FindProcShort (glGetVertexAttribLui64vARB))
2064 arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs));
2069 checkWrongVersion (1, 2);
2076 checkWrongVersion (1, 3);
2083 checkWrongVersion (1, 4);
2090 checkWrongVersion (1, 5);
2097 core15 = (OpenGl_GlCore15* )(&(*myFuncs));
2099 core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
2103 checkWrongVersion (2, 0);
2109 const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION);
2110 if (aGlslVer == NULL
2111 || *aGlslVer == '\0')
2113 // broken context has been detected
2114 TCollection_ExtendedString aMsg = TCollection_ExtendedString()
2115 + "Error! OpenGL context reports version "
2116 + myGlVerMajor + "." + myGlVerMinor
2117 + " but reports wrong GLSL version";
2118 PushMessage (GL_DEBUG_SOURCE_APPLICATION,
2119 GL_DEBUG_TYPE_ERROR,
2121 GL_DEBUG_SEVERITY_HIGH,
2130 core20 = (OpenGl_GlCore20* )(&(*myFuncs));
2132 core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
2136 checkWrongVersion (2, 1);
2144 checkWrongVersion (3, 0);
2150 // MSAA RenderBuffers have been defined in OpenGL 3.0,
2151 // but MSAA Textures - only in OpenGL 3.2+
2153 && CheckExtension ("GL_ARB_texture_multisample")
2154 && FindProcShort (glTexImage2DMultisample))
2156 GLint aNbColorSamples = 0, aNbDepthSamples = 0;
2157 ::glGetIntegerv (GL_MAX_COLOR_TEXTURE_SAMPLES, &aNbColorSamples);
2158 ::glGetIntegerv (GL_MAX_DEPTH_TEXTURE_SAMPLES, &aNbDepthSamples);
2159 myMaxMsaaSamples = Min (aNbColorSamples, aNbDepthSamples);
2162 && CheckExtension ("GL_ARB_texture_storage_multisample")
2163 && FindProcShort (glTexStorage2DMultisample))
2170 checkWrongVersion (3, 1);
2175 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
2176 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
2180 checkWrongVersion (3, 2);
2185 core32 = (OpenGl_GlCore32* )(&(*myFuncs));
2188 core32->glGenVertexArrays (1, &myDefaultVao);
2192 core32back = (OpenGl_GlCore32Back* )(&(*myFuncs));
2194 ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
2198 checkWrongVersion (3, 3);
2203 core33 = (OpenGl_GlCore33* )(&(*myFuncs));
2206 core33back = (OpenGl_GlCore33Back* )(&(*myFuncs));
2209 // initialize sampler object
2210 myTexSampler = new OpenGl_Sampler();
2211 myTexSampler->Init (*this);
2215 checkWrongVersion (4, 0);
2220 arbTboRGB32 = Standard_True; // in core since OpenGL 4.0
2224 checkWrongVersion (4, 1);
2229 core41 = (OpenGl_GlCore41* )(&(*myFuncs));
2232 core41back = (OpenGl_GlCore41Back* )(&(*myFuncs));
2237 checkWrongVersion (4, 2);
2242 core42 = (OpenGl_GlCore42* )(&(*myFuncs));
2245 core42back = (OpenGl_GlCore42Back* )(&(*myFuncs));
2250 checkWrongVersion (4, 3);
2255 core43 = (OpenGl_GlCore43* )(&(*myFuncs));
2258 core43back = (OpenGl_GlCore43Back* )(&(*myFuncs));
2263 checkWrongVersion (4, 4);
2268 core44 = (OpenGl_GlCore44* )(&(*myFuncs));
2271 core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
2276 // =======================================================================
2277 // function : MemoryInfo
2279 // =======================================================================
2280 Standard_Size OpenGl_Context::AvailableMemory() const
2282 #if !defined(GL_ES_VERSION_2_0)
2285 // this is actually information for VBO pool
2286 // however because pools are mostly shared
2287 // it can be used for total GPU memory estimations
2290 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo);
2291 // returned value is in KiB, however this maybe changed in future
2292 return Standard_Size(aMemInfo[0]) * 1024;
2296 // current available dedicated video memory (in KiB), currently unused GPU memory
2298 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo);
2299 return Standard_Size(aMemInfo) * 1024;
2305 // =======================================================================
2306 // function : MemoryInfo
2308 // =======================================================================
2309 TCollection_AsciiString OpenGl_Context::MemoryInfo() const
2311 TCollection_AsciiString anInfo;
2312 #if !defined(GL_ES_VERSION_2_0)
2316 memset (aValues, 0, sizeof(aValues));
2317 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues);
2319 // total memory free in the pool
2320 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValues[0] / 1024) + " MiB\n";
2322 // largest available free block in the pool
2323 anInfo += TCollection_AsciiString (" Largest free block: ") + (aValues[1] / 1024) + " MiB\n";
2324 if (aValues[2] != aValues[0])
2326 // total auxiliary memory free
2327 anInfo += TCollection_AsciiString (" Free memory: ") + (aValues[2] / 1024) + " MiB\n";
2332 //current available dedicated video memory (in KiB), currently unused GPU memory
2334 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue);
2335 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValue / 1024) + " MiB\n";
2337 // dedicated video memory, total size (in KiB) of the GPU memory
2338 GLint aDedicated = 0;
2339 glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated);
2340 anInfo += TCollection_AsciiString (" GPU memory: ") + (aDedicated / 1024) + " MiB\n";
2342 // total available memory, total size (in KiB) of the memory available for allocations
2343 glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue);
2344 if (aValue != aDedicated)
2346 // different only for special configurations
2347 anInfo += TCollection_AsciiString (" Total memory: ") + (aValue / 1024) + " MiB\n";
2355 // =======================================================================
2356 // function : GetResource
2358 // =======================================================================
2359 const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const
2361 return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE;
2364 // =======================================================================
2365 // function : ShareResource
2367 // =======================================================================
2368 Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey,
2369 const Handle(OpenGl_Resource)& theResource)
2371 if (theKey.IsEmpty() || theResource.IsNull())
2373 return Standard_False;
2375 return mySharedResources->Bind (theKey, theResource);
2378 // =======================================================================
2379 // function : ReleaseResource
2381 // =======================================================================
2382 void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey,
2383 const Standard_Boolean theToDelay)
2385 if (!mySharedResources->IsBound (theKey))
2389 auto& aRes = mySharedResources->Find (theKey);
2390 if (aRes->GetRefCount() > 1)
2397 myDelayed->Bind (theKey, 1);
2401 aRes->Release (this);
2402 mySharedResources->UnBind (theKey);
2406 // =======================================================================
2407 // function : ReleaseDelayed
2409 // =======================================================================
2410 void OpenGl_Context::ReleaseDelayed()
2412 // release queued elements
2413 while (!myUnusedResources->IsEmpty())
2415 myUnusedResources->First()->Release (this);
2416 myUnusedResources->RemoveFirst();
2419 // release delayed shared resources
2420 NCollection_Vector<TCollection_AsciiString> aDeadList;
2421 for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed);
2422 anIter.More(); anIter.Next())
2424 if (++anIter.ChangeValue() <= 2)
2426 continue; // postpone release one more frame to ensure noone use it periodically
2429 const TCollection_AsciiString& aKey = anIter.Key();
2430 if (!mySharedResources->IsBound (aKey))
2432 // mixed unshared strategy delayed/undelayed was used!
2433 aDeadList.Append (aKey);
2437 auto& aRes = mySharedResources->ChangeFind (aKey);
2438 if (aRes->GetRefCount() > 1)
2440 // should be only 1 instance in mySharedResources
2441 // if not - resource was reused again
2442 aDeadList.Append (aKey);
2446 // release resource if no one requiested it more than 2 redraw calls
2447 aRes->Release (this);
2448 mySharedResources->UnBind (aKey);
2449 aDeadList.Append (aKey);
2452 for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter)
2454 myDelayed->UnBind (aDeadList.Value (anIter));
2458 // =======================================================================
2459 // function : BindProgram
2461 // =======================================================================
2462 Standard_Boolean OpenGl_Context::BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram)
2464 if (core20fwd == NULL)
2466 return Standard_False;
2469 if (theProgram.IsNull()
2470 || !theProgram->IsValid())
2472 if (!myActiveProgram.IsNull())
2474 core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM);
2475 myActiveProgram.Nullify();
2477 return Standard_False;
2480 myActiveProgram = theProgram;
2481 core20fwd->glUseProgram (theProgram->ProgramId());
2482 return Standard_True;
2485 // =======================================================================
2486 // function : BindDefaultVao
2488 // =======================================================================
2489 void OpenGl_Context::BindDefaultVao()
2491 #if !defined(GL_ES_VERSION_2_0)
2492 if (myDefaultVao == 0
2498 core32->glBindVertexArray (myDefaultVao);
2502 // =======================================================================
2503 // function : SetDefaultFrameBuffer
2505 // =======================================================================
2506 Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo)
2508 Handle(OpenGl_FrameBuffer) aFbo = myDefaultFbo;
2509 myDefaultFbo = theFbo;
2513 // =======================================================================
2514 // function : SetShadingMaterial
2516 // =======================================================================
2517 void OpenGl_Context::SetShadingMaterial (const OpenGl_AspectFace* theAspect,
2518 const OpenGl_Vec4* theHighlightColor)
2520 if (!myActiveProgram.IsNull())
2522 myActiveProgram->SetUniform (this,
2523 myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_ENABLE),
2524 theAspect->DoTextureMap());
2525 myActiveProgram->SetUniform (this,
2526 myActiveProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
2527 theAspect->DistinguishingMode());
2529 OpenGl_Material aParams;
2530 for (Standard_Integer anIndex = 0; anIndex < 2; ++anIndex)
2532 const GLint aLoc = myActiveProgram->GetStateLocation (anIndex == 0
2533 ? OpenGl_OCCT_FRONT_MATERIAL
2534 : OpenGl_OCCT_BACK_MATERIAL);
2535 if (aLoc == OpenGl_ShaderProgram::INVALID_LOCATION)
2540 const OPENGL_SURF_PROP& aProp = anIndex == 0 || theAspect->DistinguishingMode() != TOn
2541 ? theAspect->IntFront()
2542 : theAspect->IntBack();
2543 aParams.Init (aProp);
2544 aParams.Diffuse.a() = aProp.trans;
2546 if (theHighlightColor != NULL)
2548 aParams.SetColor (*theHighlightColor);
2551 myActiveProgram->SetUniform (this, aLoc, OpenGl_Material::NbOfVec4(),
2557 // =======================================================================
2558 // function : SetColor4fv
2560 // =======================================================================
2561 void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor)
2563 if (!myActiveProgram.IsNull())
2565 myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR), theColor);
2567 #if !defined(GL_ES_VERSION_2_0)
2568 else if (core11 != NULL)
2570 core11->glColor4fv (theColor.GetData());
2575 // =======================================================================
2576 // function : SetTypeOfLine
2578 // =======================================================================
2579 void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType,
2580 const Standard_ShortReal theFactor)
2582 Standard_Integer aPattern = 0xFFFF;
2585 case Aspect_TOL_DASH:
2590 case Aspect_TOL_DOT:
2595 case Aspect_TOL_DOTDASH:
2600 case Aspect_TOL_SOLID:
2605 case Aspect_TOL_USERDEFINED:
2612 if (!myActiveProgram.IsNull())
2614 myActiveProgram->SetUniform (this, "uPattern", aPattern);
2615 myActiveProgram->SetUniform (this, "uFactor", theFactor);
2619 #if !defined(GL_ES_VERSION_2_0)
2620 if (theType != Aspect_TOL_SOLID)
2625 gl2psEnable (GL2PS_LINE_STIPPLE);
2631 core11fwd->glEnable (GL_LINE_STIPPLE);
2633 core11->glLineStipple (static_cast<GLint> (theFactor),
2634 static_cast<GLushort> (aPattern));
2641 core11fwd->glDisable (GL_LINE_STIPPLE);
2647 gl2psDisable (GL2PS_LINE_STIPPLE);
2654 // =======================================================================
2655 // function : SetLineWidth
2657 // =======================================================================
2658 void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth)
2662 // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
2663 core11fwd->glLineWidth (theWidth * myResolutionRatio);
2668 gl2psLineWidth (theWidth);
2673 // =======================================================================
2674 // function : SetTextureMatrix
2676 // =======================================================================
2677 void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams)
2679 if (theParams.IsNull())
2683 else if (!myActiveProgram.IsNull())
2685 const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D);
2686 if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION)
2691 // pack transformation parameters
2692 OpenGl_Vec4 aTrsf[2];
2693 aTrsf[0].xy() = theParams->Translation();
2694 aTrsf[0].zw() = theParams->Scale();
2695 aTrsf[1].x() = std::sin (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));
2696 aTrsf[1].y() = std::cos (-theParams->Rotation() * static_cast<float> (M_PI / 180.0));
2697 myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf);
2701 #if !defined(GL_ES_VERSION_2_0)
2704 GLint aMatrixMode = GL_TEXTURE;
2705 ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
2707 core11->glMatrixMode (GL_TEXTURE);
2708 OpenGl_Mat4 aTextureMat;
2709 const Graphic3d_Vec2& aScale = theParams->Scale();
2710 const Graphic3d_Vec2& aTrans = theParams->Translation();
2711 Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f);
2712 Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
2713 Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f);
2714 core11->glLoadMatrixf (aTextureMat);
2715 core11->glMatrixMode (aMatrixMode);
2720 // =======================================================================
2721 // function : SetPointSize
2723 // =======================================================================
2724 void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize)
2726 if (!myActiveProgram.IsNull())
2728 myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize);
2729 #if !defined(GL_ES_VERSION_2_0)
2730 //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE);
2733 #if !defined(GL_ES_VERSION_2_0)
2736 core11fwd->glPointSize (theSize);
2737 if (core20fwd != NULL)
2739 //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE);
2745 // =======================================================================
2746 // function : SetGlNormalizeEnabled
2748 // =======================================================================
2749 Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled)
2751 if (isEnabled == myIsGlNormalizeEnabled)
2753 return myIsGlNormalizeEnabled;
2756 Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled;
2758 myIsGlNormalizeEnabled = isEnabled;
2760 #if !defined(GL_ES_VERSION_2_0)
2765 ::glEnable (GL_NORMALIZE);
2769 ::glDisable (GL_NORMALIZE);
2774 return anOldGlNormalize;
2777 // =======================================================================
2778 // function : ApplyModelWorldMatrix
2780 // =======================================================================
2781 void OpenGl_Context::ApplyModelWorldMatrix()
2783 #if !defined(GL_ES_VERSION_2_0)
2786 core11->glMatrixMode (GL_MODELVIEW);
2787 core11->glLoadMatrixf (ModelWorldState.Current());
2791 if (!myShaderManager->IsEmpty())
2793 myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
2797 // =======================================================================
2798 // function : ApplyWorldViewMatrix
2800 // =======================================================================
2801 void OpenGl_Context::ApplyWorldViewMatrix()
2803 #if !defined(GL_ES_VERSION_2_0)
2806 core11->glMatrixMode (GL_MODELVIEW);
2807 core11->glLoadMatrixf (WorldViewState.Current());
2811 if (!myShaderManager->IsEmpty())
2813 myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
2817 // =======================================================================
2818 // function : ApplyModelViewMatrix
2820 // =======================================================================
2821 void OpenGl_Context::ApplyModelViewMatrix()
2823 #if !defined(GL_ES_VERSION_2_0)
2826 OpenGl_Mat4 aModelView = WorldViewState.Current() * ModelWorldState.Current();
2827 core11->glMatrixMode (GL_MODELVIEW);
2828 core11->glLoadMatrixf (aModelView.GetData());
2832 if (!myShaderManager->IsEmpty())
2834 myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
2835 myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
2839 // =======================================================================
2840 // function : ApplyProjectionMatrix
2842 // =======================================================================
2843 void OpenGl_Context::ApplyProjectionMatrix()
2845 #if !defined(GL_ES_VERSION_2_0)
2848 core11->glMatrixMode (GL_PROJECTION);
2849 core11->glLoadMatrixf (ProjectionState.Current().GetData());
2853 if (!myShaderManager->IsEmpty())
2855 myShaderManager->UpdateProjectionStateTo (ProjectionState.Current());
2860 // =======================================================================
2861 // function : EnableFeatures
2863 // =======================================================================
2864 void OpenGl_Context::EnableFeatures() const
2869 // =======================================================================
2870 // function : DisableFeatures
2872 // =======================================================================
2873 void OpenGl_Context::DisableFeatures() const
2875 #if !defined(GL_ES_VERSION_2_0)
2876 glPixelTransferi (GL_MAP_COLOR, GL_FALSE);
2880 * Disable stuff that's likely to slow down glDrawPixels.
2881 * (Omit as much of this as possible, when you know in advance
2882 * that the OpenGL state will already be set correctly.)
2884 glDisable(GL_DITHER);
2885 glDisable(GL_BLEND);
2886 glDisable(GL_DEPTH_TEST);
2887 glDisable(GL_TEXTURE_2D);
2888 glDisable(GL_STENCIL_TEST);
2890 #if !defined(GL_ES_VERSION_2_0)
2891 glDisable(GL_LIGHTING);
2892 glDisable(GL_ALPHA_TEST);
2894 glDisable(GL_LOGIC_OP);
2895 glDisable(GL_TEXTURE_1D);
2897 glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
2898 glPixelTransferi(GL_RED_SCALE, 1);
2899 glPixelTransferi(GL_RED_BIAS, 0);
2900 glPixelTransferi(GL_GREEN_SCALE, 1);
2901 glPixelTransferi(GL_GREEN_BIAS, 0);
2902 glPixelTransferi(GL_BLUE_SCALE, 1);
2903 glPixelTransferi(GL_BLUE_BIAS, 0);
2904 glPixelTransferi(GL_ALPHA_SCALE, 1);
2905 glPixelTransferi(GL_ALPHA_BIAS, 0);
2908 * Disable extensions that could slow down glDrawPixels.
2909 * (Actually, you should check for the presence of the proper
2910 * extension before making these calls. I've omitted that
2911 * code for simplicity.)
2914 if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2))
2916 #ifdef GL_EXT_convolution
2917 if (CheckExtension ("GL_CONVOLUTION_1D_EXT"))
2918 glDisable(GL_CONVOLUTION_1D_EXT);
2920 if (CheckExtension ("GL_CONVOLUTION_2D_EXT"))
2921 glDisable(GL_CONVOLUTION_2D_EXT);
2923 if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
2924 glDisable(GL_SEPARABLE_2D_EXT);
2927 #ifdef GL_EXT_histogram
2928 if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
2929 glDisable(GL_HISTOGRAM_EXT);
2931 if (CheckExtension ("GL_MINMAX_EXT"))
2932 glDisable(GL_MINMAX_EXT);
2935 #ifdef GL_EXT_texture3D
2936 if (CheckExtension ("GL_TEXTURE_3D_EXT"))
2937 glDisable(GL_TEXTURE_3D_EXT);