VTK
vtkOpenGLExtensionManager Class Reference

Interface class for querying and using OpenGL extensions. More...

#include <vtkOpenGLExtensionManager.h>

Detailed Description

Interface class for querying and using OpenGL extensions.

vtkOpenGLExtensionManager acts as an interface to OpenGL extensions. It provides methods to query OpenGL extensions on the current or a given render window and to load extension function pointers. Currently does not support GLU extensions since the GLU library is not linked to VTK.

Before using vtkOpenGLExtensionManager, an OpenGL context must be created. This is generally done with a vtkRenderWindow. Note that simply creating the vtkRenderWindow is not sufficient. Usually you have to call Render before the actual OpenGL context is created. You can specify the RenderWindow with the SetRenderWindow method.

vtkOpenGLExtensionManager *extensions = vtkOpenGLExtensionManager::New();
extensions->SetRenderWindow(renwin);

If no vtkRenderWindow is specified, the current OpenGL context (if any) is used.

Generally speaking, when using OpenGL extensions, you will need an vtkOpenGLExtensionManager and the prototypes defined in vtkgl.h.

@par Tests:
@ref c2_vtk_t_vtkOpenGLExtensionManager "vtkOpenGLExtensionManager (Tests)"
*/
#include "vtkRenderingOpenGLModule.h" // For export macro
// #include "vtkOpenGLExtensionManager.h"
// #include "vtkgl.h"
//

The vtkgl.h include file contains all the constants and function pointers required for using OpenGL extensions in a portable and namespace safe way. vtkgl.h is built from parsed glext.h, glxext.h, and wglext.h files. Snapshots of these files are distributed with VTK, but you can also set CMake options to use other files.

To use an OpenGL extension, you first need to make an instance of vtkOpenGLExtensionManager and give it a vtkRenderWindow. You can then query the vtkOpenGLExtensionManager to see if the extension is supported with the ExtensionSupported method. Valid names for extensions are given in the OpenGL extension registry at http://www.opengl.org/registry/ . You can also grep vtkgl.h (which will be in the binary build directory if VTK is not installed) for appropriate names. There are also special extensions GL_VERSION_X_X (where X_X is replaced with a major and minor version, respectively) which contain all the constants and functions for OpenGL versions for which the gl.h header file is of an older version than the driver.

// if ( !extensions->ExtensionSupported("GL_VERSION_1_2")
// || !extensions->ExtensionSupported("GL_ARB_multitexture") ) {
// {
// vtkErrorMacro("Required extensions not supported!");
// }
//

Once you have verified that the extensions you want exist, before you use them you have to load them with the LoadExtension method.

// extensions->LoadExtension("GL_VERSION_1_2");
// extensions->LoadExtension("GL_ARB_multitexture");
//

Alternatively, you can use the LoadSupportedExtension method, which checks whether the requested extension is supported and, if so, loads it. The LoadSupportedExtension method will not raise any errors or warnings if it fails, so it is important for callers to pay attention to the return value.

// if ( extensions->LoadSupportedExtension("GL_VERSION_1_2")
// && extensions->LoadSupportedExtension("GL_ARB_multitexture") ) {
// {
// vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
// }
// else
// {
// vtkErrorMacro("Required extensions could not be loaded!");
// }
//

Once you have queried and loaded all of the extensions you need, you can delete the vtkOpenGLExtensionManager. To use a constant of an extension, simply replace the "GL_" prefix with "vtkgl::". Likewise, replace the "gl" prefix of functions with "vtkgl::". In rare cases, an extension will add a type. In this case, add vtkgl:: to the type (i.e. vtkgl::GLchar).

// extensions->Delete();
// ...
// vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
//

For wgl extensions, replace the "WGL_" and "wgl" prefixes with "vtkwgl::". For glX extensions, replace the "GLX_" and "glX" prefixes with "vtkglX::".

#ifndef vtkOpenGLExtensionManager_h #define vtkOpenGLExtensionManager_h

#include "vtkObject.h" #include "vtkWeakPointer.h" // needed for vtkWeakPointer. #include <string> // needed for std::string

class vtkRenderWindow;

BTX extern "C" { #ifdef _WIN32 #include "vtkOpenGL.h" // Needed for WINAPI typedef int (WINAPI *vtkOpenGLExtensionManagerFunctionPointer)(void); #else typedef void (*vtkOpenGLExtensionManagerFunctionPointer)(void); #endif } ETX

class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject { public: vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject); static vtkOpenGLExtensionManager *New(); void PrintSelf(ostream &os, vtkIndent indent);

/*! Set/Get the render window to query extensions on. If set to null, justs queries the current render window.


The documentation for this class was generated from the following file: