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