VTK
dox/Rendering/OpenGL/vtkOpenGLExtensionManager.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 
00003 /*=========================================================================
00004 
00005   Program:   Visualization Toolkit
00006   Module:    vtkOpenGLExtensionManager.h
00007 
00008   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00009   All rights reserved.
00010   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016   Copyright 2003 Sandia Corporation.
00017   Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00018   license for use of this work by or on behalf of the
00019   U.S. Government. Redistribution and use in source and binary forms, with
00020   or without modification, are permitted provided that this Notice and any
00021   statement of authorship are reproduced on all copies.
00022 
00023 =========================================================================*/
00024 
00055 #include "vtkRenderingOpenGLModule.h" // For export macro
00056 // #include "vtkOpenGLExtensionManager.h"
00057 // #include "vtkgl.h"
00058 // \endcode
00059 // The vtkgl.h include file contains all the constants and function
00060 // pointers required for using OpenGL extensions in a portable and
00061 // namespace safe way.  vtkgl.h is built from parsed glext.h, glxext.h, and
00062 // wglext.h files.  Snapshots of these files are distributed with VTK,
00063 // but you can also set CMake options to use other files.
00064 //
00065 // To use an OpenGL extension, you first need to make an instance of
00066 // vtkOpenGLExtensionManager and give it a vtkRenderWindow.  You can then
00067 // query the vtkOpenGLExtensionManager to see if the extension is supported
00068 // with the ExtensionSupported method.  Valid names for extensions are
00069 // given in the OpenGL extension registry at
00070 // http://www.opengl.org/registry/ .
00071 // You can also grep vtkgl.h (which will be in the binary build directory
00072 // if VTK is not installed) for appropriate names.  There are also
00073 // special extensions GL_VERSION_X_X (where X_X is replaced with a major
00074 // and minor version, respectively) which contain all the constants and
00075 // functions for OpenGL versions for which the gl.h header file is of an
00076 // older version than the driver.
00077 //
00078 // \code
00079 // if (   !extensions->ExtensionSupported("GL_VERSION_1_2")
00080 //     || !extensions->ExtensionSupported("GL_ARB_multitexture") ) {
00081 //   {
00082 //   vtkErrorMacro("Required extensions not supported!");
00083 //   }
00084 // \endcode
00085 //
00086 // Once you have verified that the extensions you want exist, before you
00087 // use them you have to load them with the LoadExtension method.
00088 //
00089 // \code
00090 // extensions->LoadExtension("GL_VERSION_1_2");
00091 // extensions->LoadExtension("GL_ARB_multitexture");
00092 // \endcode
00093 //
00094 // Alternatively, you can use the LoadSupportedExtension method, which checks
00095 // whether the requested extension is supported and, if so, loads it. The
00096 // LoadSupportedExtension method will not raise any errors or warnings if it
00097 // fails, so it is important for callers to pay attention to the return value.
00098 //
00099 // \code
00100 // if (   extensions->LoadSupportedExtension("GL_VERSION_1_2")
00101 //     && extensions->LoadSupportedExtension("GL_ARB_multitexture") ) {
00102 //   {
00103 //   vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
00104 //   }
00105 // else
00106 //   {
00107 //   vtkErrorMacro("Required extensions could not be loaded!");
00108 //   }
00109 // \endcode
00110 //
00111 // Once you have queried and loaded all of the extensions you need, you can
00112 // delete the vtkOpenGLExtensionManager.  To use a constant of an extension,
00113 // simply replace the "GL_" prefix with "vtkgl::".  Likewise, replace the
00114 // "gl" prefix of functions with "vtkgl::".  In rare cases, an extension will
00115 // add a type. In this case, add vtkgl:: to the type (i.e. vtkgl::GLchar).
00116 //
00117 // \code
00118 // extensions->Delete();
00119 // ...
00120 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
00121 // \endcode
00122 //
00123 // For wgl extensions, replace the "WGL_" and "wgl" prefixes with
00124 // "vtkwgl::".  For glX extensions, replace the "GLX_" and "glX" prefixes
00125 // with "vtkglX::".
00126 //
00127 
00128 #ifndef __vtkOpenGLExtensionManager_h
00129 #define __vtkOpenGLExtensionManager_h
00130 
00131 #include "vtkObject.h"
00132 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00133 
00134 class vtkRenderWindow;
00135 
00136 //BTX
00137 extern "C" {
00138 #ifdef _WIN32
00139 #include "vtkOpenGL.h"  // Needed for WINAPI
00140   typedef int (WINAPI *vtkOpenGLExtensionManagerFunctionPointer)(void);
00141 #else
00142   typedef void (*vtkOpenGLExtensionManagerFunctionPointer)(void);
00143 #endif
00144 }
00145 //ETX
00146 
00147 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject
00148 {
00149 public:
00150   vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject);
00151   static vtkOpenGLExtensionManager *New();
00152   void PrintSelf(ostream &os, vtkIndent indent);
00153 
00155 
00157   vtkRenderWindow* GetRenderWindow();
00158   virtual void SetRenderWindow(vtkRenderWindow *renwin);
00160 
00162   virtual void Update();
00163 
00165 
00167   vtkGetStringMacro(ExtensionsString);
00169 
00171   virtual int ExtensionSupported(const char *name);
00172 
00173 //BTX
00175 
00177   virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(
00178     const char *fname);
00179 //ETX
00181 
00186   virtual void LoadExtension(const char *name);
00187 
00194   virtual int LoadSupportedExtension(const char *name);
00195 
00196 
00228   virtual void LoadCorePromotedExtension(const char *name);
00229 
00231 
00233   virtual void LoadAsARBExtension(const char *name);
00234 //BTX
00235 protected:
00236   vtkOpenGLExtensionManager();
00237   virtual ~vtkOpenGLExtensionManager();
00239 
00240 
00241   int OwnRenderWindow;
00242   char *ExtensionsString;
00243 
00244   vtkTimeStamp BuildTime;
00245 
00246   virtual void ReadOpenGLExtensions();
00247 
00253   virtual int SafeLoadExtension(const char *name);
00254 
00255 private:
00256   vtkOpenGLExtensionManager(const vtkOpenGLExtensionManager&); // Not implemented
00257   void operator=(const vtkOpenGLExtensionManager&); // Not implemented
00258 
00259   vtkWeakPointer<vtkRenderWindow> RenderWindow;
00260 //ETX
00261 };
00262 
00263 #endif //__vtkOpenGLExtensionManager