VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/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 #include <string> // needed for std::string
00134 
00135 class vtkRenderWindow;
00136 
00137 //BTX
00138 extern "C" {
00139 #ifdef _WIN32
00140 #include "vtkOpenGL.h"  // Needed for WINAPI
00141   typedef int (WINAPI *vtkOpenGLExtensionManagerFunctionPointer)(void);
00142 #else
00143   typedef void (*vtkOpenGLExtensionManagerFunctionPointer)(void);
00144 #endif
00145 }
00146 //ETX
00147 
00148 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject
00149 {
00150 public:
00151   vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject);
00152   static vtkOpenGLExtensionManager *New();
00153   void PrintSelf(ostream &os, vtkIndent indent);
00154 
00156 
00158   vtkRenderWindow* GetRenderWindow();
00159   virtual void SetRenderWindow(vtkRenderWindow *renwin);
00161 
00163   virtual void Update();
00164 
00166 
00168   vtkGetStringMacro(ExtensionsString);
00170 
00172   virtual int ExtensionSupported(const char *name);
00173 
00174 //BTX
00176 
00178   virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(
00179     const char *fname);
00180 //ETX
00182 
00187   virtual void LoadExtension(const char *name);
00188 
00195   virtual int LoadSupportedExtension(const char *name);
00196 
00197 
00229   virtual void LoadCorePromotedExtension(const char *name);
00230 
00233   virtual void LoadAsARBExtension(const char *name);
00234 
00236 
00238   virtual int GetDriverVersionMajor(){ return this->DriverVersionMajor; }
00239   virtual int GetDriverVersionMinor(){ return this->DriverVersionMinor; }
00240   virtual int GetDriverVersionPatch(){ return this->DriverVersionPatch; }
00242 
00244 
00247   virtual int GetDriverGLVersionMajor(){ return this->DriverGLVersionMajor; }
00248   virtual int GetDriverGLVersionMinor(){ return this->DriverGLVersionMinor; }
00249   virtual int GetDriverGLVersionPatch(){ return this->DriverGLVersionPatch; }
00251 
00253 
00256   virtual bool DriverIsATI();
00257   virtual bool DriverIsNvidia();
00258   virtual bool DriverIsIntel();
00259   virtual bool DriverIsMesa();
00260   virtual bool DriverIsMicrosoft();
00262 
00264 
00265   virtual bool DriverVersionIs(int major);
00266   virtual bool DriverVersionIs(int major, int minor);
00267   virtual bool DriverVersionIs(int major, int minor, int patch);
00269 
00271 
00272   virtual bool DriverVersionAtLeast(int major);
00273   virtual bool DriverVersionAtLeast(int major, int minor);
00274   virtual bool DriverVersionAtLeast(int major, int minor, int patch);
00276 
00278 
00281   virtual bool DriverGLVersionIs(int major, int minor, int patch);
00282   virtual bool DriverGLVersionIs(int major, int minor);
00284 
00286 
00289   virtual bool DriverGLRendererIs(const char *str);
00290   virtual bool DriverGLRendererHas(const char *str);
00291   virtual bool DriverGLRendererHasToken(const char *str);
00293 
00295   virtual bool DriverGLRendererIsOSMesa();
00296 
00298 
00300   virtual const char *GetDriverGLVendor(){ return this->DriverGLVendor.c_str(); }
00301   virtual const char *GetDriverGLVersion(){ return this->DriverGLVersion.c_str(); }
00302   virtual const char *GetDriverGLRenderer(){ return this->DriverGLRenderer.c_str(); }
00304 
00306 
00314   bool GetIgnoreDriverBugs(const char *description);
00315   vtkSetMacro(IgnoreDriverBugs, bool);
00316   vtkBooleanMacro(IgnoreDriverBugs, bool);
00318 
00319 //BTX
00320 protected:
00321   vtkOpenGLExtensionManager();
00322   virtual ~vtkOpenGLExtensionManager();
00323 
00324   int OwnRenderWindow;
00325   char *ExtensionsString;
00326 
00327   vtkTimeStamp BuildTime;
00328 
00329   // driver specific info
00330   std::string DriverGLVersion;
00331   int DriverGLVersionMajor;
00332   int DriverGLVersionMinor;
00333   int DriverGLVersionPatch;
00334   std::string DriverGLVendor;
00335   std::string DriverGLRenderer;
00336   int DriverVersionMajor;
00337   int DriverVersionMinor;
00338   int DriverVersionPatch;
00339   enum DriverGLVendorIdType
00340     {
00341     DRIVER_VENDOR_UNKNOWN=0,
00342     DRIVER_VENDOR_ATI,
00343     DRIVER_VENDOR_NVIDIA,
00344     DRIVER_VENDOR_INTEL,
00345     DRIVER_VENDOR_MESA,
00346     DRIVER_VENDOR_MICROSOFT
00347     };
00348   DriverGLVendorIdType DriverGLVendorId;
00349   bool IgnoreDriverBugs;
00350 
00351   virtual void InitializeDriverInformation();
00352 
00353   virtual void ReadOpenGLExtensions();
00354 
00360   virtual int SafeLoadExtension(const char *name);
00361 
00362 private:
00363   vtkOpenGLExtensionManager(const vtkOpenGLExtensionManager&); // Not implemented
00364   void operator=(const vtkOpenGLExtensionManager&); // Not implemented
00365 
00366   vtkWeakPointer<vtkRenderWindow> RenderWindow;
00367 //ETX
00368 };
00369 
00370 #endif // vtkOpenGLExtensionManager_h