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