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_ArbSamplerObject.hxx>
28 #include <OpenGl_ArbTexBindless.hxx>
29 #include <OpenGl_GlCore45.hxx>
30 #include <OpenGl_FrameBuffer.hxx>
31 #include <OpenGl_FrameStats.hxx>
32 #include <OpenGl_Sampler.hxx>
33 #include <OpenGl_ShaderManager.hxx>
34 #include <OpenGl_TextureSetPairIterator.hxx>
35 #include <OpenGl_Workspace.hxx>
36 #include <OpenGl_Aspects.hxx>
38 #include <Graphic3d_TransformUtils.hxx>
39 #include <Graphic3d_RenderingParams.hxx>
40 #include <Image_SupportedFormats.hxx>
41 #include <Message_Messenger.hxx>
42 #include <NCollection_Vector.hxx>
43 #include <Standard_ProgramError.hxx>
44 #include <Standard_WarningDisableFunctionCast.hxx>
46 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient)
51 #pragma comment(lib, "libEGL.lib")
55 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
57 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
60 #include <OpenGL/OpenGL.h>
61 #include <CoreGraphics/CoreGraphics.h>
64 #include <GL/glx.h> // glXGetProcAddress()
68 #include <emscripten.h>
69 #include <emscripten/html5.h>
71 //! Check if WebGL extension is available and activate it
72 //! (usage of extension without activation will generate errors).
73 static bool checkEnableWebGlExtension (const OpenGl_Context& theCtx,
74 const char* theExtName)
76 if (!theCtx.CheckExtension (theExtName))
80 if (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE aWebGlCtx = emscripten_webgl_get_current_context())
82 if (emscripten_webgl_enable_extension (aWebGlCtx, theExtName))
93 static const Handle(OpenGl_Resource) NULL_GL_RESOURCE;
94 static const OpenGl_Mat4 THE_IDENTITY_MATRIX;
96 //! Add key-value pair to the dictionary.
97 static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
98 const TCollection_AsciiString& theKey,
99 const TCollection_AsciiString& theValue)
101 theDict.ChangeFromIndex (theDict.Add (theKey, theValue)) = theValue;
104 //! Add key-value pair to the dictionary.
105 static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
106 const TCollection_AsciiString& theKey,
107 const char* theValue)
109 TCollection_AsciiString aValue (theValue != NULL ? theValue : "");
110 theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue;
114 // =======================================================================
115 // function : OpenGl_Context
117 // =======================================================================
118 OpenGl_Context::OpenGl_Context (const Handle(OpenGl_Caps)& theCaps)
141 caps (!theCaps.IsNull() ? theCaps : new OpenGl_Caps()),
142 hasGetBufferData (Standard_False),
143 #if defined(GL_ES_VERSION_2_0)
144 hasHighp (Standard_False),
145 hasUintIndex(Standard_False),
146 hasTexRGBA8(Standard_False),
148 hasHighp (Standard_True),
149 hasUintIndex(Standard_True),
150 hasTexRGBA8(Standard_True),
152 hasTexFloatLinear (Standard_False),
153 hasTexSRGB (Standard_False),
154 hasFboSRGB (Standard_False),
155 hasSRGBControl (Standard_False),
156 #if defined(GL_ES_VERSION_2_0)
157 hasFlatShading (OpenGl_FeatureNotAvailable),
159 hasFlatShading (OpenGl_FeatureInCore),
161 hasGlslBitwiseOps (OpenGl_FeatureNotAvailable),
162 hasDrawBuffers (OpenGl_FeatureNotAvailable),
163 hasFloatBuffer (OpenGl_FeatureNotAvailable),
164 hasHalfFloatBuffer (OpenGl_FeatureNotAvailable),
165 hasSampleVariables (OpenGl_FeatureNotAvailable),
166 hasGeometryStage (OpenGl_FeatureNotAvailable),
167 arbDrawBuffers (Standard_False),
168 arbNPTW (Standard_False),
169 arbTexRG (Standard_False),
170 arbTexFloat (Standard_False),
171 arbSamplerObject (NULL),
172 arbTexBindless (NULL),
174 arbTboRGB32 (Standard_False),
179 arbSampleShading (Standard_False),
180 arbDepthClamp (Standard_False),
181 extFragDepth (Standard_False),
182 extDrawBuffers (Standard_False),
184 extBgra(Standard_False),
185 extAnis(Standard_False),
186 extPDS (Standard_False),
187 atiMem (Standard_False),
188 nvxMem (Standard_False),
189 oesSampleVariables (Standard_False),
190 oesStdDerivatives (Standard_False),
191 mySharedResources (new OpenGl_ResourcesMap()),
192 myDelayed (new OpenGl_DelayReleaseMap()),
193 myUnusedResources (new OpenGl_ResourcesStack()),
195 myGlLibHandle (NULL),
196 myFuncs (new OpenGl_GlFunctions()),
197 mySupportedFormats (new Image_SupportedFormats()),
199 myTexClamp (GL_CLAMP_TO_EDGE),
201 myMaxTexCombined (1),
202 myMaxTexUnitsFFP (1),
203 myMaxDumpSizeX (1024),
204 myMaxDumpSizeY (1024),
207 myMaxDrawBuffers (1),
208 myMaxColorAttachments (1),
211 myIsInitialized (Standard_False),
212 myIsStereoBuffers (Standard_False),
213 myIsGlNormalizeEnabled (Standard_False),
214 mySpriteTexUnit (Graphic3d_TextureUnit_PointSprite),
215 myHasRayTracing (Standard_False),
216 myHasRayTracingTextures (Standard_False),
217 myHasRayTracingAdaptiveSampling (Standard_False),
218 myHasRayTracingAdaptiveSamplingAtomic (Standard_False),
219 myHasPBR (Standard_False),
220 myPBREnvLUTTexUnit (Graphic3d_TextureUnit_PbrEnvironmentLUT),
221 myPBRDiffIBLMapSHTexUnit (Graphic3d_TextureUnit_PbrIblDiffuseSH),
222 myPBRSpecIBLMapTexUnit (Graphic3d_TextureUnit_PbrIblSpecular),
223 myFrameStats (new OpenGl_FrameStats()),
224 myActiveMockTextures (0),
225 myActiveHatchType (Aspect_HS_SOLID),
226 myHatchIsEnabled (false),
227 #if !defined(GL_ES_VERSION_2_0)
228 myPointSpriteOrig (GL_UPPER_LEFT),
229 myRenderMode (GL_RENDER),
230 myShadeModel (GL_SMOOTH),
231 myPolygonMode (GL_FILL),
233 myPointSpriteOrig (0),
238 myToCullBackFaces (false),
240 myDrawBuffers (0, 7),
243 myAlphaToCoverage (false),
244 myIsGlDebugCtx (false),
245 myIsSRgbWindow (false),
246 myResolution (Graphic3d_RenderingParams::THE_DEFAULT_RESOLUTION),
247 myResolutionRatio (1.0f),
248 myLineWidthScale (1.0f),
249 myLineFeather (1.0f),
250 myRenderScale (1.0f),
251 myRenderScaleInv (1.0f)
257 myViewportVirt[0] = 0;
258 myViewportVirt[1] = 0;
259 myViewportVirt[2] = 0;
260 myViewportVirt[3] = 0;
262 myPolygonOffset.Mode = Aspect_POM_Off;
263 myPolygonOffset.Factor = 0.0f;
264 myPolygonOffset.Units = 0.0f;
266 // system-dependent fields
267 #if defined(HAVE_EGL)
268 myDisplay = (Aspect_Display )EGL_NO_DISPLAY;
269 myWindow = (Aspect_Drawable )EGL_NO_SURFACE;
270 myGContext = (Aspect_RenderingContext )EGL_NO_CONTEXT;
271 #elif defined(_WIN32)
275 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
276 // Vendors can not extend functionality on this system
277 // and developers are limited to OpenGL support provided by Mac OS X SDK.
278 // We retrieve function pointers from system library
279 // to generalize extensions support on all platforms.
280 // In this way we also reach binary compatibility benefit between OS releases
281 // if some newest functionality is optionally used.
282 // Notice that GL version / extension availability checks are required
283 // because function pointers may be available but not functionality itself
284 // (depends on renderer).
285 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
287 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGLES.framework/OpenGLES", RTLD_LAZY);
290 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
298 memset (myFuncs.operator->(), 0, sizeof(OpenGl_GlFunctions));
299 myShaderManager = new OpenGl_ShaderManager (this);
302 // =======================================================================
303 // function : ~OpenGl_Context
305 // =======================================================================
306 OpenGl_Context::~OpenGl_Context()
308 // release clean up queue
311 #if !defined(GL_ES_VERSION_2_0)
312 // release default VAO
313 if (myDefaultVao != 0
317 core32->glDeleteVertexArrays (1, &myDefaultVao);
322 // release mock textures
323 if (!myTextureRgbaBlack.IsNull())
325 myTextureRgbaBlack->Release (this);
326 myTextureRgbaBlack.Nullify();
328 if (!myTextureRgbaWhite.IsNull())
330 myTextureRgbaWhite->Release (this);
331 myTextureRgbaWhite.Nullify();
334 // release default FBO
335 if (!myDefaultFbo.IsNull())
337 myDefaultFbo->Release (this);
338 myDefaultFbo.Nullify();
341 // release shared resources if any
342 if (mySharedResources->GetRefCount() <= 1)
344 myShaderManager.Nullify();
345 for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
346 anIter.More(); anIter.Next())
348 anIter.Value()->Release (this);
351 // release delayed resources added during deletion of shared resources
352 while (!myUnusedResources->IsEmpty())
354 myUnusedResources->First()->Release (this);
355 myUnusedResources->RemoveFirst();
358 else if (myShaderManager->IsSameContext (this))
360 myShaderManager->SetContext (NULL);
362 mySharedResources.Nullify();
370 #if !defined(GL_ES_VERSION_2_0)
372 glGetPointerv (GL_DEBUG_CALLBACK_USER_PARAM, &aPtr);
376 arbDbg->glDebugMessageCallback (NULL, NULL);
378 myIsGlDebugCtx = Standard_False;
382 // =======================================================================
383 // function : forcedRelease
385 // =======================================================================
386 void OpenGl_Context::forcedRelease()
389 for (NCollection_DataMap<TCollection_AsciiString, Handle(OpenGl_Resource)>::Iterator anIter (*mySharedResources);
390 anIter.More(); anIter.Next())
392 anIter.Value()->Release (this);
394 mySharedResources->Clear();
395 myShaderManager->clear();
396 myShaderManager->SetContext (NULL);
398 // release delayed resources added during deletion of shared resources
399 while (!myUnusedResources->IsEmpty())
401 myUnusedResources->First()->Release (this);
402 myUnusedResources->RemoveFirst();
406 // =======================================================================
407 // function : ResizeViewport
409 // =======================================================================
410 void OpenGl_Context::ResizeViewport (const Standard_Integer* theRect)
412 core11fwd->glViewport (theRect[0], theRect[1], theRect[2], theRect[3]);
413 myViewport[0] = theRect[0];
414 myViewport[1] = theRect[1];
415 myViewport[2] = theRect[2];
416 myViewport[3] = theRect[3];
417 if (HasRenderScale())
419 myViewportVirt[0] = Standard_Integer(theRect[0] * myRenderScaleInv);
420 myViewportVirt[1] = Standard_Integer(theRect[1] * myRenderScaleInv);
421 myViewportVirt[2] = Standard_Integer(theRect[2] * myRenderScaleInv);
422 myViewportVirt[3] = Standard_Integer(theRect[3] * myRenderScaleInv);
426 myViewportVirt[0] = theRect[0];
427 myViewportVirt[1] = theRect[1];
428 myViewportVirt[2] = theRect[2];
429 myViewportVirt[3] = theRect[3];
433 #if !defined(GL_ES_VERSION_2_0)
434 inline Standard_Integer stereoToMonoBuffer (const Standard_Integer theBuffer)
450 // =======================================================================
451 // function : SetReadBuffer
453 // =======================================================================
454 void OpenGl_Context::SetReadBuffer (const Standard_Integer theReadBuffer)
456 #if !defined(GL_ES_VERSION_2_0)
457 myReadBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theReadBuffer) : theReadBuffer;
458 if (myReadBuffer < GL_COLOR_ATTACHMENT0
461 arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
463 ::glReadBuffer (myReadBuffer);
465 (void )theReadBuffer;
469 // =======================================================================
470 // function : SetDrawBuffer
472 // =======================================================================
473 void OpenGl_Context::SetDrawBuffer (const Standard_Integer theDrawBuffer)
475 #if !defined(GL_ES_VERSION_2_0)
476 const Standard_Integer aDrawBuffer = !myIsStereoBuffers ? stereoToMonoBuffer (theDrawBuffer) : theDrawBuffer;
477 if (aDrawBuffer < GL_COLOR_ATTACHMENT0
480 arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
482 ::glDrawBuffer (aDrawBuffer);
484 myDrawBuffers.Init (GL_NONE);
485 myDrawBuffers.SetValue (0, aDrawBuffer);
487 (void )theDrawBuffer;
491 // =======================================================================
492 // function : SetDrawBuffers
494 // =======================================================================
495 void OpenGl_Context::SetDrawBuffers (const Standard_Integer theNb, const Standard_Integer* theDrawBuffers)
497 Standard_ASSERT_RETURN (hasDrawBuffers, "Multiple draw buffers feature is not supported by the context", Standard_ASSERT_DO_NOTHING());
499 if (myDrawBuffers.Length() < theNb)
501 // should actually never happen here
502 myDrawBuffers.Resize (0, theNb - 1, false);
504 myDrawBuffers.Init (GL_NONE);
506 Standard_Boolean useDefaultFbo = Standard_False;
507 for (Standard_Integer anI = 0; anI < theNb; ++anI)
509 if (theDrawBuffers[anI] < GL_COLOR_ATTACHMENT0 && theDrawBuffers[anI] != GL_NONE)
511 useDefaultFbo = Standard_True;
515 myDrawBuffers.SetValue (anI, theDrawBuffers[anI]);
518 if (arbFBO != NULL && useDefaultFbo)
520 arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER);
523 myFuncs->glDrawBuffers (theNb, (const GLenum*)theDrawBuffers);
526 // =======================================================================
527 // function : SetFrameBufferSRGB
529 // =======================================================================
530 void OpenGl_Context::SetFrameBufferSRGB (bool theIsFbo, bool theIsFboSRgb)
534 myIsSRgbActive = false;
537 myIsSRgbActive = ToRenderSRGB()
538 && (theIsFbo || myIsSRgbWindow)
547 core11fwd->glEnable (GL_FRAMEBUFFER_SRGB);
551 core11fwd->glDisable (GL_FRAMEBUFFER_SRGB);
555 // =======================================================================
556 // function : SetCullBackFaces
558 // =======================================================================
559 void OpenGl_Context::SetCullBackFaces (bool theToEnable)
561 if (myToCullBackFaces == theToEnable)
566 myToCullBackFaces = theToEnable;
569 //glCullFace (GL_BACK); GL_BACK by default
570 core11fwd->glEnable (GL_CULL_FACE);
574 core11fwd->glDisable (GL_CULL_FACE);
578 // =======================================================================
579 // function : FetchState
581 // =======================================================================
582 void OpenGl_Context::FetchState()
584 #if !defined(GL_ES_VERSION_2_0)
585 // cache feedback mode state
588 ::glGetIntegerv (GL_RENDER_MODE, &myRenderMode);
589 ::glGetIntegerv (GL_SHADE_MODEL, &myShadeModel);
592 // cache read buffers state
593 ::glGetIntegerv (GL_READ_BUFFER, &myReadBuffer);
595 // cache draw buffers state
596 if (myDrawBuffers.Length() < myMaxDrawBuffers)
598 myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
600 myDrawBuffers.Init (GL_NONE);
602 Standard_Integer aDrawBuffer = GL_NONE;
603 if (myMaxDrawBuffers == 1)
605 ::glGetIntegerv (GL_DRAW_BUFFER, &aDrawBuffer);
606 myDrawBuffers.SetValue (0, aDrawBuffer);
610 for (Standard_Integer anI = 0; anI < myMaxDrawBuffers; ++anI)
612 ::glGetIntegerv (GL_DRAW_BUFFER0 + anI, &aDrawBuffer);
613 myDrawBuffers.SetValue (anI, aDrawBuffer);
619 // =======================================================================
622 // =======================================================================
623 void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx)
625 if (!theShareCtx.IsNull())
627 mySharedResources = theShareCtx->mySharedResources;
628 myDelayed = theShareCtx->myDelayed;
629 myUnusedResources = theShareCtx->myUnusedResources;
630 myShaderManager = theShareCtx->myShaderManager;
634 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
636 // =======================================================================
637 // function : IsCurrent
639 // =======================================================================
640 Standard_Boolean OpenGl_Context::IsCurrent() const
642 #if defined(HAVE_EGL)
643 if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
644 || (EGLContext )myGContext == EGL_NO_CONTEXT)
646 return Standard_False;
649 return (((EGLDisplay )myDisplay == eglGetCurrentDisplay())
650 && ((EGLContext )myGContext == eglGetCurrentContext())
651 && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW)));
652 #elif defined(_WIN32)
653 if (myWindowDC == NULL || myGContext == NULL)
655 return Standard_False;
657 return (( (HDC )myWindowDC == wglGetCurrentDC())
658 && ((HGLRC )myGContext == wglGetCurrentContext()));
660 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
662 return Standard_False;
665 return ( ((Display* )myDisplay == glXGetCurrentDisplay())
666 && ((GLXContext )myGContext == glXGetCurrentContext())
667 && ((GLXDrawable )myWindow == glXGetCurrentDrawable()));
671 // =======================================================================
672 // function : MakeCurrent
674 // =======================================================================
675 Standard_Boolean OpenGl_Context::MakeCurrent()
677 #if defined(HAVE_EGL)
678 if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
679 || (EGLContext )myGContext == EGL_NO_CONTEXT)
681 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
682 return Standard_False;
685 if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE)
687 // if there is no current context it might be impossible to use glGetError() correctly
688 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
689 "eglMakeCurrent() has failed!");
690 myIsInitialized = Standard_False;
691 return Standard_False;
693 #elif defined(_WIN32)
694 if (myWindowDC == NULL || myGContext == NULL)
696 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
697 return Standard_False;
700 // technically it should be safe to activate already bound GL context
701 // however some drivers (Intel etc.) may FAIL doing this for unknown reason
704 myShaderManager->SetContext (this);
705 return Standard_True;
707 else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
709 // notice that glGetError() couldn't be used here!
710 wchar_t* aMsgBuff = NULL;
711 DWORD anErrorCode = GetLastError();
712 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
713 NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
714 TCollection_ExtendedString aMsg ("wglMakeCurrent() has failed. ");
715 if (aMsgBuff != NULL)
717 aMsg += (Standard_ExtString )aMsgBuff;
718 LocalFree (aMsgBuff);
720 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH, aMsg);
721 myIsInitialized = Standard_False;
722 return Standard_False;
725 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
727 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
728 return Standard_False;
731 if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
733 // if there is no current context it might be impossible to use glGetError() correctly
734 PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
735 "glXMakeCurrent() has failed!");
736 myIsInitialized = Standard_False;
737 return Standard_False;
740 myShaderManager->SetContext (this);
741 return Standard_True;
744 // =======================================================================
745 // function : SwapBuffers
747 // =======================================================================
748 void OpenGl_Context::SwapBuffers()
750 #if defined(HAVE_EGL)
751 if ((EGLSurface )myWindow != EGL_NO_SURFACE)
753 eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow);
755 #elif defined(_WIN32)
756 if ((HDC )myWindowDC != NULL)
758 ::SwapBuffers ((HDC )myWindowDC);
762 if ((Display* )myDisplay != NULL)
764 glXSwapBuffers ((Display* )myDisplay, (GLXDrawable )myWindow);
771 // =======================================================================
772 // function : SetSwapInterval
774 // =======================================================================
775 Standard_Boolean OpenGl_Context::SetSwapInterval (const Standard_Integer theInterval)
777 #if defined(HAVE_EGL)
778 if (::eglSwapInterval ((EGLDisplay )myDisplay, theInterval) == EGL_TRUE)
780 return Standard_True;
782 #elif defined(_WIN32)
783 if (myFuncs->wglSwapIntervalEXT != NULL)
785 myFuncs->wglSwapIntervalEXT (theInterval);
786 return Standard_True;
788 #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
790 #elif defined(__APPLE__)
791 if (::CGLSetParameter (CGLGetCurrentContext(), kCGLCPSwapInterval, &theInterval) == kCGLNoError)
793 return Standard_True;
796 if (theInterval == -1
797 && myFuncs->glXSwapIntervalEXT != NULL)
799 typedef int (*glXSwapIntervalEXT_t_x)(Display* theDisplay, GLXDrawable theDrawable, int theInterval);
800 glXSwapIntervalEXT_t_x aFuncPtr = (glXSwapIntervalEXT_t_x )myFuncs->glXSwapIntervalEXT;
801 aFuncPtr ((Display* )myDisplay, (GLXDrawable )myWindow, theInterval);
802 return Standard_True;
804 else if (myFuncs->glXSwapIntervalSGI != NULL)
806 myFuncs->glXSwapIntervalSGI (theInterval);
807 return Standard_True;
810 return Standard_False;
813 // =======================================================================
814 // function : findProc
816 // =======================================================================
817 void* OpenGl_Context::findProc (const char* theFuncName)
819 #if defined(HAVE_EGL)
820 return (void* )eglGetProcAddress (theFuncName);
821 #elif defined(_WIN32)
822 return (void* )wglGetProcAddress (theFuncName);
823 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
824 return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
826 return (void* )glXGetProcAddress ((const GLubyte* )theFuncName);
830 // =======================================================================
831 // function : CheckExtension
833 // =======================================================================
834 Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
836 if (theExtName == NULL)
839 std::cerr << "CheckExtension called with NULL string!\n";
841 return Standard_False;
843 else if (caps->contextNoExtensions)
845 return Standard_False;
848 #if !defined(GL_ES_VERSION_2_0)
849 // available since OpenGL 3.0
850 // and the ONLY way to check extensions with OpenGL 3.1+ core profile
851 if (IsGlGreaterEqual (3, 0)
852 && myFuncs->glGetStringi != NULL)
855 ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
856 const size_t anExtNameLen = strlen (theExtName);
857 for (GLint anIter = 0; anIter < anExtNb; ++anIter)
859 const char* anExtension = (const char* )myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint )anIter);
860 const size_t aTestExtNameLen = strlen (anExtension);
861 if (aTestExtNameLen == anExtNameLen
862 && strncmp (anExtension, theExtName, anExtNameLen) == 0)
864 return Standard_True;
867 return Standard_False;
871 // use old way with huge string for all extensions
872 const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
873 if (anExtString == NULL)
875 Messenger()->Send ("TKOpenGL: glGetString (GL_EXTENSIONS) has returned NULL! No GL context?", Message_Warning);
876 return Standard_False;
878 return CheckExtension (anExtString, theExtName);
881 // =======================================================================
882 // function : CheckExtension
884 // =======================================================================
885 Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtString,
886 const char* theExtName)
888 if (theExtString == NULL)
890 return Standard_False;
893 // Search for theExtName in the extensions string.
894 // Use of strstr() is not sufficient because extension names can be prefixes of other extension names.
895 char* aPtrIter = (char* )theExtString;
896 const char* aPtrEnd = aPtrIter + strlen (theExtString);
897 const size_t anExtNameLen = strlen (theExtName);
898 while (aPtrIter < aPtrEnd)
900 const size_t n = strcspn (aPtrIter, " ");
901 if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0))
903 return Standard_True;
907 return Standard_False;
910 #if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
912 // =======================================================================
915 // =======================================================================
916 Standard_Boolean OpenGl_Context::Init (const Standard_Boolean theIsCoreProfile)
920 return Standard_True;
923 #if defined(HAVE_EGL)
924 myDisplay = (Aspect_Display )eglGetCurrentDisplay();
925 myGContext = (Aspect_RenderingContext )eglGetCurrentContext();
926 myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW);
927 #elif defined(_WIN32)
928 myWindowDC = (Aspect_Handle )wglGetCurrentDC();
929 myGContext = (Aspect_RenderingContext )wglGetCurrentContext();
931 myDisplay = (Aspect_Display )glXGetCurrentDisplay();
932 myGContext = (Aspect_RenderingContext )glXGetCurrentContext();
933 myWindow = (Aspect_Drawable )glXGetCurrentDrawable();
935 if (myGContext == NULL)
937 return Standard_False;
940 init (theIsCoreProfile);
941 myIsInitialized = Standard_True;
942 return Standard_True;
947 // =======================================================================
950 // =======================================================================
951 #if defined(HAVE_EGL)
952 Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface,
953 const Aspect_Display theEglDisplay,
954 const Aspect_RenderingContext theEglContext,
955 const Standard_Boolean theIsCoreProfile)
956 #elif defined(_WIN32)
957 Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
958 const Aspect_Handle theWindowDC,
959 const Aspect_RenderingContext theGContext,
960 const Standard_Boolean theIsCoreProfile)
961 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
963 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
964 Standard_Boolean OpenGl_Context::Init (EAGLContext* theGContext,
965 const Standard_Boolean theIsCoreProfile)
967 Standard_Boolean OpenGl_Context::Init (NSOpenGLContext* theGContext,
968 const Standard_Boolean theIsCoreProfile)
972 Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
973 const Aspect_Display theDisplay,
974 const Aspect_RenderingContext theGContext,
975 const Standard_Boolean theIsCoreProfile)
978 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
979 #if defined(HAVE_EGL)
980 myWindow = theEglSurface;
981 myGContext = theEglContext;
982 myDisplay = theEglDisplay;
983 #elif defined(_WIN32)
984 myWindow = theWindow;
985 myGContext = theGContext;
986 myWindowDC = theWindowDC;
987 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
988 myGContext = theGContext;
990 myWindow = theWindow;
991 myGContext = theGContext;
992 myDisplay = theDisplay;
994 if (myGContext == NULL || !MakeCurrent())
996 return Standard_False;
999 init (theIsCoreProfile);
1000 myIsInitialized = Standard_True;
1001 return Standard_True;
1004 // =======================================================================
1005 // function : ResetErrors
1007 // =======================================================================
1008 bool OpenGl_Context::ResetErrors (const bool theToPrintErrors)
1011 int anErr = ::glGetError();
1012 const bool hasError = anErr != GL_NO_ERROR;
1013 if (!theToPrintErrors)
1015 for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
1022 for (; anErr != GL_NO_ERROR && aPrevErr != anErr; aPrevErr = anErr, anErr = ::glGetError())
1024 TCollection_ExtendedString anErrId;
1027 case GL_INVALID_ENUM: anErrId = "GL_INVALID_ENUM"; break;
1028 case GL_INVALID_VALUE: anErrId = "GL_INVALID_VALUE"; break;
1029 case GL_INVALID_OPERATION: anErrId = "GL_INVALID_OPERATION"; break;
1030 #ifdef GL_STACK_OVERFLOW
1031 case GL_STACK_OVERFLOW: anErrId = "GL_STACK_OVERFLOW"; break;
1032 case GL_STACK_UNDERFLOW: anErrId = "GL_STACK_UNDERFLOW"; break;
1034 case GL_OUT_OF_MEMORY: anErrId = "GL_OUT_OF_MEMORY"; break;
1035 case GL_INVALID_FRAMEBUFFER_OPERATION:
1036 anErrId = "GL_INVALID_FRAMEBUFFER_OPERATION";
1039 anErrId = TCollection_ExtendedString("#") + anErr;
1043 const TCollection_ExtendedString aMsg = TCollection_ExtendedString ("Unhandled GL error: ") + anErrId;
1044 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_OTHER, 0, GL_DEBUG_SEVERITY_LOW, aMsg);
1049 // =======================================================================
1050 // function : ReadGlVersion
1052 // =======================================================================
1053 void OpenGl_Context::ReadGlVersion (Standard_Integer& theGlVerMajor,
1054 Standard_Integer& theGlVerMinor)
1060 bool toCheckVer3 = true;
1061 #if defined(__EMSCRIPTEN__)
1062 // WebGL 1.0 prints annoying invalid enumeration warnings to console.
1063 toCheckVer3 = false;
1064 if (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE aWebGlCtx = emscripten_webgl_get_current_context())
1066 EmscriptenWebGLContextAttributes anAttribs = {};
1067 if (emscripten_webgl_get_context_attributes (aWebGlCtx, &anAttribs) == EMSCRIPTEN_RESULT_SUCCESS)
1069 toCheckVer3 = anAttribs.majorVersion >= 2;
1074 // Available since OpenGL 3.0 and OpenGL ES 3.0.
1077 GLint aMajor = 0, aMinor = 0;
1078 glGetIntegerv (GL_MAJOR_VERSION, &aMajor);
1079 glGetIntegerv (GL_MINOR_VERSION, &aMinor);
1080 // glGetError() sometimes does not report an error here even if
1081 // GL does not know GL_MAJOR_VERSION and GL_MINOR_VERSION constants.
1082 // This happens on some renderers like e.g. Cygwin MESA.
1083 // Thus checking additionally if GL has put anything to
1084 // the output variables.
1085 if (::glGetError() == GL_NO_ERROR && aMajor != 0 && aMinor != 0)
1087 theGlVerMajor = aMajor;
1088 theGlVerMinor = aMinor;
1091 for (GLenum anErr = ::glGetError(), aPrevErr = GL_NO_ERROR;; aPrevErr = anErr, anErr = ::glGetError())
1093 if (anErr == GL_NO_ERROR
1094 || anErr == aPrevErr)
1101 // Read version string.
1102 // Notice that only first two numbers split by point '2.1 XXXXX' are significant.
1103 // Following trash (after space) is vendor-specific.
1104 // New drivers also returns micro version of GL like '3.3.0' which has no meaning
1105 // and should be considered as vendor-specific too.
1106 const char* aVerStr = (const char* )glGetString (GL_VERSION);
1107 if (aVerStr == NULL || *aVerStr == '\0')
1109 // invalid GL context
1113 //#if defined(GL_ES_VERSION_2_0)
1114 // skip "OpenGL ES-** " section
1115 for (; *aVerStr != '\0'; ++aVerStr)
1117 if (*aVerStr >= '0' && *aVerStr <= '9')
1124 // parse string for major number
1127 size_t aMajIter = 0;
1128 while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9')
1132 if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr))
1136 memcpy (aMajorStr, aVerStr, aMajIter);
1137 aMajorStr[aMajIter] = '\0';
1139 // parse string for minor number
1140 aVerStr += aMajIter + 1;
1141 size_t aMinIter = 0;
1142 while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9')
1146 if (aMinIter == 0 || aMinIter >= sizeof(aMinorStr))
1150 memcpy (aMinorStr, aVerStr, aMinIter);
1151 aMinorStr[aMinIter] = '\0';
1154 theGlVerMajor = atoi (aMajorStr);
1155 theGlVerMinor = atoi (aMinorStr);
1157 if (theGlVerMajor <= 0)
1164 static Standard_CString THE_DBGMSG_UNKNOWN = "UNKNOWN";
1165 static Standard_CString THE_DBGMSG_SOURCES[] =
1167 ".OpenGL", // GL_DEBUG_SOURCE_API
1168 ".WinSystem", // GL_DEBUG_SOURCE_WINDOW_SYSTEM
1169 ".GLSL", // GL_DEBUG_SOURCE_SHADER_COMPILER
1170 ".3rdParty", // GL_DEBUG_SOURCE_THIRD_PARTY
1171 "", // GL_DEBUG_SOURCE_APPLICATION
1172 ".Other" // GL_DEBUG_SOURCE_OTHER
1175 static Standard_CString THE_DBGMSG_TYPES[] =
1177 "Error", // GL_DEBUG_TYPE_ERROR
1178 "Deprecated", // GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR
1179 "Undef. behavior", // GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR
1180 "Portability", // GL_DEBUG_TYPE_PORTABILITY
1181 "Performance", // GL_DEBUG_TYPE_PERFORMANCE
1182 "Other" // GL_DEBUG_TYPE_OTHER
1185 static Standard_CString THE_DBGMSG_SEV_HIGH = "High"; // GL_DEBUG_SEVERITY_HIGH
1186 static Standard_CString THE_DBGMSG_SEV_MEDIUM = "Medium"; // GL_DEBUG_SEVERITY_MEDIUM
1187 static Standard_CString THE_DBGMSG_SEV_LOW = "Low"; // GL_DEBUG_SEVERITY_LOW
1189 //! Callback for GL_ARB_debug_output extension
1190 static void APIENTRY debugCallbackWrap(unsigned int theSource,
1191 unsigned int theType,
1193 unsigned int theSeverity,
1195 const char* theMessage,
1196 const void* theUserParam)
1198 OpenGl_Context* aCtx = (OpenGl_Context* )theUserParam;
1199 aCtx->PushMessage (theSource, theType, theId, theSeverity, theMessage);
1202 // =======================================================================
1203 // function : PushMessage
1205 // =======================================================================
1206 void OpenGl_Context::PushMessage (const unsigned int theSource,
1207 const unsigned int theType,
1208 const unsigned int theId,
1209 const unsigned int theSeverity,
1210 const TCollection_ExtendedString& theMessage)
1212 if (caps->suppressExtraMsg
1213 && theSource >= GL_DEBUG_SOURCE_API
1214 && theSource <= GL_DEBUG_SOURCE_OTHER
1215 && myFilters[theSource - GL_DEBUG_SOURCE_API].Contains (theId))
1220 Standard_CString& aSrc = (theSource >= GL_DEBUG_SOURCE_API
1221 && theSource <= GL_DEBUG_SOURCE_OTHER)
1222 ? THE_DBGMSG_SOURCES[theSource - GL_DEBUG_SOURCE_API]
1223 : THE_DBGMSG_UNKNOWN;
1224 Standard_CString& aType = (theType >= GL_DEBUG_TYPE_ERROR
1225 && theType <= GL_DEBUG_TYPE_OTHER)
1226 ? THE_DBGMSG_TYPES[theType - GL_DEBUG_TYPE_ERROR]
1227 : THE_DBGMSG_UNKNOWN;
1228 Standard_CString& aSev = theSeverity == GL_DEBUG_SEVERITY_HIGH
1229 ? THE_DBGMSG_SEV_HIGH
1230 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
1231 ? THE_DBGMSG_SEV_MEDIUM
1232 : THE_DBGMSG_SEV_LOW);
1233 Message_Gravity aGrav = theSeverity == GL_DEBUG_SEVERITY_HIGH
1235 : (theSeverity == GL_DEBUG_SEVERITY_MEDIUM
1239 TCollection_ExtendedString aMsg;
1240 aMsg += "TKOpenGl"; aMsg += aSrc;
1241 aMsg += " | Type: "; aMsg += aType;
1242 aMsg += " | ID: "; aMsg += (Standard_Integer )theId;
1243 aMsg += " | Severity: "; aMsg += aSev;
1244 aMsg += " | Message:\n ";
1246 Messenger()->Send (aMsg, aGrav);
1249 // =======================================================================
1250 // function : ExcludeMessage
1252 // ======================================================================
1253 Standard_Boolean OpenGl_Context::ExcludeMessage (const unsigned int theSource,
1254 const unsigned int theId)
1256 return theSource >= GL_DEBUG_SOURCE_API
1257 && theSource <= GL_DEBUG_SOURCE_OTHER
1258 && myFilters[theSource - GL_DEBUG_SOURCE_API].Add (theId);
1261 // =======================================================================
1262 // function : IncludeMessage
1264 // ======================================================================
1265 Standard_Boolean OpenGl_Context::IncludeMessage (const unsigned int theSource,
1266 const unsigned int theId)
1268 return theSource >= GL_DEBUG_SOURCE_API
1269 && theSource <= GL_DEBUG_SOURCE_OTHER
1270 && myFilters[theSource - GL_DEBUG_SOURCE_API].Remove (theId);
1273 // =======================================================================
1274 // function : checkWrongVersion
1276 // ======================================================================
1277 void OpenGl_Context::checkWrongVersion (Standard_Integer theGlVerMajor, Standard_Integer theGlVerMinor,
1278 const char* theLastFailedProc)
1280 if (!IsGlGreaterEqual (theGlVerMajor, theGlVerMinor))
1285 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
1286 TCollection_AsciiString()
1287 + "Error! OpenGL context reports version "
1288 + myGlVerMajor + "." + myGlVerMinor
1289 + " but does not export required functions for " + theGlVerMajor + "." + theGlVerMinor
1290 + " (" + (theLastFailedProc != NULL ? theLastFailedProc : "") + ")\n"
1291 + "Please report this issue to OpenGL driver vendor '" + myVendor + "'");
1293 // lower internal version
1294 if (theGlVerMinor > 0)
1296 myGlVerMajor = theGlVerMajor;
1297 myGlVerMinor = theGlVerMinor - 1;
1300 #if defined(GL_ES_VERSION_2_0)
1301 switch (theGlVerMajor)
1303 case 3: myGlVerMajor = 2; myGlVerMinor = 0; return;
1306 switch (theGlVerMajor)
1308 case 2: myGlVerMajor = 1; myGlVerMinor = 5; return;
1309 case 3: myGlVerMajor = 2; myGlVerMinor = 1; return;
1310 case 4: myGlVerMajor = 3; myGlVerMinor = 3; return;
1315 // =======================================================================
1318 // =======================================================================
1319 void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
1324 myMaxMsaaSamples = 0;
1325 myMaxDrawBuffers = 1;
1326 myMaxColorAttachments = 1;
1327 ReadGlVersion (myGlVerMajor, myGlVerMinor);
1328 myVendor = (const char* )::glGetString (GL_VENDOR);
1329 myVendor.LowerCase();
1332 mySupportedFormats->Clear();
1333 mySupportedFormats->Add (Image_PixMap::ImgGray);
1334 mySupportedFormats->Add (Image_PixMap::ImgAlpha);
1335 mySupportedFormats->Add (Image_PixMap::ImgRGB);
1336 mySupportedFormats->Add (Image_PixMap::ImgRGB32);
1337 mySupportedFormats->Add (Image_PixMap::ImgRGBA);
1339 if (caps->contextMajorVersionUpper != -1)
1341 // synthetically restrict OpenGL version for testing
1342 Standard_Integer aCtxVer[2] = { myGlVerMajor, myGlVerMinor };
1343 bool isLowered = false;
1344 if (myGlVerMajor > caps->contextMajorVersionUpper)
1347 myGlVerMajor = caps->contextMajorVersionUpper;
1348 #if defined(GL_ES_VERSION_2_0)
1349 switch (myGlVerMajor)
1351 case 2: myGlVerMinor = 0; break;
1354 switch (myGlVerMajor)
1356 case 1: myGlVerMinor = 5; break;
1357 case 2: myGlVerMinor = 1; break;
1358 case 3: myGlVerMinor = 3; break;
1362 if (caps->contextMinorVersionUpper != -1
1363 && myGlVerMinor > caps->contextMinorVersionUpper)
1366 myGlVerMinor = caps->contextMinorVersionUpper;
1370 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_MEDIUM,
1371 TCollection_AsciiString ("OpenGL version ") + aCtxVer[0] + "." + aCtxVer[1]
1372 + " has been lowered to " + myGlVerMajor + "." + myGlVerMinor);
1376 if (!caps->ffpEnable
1377 && !IsGlGreaterEqual (2, 0))
1379 caps->ffpEnable = true;
1380 TCollection_ExtendedString aMsg =
1381 TCollection_ExtendedString("OpenGL driver is too old! Context info:\n")
1382 + " Vendor: " + (const char* )::glGetString (GL_VENDOR) + "\n"
1383 + " Renderer: " + (const char* )::glGetString (GL_RENDERER) + "\n"
1384 + " Version: " + (const char* )::glGetString (GL_VERSION) + "\n"
1385 + " Fallback using deprecated fixed-function pipeline.\n"
1386 + " Visualization might work incorrectly.\n"
1387 " Consider upgrading the graphics driver.";
1388 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH, aMsg);
1391 #if defined(GL_ES_VERSION_2_0)
1392 (void )theIsCoreProfile;
1393 const bool isCoreProfile = false;
1396 if (myVendor.Search ("nvidia") != -1)
1398 // Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW)
1399 // will use VIDEO memory as the source for buffer object operations.
1400 ExcludeMessage (GL_DEBUG_SOURCE_API, 131185);
1402 if (IsGlGreaterEqual (3, 0))
1404 // retrieve auxiliary function in advance
1405 FindProc ("glGetStringi", myFuncs->glGetStringi);
1408 bool isCoreProfile = false;
1409 if (IsGlGreaterEqual (3, 2))
1411 isCoreProfile = (theIsCoreProfile == Standard_True);
1413 // detect Core profile
1417 ::glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &aProfile);
1418 isCoreProfile = (aProfile & GL_CONTEXT_CORE_PROFILE_BIT) != 0;
1426 core11 = (OpenGl_GlCore11* )(&(*myFuncs));
1428 core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
1450 arbTboRGB32 = Standard_False;
1458 //! Make record shorter to retrieve function pointer using variable with same name
1459 const char* aLastFailedProc = NULL;
1460 #define FindProcShort(theFunc) FindProcVerbose(aLastFailedProc, #theFunc, myFuncs->theFunc)
1462 #if defined(GL_ES_VERSION_2_0)
1464 hasTexRGBA8 = IsGlGreaterEqual (3, 0)
1465 || CheckExtension ("GL_OES_rgb8_rgba8");
1466 hasTexSRGB = IsGlGreaterEqual (3, 0);
1467 hasFboSRGB = IsGlGreaterEqual (3, 0);
1468 hasSRGBControl = CheckExtension ("GL_EXT_sRGB_write_control");
1469 // NPOT textures has limited support within OpenGL ES 2.0
1470 // which are relaxed by OpenGL ES 3.0 or some extensions
1471 //arbNPTW = IsGlGreaterEqual (3, 0)
1472 // || CheckExtension ("GL_OES_texture_npot")
1473 // || CheckExtension ("GL_NV_texture_npot_2D_mipmap");
1474 arbNPTW = Standard_True;
1475 arbTexRG = IsGlGreaterEqual (3, 0)
1476 || CheckExtension ("GL_EXT_texture_rg");
1477 extBgra = CheckExtension ("GL_EXT_texture_format_BGRA8888");
1478 extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
1479 extPDS = IsGlGreaterEqual (3, 0)
1480 || CheckExtension ("GL_OES_packed_depth_stencil");
1481 #ifdef __EMSCRIPTEN__
1483 && checkEnableWebGlExtension (*this, "GL_WEBGL_depth_texture"))
1485 extPDS = true; // WebGL 1.0 extension (in WebGL 2.0 core)
1491 // no BGR on OpenGL ES - only BGRA as extension
1492 mySupportedFormats->Add (Image_PixMap::ImgBGR32);
1493 mySupportedFormats->Add (Image_PixMap::ImgBGRA);
1496 core11fwd = (OpenGl_GlCore11Fwd* )(&(*myFuncs));
1497 if (IsGlGreaterEqual (2, 0))
1499 // enable compatible functions
1500 core20 = (OpenGl_GlCore20* )(&(*myFuncs));
1501 core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
1502 core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
1503 arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
1505 if (IsGlGreaterEqual (3, 0)
1506 && FindProcShort (glBlitFramebuffer))
1508 arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs));
1510 if (IsGlGreaterEqual (3, 0)
1511 && FindProcShort (glGenSamplers)
1512 && FindProcShort (glDeleteSamplers)
1513 && FindProcShort (glIsSampler)
1514 && FindProcShort (glBindSampler)
1515 && FindProcShort (glSamplerParameteri)
1516 && FindProcShort (glSamplerParameteriv)
1517 && FindProcShort (glSamplerParameterf)
1518 && FindProcShort (glSamplerParameterfv)
1519 && FindProcShort (glGetSamplerParameteriv)
1520 && FindProcShort (glGetSamplerParameterfv))
1521 //&& FindProcShort (glSamplerParameterIiv) // only on Desktop or with extensions GL_OES_texture_border_clamp/GL_EXT_texture_border_clamp
1522 //&& FindProcShort (glSamplerParameterIuiv)
1523 //&& FindProcShort (glGetSamplerParameterIiv)
1524 //&& FindProcShort (glGetSamplerParameterIuiv))
1526 arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs));
1528 extFragDepth = !IsGlGreaterEqual(3, 0)
1529 && CheckExtension ("GL_EXT_frag_depth");
1530 if (IsGlGreaterEqual (3, 1)
1531 && FindProcShort (glTexStorage2DMultisample))
1533 // MSAA RenderBuffers have been defined in OpenGL ES 3.0,
1534 // but MSAA Textures - only in OpenGL ES 3.1+
1535 ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
1538 hasUintIndex = IsGlGreaterEqual (3, 0)
1539 || CheckExtension ("GL_OES_element_index_uint");
1540 hasHighp = CheckExtension ("GL_OES_fragment_precision_high");
1541 GLint aRange[2] = {0, 0};
1543 ::glGetShaderPrecisionFormat (GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, aRange, &aPrec);
1546 hasHighp = Standard_True;
1549 arbTexFloat = (IsGlGreaterEqual (3, 0)
1550 && FindProcShort (glTexImage3D))
1551 || CheckExtension ("GL_OES_texture_float");
1552 hasTexFloatLinear = arbTexFloat
1553 && CheckExtension ("GL_OES_texture_float_linear");
1555 const bool hasTexBuffer32 = IsGlGreaterEqual (3, 2) && FindProcShort (glTexBuffer);
1556 const bool hasExtTexBuffer = CheckExtension ("GL_EXT_texture_buffer") && FindProc ("glTexBufferEXT", myFuncs->glTexBuffer);
1557 if (hasTexBuffer32 || hasExtTexBuffer)
1559 arbTBO = reinterpret_cast<OpenGl_ArbTBO*> (myFuncs.get());
1562 bool hasInstanced = IsGlGreaterEqual (3, 0)
1563 && FindProcShort (glVertexAttribDivisor)
1564 && FindProcShort (glDrawArraysInstanced)
1565 && FindProcShort (glDrawElementsInstanced);
1568 hasInstanced = CheckExtension ("GL_ANGLE_instanced_arrays")
1569 && FindProc ("glVertexAttribDivisorANGLE", myFuncs->glVertexAttribDivisor)
1570 && FindProc ("glDrawArraysInstancedANGLE", myFuncs->glDrawArraysInstanced)
1571 && FindProc ("glDrawElementsInstancedANGLE", myFuncs->glDrawElementsInstanced);
1575 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
1578 const bool hasVAO = IsGlGreaterEqual (3, 0)
1579 && FindProcShort (glBindVertexArray)
1580 && FindProcShort (glDeleteVertexArrays)
1581 && FindProcShort (glGenVertexArrays)
1582 && FindProcShort (glIsVertexArray);
1583 #ifndef __EMSCRIPTEN__ // latest Emscripten does not pretend having / simulating mapping buffer functions
1584 const bool hasMapBufferRange = IsGlGreaterEqual (3, 0)
1585 && FindProcShort (glMapBufferRange)
1586 && FindProcShort (glUnmapBuffer)
1587 && FindProcShort (glGetBufferPointerv)
1588 && FindProcShort (glFlushMappedBufferRange);
1591 // load OpenGL ES 3.0 new functions
1592 const bool has30es = IsGlGreaterEqual (3, 0)
1594 #ifndef __EMSCRIPTEN__
1595 && hasMapBufferRange
1598 && arbSamplerObject != NULL
1599 && arbFBOBlit != NULL
1600 && FindProcShort (glReadBuffer)
1601 && FindProcShort (glDrawRangeElements)
1602 && FindProcShort (glTexImage3D)
1603 && FindProcShort (glTexSubImage3D)
1604 && FindProcShort (glCopyTexSubImage3D)
1605 && FindProcShort (glCompressedTexImage3D)
1606 && FindProcShort (glCompressedTexSubImage3D)
1607 && FindProcShort (glGenQueries)
1608 && FindProcShort (glDeleteQueries)
1609 && FindProcShort (glIsQuery)
1610 && FindProcShort (glBeginQuery)
1611 && FindProcShort (glEndQuery)
1612 && FindProcShort (glGetQueryiv)
1613 && FindProcShort (glGetQueryObjectuiv)
1614 && FindProcShort (glDrawBuffers)
1615 && FindProcShort (glUniformMatrix2x3fv)
1616 && FindProcShort (glUniformMatrix3x2fv)
1617 && FindProcShort (glUniformMatrix2x4fv)
1618 && FindProcShort (glUniformMatrix4x2fv)
1619 && FindProcShort (glUniformMatrix3x4fv)
1620 && FindProcShort (glUniformMatrix4x3fv)
1621 && FindProcShort (glRenderbufferStorageMultisample)
1622 && FindProcShort (glFramebufferTextureLayer)
1623 && FindProcShort (glGetIntegeri_v)
1624 && FindProcShort (glBeginTransformFeedback)
1625 && FindProcShort (glEndTransformFeedback)
1626 && FindProcShort (glBindBufferRange)
1627 && FindProcShort (glBindBufferBase)
1628 && FindProcShort (glTransformFeedbackVaryings)
1629 && FindProcShort (glGetTransformFeedbackVarying)
1630 && FindProcShort (glVertexAttribIPointer)
1631 && FindProcShort (glGetVertexAttribIiv)
1632 && FindProcShort (glGetVertexAttribIuiv)
1633 && FindProcShort (glVertexAttribI4i)
1634 && FindProcShort (glVertexAttribI4ui)
1635 && FindProcShort (glVertexAttribI4iv)
1636 && FindProcShort (glVertexAttribI4uiv)
1637 && FindProcShort (glGetUniformuiv)
1638 && FindProcShort (glGetFragDataLocation)
1639 && FindProcShort (glUniform1ui)
1640 && FindProcShort (glUniform2ui)
1641 && FindProcShort (glUniform3ui)
1642 && FindProcShort (glUniform4ui)
1643 && FindProcShort (glUniform1uiv)
1644 && FindProcShort (glUniform2uiv)
1645 && FindProcShort (glUniform3uiv)
1646 && FindProcShort (glUniform4uiv)
1647 && FindProcShort (glClearBufferiv)
1648 && FindProcShort (glClearBufferuiv)
1649 && FindProcShort (glClearBufferfv)
1650 && FindProcShort (glClearBufferfi)
1651 && FindProcShort (glGetStringi)
1652 && FindProcShort (glCopyBufferSubData)
1653 && FindProcShort (glGetUniformIndices)
1654 && FindProcShort (glGetActiveUniformsiv)
1655 && FindProcShort (glGetUniformBlockIndex)
1656 && FindProcShort (glGetActiveUniformBlockiv)
1657 && FindProcShort (glGetActiveUniformBlockName)
1658 && FindProcShort (glUniformBlockBinding)
1659 && FindProcShort (glFenceSync)
1660 && FindProcShort (glIsSync)
1661 && FindProcShort (glDeleteSync)
1662 && FindProcShort (glClientWaitSync)
1663 && FindProcShort (glWaitSync)
1664 && FindProcShort (glGetInteger64v)
1665 && FindProcShort (glGetSynciv)
1666 && FindProcShort (glGetInteger64i_v)
1667 && FindProcShort (glGetBufferParameteri64v)
1668 && FindProcShort (glBindTransformFeedback)
1669 && FindProcShort (glDeleteTransformFeedbacks)
1670 && FindProcShort (glGenTransformFeedbacks)
1671 && FindProcShort (glIsTransformFeedback)
1672 && FindProcShort (glPauseTransformFeedback)
1673 && FindProcShort (glResumeTransformFeedback)
1674 && FindProcShort (glGetProgramBinary)
1675 && FindProcShort (glProgramBinary)
1676 && FindProcShort (glProgramParameteri)
1677 && FindProcShort (glInvalidateFramebuffer)
1678 && FindProcShort (glInvalidateSubFramebuffer)
1679 && FindProcShort (glTexStorage2D)
1680 && FindProcShort (glTexStorage3D)
1681 && FindProcShort (glGetInternalformativ);
1684 checkWrongVersion (3, 0, aLastFailedProc);
1688 core30 = (OpenGl_GlCore30* )(&(*myFuncs));
1689 core30fwd = (OpenGl_GlCore30Fwd* )(&(*myFuncs));
1690 hasGetBufferData = true;
1693 // load OpenGL ES 3.1 new functions
1694 const bool has31es = IsGlGreaterEqual (3, 1)
1696 && FindProcShort (glDispatchCompute)
1697 && FindProcShort (glDispatchComputeIndirect)
1698 && FindProcShort (glDrawArraysIndirect)
1699 && FindProcShort (glDrawElementsIndirect)
1700 && FindProcShort (glFramebufferParameteri)
1701 && FindProcShort (glGetFramebufferParameteriv)
1702 && FindProcShort (glGetProgramInterfaceiv)
1703 && FindProcShort (glGetProgramResourceIndex)
1704 && FindProcShort (glGetProgramResourceName)
1705 && FindProcShort (glGetProgramResourceiv)
1706 && FindProcShort (glGetProgramResourceLocation)
1707 && FindProcShort (glUseProgramStages)
1708 && FindProcShort (glActiveShaderProgram)
1709 && FindProcShort (glCreateShaderProgramv)
1710 && FindProcShort (glBindProgramPipeline)
1711 && FindProcShort (glDeleteProgramPipelines)
1712 && FindProcShort (glGenProgramPipelines)
1713 && FindProcShort (glIsProgramPipeline)
1714 && FindProcShort (glGetProgramPipelineiv)
1715 && FindProcShort (glProgramUniform1i)
1716 && FindProcShort (glProgramUniform2i)
1717 && FindProcShort (glProgramUniform3i)
1718 && FindProcShort (glProgramUniform4i)
1719 && FindProcShort (glProgramUniform1ui)
1720 && FindProcShort (glProgramUniform2ui)
1721 && FindProcShort (glProgramUniform3ui)
1722 && FindProcShort (glProgramUniform4ui)
1723 && FindProcShort (glProgramUniform1f)
1724 && FindProcShort (glProgramUniform2f)
1725 && FindProcShort (glProgramUniform3f)
1726 && FindProcShort (glProgramUniform4f)
1727 && FindProcShort (glProgramUniform1iv)
1728 && FindProcShort (glProgramUniform2iv)
1729 && FindProcShort (glProgramUniform3iv)
1730 && FindProcShort (glProgramUniform4iv)
1731 && FindProcShort (glProgramUniform1uiv)
1732 && FindProcShort (glProgramUniform2uiv)
1733 && FindProcShort (glProgramUniform3uiv)
1734 && FindProcShort (glProgramUniform4uiv)
1735 && FindProcShort (glProgramUniform1fv)
1736 && FindProcShort (glProgramUniform2fv)
1737 && FindProcShort (glProgramUniform3fv)
1738 && FindProcShort (glProgramUniform4fv)
1739 && FindProcShort (glProgramUniformMatrix2fv)
1740 && FindProcShort (glProgramUniformMatrix3fv)
1741 && FindProcShort (glProgramUniformMatrix4fv)
1742 && FindProcShort (glProgramUniformMatrix2x3fv)
1743 && FindProcShort (glProgramUniformMatrix3x2fv)
1744 && FindProcShort (glProgramUniformMatrix2x4fv)
1745 && FindProcShort (glProgramUniformMatrix4x2fv)
1746 && FindProcShort (glProgramUniformMatrix3x4fv)
1747 && FindProcShort (glProgramUniformMatrix4x3fv)
1748 && FindProcShort (glValidateProgramPipeline)
1749 && FindProcShort (glGetProgramPipelineInfoLog)
1750 && FindProcShort (glBindImageTexture)
1751 && FindProcShort (glGetBooleani_v)
1752 && FindProcShort (glMemoryBarrier)
1753 && FindProcShort (glMemoryBarrierByRegion)
1754 && FindProcShort (glTexStorage2DMultisample)
1755 && FindProcShort (glGetMultisamplefv)
1756 && FindProcShort (glSampleMaski)
1757 && FindProcShort (glGetTexLevelParameteriv)
1758 && FindProcShort (glGetTexLevelParameterfv)
1759 && FindProcShort (glBindVertexBuffer)
1760 && FindProcShort (glVertexAttribFormat)
1761 && FindProcShort (glVertexAttribIFormat)
1762 && FindProcShort (glVertexAttribBinding)
1763 && FindProcShort (glVertexBindingDivisor);
1766 checkWrongVersion (3, 1, aLastFailedProc);
1769 // initialize debug context extension
1770 if (IsGlGreaterEqual (3, 2)
1771 || CheckExtension ("GL_KHR_debug"))
1773 // this functionality become a part of OpenGL ES 3.2
1775 if (IsGlGreaterEqual (3, 2)
1776 && FindProcShort (glDebugMessageControl)
1777 && FindProcShort (glDebugMessageInsert)
1778 && FindProcShort (glDebugMessageCallback)
1779 && FindProcShort (glGetDebugMessageLog))
1781 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
1783 // According to GL_KHR_debug spec, all functions should have KHR suffix.
1784 // However, some implementations can export these functions without suffix.
1785 else if (!IsGlGreaterEqual (3, 2)
1786 && FindProc ("glDebugMessageControlKHR", myFuncs->glDebugMessageControl)
1787 && FindProc ("glDebugMessageInsertKHR", myFuncs->glDebugMessageInsert)
1788 && FindProc ("glDebugMessageCallbackKHR", myFuncs->glDebugMessageCallback)
1789 && FindProc ("glGetDebugMessageLogKHR", myFuncs->glGetDebugMessageLog))
1791 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
1795 && caps->contextDebug)
1797 // setup default callback
1798 myIsGlDebugCtx = Standard_True;
1799 arbDbg->glDebugMessageCallback (debugCallbackWrap, this);
1800 ::glEnable (GL_DEBUG_OUTPUT);
1801 if (caps->contextSyncDebug)
1803 // note that some broken implementations (e.g. simulators) might generate error message on this call
1804 ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
1809 // load OpenGL ES 3.2 new functions
1810 const bool has32es = IsGlGreaterEqual (3, 2)
1814 && FindProcShort (glBlendBarrier)
1815 && FindProcShort (glCopyImageSubData)
1816 && FindProcShort (glPushDebugGroup)
1817 && FindProcShort (glPopDebugGroup)
1818 && FindProcShort (glObjectLabel)
1819 && FindProcShort (glGetObjectLabel)
1820 && FindProcShort (glObjectPtrLabel)
1821 && FindProcShort (glGetObjectPtrLabel)
1822 && FindProcShort (glGetPointerv)
1823 && FindProcShort (glEnablei)
1824 && FindProcShort (glDisablei)
1825 && FindProcShort (glBlendEquationi)
1826 && FindProcShort (glBlendEquationSeparatei)
1827 && FindProcShort (glBlendFunci)
1828 && FindProcShort (glBlendFuncSeparatei)
1829 && FindProcShort (glColorMaski)
1830 && FindProcShort (glIsEnabledi)
1831 && FindProcShort (glDrawElementsBaseVertex)
1832 && FindProcShort (glDrawRangeElementsBaseVertex)
1833 && FindProcShort (glDrawElementsInstancedBaseVertex)
1834 && FindProcShort (glFramebufferTexture)
1835 && FindProcShort (glPrimitiveBoundingBox)
1836 && FindProcShort (glGetGraphicsResetStatus)
1837 && FindProcShort (glReadnPixels)
1838 && FindProcShort (glGetnUniformfv)
1839 && FindProcShort (glGetnUniformiv)
1840 && FindProcShort (glGetnUniformuiv)
1841 && FindProcShort (glMinSampleShading)
1842 && FindProcShort (glPatchParameteri)
1843 && FindProcShort (glTexParameterIiv)
1844 && FindProcShort (glTexParameterIuiv)
1845 && FindProcShort (glGetTexParameterIiv)
1846 && FindProcShort (glGetTexParameterIuiv)
1847 && FindProcShort (glSamplerParameterIiv)
1848 && FindProcShort (glSamplerParameterIuiv)
1849 && FindProcShort (glGetSamplerParameterIiv)
1850 && FindProcShort (glGetSamplerParameterIuiv)
1851 && FindProcShort (glTexBufferRange)
1852 && FindProcShort (glTexStorage3DMultisample);
1855 checkWrongVersion (3, 2, aLastFailedProc);
1858 extDrawBuffers = CheckExtension ("GL_EXT_draw_buffers") && FindProc ("glDrawBuffersEXT", myFuncs->glDrawBuffers);
1859 arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers") && FindProc ("glDrawBuffersARB", myFuncs->glDrawBuffers);
1861 if (IsGlGreaterEqual (3, 0) && FindProcShort (glDrawBuffers))
1863 hasDrawBuffers = OpenGl_FeatureInCore;
1865 else if (extDrawBuffers || arbDrawBuffers)
1867 hasDrawBuffers = OpenGl_FeatureInExtensions;
1870 hasFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
1871 CheckExtension ("GL_EXT_color_buffer_float") ? OpenGl_FeatureInExtensions
1872 : OpenGl_FeatureNotAvailable;
1873 hasHalfFloatBuffer = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
1874 CheckExtension ("GL_EXT_color_buffer_half_float") ? OpenGl_FeatureInExtensions
1875 : OpenGl_FeatureNotAvailable;
1877 oesSampleVariables = CheckExtension ("GL_OES_sample_variables");
1878 oesStdDerivatives = CheckExtension ("GL_OES_standard_derivatives");
1879 hasSampleVariables = IsGlGreaterEqual (3, 2) ? OpenGl_FeatureInCore :
1880 oesSampleVariables ? OpenGl_FeatureInExtensions
1881 : OpenGl_FeatureNotAvailable;
1882 hasGlslBitwiseOps = IsGlGreaterEqual (3, 0)
1883 ? OpenGl_FeatureInCore
1884 : OpenGl_FeatureNotAvailable;
1885 // without hasHighp, dFdx/dFdy precision is considered too low for flat shading (visual artifacts)
1886 hasFlatShading = IsGlGreaterEqual (3, 0)
1887 ? OpenGl_FeatureInCore
1888 : (oesStdDerivatives && hasHighp
1889 ? OpenGl_FeatureInExtensions
1890 : OpenGl_FeatureNotAvailable);
1891 if (!IsGlGreaterEqual (3, 1)
1892 && myVendor.Search("qualcomm") != -1)
1894 // dFdx/dFdy are completely broken on tested Adreno devices with versions below OpenGl ES 3.1
1895 hasFlatShading = OpenGl_FeatureNotAvailable;
1898 hasGeometryStage = IsGlGreaterEqual (3, 2)
1899 ? OpenGl_FeatureInCore
1900 : (CheckExtension ("GL_EXT_geometry_shader") && CheckExtension ("GL_EXT_shader_io_blocks")
1901 ? OpenGl_FeatureInExtensions
1902 : OpenGl_FeatureNotAvailable);
1905 myTexClamp = IsGlGreaterEqual (1, 2) ? GL_CLAMP_TO_EDGE : GL_CLAMP;
1907 hasTexRGBA8 = Standard_True;
1908 hasTexSRGB = IsGlGreaterEqual (2, 1);
1909 hasFboSRGB = IsGlGreaterEqual (2, 1);
1910 hasSRGBControl = hasFboSRGB;
1911 arbDrawBuffers = CheckExtension ("GL_ARB_draw_buffers");
1912 arbNPTW = CheckExtension ("GL_ARB_texture_non_power_of_two");
1913 arbTexFloat = IsGlGreaterEqual (3, 0)
1914 || CheckExtension ("GL_ARB_texture_float");
1915 hasTexFloatLinear = arbTexFloat;
1916 arbSampleShading = CheckExtension ("GL_ARB_sample_shading");
1917 arbDepthClamp = IsGlGreaterEqual (3, 2)
1918 || CheckExtension ("GL_ARB_depth_clamp")
1919 || CheckExtension ("NV_depth_clamp");
1920 extBgra = IsGlGreaterEqual (1, 2)
1921 || CheckExtension ("GL_EXT_bgra");
1922 extAnis = CheckExtension ("GL_EXT_texture_filter_anisotropic");
1923 extPDS = CheckExtension ("GL_EXT_packed_depth_stencil");
1924 atiMem = CheckExtension ("GL_ATI_meminfo");
1925 nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
1929 mySupportedFormats->Add (Image_PixMap::ImgBGR);
1930 mySupportedFormats->Add (Image_PixMap::ImgBGR32);
1931 mySupportedFormats->Add (Image_PixMap::ImgBGRA);
1934 hasDrawBuffers = IsGlGreaterEqual (2, 0) ? OpenGl_FeatureInCore :
1935 arbDrawBuffers ? OpenGl_FeatureInExtensions
1936 : OpenGl_FeatureNotAvailable;
1938 hasGlslBitwiseOps = IsGlGreaterEqual (3, 0)
1939 ? OpenGl_FeatureInCore
1940 : CheckExtension ("GL_EXT_gpu_shader4")
1941 ? OpenGl_FeatureInExtensions
1942 : OpenGl_FeatureNotAvailable;
1944 hasFloatBuffer = hasHalfFloatBuffer = IsGlGreaterEqual (3, 0) ? OpenGl_FeatureInCore :
1945 CheckExtension ("GL_ARB_color_buffer_float") ? OpenGl_FeatureInExtensions
1946 : OpenGl_FeatureNotAvailable;
1948 hasGeometryStage = IsGlGreaterEqual (3, 2)
1949 ? OpenGl_FeatureInCore
1950 : OpenGl_FeatureNotAvailable;
1952 hasSampleVariables = IsGlGreaterEqual (4, 0) ? OpenGl_FeatureInCore :
1953 arbSampleShading ? OpenGl_FeatureInExtensions
1954 : OpenGl_FeatureNotAvailable;
1956 GLint aStereo = GL_FALSE;
1957 glGetIntegerv (GL_STEREO, &aStereo);
1958 myIsStereoBuffers = aStereo == 1;
1960 // get number of maximum clipping planes
1961 glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes);
1966 glGetIntegerv (GL_MAX_DRAW_BUFFERS, &myMaxDrawBuffers);
1967 glGetIntegerv (GL_MAX_COLOR_ATTACHMENTS, &myMaxColorAttachments);
1968 if (myDrawBuffers.Length() < myMaxDrawBuffers)
1970 myDrawBuffers.Resize (0, myMaxDrawBuffers - 1, false);
1974 glGetIntegerv (GL_MAX_TEXTURE_SIZE, &myMaxTexDim);
1975 #if !defined(GL_ES_VERSION_2_0)
1976 if (IsGlGreaterEqual (1, 3) && core11 != NULL)
1978 // this is a maximum of texture units for FFP functionality,
1979 // usually smaller than combined texture units available for GLSL
1980 glGetIntegerv (GL_MAX_TEXTURE_UNITS, &myMaxTexUnitsFFP);
1981 myMaxTexCombined = myMaxTexUnitsFFP;
1984 if (IsGlGreaterEqual (2, 0))
1986 glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &myMaxTexCombined);
1988 mySpriteTexUnit = myMaxTexCombined >= 2
1989 ? Graphic3d_TextureUnit_PointSprite
1990 : Graphic3d_TextureUnit_0;
1992 GLint aMaxVPortSize[2] = {0, 0};
1993 glGetIntegerv (GL_MAX_VIEWPORT_DIMS, aMaxVPortSize);
1994 myMaxDumpSizeX = Min (aMaxVPortSize[0], myMaxTexDim);
1995 myMaxDumpSizeY = Min (aMaxVPortSize[1], myMaxTexDim);
1996 if (myVendor == "intel")
1998 // Intel drivers have known bug with empty dump for images with width>=5462
1999 myMaxDumpSizeX = Min (myMaxDumpSizeX, 4096);
2004 glGetIntegerv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &myAnisoMax);
2007 myClippingState.Init();
2009 #if !defined(GL_ES_VERSION_2_0)
2028 // retrieve platform-dependent extensions
2029 #if defined(HAVE_EGL)
2031 #elif defined(_WIN32)
2032 if (FindProcShort (wglGetExtensionsStringARB))
2034 const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC());
2035 if (CheckExtension (aWglExts, "WGL_EXT_swap_control"))
2037 FindProcShort (wglSwapIntervalEXT);
2039 if (CheckExtension (aWglExts, "WGL_ARB_pixel_format"))
2041 FindProcShort (wglChoosePixelFormatARB);
2043 if (CheckExtension (aWglExts, "WGL_ARB_create_context_profile"))
2045 FindProcShort (wglCreateContextAttribsARB);
2047 if (CheckExtension (aWglExts, "WGL_NV_DX_interop"))
2049 FindProcShort (wglDXSetResourceShareHandleNV);
2050 FindProcShort (wglDXOpenDeviceNV);
2051 FindProcShort (wglDXCloseDeviceNV);
2052 FindProcShort (wglDXRegisterObjectNV);
2053 FindProcShort (wglDXUnregisterObjectNV);
2054 FindProcShort (wglDXObjectAccessNV);
2055 FindProcShort (wglDXLockObjectsNV);
2056 FindProcShort (wglDXUnlockObjectsNV);
2058 if (CheckExtension (aWglExts, "WGL_AMD_gpu_association"))
2060 FindProcShort (wglGetGPUIDsAMD);
2061 FindProcShort (wglGetGPUInfoAMD);
2062 FindProcShort (wglGetContextGPUIDAMD);
2065 #elif defined(__APPLE__)
2068 const char* aGlxExts = ::glXQueryExtensionsString ((Display* )myDisplay, DefaultScreen ((Display* )myDisplay));
2069 if (CheckExtension (aGlxExts, "GLX_EXT_swap_control"))
2071 FindProcShort (glXSwapIntervalEXT);
2073 if (CheckExtension (aGlxExts, "GLX_SGI_swap_control"))
2075 FindProcShort (glXSwapIntervalSGI);
2077 if (CheckExtension (aGlxExts, "GLX_MESA_query_renderer"))
2079 FindProcShort (glXQueryRendererIntegerMESA);
2080 FindProcShort (glXQueryCurrentRendererIntegerMESA);
2081 FindProcShort (glXQueryRendererStringMESA);
2082 FindProcShort (glXQueryCurrentRendererStringMESA);
2084 //extSwapTear = CheckExtension (aGlxExts, "GLX_EXT_swap_control_tear");
2087 // load OpenGL 1.2 new functions
2088 has12 = IsGlGreaterEqual (1, 2)
2089 && FindProcShort (glBlendColor)
2090 && FindProcShort (glBlendEquation)
2091 && FindProcShort (glDrawRangeElements)
2092 && FindProcShort (glTexImage3D)
2093 && FindProcShort (glTexSubImage3D)
2094 && FindProcShort (glCopyTexSubImage3D);
2097 checkWrongVersion (1, 2, aLastFailedProc);
2100 // load OpenGL 1.3 new functions
2101 has13 = IsGlGreaterEqual (1, 3)
2102 && FindProcShort (glActiveTexture)
2103 && FindProcShort (glSampleCoverage)
2104 && FindProcShort (glCompressedTexImage3D)
2105 && FindProcShort (glCompressedTexImage2D)
2106 && FindProcShort (glCompressedTexImage1D)
2107 && FindProcShort (glCompressedTexSubImage3D)
2108 && FindProcShort (glCompressedTexSubImage2D)
2109 && FindProcShort (glCompressedTexSubImage1D)
2110 && FindProcShort (glGetCompressedTexImage);
2115 && FindProcShort (glClientActiveTexture)
2116 && FindProcShort (glMultiTexCoord1d)
2117 && FindProcShort (glMultiTexCoord1dv)
2118 && FindProcShort (glMultiTexCoord1f)
2119 && FindProcShort (glMultiTexCoord1fv)
2120 && FindProcShort (glMultiTexCoord1i)
2121 && FindProcShort (glMultiTexCoord1iv)
2122 && FindProcShort (glMultiTexCoord1s)
2123 && FindProcShort (glMultiTexCoord1sv)
2124 && FindProcShort (glMultiTexCoord2d)
2125 && FindProcShort (glMultiTexCoord2dv)
2126 && FindProcShort (glMultiTexCoord2f)
2127 && FindProcShort (glMultiTexCoord2fv)
2128 && FindProcShort (glMultiTexCoord2i)
2129 && FindProcShort (glMultiTexCoord2iv)
2130 && FindProcShort (glMultiTexCoord2s)
2131 && FindProcShort (glMultiTexCoord2sv)
2132 && FindProcShort (glMultiTexCoord3d)
2133 && FindProcShort (glMultiTexCoord3dv)
2134 && FindProcShort (glMultiTexCoord3f)
2135 && FindProcShort (glMultiTexCoord3fv)
2136 && FindProcShort (glMultiTexCoord3i)
2137 && FindProcShort (glMultiTexCoord3iv)
2138 && FindProcShort (glMultiTexCoord3s)
2139 && FindProcShort (glMultiTexCoord3sv)
2140 && FindProcShort (glMultiTexCoord4d)
2141 && FindProcShort (glMultiTexCoord4dv)
2142 && FindProcShort (glMultiTexCoord4f)
2143 && FindProcShort (glMultiTexCoord4fv)
2144 && FindProcShort (glMultiTexCoord4i)
2145 && FindProcShort (glMultiTexCoord4iv)
2146 && FindProcShort (glMultiTexCoord4s)
2147 && FindProcShort (glMultiTexCoord4sv)
2148 && FindProcShort (glLoadTransposeMatrixf)
2149 && FindProcShort (glLoadTransposeMatrixd)
2150 && FindProcShort (glMultTransposeMatrixf)
2151 && FindProcShort (glMultTransposeMatrixd);
2155 checkWrongVersion (1, 3, aLastFailedProc);
2158 // load OpenGL 1.4 new functions
2159 has14 = IsGlGreaterEqual (1, 4)
2160 && FindProcShort (glBlendFuncSeparate)
2161 && FindProcShort (glMultiDrawArrays)
2162 && FindProcShort (glMultiDrawElements)
2163 && FindProcShort (glPointParameterf)
2164 && FindProcShort (glPointParameterfv)
2165 && FindProcShort (glPointParameteri)
2166 && FindProcShort (glPointParameteriv);
2169 checkWrongVersion (1, 4, aLastFailedProc);
2172 // load OpenGL 1.5 new functions
2173 has15 = IsGlGreaterEqual (1, 5)
2174 && FindProcShort (glGenQueries)
2175 && FindProcShort (glDeleteQueries)
2176 && FindProcShort (glIsQuery)
2177 && FindProcShort (glBeginQuery)
2178 && FindProcShort (glEndQuery)
2179 && FindProcShort (glGetQueryiv)
2180 && FindProcShort (glGetQueryObjectiv)
2181 && FindProcShort (glGetQueryObjectuiv)
2182 && FindProcShort (glBindBuffer)
2183 && FindProcShort (glDeleteBuffers)
2184 && FindProcShort (glGenBuffers)
2185 && FindProcShort (glIsBuffer)
2186 && FindProcShort (glBufferData)
2187 && FindProcShort (glBufferSubData)
2188 && FindProcShort (glGetBufferSubData)
2189 && FindProcShort (glMapBuffer)
2190 && FindProcShort (glUnmapBuffer)
2191 && FindProcShort (glGetBufferParameteriv)
2192 && FindProcShort (glGetBufferPointerv);
2197 core15 = (OpenGl_GlCore15* )(&(*myFuncs));
2199 core15fwd = (OpenGl_GlCore15Fwd* )(&(*myFuncs));
2200 hasGetBufferData = true;
2204 checkWrongVersion (1, 5, aLastFailedProc);
2207 // load OpenGL 2.0 new functions
2208 has20 = IsGlGreaterEqual (2, 0)
2209 && FindProcShort (glBlendEquationSeparate)
2210 && FindProcShort (glDrawBuffers)
2211 && FindProcShort (glStencilOpSeparate)
2212 && FindProcShort (glStencilFuncSeparate)
2213 && FindProcShort (glStencilMaskSeparate)
2214 && FindProcShort (glAttachShader)
2215 && FindProcShort (glBindAttribLocation)
2216 && FindProcShort (glCompileShader)
2217 && FindProcShort (glCreateProgram)
2218 && FindProcShort (glCreateShader)
2219 && FindProcShort (glDeleteProgram)
2220 && FindProcShort (glDeleteShader)
2221 && FindProcShort (glDetachShader)
2222 && FindProcShort (glDisableVertexAttribArray)
2223 && FindProcShort (glEnableVertexAttribArray)
2224 && FindProcShort (glGetActiveAttrib)
2225 && FindProcShort (glGetActiveUniform)
2226 && FindProcShort (glGetAttachedShaders)
2227 && FindProcShort (glGetAttribLocation)
2228 && FindProcShort (glGetProgramiv)
2229 && FindProcShort (glGetProgramInfoLog)
2230 && FindProcShort (glGetShaderiv)
2231 && FindProcShort (glGetShaderInfoLog)
2232 && FindProcShort (glGetShaderSource)
2233 && FindProcShort (glGetUniformLocation)
2234 && FindProcShort (glGetUniformfv)
2235 && FindProcShort (glGetUniformiv)
2236 && FindProcShort (glGetVertexAttribdv)
2237 && FindProcShort (glGetVertexAttribfv)
2238 && FindProcShort (glGetVertexAttribiv)
2239 && FindProcShort (glGetVertexAttribPointerv)
2240 && FindProcShort (glIsProgram)
2241 && FindProcShort (glIsShader)
2242 && FindProcShort (glLinkProgram)
2243 && FindProcShort (glShaderSource)
2244 && FindProcShort (glUseProgram)
2245 && FindProcShort (glUniform1f)
2246 && FindProcShort (glUniform2f)
2247 && FindProcShort (glUniform3f)
2248 && FindProcShort (glUniform4f)
2249 && FindProcShort (glUniform1i)
2250 && FindProcShort (glUniform2i)
2251 && FindProcShort (glUniform3i)
2252 && FindProcShort (glUniform4i)
2253 && FindProcShort (glUniform1fv)
2254 && FindProcShort (glUniform2fv)
2255 && FindProcShort (glUniform3fv)
2256 && FindProcShort (glUniform4fv)
2257 && FindProcShort (glUniform1iv)
2258 && FindProcShort (glUniform2iv)
2259 && FindProcShort (glUniform3iv)
2260 && FindProcShort (glUniform4iv)
2261 && FindProcShort (glUniformMatrix2fv)
2262 && FindProcShort (glUniformMatrix3fv)
2263 && FindProcShort (glUniformMatrix4fv)
2264 && FindProcShort (glValidateProgram)
2265 && FindProcShort (glVertexAttrib1d)
2266 && FindProcShort (glVertexAttrib1dv)
2267 && FindProcShort (glVertexAttrib1f)
2268 && FindProcShort (glVertexAttrib1fv)
2269 && FindProcShort (glVertexAttrib1s)
2270 && FindProcShort (glVertexAttrib1sv)
2271 && FindProcShort (glVertexAttrib2d)
2272 && FindProcShort (glVertexAttrib2dv)
2273 && FindProcShort (glVertexAttrib2f)
2274 && FindProcShort (glVertexAttrib2fv)
2275 && FindProcShort (glVertexAttrib2s)
2276 && FindProcShort (glVertexAttrib2sv)
2277 && FindProcShort (glVertexAttrib3d)
2278 && FindProcShort (glVertexAttrib3dv)
2279 && FindProcShort (glVertexAttrib3f)
2280 && FindProcShort (glVertexAttrib3fv)
2281 && FindProcShort (glVertexAttrib3s)
2282 && FindProcShort (glVertexAttrib3sv)
2283 && FindProcShort (glVertexAttrib4Nbv)
2284 && FindProcShort (glVertexAttrib4Niv)
2285 && FindProcShort (glVertexAttrib4Nsv)
2286 && FindProcShort (glVertexAttrib4Nub)
2287 && FindProcShort (glVertexAttrib4Nubv)
2288 && FindProcShort (glVertexAttrib4Nuiv)
2289 && FindProcShort (glVertexAttrib4Nusv)
2290 && FindProcShort (glVertexAttrib4bv)
2291 && FindProcShort (glVertexAttrib4d)
2292 && FindProcShort (glVertexAttrib4dv)
2293 && FindProcShort (glVertexAttrib4f)
2294 && FindProcShort (glVertexAttrib4fv)
2295 && FindProcShort (glVertexAttrib4iv)
2296 && FindProcShort (glVertexAttrib4s)
2297 && FindProcShort (glVertexAttrib4sv)
2298 && FindProcShort (glVertexAttrib4ubv)
2299 && FindProcShort (glVertexAttrib4uiv)
2300 && FindProcShort (glVertexAttrib4usv)
2301 && FindProcShort (glVertexAttribPointer);
2304 const char* aGlslVer = (const char* )::glGetString (GL_SHADING_LANGUAGE_VERSION);
2305 if (aGlslVer == NULL
2306 || *aGlslVer == '\0')
2308 // broken context has been detected
2309 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
2310 TCollection_AsciiString("Error! OpenGL context reports version ")
2311 + myGlVerMajor + "." + myGlVerMinor + " but reports wrong GLSL version");
2319 core20 = (OpenGl_GlCore20* )(&(*myFuncs));
2321 core20fwd = (OpenGl_GlCore20Fwd* )(&(*myFuncs));
2326 checkWrongVersion (2, 0, aLastFailedProc);
2329 // load OpenGL 2.1 new functions
2330 has21 = IsGlGreaterEqual (2, 1)
2331 && FindProcShort (glUniformMatrix2x3fv)
2332 && FindProcShort (glUniformMatrix3x2fv)
2333 && FindProcShort (glUniformMatrix2x4fv)
2334 && FindProcShort (glUniformMatrix4x2fv)
2335 && FindProcShort (glUniformMatrix3x4fv)
2336 && FindProcShort (glUniformMatrix4x3fv);
2339 checkWrongVersion (2, 1, aLastFailedProc);
2342 // load GL_ARB_framebuffer_object (added to OpenGL 3.0 core)
2343 const bool hasFBO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_framebuffer_object"))
2344 && FindProcShort (glIsRenderbuffer)
2345 && FindProcShort (glBindRenderbuffer)
2346 && FindProcShort (glDeleteRenderbuffers)
2347 && FindProcShort (glGenRenderbuffers)
2348 && FindProcShort (glRenderbufferStorage)
2349 && FindProcShort (glGetRenderbufferParameteriv)
2350 && FindProcShort (glIsFramebuffer)
2351 && FindProcShort (glBindFramebuffer)
2352 && FindProcShort (glDeleteFramebuffers)
2353 && FindProcShort (glGenFramebuffers)
2354 && FindProcShort (glCheckFramebufferStatus)
2355 && FindProcShort (glFramebufferTexture1D)
2356 && FindProcShort (glFramebufferTexture2D)
2357 && FindProcShort (glFramebufferTexture3D)
2358 && FindProcShort (glFramebufferRenderbuffer)
2359 && FindProcShort (glGetFramebufferAttachmentParameteriv)
2360 && FindProcShort (glGenerateMipmap)
2361 && FindProcShort (glBlitFramebuffer)
2362 && FindProcShort (glRenderbufferStorageMultisample)
2363 && FindProcShort (glFramebufferTextureLayer);
2365 // load GL_ARB_vertex_array_object (added to OpenGL 3.0 core)
2366 const bool hasVAO = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_vertex_array_object"))
2367 && FindProcShort (glBindVertexArray)
2368 && FindProcShort (glDeleteVertexArrays)
2369 && FindProcShort (glGenVertexArrays)
2370 && FindProcShort (glIsVertexArray);
2372 // load GL_ARB_map_buffer_range (added to OpenGL 3.0 core)
2373 const bool hasMapBufferRange = (IsGlGreaterEqual (3, 0) || CheckExtension ("GL_ARB_map_buffer_range"))
2374 && FindProcShort (glMapBufferRange)
2375 && FindProcShort (glFlushMappedBufferRange);
2377 // load OpenGL 3.0 new functions
2378 has30 = IsGlGreaterEqual (3, 0)
2381 && hasMapBufferRange
2382 && FindProcShort (glColorMaski)
2383 && FindProcShort (glGetBooleani_v)
2384 && FindProcShort (glGetIntegeri_v)
2385 && FindProcShort (glEnablei)
2386 && FindProcShort (glDisablei)
2387 && FindProcShort (glIsEnabledi)
2388 && FindProcShort (glBeginTransformFeedback)
2389 && FindProcShort (glEndTransformFeedback)
2390 && FindProcShort (glBindBufferRange)
2391 && FindProcShort (glBindBufferBase)
2392 && FindProcShort (glTransformFeedbackVaryings)
2393 && FindProcShort (glGetTransformFeedbackVarying)
2394 && FindProcShort (glClampColor)
2395 && FindProcShort (glBeginConditionalRender)
2396 && FindProcShort (glEndConditionalRender)
2397 && FindProcShort (glVertexAttribIPointer)
2398 && FindProcShort (glGetVertexAttribIiv)
2399 && FindProcShort (glGetVertexAttribIuiv)
2400 && FindProcShort (glVertexAttribI1i)
2401 && FindProcShort (glVertexAttribI2i)
2402 && FindProcShort (glVertexAttribI3i)
2403 && FindProcShort (glVertexAttribI4i)
2404 && FindProcShort (glVertexAttribI1ui)
2405 && FindProcShort (glVertexAttribI2ui)
2406 && FindProcShort (glVertexAttribI3ui)
2407 && FindProcShort (glVertexAttribI4ui)
2408 && FindProcShort (glVertexAttribI1iv)
2409 && FindProcShort (glVertexAttribI2iv)
2410 && FindProcShort (glVertexAttribI3iv)
2411 && FindProcShort (glVertexAttribI4iv)
2412 && FindProcShort (glVertexAttribI1uiv)
2413 && FindProcShort (glVertexAttribI2uiv)
2414 && FindProcShort (glVertexAttribI3uiv)
2415 && FindProcShort (glVertexAttribI4uiv)
2416 && FindProcShort (glVertexAttribI4bv)
2417 && FindProcShort (glVertexAttribI4sv)
2418 && FindProcShort (glVertexAttribI4ubv)
2419 && FindProcShort (glVertexAttribI4usv)
2420 && FindProcShort (glGetUniformuiv)
2421 && FindProcShort (glBindFragDataLocation)
2422 && FindProcShort (glGetFragDataLocation)
2423 && FindProcShort (glUniform1ui)
2424 && FindProcShort (glUniform2ui)
2425 && FindProcShort (glUniform3ui)
2426 && FindProcShort (glUniform4ui)
2427 && FindProcShort (glUniform1uiv)
2428 && FindProcShort (glUniform2uiv)
2429 && FindProcShort (glUniform3uiv)
2430 && FindProcShort (glUniform4uiv)
2431 && FindProcShort (glTexParameterIiv)
2432 && FindProcShort (glTexParameterIuiv)
2433 && FindProcShort (glGetTexParameterIiv)
2434 && FindProcShort (glGetTexParameterIuiv)
2435 && FindProcShort (glClearBufferiv)
2436 && FindProcShort (glClearBufferuiv)
2437 && FindProcShort (glClearBufferfv)
2438 && FindProcShort (glClearBufferfi)
2439 && FindProcShort (glGetStringi);
2442 checkWrongVersion (3, 0, aLastFailedProc);
2445 // load GL_ARB_uniform_buffer_object (added to OpenGL 3.1 core)
2446 const bool hasUBO = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_uniform_buffer_object"))
2447 && FindProcShort (glGetUniformIndices)
2448 && FindProcShort (glGetActiveUniformsiv)
2449 && FindProcShort (glGetActiveUniformName)
2450 && FindProcShort (glGetUniformBlockIndex)
2451 && FindProcShort (glGetActiveUniformBlockiv)
2452 && FindProcShort (glGetActiveUniformBlockName)
2453 && FindProcShort (glUniformBlockBinding);
2455 // load GL_ARB_copy_buffer (added to OpenGL 3.1 core)
2456 const bool hasCopyBufSubData = (IsGlGreaterEqual (3, 1) || CheckExtension ("GL_ARB_copy_buffer"))
2457 && FindProcShort (glCopyBufferSubData);
2461 // NPOT textures are required by OpenGL 2.0 specifications
2462 // but doesn't hardware accelerated by some ancient OpenGL 2.1 hardware (GeForce FX, RadeOn 9700 etc.)
2463 arbNPTW = Standard_True;
2464 arbTexRG = Standard_True;
2468 core30 = (OpenGl_GlCore30* )(&(*myFuncs));
2470 core30fwd = (OpenGl_GlCore30Fwd* )(&(*myFuncs));
2473 // load OpenGL 3.1 new functions
2474 has31 = IsGlGreaterEqual (3, 1)
2476 && hasCopyBufSubData
2477 && FindProcShort (glDrawArraysInstanced)
2478 && FindProcShort (glDrawElementsInstanced)
2479 && FindProcShort (glTexBuffer)
2480 && FindProcShort (glPrimitiveRestartIndex);
2483 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
2484 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
2488 checkWrongVersion (3, 1, aLastFailedProc);
2490 // initialize TBO extension (ARB)
2491 if (CheckExtension ("GL_ARB_texture_buffer_object")
2492 && FindProc ("glTexBufferARB", myFuncs->glTexBuffer))
2494 arbTBO = (OpenGl_ArbTBO* )(&(*myFuncs));
2497 // initialize hardware instancing extension (ARB)
2498 if (CheckExtension ("GL_ARB_draw_instanced")
2499 && FindProc ("glDrawArraysInstancedARB", myFuncs->glDrawArraysInstanced)
2500 && FindProc ("glDrawElementsInstancedARB", myFuncs->glDrawElementsInstanced))
2502 arbIns = (OpenGl_ArbIns* )(&(*myFuncs));
2506 arbTboRGB32 = CheckExtension ("GL_ARB_texture_buffer_object_rgb32");
2508 // load GL_ARB_draw_elements_base_vertex (added to OpenGL 3.2 core)
2509 const bool hasDrawElemsBaseVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_draw_elements_base_vertex"))
2510 && FindProcShort (glDrawElementsBaseVertex)
2511 && FindProcShort (glDrawRangeElementsBaseVertex)
2512 && FindProcShort (glDrawElementsInstancedBaseVertex)
2513 && FindProcShort (glMultiDrawElementsBaseVertex);
2515 // load GL_ARB_provoking_vertex (added to OpenGL 3.2 core)
2516 const bool hasProvokingVert = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_provoking_vertex"))
2517 && FindProcShort (glProvokingVertex);
2519 // load GL_ARB_sync (added to OpenGL 3.2 core)
2520 const bool hasSync = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_sync"))
2521 && FindProcShort (glFenceSync)
2522 && FindProcShort (glIsSync)
2523 && FindProcShort (glDeleteSync)
2524 && FindProcShort (glClientWaitSync)
2525 && FindProcShort (glWaitSync)
2526 && FindProcShort (glGetInteger64v)
2527 && FindProcShort (glGetSynciv);
2529 // load GL_ARB_texture_multisample (added to OpenGL 3.2 core)
2530 const bool hasTextureMultisample = (IsGlGreaterEqual (3, 2) || CheckExtension ("GL_ARB_texture_multisample"))
2531 && FindProcShort (glTexImage2DMultisample)
2532 && FindProcShort (glTexImage3DMultisample)
2533 && FindProcShort (glGetMultisamplefv)
2534 && FindProcShort (glSampleMaski);
2536 // load OpenGL 3.2 new functions
2537 has32 = IsGlGreaterEqual (3, 2)
2538 && hasDrawElemsBaseVert
2541 && hasTextureMultisample
2542 && FindProcShort (glGetInteger64i_v)
2543 && FindProcShort (glGetBufferParameteri64v)
2544 && FindProcShort (glFramebufferTexture);
2547 core32 = (OpenGl_GlCore32* )(&(*myFuncs));
2550 core32->glGenVertexArrays (1, &myDefaultVao);
2554 core32back = (OpenGl_GlCore32Back* )(&(*myFuncs));
2556 ::glGetIntegerv (GL_MAX_SAMPLES, &myMaxMsaaSamples);
2560 checkWrongVersion (3, 2, aLastFailedProc);
2563 // load GL_ARB_blend_func_extended (added to OpenGL 3.3 core)
2564 const bool hasBlendFuncExtended = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_blend_func_extended"))
2565 && FindProcShort (glBindFragDataLocationIndexed)
2566 && FindProcShort (glGetFragDataIndex);
2568 // load GL_ARB_sampler_objects (added to OpenGL 3.3 core)
2569 const bool hasSamplerObjects = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_sampler_objects"))
2570 && FindProcShort (glGenSamplers)
2571 && FindProcShort (glDeleteSamplers)
2572 && FindProcShort (glIsSampler)
2573 && FindProcShort (glBindSampler)
2574 && FindProcShort (glSamplerParameteri)
2575 && FindProcShort (glSamplerParameteriv)
2576 && FindProcShort (glSamplerParameterf)
2577 && FindProcShort (glSamplerParameterfv)
2578 && FindProcShort (glSamplerParameterIiv)
2579 && FindProcShort (glSamplerParameterIuiv)
2580 && FindProcShort (glGetSamplerParameteriv)
2581 && FindProcShort (glGetSamplerParameterIiv)
2582 && FindProcShort (glGetSamplerParameterfv)
2583 && FindProcShort (glGetSamplerParameterIuiv);
2584 if (hasSamplerObjects)
2586 arbSamplerObject = (OpenGl_ArbSamplerObject* )(&(*myFuncs));
2589 // load GL_ARB_timer_query (added to OpenGL 3.3 core)
2590 const bool hasTimerQuery = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_timer_query"))
2591 && FindProcShort (glQueryCounter)
2592 && FindProcShort (glGetQueryObjecti64v)
2593 && FindProcShort (glGetQueryObjectui64v);
2595 // load GL_ARB_vertex_type_2_10_10_10_rev (added to OpenGL 3.3 core)
2596 const bool hasVertType21010101rev = (IsGlGreaterEqual (3, 3) || CheckExtension ("GL_ARB_vertex_type_2_10_10_10_rev"))
2597 && FindProcShort (glVertexAttribP1ui)
2598 && FindProcShort (glVertexAttribP1uiv)
2599 && FindProcShort (glVertexAttribP2ui)
2600 && FindProcShort (glVertexAttribP2uiv)
2601 && FindProcShort (glVertexAttribP3ui)
2602 && FindProcShort (glVertexAttribP3uiv)
2603 && FindProcShort (glVertexAttribP4ui)
2604 && FindProcShort (glVertexAttribP4uiv);
2606 if ( hasVertType21010101rev
2609 // load deprecated functions
2610 const bool hasVertType21010101revExt =
2611 FindProcShort (glVertexP2ui)
2612 && FindProcShort (glVertexP2uiv)
2613 && FindProcShort (glVertexP3ui)
2614 && FindProcShort (glVertexP3uiv)
2615 && FindProcShort (glVertexP4ui)
2616 && FindProcShort (glVertexP4uiv)
2617 && FindProcShort (glTexCoordP1ui)
2618 && FindProcShort (glTexCoordP1uiv)
2619 && FindProcShort (glTexCoordP2ui)
2620 && FindProcShort (glTexCoordP2uiv)
2621 && FindProcShort (glTexCoordP3ui)
2622 && FindProcShort (glTexCoordP3uiv)
2623 && FindProcShort (glTexCoordP4ui)
2624 && FindProcShort (glTexCoordP4uiv)
2625 && FindProcShort (glMultiTexCoordP1ui)
2626 && FindProcShort (glMultiTexCoordP1uiv)
2627 && FindProcShort (glMultiTexCoordP2ui)
2628 && FindProcShort (glMultiTexCoordP2uiv)
2629 && FindProcShort (glMultiTexCoordP3ui)
2630 && FindProcShort (glMultiTexCoordP3uiv)
2631 && FindProcShort (glMultiTexCoordP4ui)
2632 && FindProcShort (glMultiTexCoordP4uiv)
2633 && FindProcShort (glNormalP3ui)
2634 && FindProcShort (glNormalP3uiv)
2635 && FindProcShort (glColorP3ui)
2636 && FindProcShort (glColorP3uiv)
2637 && FindProcShort (glColorP4ui)
2638 && FindProcShort (glColorP4uiv)
2639 && FindProcShort (glSecondaryColorP3ui)
2640 && FindProcShort (glSecondaryColorP3uiv);
2641 (void )hasVertType21010101revExt;
2644 // load OpenGL 3.3 extra functions
2645 has33 = IsGlGreaterEqual (3, 3)
2646 && hasBlendFuncExtended
2647 && hasSamplerObjects
2649 && hasVertType21010101rev
2650 && FindProcShort (glVertexAttribDivisor);
2653 core33 = (OpenGl_GlCore33* )(&(*myFuncs));
2656 core33back = (OpenGl_GlCore33Back* )(&(*myFuncs));
2661 checkWrongVersion (3, 3, aLastFailedProc);
2664 // load GL_ARB_draw_indirect (added to OpenGL 4.0 core)
2665 const bool hasDrawIndirect = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_draw_indirect"))
2666 && FindProcShort (glDrawArraysIndirect)
2667 && FindProcShort (glDrawElementsIndirect);
2669 // load GL_ARB_gpu_shader_fp64 (added to OpenGL 4.0 core)
2670 const bool hasShaderFP64 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_gpu_shader_fp64"))
2671 && FindProcShort (glUniform1d)
2672 && FindProcShort (glUniform2d)
2673 && FindProcShort (glUniform3d)
2674 && FindProcShort (glUniform4d)
2675 && FindProcShort (glUniform1dv)
2676 && FindProcShort (glUniform2dv)
2677 && FindProcShort (glUniform3dv)
2678 && FindProcShort (glUniform4dv)
2679 && FindProcShort (glUniformMatrix2dv)
2680 && FindProcShort (glUniformMatrix3dv)
2681 && FindProcShort (glUniformMatrix4dv)
2682 && FindProcShort (glUniformMatrix2x3dv)
2683 && FindProcShort (glUniformMatrix2x4dv)
2684 && FindProcShort (glUniformMatrix3x2dv)
2685 && FindProcShort (glUniformMatrix3x4dv)
2686 && FindProcShort (glUniformMatrix4x2dv)
2687 && FindProcShort (glUniformMatrix4x3dv)
2688 && FindProcShort (glGetUniformdv);
2690 // load GL_ARB_shader_subroutine (added to OpenGL 4.0 core)
2691 const bool hasShaderSubroutine = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_shader_subroutine"))
2692 && FindProcShort (glGetSubroutineUniformLocation)
2693 && FindProcShort (glGetSubroutineIndex)
2694 && FindProcShort (glGetActiveSubroutineUniformiv)
2695 && FindProcShort (glGetActiveSubroutineUniformName)
2696 && FindProcShort (glGetActiveSubroutineName)
2697 && FindProcShort (glUniformSubroutinesuiv)
2698 && FindProcShort (glGetUniformSubroutineuiv)
2699 && FindProcShort (glGetProgramStageiv);
2701 // load GL_ARB_tessellation_shader (added to OpenGL 4.0 core)
2702 const bool hasTessellationShader = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_tessellation_shader"))
2703 && FindProcShort (glPatchParameteri)
2704 && FindProcShort (glPatchParameterfv);
2706 // load GL_ARB_transform_feedback2 (added to OpenGL 4.0 core)
2707 const bool hasTrsfFeedback2 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback2"))
2708 && FindProcShort (glBindTransformFeedback)
2709 && FindProcShort (glDeleteTransformFeedbacks)
2710 && FindProcShort (glGenTransformFeedbacks)
2711 && FindProcShort (glIsTransformFeedback)
2712 && FindProcShort (glPauseTransformFeedback)
2713 && FindProcShort (glResumeTransformFeedback)
2714 && FindProcShort (glDrawTransformFeedback);
2716 // load GL_ARB_transform_feedback3 (added to OpenGL 4.0 core)
2717 const bool hasTrsfFeedback3 = (IsGlGreaterEqual (4, 0) || CheckExtension ("GL_ARB_transform_feedback3"))
2718 && FindProcShort (glDrawTransformFeedbackStream)
2719 && FindProcShort (glBeginQueryIndexed)
2720 && FindProcShort (glEndQueryIndexed)
2721 && FindProcShort (glGetQueryIndexediv);
2723 // load OpenGL 4.0 new functions
2724 has40 = IsGlGreaterEqual (4, 0)
2727 && hasShaderSubroutine
2728 && hasTessellationShader
2731 && FindProcShort (glMinSampleShading)
2732 && FindProcShort (glBlendEquationi)
2733 && FindProcShort (glBlendEquationSeparatei)
2734 && FindProcShort (glBlendFunci)
2735 && FindProcShort (glBlendFuncSeparatei);
2738 arbTboRGB32 = Standard_True; // in core since OpenGL 4.0
2742 checkWrongVersion (4, 0, aLastFailedProc);
2745 // load GL_ARB_ES2_compatibility (added to OpenGL 4.1 core)
2746 const bool hasES2Compatibility = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_ES2_compatibility"))
2747 && FindProcShort (glReleaseShaderCompiler)
2748 && FindProcShort (glShaderBinary)
2749 && FindProcShort (glGetShaderPrecisionFormat)
2750 && FindProcShort (glDepthRangef)
2751 && FindProcShort (glClearDepthf);
2753 // load GL_ARB_get_program_binary (added to OpenGL 4.1 core)
2754 const bool hasGetProgramBinary = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_get_program_binary"))
2755 && FindProcShort (glGetProgramBinary)
2756 && FindProcShort (glProgramBinary)
2757 && FindProcShort (glProgramParameteri);
2760 // load GL_ARB_separate_shader_objects (added to OpenGL 4.1 core)
2761 const bool hasSeparateShaderObjects = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_separate_shader_objects"))
2762 && FindProcShort (glUseProgramStages)
2763 && FindProcShort (glActiveShaderProgram)
2764 && FindProcShort (glCreateShaderProgramv)
2765 && FindProcShort (glBindProgramPipeline)
2766 && FindProcShort (glDeleteProgramPipelines)
2767 && FindProcShort (glGenProgramPipelines)
2768 && FindProcShort (glIsProgramPipeline)
2769 && FindProcShort (glGetProgramPipelineiv)
2770 && FindProcShort (glProgramUniform1i)
2771 && FindProcShort (glProgramUniform1iv)
2772 && FindProcShort (glProgramUniform1f)
2773 && FindProcShort (glProgramUniform1fv)
2774 && FindProcShort (glProgramUniform1d)
2775 && FindProcShort (glProgramUniform1dv)
2776 && FindProcShort (glProgramUniform1ui)
2777 && FindProcShort (glProgramUniform1uiv)
2778 && FindProcShort (glProgramUniform2i)
2779 && FindProcShort (glProgramUniform2iv)
2780 && FindProcShort (glProgramUniform2f)
2781 && FindProcShort (glProgramUniform2fv)
2782 && FindProcShort (glProgramUniform2d)
2783 && FindProcShort (glProgramUniform2dv)
2784 && FindProcShort (glProgramUniform2ui)
2785 && FindProcShort (glProgramUniform2uiv)
2786 && FindProcShort (glProgramUniform3i)
2787 && FindProcShort (glProgramUniform3iv)
2788 && FindProcShort (glProgramUniform3f)
2789 && FindProcShort (glProgramUniform3fv)
2790 && FindProcShort (glProgramUniform3d)
2791 && FindProcShort (glProgramUniform3dv)
2792 && FindProcShort (glProgramUniform3ui)
2793 && FindProcShort (glProgramUniform3uiv)
2794 && FindProcShort (glProgramUniform4i)
2795 && FindProcShort (glProgramUniform4iv)
2796 && FindProcShort (glProgramUniform4f)
2797 && FindProcShort (glProgramUniform4fv)
2798 && FindProcShort (glProgramUniform4d)
2799 && FindProcShort (glProgramUniform4dv)
2800 && FindProcShort (glProgramUniform4ui)
2801 && FindProcShort (glProgramUniform4uiv)
2802 && FindProcShort (glProgramUniformMatrix2fv)
2803 && FindProcShort (glProgramUniformMatrix3fv)
2804 && FindProcShort (glProgramUniformMatrix4fv)
2805 && FindProcShort (glProgramUniformMatrix2dv)
2806 && FindProcShort (glProgramUniformMatrix3dv)
2807 && FindProcShort (glProgramUniformMatrix4dv)
2808 && FindProcShort (glProgramUniformMatrix2x3fv)
2809 && FindProcShort (glProgramUniformMatrix3x2fv)
2810 && FindProcShort (glProgramUniformMatrix2x4fv)
2811 && FindProcShort (glProgramUniformMatrix4x2fv)
2812 && FindProcShort (glProgramUniformMatrix3x4fv)
2813 && FindProcShort (glProgramUniformMatrix4x3fv)
2814 && FindProcShort (glProgramUniformMatrix2x3dv)
2815 && FindProcShort (glProgramUniformMatrix3x2dv)
2816 && FindProcShort (glProgramUniformMatrix2x4dv)
2817 && FindProcShort (glProgramUniformMatrix4x2dv)
2818 && FindProcShort (glProgramUniformMatrix3x4dv)
2819 && FindProcShort (glProgramUniformMatrix4x3dv)
2820 && FindProcShort (glValidateProgramPipeline)
2821 && FindProcShort (glGetProgramPipelineInfoLog);
2823 // load GL_ARB_vertex_attrib_64bit (added to OpenGL 4.1 core)
2824 const bool hasVertAttrib64bit = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_vertex_attrib_64bit"))
2825 && FindProcShort (glVertexAttribL1d)
2826 && FindProcShort (glVertexAttribL2d)
2827 && FindProcShort (glVertexAttribL3d)
2828 && FindProcShort (glVertexAttribL4d)
2829 && FindProcShort (glVertexAttribL1dv)
2830 && FindProcShort (glVertexAttribL2dv)
2831 && FindProcShort (glVertexAttribL3dv)
2832 && FindProcShort (glVertexAttribL4dv)
2833 && FindProcShort (glVertexAttribLPointer)
2834 && FindProcShort (glGetVertexAttribLdv);
2836 // load GL_ARB_viewport_array (added to OpenGL 4.1 core)
2837 const bool hasViewportArray = (IsGlGreaterEqual (4, 1) || CheckExtension ("GL_ARB_viewport_array"))
2838 && FindProcShort (glViewportArrayv)
2839 && FindProcShort (glViewportIndexedf)
2840 && FindProcShort (glViewportIndexedfv)
2841 && FindProcShort (glScissorArrayv)
2842 && FindProcShort (glScissorIndexed)
2843 && FindProcShort (glScissorIndexedv)
2844 && FindProcShort (glDepthRangeArrayv)
2845 && FindProcShort (glDepthRangeIndexed)
2846 && FindProcShort (glGetFloati_v)
2847 && FindProcShort (glGetDoublei_v);
2849 has41 = IsGlGreaterEqual (4, 1)
2850 && hasES2Compatibility
2851 && hasGetProgramBinary
2852 && hasSeparateShaderObjects
2853 && hasVertAttrib64bit
2854 && hasViewportArray;
2857 core41 = (OpenGl_GlCore41* )(&(*myFuncs));
2860 core41back = (OpenGl_GlCore41Back* )(&(*myFuncs));
2865 checkWrongVersion (4, 1, aLastFailedProc);
2868 // load GL_ARB_base_instance (added to OpenGL 4.2 core)
2869 const bool hasBaseInstance = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_base_instance"))
2870 && FindProcShort (glDrawArraysInstancedBaseInstance)
2871 && FindProcShort (glDrawElementsInstancedBaseInstance)
2872 && FindProcShort (glDrawElementsInstancedBaseVertexBaseInstance);
2874 // load GL_ARB_transform_feedback_instanced (added to OpenGL 4.2 core)
2875 const bool hasTrsfFeedbackInstanced = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_transform_feedback_instanced"))
2876 && FindProcShort (glDrawTransformFeedbackInstanced)
2877 && FindProcShort (glDrawTransformFeedbackStreamInstanced);
2879 // load GL_ARB_internalformat_query (added to OpenGL 4.2 core)
2880 const bool hasInternalFormatQuery = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_internalformat_query"))
2881 && FindProcShort (glGetInternalformativ);
2883 // load GL_ARB_shader_atomic_counters (added to OpenGL 4.2 core)
2884 const bool hasShaderAtomicCounters = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_atomic_counters"))
2885 && FindProcShort (glGetActiveAtomicCounterBufferiv);
2887 // load GL_ARB_shader_image_load_store (added to OpenGL 4.2 core)
2888 const bool hasShaderImgLoadStore = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_shader_image_load_store"))
2889 && FindProcShort (glBindImageTexture)
2890 && FindProcShort (glMemoryBarrier);
2892 // load GL_ARB_texture_storage (added to OpenGL 4.2 core)
2893 const bool hasTextureStorage = (IsGlGreaterEqual (4, 2) || CheckExtension ("GL_ARB_texture_storage"))
2894 && FindProcShort (glTexStorage1D)
2895 && FindProcShort (glTexStorage2D)
2896 && FindProcShort (glTexStorage3D);
2898 has42 = IsGlGreaterEqual (4, 2)
2900 && hasTrsfFeedbackInstanced
2901 && hasInternalFormatQuery
2902 && hasShaderAtomicCounters
2903 && hasShaderImgLoadStore
2904 && hasTextureStorage;
2907 core42 = (OpenGl_GlCore42* )(&(*myFuncs));
2910 core42back = (OpenGl_GlCore42Back* )(&(*myFuncs));
2915 checkWrongVersion (4, 2, aLastFailedProc);
2918 has43 = IsGlGreaterEqual (4, 3)
2919 && FindProcShort (glClearBufferData)
2920 && FindProcShort (glClearBufferSubData)
2921 && FindProcShort (glDispatchCompute)
2922 && FindProcShort (glDispatchComputeIndirect)
2923 && FindProcShort (glCopyImageSubData)
2924 && FindProcShort (glFramebufferParameteri)
2925 && FindProcShort (glGetFramebufferParameteriv)
2926 && FindProcShort (glGetInternalformati64v)
2927 && FindProcShort (glInvalidateTexSubImage)
2928 && FindProcShort (glInvalidateTexImage)
2929 && FindProcShort (glInvalidateBufferSubData)
2930 && FindProcShort (glInvalidateBufferData)
2931 && FindProcShort (glInvalidateFramebuffer)
2932 && FindProcShort (glInvalidateSubFramebuffer)
2933 && FindProcShort (glMultiDrawArraysIndirect)
2934 && FindProcShort (glMultiDrawElementsIndirect)
2935 && FindProcShort (glGetProgramInterfaceiv)
2936 && FindProcShort (glGetProgramResourceIndex)
2937 && FindProcShort (glGetProgramResourceName)
2938 && FindProcShort (glGetProgramResourceiv)
2939 && FindProcShort (glGetProgramResourceLocation)
2940 && FindProcShort (glGetProgramResourceLocationIndex)
2941 && FindProcShort (glShaderStorageBlockBinding)
2942 && FindProcShort (glTexBufferRange)
2943 && FindProcShort (glTexStorage2DMultisample)
2944 && FindProcShort (glTexStorage3DMultisample)
2945 && FindProcShort (glTextureView)
2946 && FindProcShort (glBindVertexBuffer)
2947 && FindProcShort (glVertexAttribFormat)
2948 && FindProcShort (glVertexAttribIFormat)
2949 && FindProcShort (glVertexAttribLFormat)
2950 && FindProcShort (glVertexAttribBinding)
2951 && FindProcShort (glVertexBindingDivisor)
2952 && FindProcShort (glDebugMessageControl)
2953 && FindProcShort (glDebugMessageInsert)
2954 && FindProcShort (glDebugMessageCallback)
2955 && FindProcShort (glGetDebugMessageLog)
2956 && FindProcShort (glPushDebugGroup)
2957 && FindProcShort (glPopDebugGroup)
2958 && FindProcShort (glObjectLabel)
2959 && FindProcShort (glGetObjectLabel)
2960 && FindProcShort (glObjectPtrLabel)
2961 && FindProcShort (glGetObjectPtrLabel);
2964 core43 = (OpenGl_GlCore43* )(&(*myFuncs));
2967 core43back = (OpenGl_GlCore43Back* )(&(*myFuncs));
2972 checkWrongVersion (4, 3, aLastFailedProc);
2975 // load GL_ARB_clear_texture (added to OpenGL 4.4 core)
2976 bool arbTexClear = (IsGlGreaterEqual (4, 4) || CheckExtension ("GL_ARB_clear_texture"))
2977 && FindProcShort (glClearTexImage)
2978 && FindProcShort (glClearTexSubImage);
2980 has44 = IsGlGreaterEqual (4, 4)
2982 && FindProcShort (glBufferStorage)
2983 && FindProcShort (glBindBuffersBase)
2984 && FindProcShort (glBindBuffersRange)
2985 && FindProcShort (glBindTextures)
2986 && FindProcShort (glBindSamplers)
2987 && FindProcShort (glBindImageTextures)
2988 && FindProcShort (glBindVertexBuffers);
2991 core44 = (OpenGl_GlCore44* )(&(*myFuncs));
2994 core44back = (OpenGl_GlCore44Back* )(&(*myFuncs));
2999 checkWrongVersion (4, 4, aLastFailedProc);
3002 has45 = IsGlGreaterEqual (4, 5)
3003 && FindProcShort (glBindVertexBuffers)
3004 && FindProcShort (glClipControl)
3005 && FindProcShort (glCreateTransformFeedbacks)
3006 && FindProcShort (glTransformFeedbackBufferBase)
3007 && FindProcShort (glTransformFeedbackBufferRange)
3008 && FindProcShort (glGetTransformFeedbackiv)
3009 && FindProcShort (glGetTransformFeedbacki_v)
3010 && FindProcShort (glGetTransformFeedbacki64_v)
3011 && FindProcShort (glCreateBuffers)
3012 && FindProcShort (glNamedBufferStorage)
3013 && FindProcShort (glNamedBufferData)
3014 && FindProcShort (glNamedBufferSubData)
3015 && FindProcShort (glCopyNamedBufferSubData)
3016 && FindProcShort (glClearNamedBufferData)
3017 && FindProcShort (glClearNamedBufferSubData)
3018 && FindProcShort (glMapNamedBuffer)
3019 && FindProcShort (glMapNamedBufferRange)
3020 && FindProcShort (glUnmapNamedBuffer)
3021 && FindProcShort (glFlushMappedNamedBufferRange)
3022 && FindProcShort (glGetNamedBufferParameteriv)
3023 && FindProcShort (glGetNamedBufferParameteri64v)
3024 && FindProcShort (glGetNamedBufferPointerv)
3025 && FindProcShort (glGetNamedBufferSubData)
3026 && FindProcShort (glCreateFramebuffers)
3027 && FindProcShort (glNamedFramebufferRenderbuffer)
3028 && FindProcShort (glNamedFramebufferParameteri)
3029 && FindProcShort (glNamedFramebufferTexture)
3030 && FindProcShort (glNamedFramebufferTextureLayer)
3031 && FindProcShort (glNamedFramebufferDrawBuffer)
3032 && FindProcShort (glNamedFramebufferDrawBuffers)
3033 && FindProcShort (glNamedFramebufferReadBuffer)
3034 && FindProcShort (glInvalidateNamedFramebufferData)
3035 && FindProcShort (glInvalidateNamedFramebufferSubData)
3036 && FindProcShort (glClearNamedFramebufferiv)
3037 && FindProcShort (glClearNamedFramebufferuiv)
3038 && FindProcShort (glClearNamedFramebufferfv)
3039 && FindProcShort (glClearNamedFramebufferfi)
3040 && FindProcShort (glBlitNamedFramebuffer)
3041 && FindProcShort (glCheckNamedFramebufferStatus)
3042 && FindProcShort (glGetNamedFramebufferParameteriv)
3043 && FindProcShort (glGetNamedFramebufferAttachmentParameteriv)
3044 && FindProcShort (glCreateRenderbuffers)
3045 && FindProcShort (glNamedRenderbufferStorage)
3046 && FindProcShort (glNamedRenderbufferStorageMultisample)
3047 && FindProcShort (glGetNamedRenderbufferParameteriv)
3048 && FindProcShort (glCreateTextures)
3049 && FindProcShort (glTextureBuffer)
3050 && FindProcShort (glTextureBufferRange)
3051 && FindProcShort (glTextureStorage1D)
3052 && FindProcShort (glTextureStorage2D)
3053 && FindProcShort (glTextureStorage3D)
3054 && FindProcShort (glTextureStorage2DMultisample)
3055 && FindProcShort (glTextureStorage3DMultisample)
3056 && FindProcShort (glTextureSubImage1D)
3057 && FindProcShort (glTextureSubImage2D)
3058 && FindProcShort (glTextureSubImage3D)
3059 && FindProcShort (glCompressedTextureSubImage1D)
3060 && FindProcShort (glCompressedTextureSubImage2D)
3061 && FindProcShort (glCompressedTextureSubImage3D)
3062 && FindProcShort (glCopyTextureSubImage1D)
3063 && FindProcShort (glCopyTextureSubImage2D)
3064 && FindProcShort (glCopyTextureSubImage3D)
3065 && FindProcShort (glTextureParameterf)
3066 && FindProcShort (glTextureParameterfv)
3067 && FindProcShort (glTextureParameteri)
3068 && FindProcShort (glTextureParameterIiv)
3069 && FindProcShort (glTextureParameterIuiv)
3070 && FindProcShort (glTextureParameteriv)
3071 && FindProcShort (glGenerateTextureMipmap)
3072 && FindProcShort (glBindTextureUnit)
3073 && FindProcShort (glGetTextureImage)
3074 && FindProcShort (glGetCompressedTextureImage)
3075 && FindProcShort (glGetTextureLevelParameterfv)
3076 && FindProcShort (glGetTextureLevelParameteriv)
3077 && FindProcShort (glGetTextureParameterfv)
3078 && FindProcShort (glGetTextureParameterIiv)
3079 && FindProcShort (glGetTextureParameterIuiv)
3080 && FindProcShort (glGetTextureParameteriv)
3081 && FindProcShort (glCreateVertexArrays)
3082 && FindProcShort (glDisableVertexArrayAttrib)
3083 && FindProcShort (glEnableVertexArrayAttrib)
3084 && FindProcShort (glVertexArrayElementBuffer)
3085 && FindProcShort (glVertexArrayVertexBuffer)
3086 && FindProcShort (glVertexArrayVertexBuffers)
3087 && FindProcShort (glVertexArrayAttribBinding)
3088 && FindProcShort (glVertexArrayAttribFormat)
3089 && FindProcShort (glVertexArrayAttribIFormat)
3090 && FindProcShort (glVertexArrayAttribLFormat)
3091 && FindProcShort (glVertexArrayBindingDivisor)
3092 && FindProcShort (glGetVertexArrayiv)
3093 && FindProcShort (glGetVertexArrayIndexediv)
3094 && FindProcShort (glGetVertexArrayIndexed64iv)
3095 && FindProcShort (glCreateSamplers)
3096 && FindProcShort (glCreateProgramPipelines)
3097 && FindProcShort (glCreateQueries)
3098 && FindProcShort (glGetQueryBufferObjecti64v)
3099 && FindProcShort (glGetQueryBufferObjectiv)
3100 && FindProcShort (glGetQueryBufferObjectui64v)
3101 && FindProcShort (glGetQueryBufferObjectuiv)
3102 && FindProcShort (glMemoryBarrierByRegion)
3103 && FindProcShort (glGetTextureSubImage)
3104 && FindProcShort (glGetCompressedTextureSubImage)
3105 && FindProcShort (glGetGraphicsResetStatus)
3106 && FindProcShort (glGetnCompressedTexImage)
3107 && FindProcShort (glGetnTexImage)
3108 && FindProcShort (glGetnUniformdv)
3109 && FindProcShort (glGetnUniformfv)
3110 && FindProcShort (glGetnUniformiv)
3111 && FindProcShort (glGetnUniformuiv)
3112 && FindProcShort (glReadnPixels)
3113 && FindProcShort (glGetnMapdv)
3114 && FindProcShort (glGetnMapfv)
3115 && FindProcShort (glGetnMapiv)
3116 && FindProcShort (glGetnPixelMapfv)
3117 && FindProcShort (glGetnPixelMapuiv)
3118 && FindProcShort (glGetnPixelMapusv)
3119 && FindProcShort (glGetnPolygonStipple)
3120 && FindProcShort (glGetnColorTable)
3121 && FindProcShort (glGetnConvolutionFilter)
3122 && FindProcShort (glGetnSeparableFilter)
3123 && FindProcShort (glGetnHistogram)
3124 && FindProcShort (glGetnMinmax)
3125 && FindProcShort (glTextureBarrier);
3128 core45 = (OpenGl_GlCore45* )(&(*myFuncs));
3131 core45back = (OpenGl_GlCore45Back* )(&(*myFuncs));
3136 checkWrongVersion (4, 5, aLastFailedProc);
3139 // initialize debug context extension
3140 if (CheckExtension ("GL_ARB_debug_output"))
3145 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
3147 else if (FindProc ("glDebugMessageControlARB", myFuncs->glDebugMessageControl)
3148 && FindProc ("glDebugMessageInsertARB", myFuncs->glDebugMessageInsert)
3149 && FindProc ("glDebugMessageCallbackARB", myFuncs->glDebugMessageCallback)
3150 && FindProc ("glGetDebugMessageLogARB", myFuncs->glGetDebugMessageLog))
3152 arbDbg = (OpenGl_ArbDbg* )(&(*myFuncs));
3156 && caps->contextDebug)
3158 // setup default callback
3159 myIsGlDebugCtx = Standard_True;
3160 arbDbg->glDebugMessageCallback (debugCallbackWrap, this);
3163 ::glEnable (GL_DEBUG_OUTPUT);
3165 if (caps->contextSyncDebug)
3167 ::glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
3172 // initialize FBO extension (ARB)
3175 arbFBO = (OpenGl_ArbFBO* )(&(*myFuncs));
3176 arbFBOBlit = (OpenGl_ArbFBOBlit* )(&(*myFuncs));
3177 extPDS = Standard_True; // extension for EXT, but part of ARB
3180 // initialize GS extension (EXT)
3181 if (CheckExtension ("GL_EXT_geometry_shader4")
3182 && FindProcShort (glProgramParameteriEXT))
3184 extGS = (OpenGl_ExtGS* )(&(*myFuncs));
3187 // initialize bindless texture extension (ARB)
3188 if (CheckExtension ("GL_ARB_bindless_texture")
3189 && FindProcShort (glGetTextureHandleARB)
3190 && FindProcShort (glGetTextureSamplerHandleARB)
3191 && FindProcShort (glMakeTextureHandleResidentARB)
3192 && FindProcShort (glMakeTextureHandleNonResidentARB)
3193 && FindProcShort (glGetImageHandleARB)
3194 && FindProcShort (glMakeImageHandleResidentARB)
3195 && FindProcShort (glMakeImageHandleNonResidentARB)
3196 && FindProcShort (glUniformHandleui64ARB)
3197 && FindProcShort (glUniformHandleui64vARB)
3198 && FindProcShort (glProgramUniformHandleui64ARB)
3199 && FindProcShort (glProgramUniformHandleui64vARB)
3200 && FindProcShort (glIsTextureHandleResidentARB)
3201 && FindProcShort (glIsImageHandleResidentARB)
3202 && FindProcShort (glVertexAttribL1ui64ARB)
3203 && FindProcShort (glVertexAttribL1ui64vARB)
3204 && FindProcShort (glGetVertexAttribLui64vARB))
3206 arbTexBindless = (OpenGl_ArbTexBindless* )(&(*myFuncs));
3211 // MSAA RenderBuffers have been defined in OpenGL 3.0,
3212 // but MSAA Textures - only in OpenGL 3.2+
3214 && CheckExtension ("GL_ARB_texture_multisample")
3215 && FindProcShort (glTexImage2DMultisample))
3217 GLint aNbColorSamples = 0, aNbDepthSamples = 0;
3218 ::glGetIntegerv (GL_MAX_COLOR_TEXTURE_SAMPLES, &aNbColorSamples);
3219 ::glGetIntegerv (GL_MAX_DEPTH_TEXTURE_SAMPLES, &aNbDepthSamples);
3220 myMaxMsaaSamples = Min (aNbColorSamples, aNbDepthSamples);
3223 && CheckExtension ("GL_ARB_texture_storage_multisample")
3224 && FindProcShort (glTexStorage2DMultisample))
3230 // check whether ray tracing mode is supported
3231 myHasRayTracing = has31
3233 && arbFBOBlit != NULL;
3235 // check whether textures in ray tracing mode are supported
3236 myHasRayTracingTextures = myHasRayTracing
3237 && arbTexBindless != NULL;
3239 // check whether adaptive screen sampling in ray tracing mode is supported
3240 myHasRayTracingAdaptiveSampling = myHasRayTracing
3242 myHasRayTracingAdaptiveSamplingAtomic = myHasRayTracingAdaptiveSampling
3243 && CheckExtension ("GL_NV_shader_atomic_float");
3249 // Detect if window buffer is considered by OpenGL as sRGB-ready
3250 // (linear RGB color written by shader is automatically converted into sRGB)
3251 // or not (offscreen FBO should be blit into window buffer with gamma correction).
3252 const GLenum aDefWinBuffer =
3253 #if !defined(GL_ES_VERSION_2_0)
3258 GLint aWinColorEncoding = 0; // GL_LINEAR
3259 arbFBO->glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER, aDefWinBuffer, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &aWinColorEncoding);
3261 myIsSRgbWindow = aWinColorEncoding == GL_SRGB;
3263 // On desktop OpenGL, pixel formats are almost always sRGB-ready, even when not requested;
3264 // it is safe behavior on desktop where GL_FRAMEBUFFER_SRGB is disabled by default
3265 // (contrary to OpenGL ES, where it is enabled by default).
3266 // NVIDIA drivers, however, always return GL_LINEAR even for sRGB-ready pixel formats on Windows platform,
3267 // while AMD and Intel report GL_SRGB as expected.
3268 // macOS drivers seems to be also report GL_LINEAR even for [NSColorSpace sRGBColorSpace].
3269 #if !defined(GL_ES_VERSION_2_0)
3271 myIsSRgbWindow = true;
3274 && myVendor.Search ("nvidia") != -1)
3276 myIsSRgbWindow = true;
3280 if (!myIsSRgbWindow)
3282 Message::SendTrace ("OpenGl_Context, warning: window buffer is not sRGB-ready.\n"
3283 "Check OpenGL window creation parameters for optimal performance.");
3289 mySupportedFormats->Add (Image_Format_GrayF);
3290 mySupportedFormats->Add (Image_Format_AlphaF);
3291 mySupportedFormats->Add (Image_Format_RGBF);
3292 mySupportedFormats->Add (Image_Format_RGBAF);
3295 mySupportedFormats->Add (Image_Format_RGF);
3299 #if !defined(GL_ES_VERSION_2_0)
3300 mySupportedFormats->Add (Image_Format_BGRF);
3302 mySupportedFormats->Add (Image_Format_BGRAF);
3306 #ifdef __EMSCRIPTEN__
3307 if (checkEnableWebGlExtension (*this, "GL_WEBGL_compressed_texture_s3tc")) // GL_WEBGL_compressed_texture_s3tc_srgb for sRGB formats
3309 mySupportedFormats->Add (Image_CompressedFormat_RGB_S3TC_DXT1);
3310 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT1);
3311 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT3);
3312 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT5);
3315 if (CheckExtension ("GL_EXT_texture_compression_s3tc")) // GL_EXT_texture_sRGB for sRGB formats
3317 mySupportedFormats->Add (Image_CompressedFormat_RGB_S3TC_DXT1);
3318 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT1);
3319 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT3);
3320 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT5);
3324 if (CheckExtension ("GL_EXT_texture_compression_dxt1"))
3326 mySupportedFormats->Add (Image_CompressedFormat_RGB_S3TC_DXT1);
3327 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT1);
3329 if (CheckExtension ("GL_ANGLE_texture_compression_dxt3"))
3331 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT3);
3333 if (CheckExtension ("GL_ANGLE_texture_compression_dxt5"))
3335 mySupportedFormats->Add (Image_CompressedFormat_RGBA_S3TC_DXT5);
3340 // check whether PBR shading model is supported
3341 myHasPBR = arbFBO != NULL
3342 && myMaxTexCombined >= 4
3345 && (IsGlGreaterEqual (3, 0)
3346 #if !defined(GL_ES_VERSION_2_0)
3347 || (IsGlGreaterEqual (2, 1) && CheckExtension ("GL_EXT_gpu_shader4"))
3352 myPBREnvLUTTexUnit = static_cast<Graphic3d_TextureUnit>(myMaxTexCombined + Graphic3d_TextureUnit_PbrEnvironmentLUT);
3353 myPBRDiffIBLMapSHTexUnit = static_cast<Graphic3d_TextureUnit>(myMaxTexCombined + Graphic3d_TextureUnit_PbrIblDiffuseSH);
3354 myPBRSpecIBLMapTexUnit = static_cast<Graphic3d_TextureUnit>(myMaxTexCombined + Graphic3d_TextureUnit_PbrIblSpecular);
3358 // =======================================================================
3359 // function : MemoryInfo
3361 // =======================================================================
3362 Standard_Size OpenGl_Context::AvailableMemory() const
3364 #if !defined(GL_ES_VERSION_2_0)
3367 // this is actually information for VBO pool
3368 // however because pools are mostly shared
3369 // it can be used for total GPU memory estimations
3372 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo);
3373 // returned value is in KiB, however this maybe changed in future
3374 return Standard_Size(aMemInfo[0]) * 1024;
3378 // current available dedicated video memory (in KiB), currently unused GPU memory
3380 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo);
3381 return Standard_Size(aMemInfo) * 1024;
3387 // =======================================================================
3388 // function : MemoryInfo
3390 // =======================================================================
3391 TCollection_AsciiString OpenGl_Context::MemoryInfo() const
3393 TColStd_IndexedDataMapOfStringString aDict;
3396 TCollection_AsciiString aText;
3397 for (TColStd_IndexedDataMapOfStringString::Iterator anIter (aDict); anIter.More(); anIter.Next())
3399 if (!aText.IsEmpty())
3403 aText += TCollection_AsciiString(" ") + anIter.Key() + ": " + anIter.Value();
3408 // =======================================================================
3409 // function : MemoryInfo
3411 // =======================================================================
3412 void OpenGl_Context::MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict) const
3414 #if defined(GL_ES_VERSION_2_0)
3416 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
3417 GLint aGlRendId = 0;
3418 CGLGetParameter (CGLGetCurrentContext(), kCGLCPCurrentRendererID, &aGlRendId);
3420 CGLRendererInfoObj aRendObj = NULL;
3421 CGOpenGLDisplayMask aDispMask = CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay);
3423 CGLQueryRendererInfo (aDispMask, &aRendObj, &aRendNb);
3424 for (GLint aRendIter = 0; aRendIter < aRendNb; ++aRendIter)
3427 if (CGLDescribeRenderer (aRendObj, aRendIter, kCGLRPRendererID, &aRendId) != kCGLNoError
3428 || aRendId != aGlRendId)
3433 //kCGLRPVideoMemoryMegabytes = 131;
3434 //kCGLRPTextureMemoryMegabytes = 132;
3436 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
3437 if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemoryMegabytes, &aVMem) == kCGLNoError)
3439 addInfo (theDict, "GPU memory", TCollection_AsciiString() + aVMem + " MiB");
3441 if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemoryMegabytes, &aVMem) == kCGLNoError)
3443 addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + aVMem + " MiB");
3446 if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPVideoMemory, &aVMem) == kCGLNoError)
3448 addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB");
3450 if (CGLDescribeRenderer(aRendObj, aRendIter, kCGLRPTextureMemory, &aVMem) == kCGLNoError)
3452 addInfo (theDict, "GPU Texture memory", TCollection_AsciiString() + (aVMem / (1024 * 1024)) + " MiB");
3458 #if !defined(GL_ES_VERSION_2_0)
3462 memset (aValues, 0, sizeof(aValues));
3463 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues);
3465 // total memory free in the pool
3466 addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValues[0] / 1024) + " MiB");
3468 if (aValues[1] != aValues[0])
3470 // largest available free block in the pool
3471 addInfo (theDict, "Largest free block", TCollection_AsciiString() + (aValues[1] / 1024) + " MiB");
3473 if (aValues[2] != aValues[0])
3475 // total auxiliary memory free
3476 addInfo (theDict, "Free auxiliary memory", TCollection_AsciiString() + (aValues[2] / 1024) + " MiB");
3481 //current available dedicated video memory (in KiB), currently unused GPU memory
3483 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue);
3484 addInfo (theDict, "GPU free memory", TCollection_AsciiString() + (aValue / 1024) + " MiB");
3486 // dedicated video memory, total size (in KiB) of the GPU memory
3487 GLint aDedicated = 0;
3488 glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated);
3489 addInfo (theDict, "GPU memory", TCollection_AsciiString() + (aDedicated / 1024) + " MiB");
3491 // total available memory, total size (in KiB) of the memory available for allocations
3492 glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue);
3493 if (aValue != aDedicated)
3495 // different only for special configurations
3496 addInfo (theDict, "Total memory", TCollection_AsciiString() + (aValue / 1024) + " MiB");
3500 else if (myFuncs->wglGetGPUInfoAMD != NULL
3501 && myFuncs->wglGetContextGPUIDAMD != NULL)
3503 GLuint aTotalMemMiB = 0;
3504 UINT anAmdId = myFuncs->wglGetContextGPUIDAMD ((HGLRC )myGContext);
3507 if (myFuncs->wglGetGPUInfoAMD (anAmdId, WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(aTotalMemMiB), &aTotalMemMiB) > 0)
3509 addInfo (theDict, "GPU memory", TCollection_AsciiString() + (int )aTotalMemMiB + " MiB");
3516 #if !defined(GL_ES_VERSION_2_0) && !defined(__APPLE__) && !defined(_WIN32)
3517 // GLX_RENDERER_VENDOR_ID_MESA
3518 if (myFuncs->glXQueryCurrentRendererIntegerMESA != NULL)
3520 unsigned int aVMemMiB = 0;
3521 if (myFuncs->glXQueryCurrentRendererIntegerMESA (GLX_RENDERER_VIDEO_MEMORY_MESA, &aVMemMiB) != False)
3523 addInfo (theDict, "GPU memory", TCollection_AsciiString() + int(aVMemMiB) + " MiB");
3529 // =======================================================================
3530 // function : DiagnosticInfo
3532 // =======================================================================
3533 void OpenGl_Context::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
3534 Graphic3d_DiagnosticInfo theFlags) const
3536 if ((theFlags & Graphic3d_DiagnosticInfo_NativePlatform) != 0)
3538 #if defined(HAVE_EGL)
3539 addInfo (theDict, "EGLVersion", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VERSION));
3540 addInfo (theDict, "EGLVendor", ::eglQueryString ((EGLDisplay )myDisplay, EGL_VENDOR));
3541 addInfo (theDict, "EGLClientAPIs", ::eglQueryString ((EGLDisplay )myDisplay, EGL_CLIENT_APIS));
3542 if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
3544 addInfo (theDict, "EGLExtensions", ::eglQueryString ((EGLDisplay )myDisplay, EGL_EXTENSIONS));
3546 #elif defined(_WIN32)
3547 if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0
3548 && myFuncs->wglGetExtensionsStringARB != NULL)
3550 const char* aWglExts = myFuncs->wglGetExtensionsStringARB ((HDC )myWindowDC);
3551 addInfo (theDict, "WGLExtensions", aWglExts);
3553 #elif defined(__APPLE__)
3556 Display* aDisplay = (Display*)myDisplay;
3557 const int aScreen = DefaultScreen(aDisplay);
3558 addInfo (theDict, "GLXDirectRendering", ::glXIsDirect (aDisplay, (GLXContext )myGContext) ? "Yes" : "No");
3559 addInfo (theDict, "GLXVendor", ::glXQueryServerString (aDisplay, aScreen, GLX_VENDOR));
3560 addInfo (theDict, "GLXVersion", ::glXQueryServerString (aDisplay, aScreen, GLX_VERSION));
3561 if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
3563 const char* aGlxExts = ::glXQueryExtensionsString (aDisplay, aScreen);
3564 addInfo(theDict, "GLXExtensions", aGlxExts);
3567 addInfo (theDict, "GLXClientVendor", ::glXGetClientString (aDisplay, GLX_VENDOR));
3568 addInfo (theDict, "GLXClientVersion", ::glXGetClientString (aDisplay, GLX_VERSION));
3569 if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
3571 addInfo (theDict, "GLXClientExtensions", ::glXGetClientString (aDisplay, GLX_EXTENSIONS));
3576 if ((theFlags & Graphic3d_DiagnosticInfo_Device) != 0)
3578 Standard_Integer aDriverVer[2] = {};
3579 ReadGlVersion (aDriverVer[0], aDriverVer[1]);
3580 addInfo (theDict, "GLvendor", (const char*)::glGetString (GL_VENDOR));
3581 addInfo (theDict, "GLdevice", (const char*)::glGetString (GL_RENDERER));
3582 #ifdef __EMSCRIPTEN__
3583 if (checkEnableWebGlExtension (*this, "GL_WEBGL_debug_renderer_info"))
3585 if (const char* aVendor = (const char*)::glGetString (0x9245))
3587 addInfo (theDict, "GLunmaskedVendor", aVendor);
3589 if (const char* aDevice = (const char*)::glGetString (0x9246))
3591 addInfo (theDict, "GLunmaskedDevice", aDevice);
3596 addInfo (theDict, "GLversion", (const char*)::glGetString (GL_VERSION));
3597 if (myGlVerMajor != aDriverVer[0]
3598 || myGlVerMinor != aDriverVer[1])
3600 addInfo (theDict, "GLversionOcct", TCollection_AsciiString (myGlVerMajor) + "." + TCollection_AsciiString (myGlVerMinor));
3602 if (IsGlGreaterEqual (2, 0))
3604 addInfo (theDict, "GLSLversion", (const char*)::glGetString (GL_SHADING_LANGUAGE_VERSION));
3608 addInfo (theDict, "GLdebug", "ON");
3612 if ((theFlags & Graphic3d_DiagnosticInfo_Limits) != 0)
3614 addInfo (theDict, "Max texture size", TCollection_AsciiString(myMaxTexDim));
3615 addInfo (theDict, "Max FBO dump size", TCollection_AsciiString() + myMaxDumpSizeX + "x" + myMaxDumpSizeY);
3616 addInfo (theDict, "Max combined texture units", TCollection_AsciiString(myMaxTexCombined));
3617 addInfo (theDict, "Max MSAA samples", TCollection_AsciiString(myMaxMsaaSamples));
3620 if ((theFlags & Graphic3d_DiagnosticInfo_FrameBuffer) != 0)
3622 GLint aViewport[4] = {};
3623 ::glGetIntegerv (GL_VIEWPORT, aViewport);
3624 addInfo (theDict, "Viewport", TCollection_AsciiString() + aViewport[2] + "x" + aViewport[3]);
3627 if ((theFlags & Graphic3d_DiagnosticInfo_Memory) != 0)
3629 MemoryInfo (theDict);
3632 if ((theFlags & Graphic3d_DiagnosticInfo_Extensions) != 0)
3634 #if !defined(GL_ES_VERSION_2_0)
3635 if (IsGlGreaterEqual (3, 0)
3636 && myFuncs->glGetStringi != NULL)
3638 TCollection_AsciiString anExtList;
3640 ::glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
3641 for (GLint anIter = 0; anIter < anExtNb; ++anIter)
3643 const char* anExtension = (const char*)myFuncs->glGetStringi (GL_EXTENSIONS, (GLuint)anIter);
3644 if (!anExtList.IsEmpty())
3648 anExtList += anExtension;
3650 addInfo(theDict, "GLextensions", anExtList);
3655 addInfo (theDict, "GLextensions", (const char*)::glGetString (GL_EXTENSIONS));
3660 // =======================================================================
3661 // function : GetResource
3663 // =======================================================================
3664 const Handle(OpenGl_Resource)& OpenGl_Context::GetResource (const TCollection_AsciiString& theKey) const
3666 return mySharedResources->IsBound (theKey) ? mySharedResources->Find (theKey) : NULL_GL_RESOURCE;
3669 // =======================================================================
3670 // function : ShareResource
3672 // =======================================================================
3673 Standard_Boolean OpenGl_Context::ShareResource (const TCollection_AsciiString& theKey,
3674 const Handle(OpenGl_Resource)& theResource)
3676 if (theKey.IsEmpty() || theResource.IsNull())
3678 return Standard_False;
3680 return mySharedResources->Bind (theKey, theResource);
3683 // =======================================================================
3684 // function : ReleaseResource
3686 // =======================================================================
3687 void OpenGl_Context::ReleaseResource (const TCollection_AsciiString& theKey,
3688 const Standard_Boolean theToDelay)
3690 if (!mySharedResources->IsBound (theKey))
3694 const Handle(OpenGl_Resource)& aRes = mySharedResources->Find (theKey);
3695 if (aRes->GetRefCount() > 1)
3702 myDelayed->Bind (theKey, 1);
3706 aRes->Release (this);
3707 mySharedResources->UnBind (theKey);
3711 // =======================================================================
3712 // function : ReleaseDelayed
3714 // =======================================================================
3715 void OpenGl_Context::ReleaseDelayed()
3717 // release queued elements
3718 while (!myUnusedResources->IsEmpty())
3720 myUnusedResources->First()->Release (this);
3721 myUnusedResources->RemoveFirst();
3724 // release delayed shared resources
3725 NCollection_Vector<TCollection_AsciiString> aDeadList;
3726 for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed);
3727 anIter.More(); anIter.Next())
3729 if (++anIter.ChangeValue() <= 2)
3731 continue; // postpone release one more frame to ensure noone use it periodically
3734 const TCollection_AsciiString& aKey = anIter.Key();
3735 if (!mySharedResources->IsBound (aKey))
3737 // mixed unshared strategy delayed/undelayed was used!
3738 aDeadList.Append (aKey);
3742 const Handle(OpenGl_Resource)& aRes = mySharedResources->ChangeFind (aKey);
3743 if (aRes->GetRefCount() > 1)
3745 // should be only 1 instance in mySharedResources
3746 // if not - resource was reused again
3747 aDeadList.Append (aKey);
3751 // release resource if no one requiested it more than 2 redraw calls
3752 aRes->Release (this);
3753 mySharedResources->UnBind (aKey);
3754 aDeadList.Append (aKey);
3757 for (Standard_Integer anIter = 0; anIter < aDeadList.Length(); ++anIter)
3759 myDelayed->UnBind (aDeadList.Value (anIter));
3763 // =======================================================================
3764 // function : BindTextures
3766 // =======================================================================
3767 Handle(OpenGl_TextureSet) OpenGl_Context::BindTextures (const Handle(OpenGl_TextureSet)& theTextures,
3768 const Handle(OpenGl_ShaderProgram)& theProgram)
3770 const Standard_Integer aTextureSetBits = !theTextures.IsNull() ? theTextures->TextureSetBits() : 0;
3771 const Standard_Integer aProgramBits = !theProgram.IsNull() ? theProgram->TextureSetBits() : 0;
3772 Standard_Integer aMissingBits = aProgramBits & ~aTextureSetBits;
3773 if (aMissingBits != 0
3774 && myTextureRgbaBlack.IsNull())
3776 // allocate mock textures
3777 myTextureRgbaBlack = new OpenGl_Texture();
3778 myTextureRgbaWhite = new OpenGl_Texture();
3779 Image_PixMap anImage;
3780 anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )0);
3781 if (!myTextureRgbaBlack->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TOT_2D, &anImage))
3783 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
3784 "Error: unable to create unit mock PBR texture map.");
3786 anImage.InitZero (Image_Format_RGBA, 2, 2, 0, (Standard_Byte )255);
3787 if (!myTextureRgbaWhite->Init (this, OpenGl_TextureFormat::Create<GLubyte, 4>(), Graphic3d_Vec2i (2, 2), Graphic3d_TOT_2D, &anImage))
3789 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PORTABILITY, 0, GL_DEBUG_SEVERITY_HIGH,
3790 "Error: unable to create normal mock PBR texture map.");
3794 Handle(OpenGl_TextureSet) anOldTextures = myActiveTextures;
3795 if (myActiveTextures != theTextures)
3797 Handle(OpenGl_Context) aThisCtx (this);
3798 for (OpenGl_TextureSetPairIterator aSlotIter (myActiveTextures, theTextures); aSlotIter.More(); aSlotIter.Next())
3800 const Graphic3d_TextureUnit aTexUnit = aSlotIter.Unit();
3801 const OpenGl_Texture* aTextureOld = aSlotIter.Texture1();
3802 const OpenGl_Texture* aTextureNew = aSlotIter.Texture2();
3803 if (aTextureNew == aTextureOld)
3808 if (aTextureNew != NULL
3809 && aTextureNew->IsValid())
3811 if (aTexUnit >= myMaxTexCombined)
3813 PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR, 0, GL_DEBUG_SEVERITY_HIGH,
3814 TCollection_AsciiString("Texture unit ") + aTexUnit + " for " + aTextureNew->ResourceId() + " exceeds hardware limit " + myMaxTexCombined);
3818 aTextureNew->Bind (aThisCtx, aTexUnit);
3819 if (aTextureNew->Sampler()->ToUpdateParameters())
3821 if (aTextureNew->Sampler()->IsImmutable())
3823 aTextureNew->Sampler()->Init (aThisCtx, *aTextureNew);
3827 OpenGl_Sampler::applySamplerParams (aThisCtx, aTextureNew->Sampler()->Parameters(), aTextureNew->Sampler().get(), aTextureNew->GetTarget(), aTextureNew->MaxMipmapLevel());
3830 #if !defined(GL_ES_VERSION_2_0)
3833 OpenGl_Sampler::applyGlobalTextureParams (aThisCtx, *aTextureNew, aTextureNew->Sampler()->Parameters());
3837 else if (aTextureOld != NULL
3838 && aTextureOld->IsValid())
3840 aTextureOld->Unbind (aThisCtx, aTexUnit);
3841 #if !defined(GL_ES_VERSION_2_0)
3844 OpenGl_Sampler::resetGlobalTextureParams (aThisCtx, *aTextureOld, aTextureOld->Sampler()->Parameters());
3849 myActiveTextures = theTextures;
3852 if (myActiveMockTextures != aMissingBits)
3854 myActiveMockTextures = aMissingBits;
3855 for (Standard_Integer aBitIter = 0; aMissingBits != 0; ++aBitIter)
3857 Standard_Integer aUnitMask = 1 << aBitIter;
3858 if ((aUnitMask & aMissingBits) != 0)
3860 aMissingBits = aMissingBits & ~aUnitMask;
3861 if (aBitIter == Graphic3d_TextureUnit_Normal)
3863 myTextureRgbaBlack->Bind (this, static_cast<Graphic3d_TextureUnit>(aBitIter));
3867 myTextureRgbaWhite->Bind (this, static_cast<Graphic3d_TextureUnit>(aBitIter));
3873 return anOldTextures;
3876 // =======================================================================
3877 // function : BindProgram
3879 // =======================================================================
3880 Standard_Boolean OpenGl_Context::BindProgram (const Handle(OpenGl_ShaderProgram)& theProgram)
3882 if (core20fwd == NULL)
3884 return Standard_False;
3886 else if (myActiveProgram == theProgram)
3888 return Standard_True;
3891 if (theProgram.IsNull()
3892 || !theProgram->IsValid())
3894 if (!myActiveProgram.IsNull())
3896 core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM);
3897 myActiveProgram.Nullify();
3899 return Standard_False;
3902 myActiveProgram = theProgram;
3903 core20fwd->glUseProgram (theProgram->ProgramId());
3904 return Standard_True;
3907 // =======================================================================
3908 // function : BindDefaultVao
3910 // =======================================================================
3911 void OpenGl_Context::BindDefaultVao()
3913 #if !defined(GL_ES_VERSION_2_0)
3914 if (myDefaultVao == 0
3920 core32->glBindVertexArray (myDefaultVao);
3924 // =======================================================================
3925 // function : SetDefaultFrameBuffer
3927 // =======================================================================
3928 Handle(OpenGl_FrameBuffer) OpenGl_Context::SetDefaultFrameBuffer (const Handle(OpenGl_FrameBuffer)& theFbo)
3930 Handle(OpenGl_FrameBuffer) aFbo = myDefaultFbo;
3931 myDefaultFbo = theFbo;
3935 // =======================================================================
3936 // function : SetShadingMaterial
3938 // =======================================================================
3939 void OpenGl_Context::SetShadingMaterial (const OpenGl_Aspects* theAspect,
3940 const Handle(Graphic3d_PresentationAttributes)& theHighlight)
3942 const Handle(Graphic3d_Aspects)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
3943 ? (const Handle(Graphic3d_Aspects)& )theHighlight->BasicFillAreaAspect()
3944 : theAspect->Aspect();
3946 const bool toDistinguish = anAspect->Distinguish();
3947 const bool toMapTexture = anAspect->ToMapTexture();
3948 const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial();
3949 const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish
3950 ? anAspect->BackMaterial()
3952 const Quantity_Color& aFrontIntColor = anAspect->InteriorColor();
3953 const Quantity_Color& aBackIntColor = toDistinguish
3954 ? anAspect->BackInteriorColor()
3957 myMatFront.Init (*this, aMatFrontSrc, aFrontIntColor);
3960 myMatBack.Init (*this, aMatBackSrc, aBackIntColor);
3964 myMatBack = myMatFront;
3967 if (!theHighlight.IsNull()
3968 && theHighlight->BasicFillAreaAspect().IsNull())
3970 myMatFront.SetColor (theHighlight->ColorRGBA());
3971 myMatBack .SetColor (theHighlight->ColorRGBA());
3974 Standard_ShortReal anAlphaFront = 1.0f;
3975 Standard_ShortReal anAlphaBack = 1.0f;
3976 if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack))
3978 myMatFront.Common.Diffuse.a() = anAlphaFront;
3979 myMatBack .Common.Diffuse.a() = anAlphaBack;
3981 myMatFront.Pbr.BaseColor.a() = anAlphaFront;
3982 myMatBack .Pbr.BaseColor.a() = anAlphaBack;
3985 // do not update material properties in case of zero reflection mode,
3986 // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway.
3987 const OpenGl_MaterialState& aMatState = myShaderManager->MaterialState();
3988 float anAlphaCutoff = anAspect->AlphaMode() == Graphic3d_AlphaMode_Mask
3989 ? anAspect->AlphaCutoff()
3991 if (anAspect->ToDrawEdges())
3993 if (anAspect->InteriorStyle() == Aspect_IS_EMPTY
3994 || (anAspect->InteriorStyle() == Aspect_IS_SOLID
3995 && anAspect->EdgeColorRGBA().Alpha() < 1.0f))
3997 anAlphaCutoff = 0.285f;
4000 if (theAspect->ShadingModel() == Graphic3d_TOSM_UNLIT)
4002 if (anAlphaCutoff == aMatState.AlphaCutoff())
4007 else if (myMatFront == aMatState.FrontMaterial()
4008 && myMatBack == aMatState.BackMaterial()
4009 && toDistinguish == aMatState.ToDistinguish()
4010 && toMapTexture == aMatState.ToMapTexture()
4011 && anAlphaCutoff == aMatState.AlphaCutoff())
4016 myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, anAlphaCutoff, toDistinguish, toMapTexture);
4019 // =======================================================================
4020 // function : CheckIsTransparent
4022 // =======================================================================
4023 Standard_Boolean OpenGl_Context::CheckIsTransparent (const OpenGl_Aspects* theAspect,
4024 const Handle(Graphic3d_PresentationAttributes)& theHighlight,
4025 Standard_ShortReal& theAlphaFront,
4026 Standard_ShortReal& theAlphaBack)
4028 const Handle(Graphic3d_Aspects)& anAspect = (!theHighlight.IsNull() && !theHighlight->BasicFillAreaAspect().IsNull())
4029 ? (const Handle(Graphic3d_Aspects)& )theHighlight->BasicFillAreaAspect()
4030 : theAspect->Aspect();
4032 const bool toDistinguish = anAspect->Distinguish();
4033 const Graphic3d_MaterialAspect& aMatFrontSrc = anAspect->FrontMaterial();
4034 const Graphic3d_MaterialAspect& aMatBackSrc = toDistinguish
4035 ? anAspect->BackMaterial()
4038 // handling transparency
4039 if (!theHighlight.IsNull()
4040 && theHighlight->BasicFillAreaAspect().IsNull())
4042 theAlphaFront = theHighlight->ColorRGBA().Alpha();
4043 theAlphaBack = theHighlight->ColorRGBA().Alpha();
4047 theAlphaFront = aMatFrontSrc.Alpha();
4048 theAlphaBack = aMatBackSrc .Alpha();
4051 if (anAspect->AlphaMode() == Graphic3d_AlphaMode_BlendAuto)
4053 return theAlphaFront < 1.0f
4054 || theAlphaBack < 1.0f;
4056 return anAspect->AlphaMode() == Graphic3d_AlphaMode_Blend;
4059 // =======================================================================
4060 // function : SetColor4fv
4062 // =======================================================================
4063 void OpenGl_Context::SetColor4fv (const OpenGl_Vec4& theColor)
4065 if (!myActiveProgram.IsNull())
4067 if (const OpenGl_ShaderUniformLocation& aLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_COLOR))
4069 myActiveProgram->SetUniform (this, aLoc, Vec4FromQuantityColor (theColor));
4072 #if !defined(GL_ES_VERSION_2_0)
4073 else if (core11 != NULL)
4075 core11->glColor4fv (theColor.GetData());
4080 // =======================================================================
4081 // function : SetTypeOfLine
4083 // =======================================================================
4084 void OpenGl_Context::SetTypeOfLine (const Aspect_TypeOfLine theType,
4085 const Standard_ShortReal theFactor)
4087 SetLineStipple (theFactor, Graphic3d_Aspects::DefaultLinePatternForType (theType));
4090 // =======================================================================
4091 // function : SetLineStipple
4093 // =======================================================================
4094 void OpenGl_Context::SetLineStipple (const Standard_ShortReal theFactor,
4095 const uint16_t thePattern)
4097 if (!myActiveProgram.IsNull())
4099 if (const OpenGl_ShaderUniformLocation aPatternLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_LINE_STIPPLE_PATTERN))
4101 if (hasGlslBitwiseOps != OpenGl_FeatureNotAvailable)
4103 myActiveProgram->SetUniform (this, aPatternLoc, (Standard_Integer )thePattern);
4107 Standard_Integer aPatArr[16] = {};
4108 for (unsigned int aBit = 0; aBit < 16; ++aBit)
4110 aPatArr[aBit] = ((unsigned int)(thePattern) & (1U << aBit)) != 0 ? 1 : 0;
4112 myActiveProgram->SetUniform (this, aPatternLoc, 16, aPatArr);
4114 myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_LINE_STIPPLE_FACTOR), theFactor);
4119 #if !defined(GL_ES_VERSION_2_0)
4120 if (thePattern != 0xFFFF)
4124 core11fwd->glEnable (GL_LINE_STIPPLE);
4126 core11->glLineStipple (static_cast<GLint> (theFactor),
4127 static_cast<GLushort> (thePattern));
4134 core11fwd->glDisable (GL_LINE_STIPPLE);
4140 // =======================================================================
4141 // function : SetLineWidth
4143 // =======================================================================
4144 void OpenGl_Context::SetLineWidth (const Standard_ShortReal theWidth)
4148 // glLineWidth() is still defined within Core Profile, but has no effect with values != 1.0f
4149 core11fwd->glLineWidth (theWidth * myLineWidthScale);
4153 // =======================================================================
4154 // function : SetTextureMatrix
4156 // =======================================================================
4157 void OpenGl_Context::SetTextureMatrix (const Handle(Graphic3d_TextureParams)& theParams,
4158 const Standard_Boolean theIsTopDown)
4160 if (theParams.IsNull())
4165 const Graphic3d_Vec2& aScale = theParams->Scale();
4166 const Graphic3d_Vec2& aTrans = theParams->Translation();
4167 if (!myActiveProgram.IsNull())
4169 const GLint aUniLoc = myActiveProgram->GetStateLocation (OpenGl_OCCT_TEXTURE_TRSF2D);
4170 if (aUniLoc == OpenGl_ShaderProgram::INVALID_LOCATION)
4175 // pack transformation parameters
4176 OpenGl_Vec4 aTrsf[2] =
4178 OpenGl_Vec4 (-aTrans.x(), -aTrans.y(), aScale.x(), aScale.y()),
4179 OpenGl_Vec4 (static_cast<float> (std::sin (-theParams->Rotation() * M_PI / 180.0)),
4180 static_cast<float> (std::cos (-theParams->Rotation() * M_PI / 180.0)),
4183 if (caps->isTopDownTextureUV != theIsTopDown)
4186 aTrsf[0].y() = -aTrans.y() + 1.0f / aScale.y();
4187 aTrsf[0].w() = -aScale.y();
4189 myActiveProgram->SetUniform (this, aUniLoc, 2, aTrsf);
4193 #if !defined(GL_ES_VERSION_2_0)
4196 GLint aMatrixMode = GL_TEXTURE;
4197 ::glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
4199 core11->glMatrixMode (GL_TEXTURE);
4200 OpenGl_Mat4 aTextureMat;
4201 if (caps->isTopDownTextureUV != theIsTopDown)
4204 Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), -aScale.y(), 1.0f);
4205 Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y() + 1.0f / aScale.y(), 0.0f);
4209 Graphic3d_TransformUtils::Scale (aTextureMat, aScale.x(), aScale.y(), 1.0f);
4210 Graphic3d_TransformUtils::Translate (aTextureMat, -aTrans.x(), -aTrans.y(), 0.0f);
4212 Graphic3d_TransformUtils::Rotate (aTextureMat, -theParams->Rotation(), 0.0f, 0.0f, 1.0f);
4213 core11->glLoadMatrixf (aTextureMat);
4214 core11->glMatrixMode (aMatrixMode);
4219 // =======================================================================
4220 // function : SetPointSize
4222 // =======================================================================
4223 void OpenGl_Context::SetPointSize (const Standard_ShortReal theSize)
4225 if (!myActiveProgram.IsNull())
4227 myActiveProgram->SetUniform (this, myActiveProgram->GetStateLocation (OpenGl_OCCT_POINT_SIZE), theSize);
4228 #if !defined(GL_ES_VERSION_2_0)
4229 //myContext->core11fwd->glEnable (GL_VERTEX_PROGRAM_POINT_SIZE);
4232 #if !defined(GL_ES_VERSION_2_0)
4235 core11fwd->glPointSize (theSize);
4236 if (core20fwd != NULL)
4238 //myContext->core11fwd->glDisable (GL_VERTEX_PROGRAM_POINT_SIZE);
4244 // =======================================================================
4245 // function : SetPointSpriteOrigin
4247 // =======================================================================
4248 void OpenGl_Context::SetPointSpriteOrigin()
4250 #if !defined(GL_ES_VERSION_2_0)
4251 if (core15fwd == NULL)
4256 const int aNewState = !myActiveProgram.IsNull() ? GL_UPPER_LEFT : GL_LOWER_LEFT;
4257 if (myPointSpriteOrig != aNewState)
4259 myPointSpriteOrig = aNewState;
4260 core15fwd->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, aNewState);
4265 // =======================================================================
4266 // function : SetGlNormalizeEnabled
4268 // =======================================================================
4269 Standard_Boolean OpenGl_Context::SetGlNormalizeEnabled (Standard_Boolean isEnabled)
4271 if (isEnabled == myIsGlNormalizeEnabled)
4273 return myIsGlNormalizeEnabled;
4276 Standard_Boolean anOldGlNormalize = myIsGlNormalizeEnabled;
4278 myIsGlNormalizeEnabled = isEnabled;
4280 #if !defined(GL_ES_VERSION_2_0)
4285 ::glEnable (GL_NORMALIZE);
4289 ::glDisable (GL_NORMALIZE);
4294 return anOldGlNormalize;
4297 // =======================================================================
4298 // function : SetShadeModel
4300 // =======================================================================
4301 void OpenGl_Context::SetShadeModel (Graphic3d_TypeOfShadingModel theModel)
4303 #if !defined(GL_ES_VERSION_2_0)
4306 const Standard_Integer aModel = theModel == Graphic3d_TOSM_FACET
4307 || theModel == Graphic3d_TOSM_PBR_FACET ? GL_FLAT : GL_SMOOTH;
4308 if (myShadeModel == aModel)
4312 myShadeModel = aModel;
4313 core11->glShadeModel (aModel);
4320 // =======================================================================
4321 // function : SetPolygonMode
4323 // =======================================================================
4324 Standard_Integer OpenGl_Context::SetPolygonMode (const Standard_Integer theMode)
4326 if (myPolygonMode == theMode)
4328 return myPolygonMode;
4331 const Standard_Integer anOldPolygonMode = myPolygonMode;
4333 myPolygonMode = theMode;
4335 #if !defined(GL_ES_VERSION_2_0)
4336 ::glPolygonMode (GL_FRONT_AND_BACK, (GLenum)theMode);
4339 return anOldPolygonMode;
4342 // =======================================================================
4343 // function : SetPolygonHatchEnabled
4345 // =======================================================================
4346 bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
4352 else if (myHatchIsEnabled == theIsEnabled)
4354 return theIsEnabled;
4357 const bool anOldIsEnabled = myHatchIsEnabled;
4358 #if !defined(GL_ES_VERSION_2_0)
4360 && myActiveHatchType != Aspect_HS_SOLID)
4362 core11fwd->glEnable (GL_POLYGON_STIPPLE);
4366 core11fwd->glDisable (GL_POLYGON_STIPPLE);
4369 myHatchIsEnabled = theIsEnabled;
4370 return anOldIsEnabled;
4373 // =======================================================================
4374 // function : SetPolygonHatchStyle
4376 // =======================================================================
4377 Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle)
4379 const Standard_Integer aNewStyle = !theStyle.IsNull() ? theStyle->HatchType() : Aspect_HS_SOLID;
4380 if (myActiveHatchType == aNewStyle
4383 return myActiveHatchType;
4386 #if !defined(GL_ES_VERSION_2_0)
4387 if (aNewStyle == Aspect_HS_SOLID)
4389 if (myHatchIsEnabled)
4391 core11fwd->glDisable (GL_POLYGON_STIPPLE);
4393 return myActiveHatchType;
4396 if (myHatchStyles.IsNull()
4397 && !GetResource ("OpenGl_LineAttributes", myHatchStyles))
4399 // share and register for release once the resource is no longer used
4400 myHatchStyles = new OpenGl_LineAttributes();
4401 ShareResource ("OpenGl_LineAttributes", myHatchStyles);
4404 const Standard_Integer anOldType = myActiveHatchType;
4405 myActiveHatchType = aNewStyle;
4406 myHatchStyles->SetTypeOfHatch (this, theStyle);
4407 if (myHatchIsEnabled
4408 && anOldType == Aspect_HS_SOLID)
4410 core11fwd->glEnable (GL_POLYGON_STIPPLE);
4414 return myActiveHatchType;
4418 // =======================================================================
4419 // function : SetPolygonOffset
4421 // =======================================================================
4422 void OpenGl_Context::SetPolygonOffset (const Graphic3d_PolygonOffset& theOffset)
4424 const bool toFillOld = (myPolygonOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
4425 const bool toFillNew = (theOffset.Mode & Aspect_POM_Fill) == Aspect_POM_Fill;
4426 if (toFillNew != toFillOld)
4430 glEnable (GL_POLYGON_OFFSET_FILL);
4434 glDisable (GL_POLYGON_OFFSET_FILL);
4438 #if !defined(GL_ES_VERSION_2_0)
4439 const bool toLineOld = (myPolygonOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
4440 const bool toLineNew = (theOffset.Mode & Aspect_POM_Line) == Aspect_POM_Line;
4441 if (toLineNew != toLineOld)
4445 glEnable (GL_POLYGON_OFFSET_LINE);
4449 glDisable (GL_POLYGON_OFFSET_LINE);
4453 const bool toPointOld = (myPolygonOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
4454 const bool toPointNew = (theOffset.Mode & Aspect_POM_Point) == Aspect_POM_Point;
4455 if (toPointNew != toPointOld)
4459 glEnable (GL_POLYGON_OFFSET_POINT);
4463 glDisable (GL_POLYGON_OFFSET_POINT);
4468 if (myPolygonOffset.Factor != theOffset.Factor
4469 || myPolygonOffset.Units != theOffset.Units)
4471 glPolygonOffset (theOffset.Factor, theOffset.Units);
4473 myPolygonOffset = theOffset;
4476 // =======================================================================
4477 // function : SetCamera
4479 // =======================================================================
4480 void OpenGl_Context::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
4482 myCamera = theCamera;
4483 if (!theCamera.IsNull())
4485 ProjectionState.SetCurrent (theCamera->ProjectionMatrixF());
4486 WorldViewState .SetCurrent (theCamera->OrientationMatrixF());
4487 ApplyProjectionMatrix();
4488 ApplyWorldViewMatrix();
4492 // =======================================================================
4493 // function : ApplyModelWorldMatrix
4495 // =======================================================================
4496 void OpenGl_Context::ApplyModelWorldMatrix()
4498 if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current())
4500 myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
4504 // =======================================================================
4505 // function : ApplyWorldViewMatrix
4507 // =======================================================================
4508 void OpenGl_Context::ApplyWorldViewMatrix()
4510 if (myShaderManager->ModelWorldState().ModelWorldMatrix() != THE_IDENTITY_MATRIX)
4512 myShaderManager->UpdateModelWorldStateTo (THE_IDENTITY_MATRIX);
4514 if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current())
4516 myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
4520 // =======================================================================
4521 // function : ApplyModelViewMatrix
4523 // =======================================================================
4524 void OpenGl_Context::ApplyModelViewMatrix()
4526 if (myShaderManager->ModelWorldState().ModelWorldMatrix() != ModelWorldState.Current())
4528 myShaderManager->UpdateModelWorldStateTo (ModelWorldState.Current());
4530 if (myShaderManager->WorldViewState().WorldViewMatrix() != WorldViewState.Current())
4532 myShaderManager->UpdateWorldViewStateTo (WorldViewState.Current());
4536 // =======================================================================
4537 // function : ApplyProjectionMatrix
4539 // =======================================================================
4540 void OpenGl_Context::ApplyProjectionMatrix()
4542 if (myShaderManager->ProjectionState().ProjectionMatrix() != ProjectionState.Current())
4544 myShaderManager->UpdateProjectionStateTo (ProjectionState.Current());
4548 // =======================================================================
4549 // function : EnableFeatures
4551 // =======================================================================
4552 void OpenGl_Context::EnableFeatures() const
4557 // =======================================================================
4558 // function : DisableFeatures
4560 // =======================================================================
4561 void OpenGl_Context::DisableFeatures() const
4563 // Disable stuff that's likely to slow down glDrawPixels.
4564 glDisable(GL_DITHER);
4565 glDisable(GL_BLEND);
4566 glDisable(GL_DEPTH_TEST);
4567 glDisable(GL_STENCIL_TEST);
4569 #if !defined(GL_ES_VERSION_2_0)
4575 glDisable(GL_TEXTURE_1D);
4576 glDisable(GL_TEXTURE_2D);
4578 glDisable(GL_LIGHTING);
4579 glDisable(GL_ALPHA_TEST);
4581 glDisable(GL_LOGIC_OP);
4583 glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
4584 glPixelTransferi(GL_RED_SCALE, 1);
4585 glPixelTransferi(GL_RED_BIAS, 0);
4586 glPixelTransferi(GL_GREEN_SCALE, 1);
4587 glPixelTransferi(GL_GREEN_BIAS, 0);
4588 glPixelTransferi(GL_BLUE_SCALE, 1);
4589 glPixelTransferi(GL_BLUE_BIAS, 0);
4590 glPixelTransferi(GL_ALPHA_SCALE, 1);
4591 glPixelTransferi(GL_ALPHA_BIAS, 0);
4593 if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2))
4595 if (CheckExtension ("GL_CONVOLUTION_1D_EXT"))
4596 glDisable(GL_CONVOLUTION_1D_EXT);
4598 if (CheckExtension ("GL_CONVOLUTION_2D_EXT"))
4599 glDisable(GL_CONVOLUTION_2D_EXT);
4601 if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
4602 glDisable(GL_SEPARABLE_2D_EXT);
4604 if (CheckExtension ("GL_SEPARABLE_2D_EXT"))
4605 glDisable(GL_HISTOGRAM_EXT);
4607 if (CheckExtension ("GL_MINMAX_EXT"))
4608 glDisable(GL_MINMAX_EXT);
4610 if (CheckExtension ("GL_TEXTURE_3D_EXT"))
4611 glDisable(GL_TEXTURE_3D_EXT);
4616 // =======================================================================
4617 // function : SetColorMaskRGBA
4619 // =======================================================================
4620 void OpenGl_Context::SetColorMaskRGBA (const NCollection_Vec4<bool>& theVal)
4622 glColorMask (theVal.r() ? GL_TRUE : GL_FALSE,
4623 theVal.g() ? GL_TRUE : GL_FALSE,
4624 theVal.b() ? GL_TRUE : GL_FALSE,
4625 theVal.a() ? GL_TRUE : GL_FALSE);
4626 myColorMask = theVal;
4629 // =======================================================================
4630 // function : SetColorMask
4632 // =======================================================================
4633 bool OpenGl_Context::SetColorMask (bool theToWriteColor)
4635 const bool anOldValue = myColorMask.r();
4636 myColorMask.SetValues (theToWriteColor, theToWriteColor, theToWriteColor, caps->buffersOpaqueAlpha ? false : theToWriteColor);
4637 const GLboolean toWrite = theToWriteColor ? GL_TRUE : GL_FALSE;
4638 glColorMask (toWrite, toWrite, toWrite, myColorMask.a() ? GL_TRUE : GL_FALSE);
4642 // =======================================================================
4643 // function : SetSampleAlphaToCoverage
4645 // =======================================================================
4646 bool OpenGl_Context::SetSampleAlphaToCoverage (bool theToEnable)
4648 bool toEnable = myAllowAlphaToCov && theToEnable;
4649 if (myAlphaToCoverage == toEnable)
4651 return myAlphaToCoverage;
4654 if (core15fwd != NULL)
4658 //core15fwd->core15fwd->glSampleCoverage (1.0f, GL_FALSE);
4659 core15fwd->glEnable (GL_SAMPLE_ALPHA_TO_COVERAGE);
4663 core15fwd->glDisable (GL_SAMPLE_ALPHA_TO_COVERAGE);
4667 const bool anOldValue = myAlphaToCoverage;
4668 myAlphaToCoverage = toEnable;
4672 // =======================================================================
4673 // function : GetBufferSubData
4675 // =======================================================================
4676 bool OpenGl_Context::GetBufferSubData (GLenum theTarget, GLintptr theOffset, GLsizeiptr theSize, void* theData)
4678 if (!hasGetBufferData)
4682 #ifdef __EMSCRIPTEN__
4685 Module.ctx.getBufferSubData($0, $1, HEAPU8.subarray($2, $2 + $3));
4686 }, theTarget, theOffset, theData, theSize);
4688 #elif defined(GL_ES_VERSION_2_0)
4689 if (void* aData = core30fwd->glMapBufferRange (theTarget, theOffset, theSize, GL_MAP_READ_BIT))
4691 memcpy (theData, aData, theSize);
4692 core30fwd->glUnmapBuffer (theTarget);
4697 core15fwd->glGetBufferSubData (theTarget, theOffset, theSize, theData);
4702 // =======================================================================
4703 // function : DumpJson
4705 // =======================================================================
4706 void OpenGl_Context::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
4708 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
4710 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAnisoMax)
4711 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTexClamp)
4712 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxTexDim)
4713 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxTexCombined)
4714 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxDumpSizeX)
4715 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxDumpSizeY)
4716 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxClipPlanes)
4717 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxMsaaSamples)
4718 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxDrawBuffers)
4719 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMaxColorAttachments)
4720 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGlVerMajor)
4721 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myGlVerMinor)
4722 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsInitialized)
4723 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsStereoBuffers)
4724 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsGlNormalizeEnabled)
4726 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasRayTracing)
4727 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasRayTracingTextures)
4728 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasRayTracingAdaptiveSampling)
4729 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasRayTracingAdaptiveSamplingAtomic)
4731 for (int i = 0; i < 4; i++)
4733 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewport[i])
4736 for (int i = 0; i < 4; i++)
4738 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myViewportVirt[i])
4741 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPointSpriteOrig)
4742 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRenderMode)
4743 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPolygonMode)
4744 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPolygonOffset)
4745 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToCullBackFaces)
4746 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myReadBuffer)
4748 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDefaultVao)
4749 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myColorMask)
4750 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAllowAlphaToCov)
4751 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAlphaToCoverage)
4752 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsGlDebugCtx)
4754 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myResolution)
4755 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myResolutionRatio)
4757 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLineWidthScale)
4758 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myLineFeather)
4759 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRenderScale)
4760 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRenderScaleInv)
4762 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &ModelWorldState)
4763 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &WorldViewState)
4764 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &ProjectionState)
4767 // =======================================================================
4768 // function : DumpJsonOpenGlState
4770 // =======================================================================
4771 void OpenGl_Context::DumpJsonOpenGlState (Standard_OStream& theOStream, Standard_Integer)
4773 GLboolean isEnableBlend = glIsEnabled (GL_BLEND);
4774 GLboolean isEnableCullFace = glIsEnabled (GL_CULL_FACE);
4775 GLboolean isEnableDepthTest = glIsEnabled (GL_DEPTH_TEST);
4777 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, isEnableBlend)
4778 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, isEnableCullFace)
4779 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, isEnableDepthTest)