VTK
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vtkOpenGLExtensionManager Class Reference

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

#include <vtkOpenGLExtensionManager.h>

Inheritance diagram for vtkOpenGLExtensionManager:
[legend]
Collaboration diagram for vtkOpenGLExtensionManager:
[legend]

Public Types

typedef vtkObject Superclass
 
- Public Types inherited from vtkObject
typedef vtkObjectBase Superclass
 

Public Member Functions

virtual const char * GetClassName ()
 
virtual int IsA (const char *type)
 
void PrintSelf (ostream &os, vtkIndent indent)
 
virtual void Update ()
 
virtual int ExtensionSupported (const char *name)
 
virtual void LoadExtension (const char *name)
 
virtual int LoadSupportedExtension (const char *name)
 
virtual void LoadCorePromotedExtension (const char *name)
 
vtkRenderWindowGetRenderWindow ()
 
virtual void SetRenderWindow (vtkRenderWindow *renwin)
 
virtual char * GetExtensionsString ()
 
virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress (const char *fname)
 
- Public Member Functions inherited from vtkObject
virtual void DebugOn ()
 
virtual void DebugOff ()
 
unsigned char GetDebug ()
 
void SetDebug (unsigned char debugFlag)
 
virtual void Modified ()
 
virtual unsigned long GetMTime ()
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 
vtkCommandGetCommand (unsigned long tag)
 
void RemoveObserver (vtkCommand *)
 
void RemoveObservers (unsigned long event, vtkCommand *)
 
void RemoveObservers (const char *event, vtkCommand *)
 
int HasObserver (unsigned long event, vtkCommand *)
 
int HasObserver (const char *event, vtkCommand *)
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
int HasObserver (unsigned long event)
 
int HasObserver (const char *event)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
int InvokeEvent (unsigned long event, void *callData)
 
int InvokeEvent (const char *event, void *callData)
 
int InvokeEvent (unsigned long event)
 
int InvokeEvent (const char *event)
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 
virtual void Delete ()
 
virtual void FastDelete ()
 
void Print (ostream &os)
 
virtual void Register (vtkObjectBase *o)
 
virtual void UnRegister (vtkObjectBase *o)
 
void SetReferenceCount (int)
 
void PrintRevisions (ostream &os)
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 
int GetReferenceCount ()
 

Static Public Member Functions

static int IsTypeOf (const char *type)
 
static vtkOpenGLExtensionManagerSafeDownCast (vtkObject *o)
 
static vtkOpenGLExtensionManagerNew ()
 
- Static Public Member Functions inherited from vtkObject
static int IsTypeOf (const char *type)
 
static vtkObjectSafeDownCast (vtkObject *o)
 
static vtkObjectNew ()
 
static void BreakOnError ()
 
static void SetGlobalWarningDisplay (int val)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static int GetGlobalWarningDisplay ()
 
- Static Public Member Functions inherited from vtkObjectBase
static int IsTypeOf (const char *name)
 
static vtkObjectBaseNew ()
 

Protected Member Functions

virtual void ReadOpenGLExtensions ()
 
virtual int SafeLoadExtension (const char *name)
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
virtual ~vtkObject ()
 
virtual void RegisterInternal (vtkObjectBase *, int check)
 
virtual void UnRegisterInternal (vtkObjectBase *, int check)
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
 
void InternalReleaseFocus ()
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void CollectRevisions (ostream &os)
 
virtual void ReportReferences (vtkGarbageCollector *)
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Protected Attributes

int OwnRenderWindow
 
char * ExtensionsString
 
vtkTimeStamp BuildTime
 
- Protected Attributes inherited from vtkObject
unsigned char Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
- Protected Attributes inherited from vtkObjectBase
int ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 
virtual void LoadAsARBExtension (const char *name)
 
 vtkOpenGLExtensionManager ()
 
virtual ~vtkOpenGLExtensionManager ()
 

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.

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.

#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::".

Tests:
vtkOpenGLExtensionManager (Tests)

Definition at line 145 of file vtkOpenGLExtensionManager.h.

Member Typedef Documentation

Definition at line 148 of file vtkOpenGLExtensionManager.h.

Constructor & Destructor Documentation

vtkOpenGLExtensionManager::vtkOpenGLExtensionManager ( )
protected

Similar to LoadCorePromotedExtension(). It loads an EXT extension into the pointers of its ARB equivalent.

virtual vtkOpenGLExtensionManager::~vtkOpenGLExtensionManager ( )
protectedvirtual

Similar to LoadCorePromotedExtension(). It loads an EXT extension into the pointers of its ARB equivalent.

Member Function Documentation

virtual const char* vtkOpenGLExtensionManager::GetClassName ( )
virtual

Reimplemented from vtkObject.

static int vtkOpenGLExtensionManager::IsTypeOf ( const char *  type)
static
virtual int vtkOpenGLExtensionManager::IsA ( const char *  name)
virtual

Return 1 if this class is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeMacro found in vtkSetGet.h.

Reimplemented from vtkObject.

