1 // Created on: 2012-01-26
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #if (defined(_WIN32) || defined(__WIN32__))
25 #include <OpenGl_Context.hxx>
27 #include <OpenGl_ArbVBO.hxx>
28 #include <OpenGl_ExtFBO.hxx>
29 #include <OpenGl_GlCore20.hxx>
31 #include <Standard_ProgramError.hxx>
33 #if (defined(_WIN32) || defined(__WIN32__))
35 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
38 #include <GL/glx.h> // glXGetProcAddress()
41 // GL_NVX_gpu_memory_info
42 #ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
45 GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX = 0x9047,
46 GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX = 0x9048,
47 GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX = 0x9049,
48 GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX = 0x904A,
49 GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX = 0x904B
53 IMPLEMENT_STANDARD_HANDLE (OpenGl_Context, Standard_Transient)
54 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context, Standard_Transient)
56 //! Make record shorter to retrieve function pointer using variable with same name
57 #define FindProcShort(theStruct, theFunc) FindProc(#theFunc, theStruct->theFunc)
59 // =======================================================================
60 // function : OpenGl_Context
62 // =======================================================================
63 OpenGl_Context::OpenGl_Context()
71 atiMem (Standard_False),
72 nvxMem (Standard_False),
77 myIsFeedback (Standard_False),
78 myIsInitialized (Standard_False)
80 #if defined(MAC_OS_X_VERSION_10_3) && !defined(MACOSX_USE_GLX)
81 // Vendors can not extend functionality on this system
82 // and developers are limited to OpenGL support provided by Mac OS X SDK.
83 // We retrieve function pointers from system library
84 // to generalize extensions support on all platforms.
85 // In this way we also reach binary compatibility benefit between OS releases
86 // if some newest functionality is optionally used.
87 // Notice that GL version / extension availability checks are required
88 // because function pointers may be available but not functionality itself
89 // (depends on renderer).
90 myGlLibHandle = dlopen ("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
94 // =======================================================================
95 // function : ~OpenGl_Context
97 // =======================================================================
98 OpenGl_Context::~OpenGl_Context()
105 // =======================================================================
106 // function : IsCurrent
108 // =======================================================================
109 Standard_Boolean OpenGl_Context::IsCurrent() const
111 #if (defined(_WIN32) || defined(__WIN32__))
112 if (myWindowDC == NULL || myGContext == NULL)
114 return Standard_False;
116 return (( (HDC )myWindowDC == wglGetCurrentDC())
117 && ((HGLRC )myGContext == wglGetCurrentContext()));
119 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
121 return Standard_False;
124 return ( ((Display* )myDisplay == glXGetCurrentDisplay())
125 && ((GLXContext )myGContext == glXGetCurrentContext())
126 && ((GLXDrawable )myWindow == glXGetCurrentDrawable()));
130 // =======================================================================
131 // function : MakeCurrent
133 // =======================================================================
134 Standard_Boolean OpenGl_Context::MakeCurrent()
136 #if (defined(_WIN32) || defined(__WIN32__))
137 if (myWindowDC == NULL || myGContext == NULL)
139 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
140 return Standard_False;
143 // technically it should be safe to activate already bound GL context
144 // however some drivers (Intel etc.) may FAIL doing this for unknown reason
147 return Standard_True;
149 else if (wglMakeCurrent ((HDC )myWindowDC, (HGLRC )myGContext) != TRUE)
151 // notice that glGetError() couldn't be used here!
152 wchar_t* aMsgBuff = NULL;
153 DWORD anErrorCode = GetLastError();
154 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
155 NULL, anErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t* )&aMsgBuff, 0, NULL);
156 if (aMsgBuff != NULL)
158 std::wcerr << L"OpenGL interface: wglMakeCurrent() failed. " << aMsgBuff << L" (" << int(anErrorCode) << L")\n";
159 LocalFree (aMsgBuff);
163 std::wcerr << L"OpenGL interface: wglMakeCurrent() failed with #" << int(anErrorCode) << L" error code\n";
165 return Standard_False;
168 if (myDisplay == NULL || myWindow == 0 || myGContext == 0)
170 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
171 return Standard_False;
174 if (!glXMakeCurrent ((Display* )myDisplay, (GLXDrawable )myWindow, (GLXContext )myGContext))
176 // if there is no current context it might be impossible to use glGetError() correctly
177 //std::cerr << "glXMakeCurrent() failed!\n";
178 return Standard_False;
181 return Standard_True;
184 // =======================================================================
185 // function : findProc
187 // =======================================================================
188 void* OpenGl_Context::findProc (const char* theFuncName)
190 #if (defined(_WIN32) || defined(__WIN32__))
191 return wglGetProcAddress (theFuncName);
192 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
193 return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
195 return (void* )glXGetProcAddress ((const GLubyte* )theFuncName);
199 // =======================================================================
200 // function : CheckExtension
202 // =======================================================================
203 Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
205 if (theExtName == NULL)
207 std::cerr << "CheckExtension called with NULL string!\n";
208 return Standard_False;
210 int anExtNameLen = strlen (theExtName);
212 // available since OpenGL 3.0
213 // and the ONLY way to check extensions with OpenGL 3.1+ core profile
214 /**if (IsGlGreaterEqual (3, 0))
217 glGetIntegerv (GL_NUM_EXTENSIONS, &anExtNb);
218 for (GLint anIter = 0; anIter < anExtNb; ++anIter)
220 const char* anExtension = (const char* )core30->glGetStringi (GL_EXTENSIONS, (GLuint )anIter);
221 if (anExtension[anExtNameLen] == '\0' &&
222 strncmp (anExtension, theExtName, anExtNameLen) == 0)
224 return Standard_True;
227 return Standard_False;
230 // use old way with huge string for all extensions
231 const char* anExtString = (const char* )glGetString (GL_EXTENSIONS);
232 if (anExtString == NULL)
234 std::cerr << "glGetString (GL_EXTENSIONS) returns NULL! No GL context?\n";
235 return Standard_False;
238 // Search for theExtName in the extensions string.
239 // Use of strstr() is not sufficient because extension names can be prefixes of other extension names.
240 char* aPtrIter = (char* )anExtString;
241 const char* aPtrEnd = aPtrIter + strlen (anExtString);
242 while (aPtrIter < aPtrEnd)
244 int n = strcspn (aPtrIter, " ");
245 if ((n == anExtNameLen) && (strncmp (aPtrIter, theExtName, anExtNameLen) == 0))
247 return Standard_True;
251 return Standard_False;
254 // =======================================================================
257 // =======================================================================
258 Standard_Boolean OpenGl_Context::Init()
262 return Standard_True;
265 #if (defined(_WIN32) || defined(__WIN32__))
266 myWindowDC = (Aspect_Handle )wglGetCurrentDC();
267 myGContext = (Aspect_RenderingContext )wglGetCurrentContext();
269 myDisplay = (Aspect_Display )glXGetCurrentDisplay();
270 myGContext = (Aspect_RenderingContext )glXGetCurrentContext();
271 myWindow = (Aspect_Drawable )glXGetCurrentDrawable();
273 if (myGContext == NULL)
275 return Standard_False;
279 myIsInitialized = Standard_True;
280 return Standard_True;
283 // =======================================================================
286 // =======================================================================
287 #if (defined(_WIN32) || defined(__WIN32__))
288 Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
289 const Aspect_Handle theWindowDC,
290 const Aspect_RenderingContext theGContext)
292 Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
293 const Aspect_Display theDisplay,
294 const Aspect_RenderingContext theGContext)
297 Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
299 myWindow = theWindow;
300 myGContext = theGContext;
301 #if (defined(_WIN32) || defined(__WIN32__))
302 myWindowDC = theWindowDC;
304 myDisplay = theDisplay;
306 if (myGContext == NULL || !MakeCurrent())
308 return Standard_False;
312 myIsInitialized = Standard_True;
313 return Standard_True;
316 // =======================================================================
317 // function : ResetErrors
319 // =======================================================================
320 void OpenGl_Context::ResetErrors()
322 while (glGetError() != GL_NO_ERROR)
328 // =======================================================================
329 // function : readGlVersion
331 // =======================================================================
332 void OpenGl_Context::readGlVersion()
338 // available since OpenGL 3.0
339 GLint aMajor, aMinor;
340 glGetIntegerv (GL_MAJOR_VERSION, &aMajor);
341 glGetIntegerv (GL_MINOR_VERSION, &aMinor);
342 if (glGetError() == GL_NO_ERROR)
344 myGlVerMajor = aMajor;
345 myGlVerMinor = aMinor;
350 // Read version string.
351 // Notice that only first two numbers splitted by point '2.1 XXXXX' are significant.
352 // Following trash (after space) is vendor-specific.
353 // New drivers also returns micro version of GL like '3.3.0' which has no meaning
354 // and should be considered as vendor-specific too.
355 const char* aVerStr = (const char* )glGetString (GL_VERSION);
356 if (aVerStr == NULL || *aVerStr == '\0')
358 // invalid GL context
362 // parse string for major number
366 while (aVerStr[aMajIter] >= '0' && aVerStr[aMajIter] <= '9')
370 if (aMajIter == 0 || aMajIter >= sizeof(aMajorStr))
374 memcpy (aMajorStr, aVerStr, aMajIter);
375 aMajorStr[aMajIter] = '\0';
377 // parse string for minor number
378 size_t aMinIter = aMajIter + 1;
379 while (aVerStr[aMinIter] >= '0' && aVerStr[aMinIter] <= '9')
383 size_t aMinLen = aMinIter - aMajIter - 1;
384 if (aMinLen == 0 || aMinLen >= sizeof(aMinorStr))
388 memcpy (aMinorStr, aVerStr, aMinLen);
389 aMinorStr[aMinLen] = '\0';
392 myGlVerMajor = atoi (aMajorStr);
393 myGlVerMinor = atoi (aMinorStr);
395 if (myGlVerMajor <= 0)
402 // =======================================================================
405 // =======================================================================
406 void OpenGl_Context::init()
411 atiMem = CheckExtension ("GL_ATI_meminfo");
412 nvxMem = CheckExtension ("GL_NVX_gpu_memory_info");
414 // initialize VBO extension (ARB)
415 if (CheckExtension ("GL_ARB_vertex_buffer_object"))
417 arbVBO = new OpenGl_ArbVBO();
418 memset (arbVBO, 0, sizeof(OpenGl_ArbVBO)); // nullify whole structure
419 if (!FindProcShort (arbVBO, glGenBuffersARB)
420 || !FindProcShort (arbVBO, glBindBufferARB)
421 || !FindProcShort (arbVBO, glBufferDataARB)
422 || !FindProcShort (arbVBO, glDeleteBuffersARB))
429 // initialize FBO extension (EXT)
430 if (CheckExtension ("GL_EXT_framebuffer_object"))
432 extFBO = new OpenGl_ExtFBO();
433 memset (extFBO, 0, sizeof(OpenGl_ExtFBO)); // nullify whole structure
434 if (!FindProcShort (extFBO, glGenFramebuffersEXT)
435 || !FindProcShort (extFBO, glDeleteFramebuffersEXT)
436 || !FindProcShort (extFBO, glBindFramebufferEXT)
437 || !FindProcShort (extFBO, glFramebufferTexture2DEXT)
438 || !FindProcShort (extFBO, glCheckFramebufferStatusEXT)
439 || !FindProcShort (extFBO, glGenRenderbuffersEXT)
440 || !FindProcShort (extFBO, glDeleteRenderbuffersEXT)
441 || !FindProcShort (extFBO, glBindRenderbufferEXT)
442 || !FindProcShort (extFBO, glRenderbufferStorageEXT)
443 || !FindProcShort (extFBO, glFramebufferRenderbufferEXT))
450 myGlCore20 = new OpenGl_GlCore20();
451 memset (myGlCore20, 0, sizeof(OpenGl_GlCore20)); // nullify whole structure
453 // initialize OpenGL 1.2 core functionality
454 if (IsGlGreaterEqual (1, 2))
456 if (!FindProcShort (myGlCore20, glBlendColor)
457 || !FindProcShort (myGlCore20, glBlendEquation)
458 || !FindProcShort (myGlCore20, glDrawRangeElements)
459 || !FindProcShort (myGlCore20, glTexImage3D)
460 || !FindProcShort (myGlCore20, glTexSubImage3D)
461 || !FindProcShort (myGlCore20, glCopyTexSubImage3D))
468 // initialize OpenGL 1.3 core functionality
469 if (IsGlGreaterEqual (1, 3))
471 if (!FindProcShort (myGlCore20, glActiveTexture)
472 || !FindProcShort (myGlCore20, glSampleCoverage)
473 || !FindProcShort (myGlCore20, glCompressedTexImage3D)
474 || !FindProcShort (myGlCore20, glCompressedTexImage2D)
475 || !FindProcShort (myGlCore20, glCompressedTexImage1D)
476 || !FindProcShort (myGlCore20, glCompressedTexSubImage3D)
477 || !FindProcShort (myGlCore20, glCompressedTexSubImage2D)
478 || !FindProcShort (myGlCore20, glCompressedTexSubImage1D)
479 || !FindProcShort (myGlCore20, glGetCompressedTexImage)
481 || !FindProcShort (myGlCore20, glClientActiveTexture)
482 || !FindProcShort (myGlCore20, glMultiTexCoord1d)
483 || !FindProcShort (myGlCore20, glMultiTexCoord1dv)
484 || !FindProcShort (myGlCore20, glMultiTexCoord1f)
485 || !FindProcShort (myGlCore20, glMultiTexCoord1fv)
486 || !FindProcShort (myGlCore20, glMultiTexCoord1i)
487 || !FindProcShort (myGlCore20, glMultiTexCoord1iv)
488 || !FindProcShort (myGlCore20, glMultiTexCoord1s)
489 || !FindProcShort (myGlCore20, glMultiTexCoord1sv)
490 || !FindProcShort (myGlCore20, glMultiTexCoord2d)
491 || !FindProcShort (myGlCore20, glMultiTexCoord2dv)
492 || !FindProcShort (myGlCore20, glMultiTexCoord2f)
493 || !FindProcShort (myGlCore20, glMultiTexCoord2fv)
494 || !FindProcShort (myGlCore20, glMultiTexCoord2i)
495 || !FindProcShort (myGlCore20, glMultiTexCoord2iv)
496 || !FindProcShort (myGlCore20, glMultiTexCoord2s)
497 || !FindProcShort (myGlCore20, glMultiTexCoord2sv)
498 || !FindProcShort (myGlCore20, glMultiTexCoord3d)
499 || !FindProcShort (myGlCore20, glMultiTexCoord3dv)
500 || !FindProcShort (myGlCore20, glMultiTexCoord3f)
501 || !FindProcShort (myGlCore20, glMultiTexCoord3fv)
502 || !FindProcShort (myGlCore20, glMultiTexCoord3i)
503 || !FindProcShort (myGlCore20, glMultiTexCoord3iv)
504 || !FindProcShort (myGlCore20, glMultiTexCoord3s)
505 || !FindProcShort (myGlCore20, glMultiTexCoord3sv)
506 || !FindProcShort (myGlCore20, glMultiTexCoord4d)
507 || !FindProcShort (myGlCore20, glMultiTexCoord4dv)
508 || !FindProcShort (myGlCore20, glMultiTexCoord4f)
509 || !FindProcShort (myGlCore20, glMultiTexCoord4fv)
510 || !FindProcShort (myGlCore20, glMultiTexCoord4i)
511 || !FindProcShort (myGlCore20, glMultiTexCoord4iv)
512 || !FindProcShort (myGlCore20, glMultiTexCoord4s)
513 || !FindProcShort (myGlCore20, glMultiTexCoord4sv)
514 || !FindProcShort (myGlCore20, glLoadTransposeMatrixf)
515 || !FindProcShort (myGlCore20, glLoadTransposeMatrixd)
516 || !FindProcShort (myGlCore20, glMultTransposeMatrixf)
517 || !FindProcShort (myGlCore20, glMultTransposeMatrixd))
525 // initialize OpenGL 1.4 core functionality
526 if (IsGlGreaterEqual (1, 4))
528 if (!FindProcShort (myGlCore20, glBlendFuncSeparate)
529 || !FindProcShort (myGlCore20, glMultiDrawArrays)
530 || !FindProcShort (myGlCore20, glMultiDrawElements)
531 || !FindProcShort (myGlCore20, glPointParameterf)
532 || !FindProcShort (myGlCore20, glPointParameterfv)
533 || !FindProcShort (myGlCore20, glPointParameteri)
534 || !FindProcShort (myGlCore20, glPointParameteriv))
543 // initialize OpenGL 1.5 core functionality
544 if (IsGlGreaterEqual (1, 5))
546 if (!FindProcShort (myGlCore20, glGenQueries)
547 || !FindProcShort (myGlCore20, glDeleteQueries)
548 || !FindProcShort (myGlCore20, glIsQuery)
549 || !FindProcShort (myGlCore20, glBeginQuery)
550 || !FindProcShort (myGlCore20, glEndQuery)
551 || !FindProcShort (myGlCore20, glGetQueryiv)
552 || !FindProcShort (myGlCore20, glGetQueryObjectiv)
553 || !FindProcShort (myGlCore20, glGetQueryObjectuiv)
554 || !FindProcShort (myGlCore20, glBindBuffer)
555 || !FindProcShort (myGlCore20, glDeleteBuffers)
556 || !FindProcShort (myGlCore20, glGenBuffers)
557 || !FindProcShort (myGlCore20, glIsBuffer)
558 || !FindProcShort (myGlCore20, glBufferData)
559 || !FindProcShort (myGlCore20, glBufferSubData)
560 || !FindProcShort (myGlCore20, glGetBufferSubData)
561 || !FindProcShort (myGlCore20, glMapBuffer)
562 || !FindProcShort (myGlCore20, glUnmapBuffer)
563 || !FindProcShort (myGlCore20, glGetBufferParameteriv)
564 || !FindProcShort (myGlCore20, glGetBufferPointerv))
574 // initialize OpenGL 2.0 core functionality
575 if (IsGlGreaterEqual (2, 0))
577 if (!FindProcShort (myGlCore20, glBlendEquationSeparate)
578 || !FindProcShort (myGlCore20, glDrawBuffers)
579 || !FindProcShort (myGlCore20, glStencilOpSeparate)
580 || !FindProcShort (myGlCore20, glStencilFuncSeparate)
581 || !FindProcShort (myGlCore20, glStencilMaskSeparate)
582 || !FindProcShort (myGlCore20, glAttachShader)
583 || !FindProcShort (myGlCore20, glBindAttribLocation)
584 || !FindProcShort (myGlCore20, glCompileShader)
585 || !FindProcShort (myGlCore20, glCreateProgram)
586 || !FindProcShort (myGlCore20, glCreateShader)
587 || !FindProcShort (myGlCore20, glDeleteProgram)
588 || !FindProcShort (myGlCore20, glDeleteShader)
589 || !FindProcShort (myGlCore20, glDetachShader)
590 || !FindProcShort (myGlCore20, glDisableVertexAttribArray)
591 || !FindProcShort (myGlCore20, glEnableVertexAttribArray)
592 || !FindProcShort (myGlCore20, glGetActiveAttrib)
593 || !FindProcShort (myGlCore20, glGetActiveUniform)
594 || !FindProcShort (myGlCore20, glGetAttachedShaders)
595 || !FindProcShort (myGlCore20, glGetAttribLocation)
596 || !FindProcShort (myGlCore20, glGetProgramiv)
597 || !FindProcShort (myGlCore20, glGetProgramInfoLog)
598 || !FindProcShort (myGlCore20, glGetShaderiv)
599 || !FindProcShort (myGlCore20, glGetShaderInfoLog)
600 || !FindProcShort (myGlCore20, glGetShaderSource)
601 || !FindProcShort (myGlCore20, glGetUniformLocation)
602 || !FindProcShort (myGlCore20, glGetUniformfv)
603 || !FindProcShort (myGlCore20, glGetUniformiv)
604 || !FindProcShort (myGlCore20, glGetVertexAttribdv)
605 || !FindProcShort (myGlCore20, glGetVertexAttribfv)
606 || !FindProcShort (myGlCore20, glGetVertexAttribiv)
607 || !FindProcShort (myGlCore20, glGetVertexAttribPointerv)
608 || !FindProcShort (myGlCore20, glIsProgram)
609 || !FindProcShort (myGlCore20, glIsShader)
610 || !FindProcShort (myGlCore20, glLinkProgram)
611 || !FindProcShort (myGlCore20, glShaderSource)
612 || !FindProcShort (myGlCore20, glUseProgram)
613 || !FindProcShort (myGlCore20, glUniform1f)
614 || !FindProcShort (myGlCore20, glUniform2f)
615 || !FindProcShort (myGlCore20, glUniform3f)
616 || !FindProcShort (myGlCore20, glUniform4f)
617 || !FindProcShort (myGlCore20, glUniform1i)
618 || !FindProcShort (myGlCore20, glUniform2i)
619 || !FindProcShort (myGlCore20, glUniform3i)
620 || !FindProcShort (myGlCore20, glUniform4i)
621 || !FindProcShort (myGlCore20, glUniform1fv)
622 || !FindProcShort (myGlCore20, glUniform2fv)
623 || !FindProcShort (myGlCore20, glUniform3fv)
624 || !FindProcShort (myGlCore20, glUniform4fv)
625 || !FindProcShort (myGlCore20, glUniform1iv)
626 || !FindProcShort (myGlCore20, glUniform2iv)
627 || !FindProcShort (myGlCore20, glUniform3iv)
628 || !FindProcShort (myGlCore20, glUniform4iv)
629 || !FindProcShort (myGlCore20, glUniformMatrix2fv)
630 || !FindProcShort (myGlCore20, glUniformMatrix3fv)
631 || !FindProcShort (myGlCore20, glUniformMatrix4fv)
632 || !FindProcShort (myGlCore20, glValidateProgram)
633 || !FindProcShort (myGlCore20, glVertexAttrib1d)
634 || !FindProcShort (myGlCore20, glVertexAttrib1dv)
635 || !FindProcShort (myGlCore20, glVertexAttrib1f)
636 || !FindProcShort (myGlCore20, glVertexAttrib1fv)
637 || !FindProcShort (myGlCore20, glVertexAttrib1s)
638 || !FindProcShort (myGlCore20, glVertexAttrib1sv)
639 || !FindProcShort (myGlCore20, glVertexAttrib2d)
640 || !FindProcShort (myGlCore20, glVertexAttrib2dv)
641 || !FindProcShort (myGlCore20, glVertexAttrib2f)
642 || !FindProcShort (myGlCore20, glVertexAttrib2fv)
643 || !FindProcShort (myGlCore20, glVertexAttrib2s)
644 || !FindProcShort (myGlCore20, glVertexAttrib2sv)
645 || !FindProcShort (myGlCore20, glVertexAttrib3d)
646 || !FindProcShort (myGlCore20, glVertexAttrib3dv)
647 || !FindProcShort (myGlCore20, glVertexAttrib3f)
648 || !FindProcShort (myGlCore20, glVertexAttrib3fv)
649 || !FindProcShort (myGlCore20, glVertexAttrib3s)
650 || !FindProcShort (myGlCore20, glVertexAttrib3sv)
651 || !FindProcShort (myGlCore20, glVertexAttrib4Nbv)
652 || !FindProcShort (myGlCore20, glVertexAttrib4Niv)
653 || !FindProcShort (myGlCore20, glVertexAttrib4Nsv)
654 || !FindProcShort (myGlCore20, glVertexAttrib4Nub)
655 || !FindProcShort (myGlCore20, glVertexAttrib4Nubv)
656 || !FindProcShort (myGlCore20, glVertexAttrib4Nuiv)
657 || !FindProcShort (myGlCore20, glVertexAttrib4Nusv)
658 || !FindProcShort (myGlCore20, glVertexAttrib4bv)
659 || !FindProcShort (myGlCore20, glVertexAttrib4d)
660 || !FindProcShort (myGlCore20, glVertexAttrib4dv)
661 || !FindProcShort (myGlCore20, glVertexAttrib4f)
662 || !FindProcShort (myGlCore20, glVertexAttrib4fv)
663 || !FindProcShort (myGlCore20, glVertexAttrib4iv)
664 || !FindProcShort (myGlCore20, glVertexAttrib4s)
665 || !FindProcShort (myGlCore20, glVertexAttrib4sv)
666 || !FindProcShort (myGlCore20, glVertexAttrib4ubv)
667 || !FindProcShort (myGlCore20, glVertexAttrib4uiv)
668 || !FindProcShort (myGlCore20, glVertexAttrib4usv)
669 || !FindProcShort (myGlCore20, glVertexAttribPointer))
680 if (IsGlGreaterEqual (2, 0))
689 // =======================================================================
690 // function : IsFeedback
692 // =======================================================================
693 Standard_Boolean OpenGl_Context::IsFeedback() const
698 // =======================================================================
699 // function : SetFeedback
701 // =======================================================================
702 void OpenGl_Context::SetFeedback (const Standard_Boolean theFeedbackOn)
704 myIsFeedback = theFeedbackOn;
707 // =======================================================================
708 // function : MemoryInfo
710 // =======================================================================
711 Standard_Size OpenGl_Context::AvailableMemory() const
715 // this is actually information for VBO pool
716 // however because pools are mostly shared
717 // it can be used for total GPU memory estimations
720 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aMemInfo);
721 // returned value is in KiB, however this maybe changed in future
722 return Standard_Size(aMemInfo[0]) * 1024;
726 // current available dedicated video memory (in KiB), currently unused GPU memory
728 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aMemInfo);
729 return Standard_Size(aMemInfo) * 1024;
734 // =======================================================================
735 // function : MemoryInfo
737 // =======================================================================
738 TCollection_AsciiString OpenGl_Context::MemoryInfo() const
740 TCollection_AsciiString anInfo;
744 memset (aValues, 0, sizeof(aValues));
745 glGetIntegerv (GL_VBO_FREE_MEMORY_ATI, aValues);
747 // total memory free in the pool
748 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValues[0] / 1024) + " MiB\n";
750 // largest available free block in the pool
751 anInfo += TCollection_AsciiString (" Largest free block: ") + (aValues[1] / 1024) + " MiB\n";
752 if (aValues[2] != aValues[0])
754 // total auxiliary memory free
755 anInfo += TCollection_AsciiString (" Free memory: ") + (aValues[2] / 1024) + " MiB\n";
760 //current available dedicated video memory (in KiB), currently unused GPU memory
762 glGetIntegerv (GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &aValue);
763 anInfo += TCollection_AsciiString (" GPU free memory: ") + (aValue / 1024) + " MiB\n";
765 // dedicated video memory, total size (in KiB) of the GPU memory
766 GLint aDedicated = 0;
767 glGetIntegerv (GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &aDedicated);
768 anInfo += TCollection_AsciiString (" GPU memory: ") + (aDedicated / 1024) + " MiB\n";
770 // total available memory, total size (in KiB) of the memory available for allocations
771 glGetIntegerv (GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &aValue);
772 if (aValue != aDedicated)
774 // different only for special configurations
775 anInfo += TCollection_AsciiString (" Total memory: ") + (aValue / 1024) + " MiB\n";