static vtkOpenGLExtensionManager* vtkOpenGLExtensionManager::SafeDownCast ( vtkObject o)
static
static vtkOpenGLExtensionManager* vtkOpenGLExtensionManager::New ( )
static
void vtkOpenGLExtensionManager::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
virtual

Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes.

Reimplemented from vtkObject.

vtkRenderWindow* vtkOpenGLExtensionManager::GetRenderWindow ( )

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

virtual void vtkOpenGLExtensionManager::SetRenderWindow ( vtkRenderWindow renwin)
virtual

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

virtual void vtkOpenGLExtensionManager::Update ( )
virtual

Updates the extensions string.

virtual char* vtkOpenGLExtensionManager::GetExtensionsString ( )
virtual

Returns a string listing all available extensions. Call Update first to validate this string.

virtual int vtkOpenGLExtensionManager::ExtensionSupported ( const char *  name)
virtual

Returns true if the extension is supported, false otherwise.

virtual vtkOpenGLExtensionManagerFunctionPointer vtkOpenGLExtensionManager::GetProcAddress ( const char *  fname)
virtual

Returns a function pointer to the OpenGL extension function with the given name. Returns NULL if the function could not be retrieved.

virtual void vtkOpenGLExtensionManager::LoadExtension ( const char *  name)
virtual

Loads all the functions associated with the given extension into the appropriate static members of vtkgl. This method emits a warning if the requested extension is not supported. It emits an error if the extension does not load successfully.

virtual int vtkOpenGLExtensionManager::LoadSupportedExtension ( const char *  name)
virtual

Returns true if the extension is supported and loaded successfully, false otherwise. This method will "fail silently/gracefully" if the extension is not supported or does not load properly. It emits neither warnings nor errors. It is up to the caller to determine if the extension loaded properly by paying attention to the return value.

virtual void vtkOpenGLExtensionManager::LoadCorePromotedExtension ( const char *  name)
virtual

Loads all the functions associated with the given core-promoted extension into the appropriate static members of vtkgl associated with the OpenGL version that promoted the extension as a core feature. This method emits a warning if the requested extension is not supported. It emits an error if the extension does not load successfully. For instance, extension GL_ARB_multitexture was promoted as a core feature into OpenGL 1.3. An implementation that uses this feature has to (IN THIS ORDER), check if OpenGL 1.3 is supported with ExtensionSupported("GL_VERSION_1_3"), if true, load the extension with LoadExtension("GL_VERSION_1_3"). If false, test for the extension with ExtensionSupported("GL_ARB_multitexture"),if true load the extension with this method LoadCorePromotedExtension("GL_ARB_multitexture"). If any of those loading stage succeeded, use vtgl::ActiveTexture() in any case, NOT vtgl::ActiveTextureARB(). This method avoids the use of if statements everywhere in implementations using core-promoted extensions. Without this method, the implementation code should look like:

int
opengl_1_3=extensions->ExtensionSupported("GL_VERSION_1_3");
if(opengl_1_3) { extensions->LoadExtension("GL_VERSION_1_3"); } else
{ if(extensions->ExtensionSupported("GL_ARB_multitexture")) {
extensions->LoadCorePromotedExtension("GL_ARB_multitexture"); } else
{ vtkErrorMacro("Required multitexture feature is not supported!"); }
} ... if(opengl_1_3) { vtkgl::ActiveTexture(vtkgl::TEXTURE0) } else {
vtkgl::ActiveTextureARB(vtkgl::TEXTURE0_ARB) }

Thanks to this method, the code looks like:

int
opengl_1_3=extensions->ExtensionSupported("GL_VERSION_1_3");
if(opengl_1_3) { extensions->LoadExtension("GL_VERSION_1_3"); } else
{ if(extensions->ExtensionSupported("GL_ARB_multitexture")) {
extensions->LoadCorePromotedExtension("GL_ARB_multitexture"); } else
{ vtkErrorMacro("Required multitexture feature is not supported!"); }
} ... vtkgl::ActiveTexture(vtkgl::TEXTURE0);
virtual void vtkOpenGLExtensionManager::LoadAsARBExtension ( const char *  name)
virtual

Similar to LoadCorePromotedExtension(). It loads an EXT extension into the pointers of its ARB equivalent.

virtual void vtkOpenGLExtensionManager::ReadOpenGLExtensions ( )
protectedvirtual
virtual int vtkOpenGLExtensionManager::SafeLoadExtension ( const char *  name)
protectedvirtual

Wrap around the generated vtkgl::LoadExtension to deal with OpenGL 1.2 and its optional part GL_ARB_imaging. Also functions like glBlendEquation() or glBlendColor() are optional in OpenGL 1.2 or 1.3 and provided by the GL_ARB_imaging but there are core features in OpenGL 1.4.

Member Data Documentation

int vtkOpenGLExtensionManager::OwnRenderWindow
protected

Definition at line 239 of file vtkOpenGLExtensionManager.h.

char* vtkOpenGLExtensionManager::ExtensionsString
protected

Definition at line 240 of file vtkOpenGLExtensionManager.h.

vtkTimeStamp vtkOpenGLExtensionManager::BuildTime
protected

Definition at line 242 of file vtkOpenGLExtensionManager.h.


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