VTK
vtkOpenGLExtensionManager.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 
3 /*=========================================================================
4 
5  Program: Visualization Toolkit
6  Module: vtkOpenGLExtensionManager.h
7 
8  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
9  All rights reserved.
10  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notice for more information.
15 
16  Copyright 2003 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
18  license for use of this work by or on behalf of the
19  U.S. Government. Redistribution and use in source and binary forms, with
20  or without modification, are permitted provided that this Notice and any
21  statement of authorship are reproduced on all copies.
22 
23 =========================================================================*/
24 
55 #include "vtkRenderingOpenGLModule.h" // For export macro
56 // #include "vtkOpenGLExtensionManager.h"
57 // #include "vtkgl.h"
58 // \endcode
59 // The vtkgl.h include file contains all the constants and function
60 // pointers required for using OpenGL extensions in a portable and
61 // namespace safe way. vtkgl.h is built from parsed glext.h, glxext.h, and
62 // wglext.h files. Snapshots of these files are distributed with VTK,
63 // but you can also set CMake options to use other files.
64 //
65 // To use an OpenGL extension, you first need to make an instance of
66 // vtkOpenGLExtensionManager and give it a vtkRenderWindow. You can then
67 // query the vtkOpenGLExtensionManager to see if the extension is supported
68 // with the ExtensionSupported method. Valid names for extensions are
69 // given in the OpenGL extension registry at
70 // http://www.opengl.org/registry/ .
71 // You can also grep vtkgl.h (which will be in the binary build directory
72 // if VTK is not installed) for appropriate names. There are also
73 // special extensions GL_VERSION_X_X (where X_X is replaced with a major
74 // and minor version, respectively) which contain all the constants and
75 // functions for OpenGL versions for which the gl.h header file is of an
76 // older version than the driver.
77 //
78 // \code
79 // if ( !extensions->ExtensionSupported("GL_VERSION_1_2")
80 // || !extensions->ExtensionSupported("GL_ARB_multitexture") ) {
81 // {
82 // vtkErrorMacro("Required extensions not supported!");
83 // }
84 // \endcode
85 //
86 // Once you have verified that the extensions you want exist, before you
87 // use them you have to load them with the LoadExtension method.
88 //
89 // \code
90 // extensions->LoadExtension("GL_VERSION_1_2");
91 // extensions->LoadExtension("GL_ARB_multitexture");
92 // \endcode
93 //
94 // Alternatively, you can use the LoadSupportedExtension method, which checks
95 // whether the requested extension is supported and, if so, loads it. The
96 // LoadSupportedExtension method will not raise any errors or warnings if it
97 // fails, so it is important for callers to pay attention to the return value.
98 //
99 // \code
100 // if ( extensions->LoadSupportedExtension("GL_VERSION_1_2")
101 // && extensions->LoadSupportedExtension("GL_ARB_multitexture") ) {
102 // {
103 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
104 // }
105 // else
106 // {
107 // vtkErrorMacro("Required extensions could not be loaded!");
108 // }
109 // \endcode
110 //
111 // Once you have queried and loaded all of the extensions you need, you can
112 // delete the vtkOpenGLExtensionManager. To use a constant of an extension,
113 // simply replace the "GL_" prefix with "vtkgl::". Likewise, replace the
114 // "gl" prefix of functions with "vtkgl::". In rare cases, an extension will
115 // add a type. In this case, add vtkgl:: to the type (i.e. vtkgl::GLchar).
116 //
117 // \code
118 // extensions->Delete();
119 // ...
120 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
121 // \endcode
122 //
123 // For wgl extensions, replace the "WGL_" and "wgl" prefixes with
124 // "vtkwgl::". For glX extensions, replace the "GLX_" and "glX" prefixes
125 // with "vtkglX::".
126 //
127 
128 #ifndef vtkOpenGLExtensionManager_h
129 #define vtkOpenGLExtensionManager_h
130 
131 #include "vtkObject.h"
132 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
133 #include <string> // needed for std::string
134 
135 class vtkRenderWindow;
136 
137 //BTX
138 extern "C" {
139 #ifdef _WIN32
140 #include "vtkOpenGL.h" // Needed for WINAPI
141  typedef int (WINAPI *vtkOpenGLExtensionManagerFunctionPointer)(void);
142 #else
143  typedef void (*vtkOpenGLExtensionManagerFunctionPointer)(void);
144 #endif
145 }
146 //ETX
147 
149 {
150 public:
152  static vtkOpenGLExtensionManager *New();
153  void PrintSelf(ostream &os, vtkIndent indent);
154 
156 
159  virtual void SetRenderWindow(vtkRenderWindow *renwin);
161 
163  virtual void Update();
164 
166 
170 
172  virtual int ExtensionSupported(const char *name);
173 
174 //BTX
176 
178  virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(
179  const char *fname);
180 //ETX
182 
187  virtual void LoadExtension(const char *name);
188 
195  virtual int LoadSupportedExtension(const char *name);
196 
197 
229  virtual void LoadCorePromotedExtension(const char *name);
230 
233  virtual void LoadAsARBExtension(const char *name);
234 
236 
238  virtual int GetDriverVersionMajor(){ return this->DriverVersionMajor; }
239  virtual int GetDriverVersionMinor(){ return this->DriverVersionMinor; }
240  virtual int GetDriverVersionPatch(){ return this->DriverVersionPatch; }
242 
244 
247  virtual int GetDriverGLVersionMajor(){ return this->DriverGLVersionMajor; }
248  virtual int GetDriverGLVersionMinor(){ return this->DriverGLVersionMinor; }
249  virtual int GetDriverGLVersionPatch(){ return this->DriverGLVersionPatch; }
251 
253 
256  virtual bool DriverIsATI();
257  virtual bool DriverIsNvidia();
258  virtual bool DriverIsIntel();
259  virtual bool DriverIsMesa();
260  virtual bool DriverIsMicrosoft();
262 
264 
265  virtual bool DriverVersionIs(int major);
266  virtual bool DriverVersionIs(int major, int minor);
267  virtual bool DriverVersionIs(int major, int minor, int patch);
269 
271 
272  virtual bool DriverVersionAtLeast(int major);
273  virtual bool DriverVersionAtLeast(int major, int minor);
274  virtual bool DriverVersionAtLeast(int major, int minor, int patch);
276 
278 
281  virtual bool DriverGLVersionIs(int major, int minor, int patch);
282  virtual bool DriverGLVersionIs(int major, int minor);
284 
286 
289  virtual bool DriverGLRendererIs(const char *str);
290  virtual bool DriverGLRendererHas(const char *str);
291  virtual bool DriverGLRendererHasToken(const char *str);
293 
295  virtual bool DriverGLRendererIsOSMesa();
296 
298 
300  virtual const char *GetDriverGLVendor(){ return this->DriverGLVendor.c_str(); }
301  virtual const char *GetDriverGLVersion(){ return this->DriverGLVersion.c_str(); }
302  virtual const char *GetDriverGLRenderer(){ return this->DriverGLRenderer.c_str(); }
304 
306 
314  bool GetIgnoreDriverBugs(const char *description);
318 
319 //BTX
320 protected:
323 
326 
328 
329  // driver specific info
340  {
347  };
350 
352 
353  virtual void ReadOpenGLExtensions();
354 
360  virtual int SafeLoadExtension(const char *name);
361 
362 private:
363  vtkOpenGLExtensionManager(const vtkOpenGLExtensionManager&); // Not implemented
364  void operator=(const vtkOpenGLExtensionManager&); // Not implemented
365 
366  vtkWeakPointer<vtkRenderWindow> RenderWindow;
367 //ETX
368 };
369 
370 #endif // vtkOpenGLExtensionManager_h
LoadAsARBExtension
virtual void LoadAsARBExtension(const char *name)
DriverVersionIs
virtual bool DriverVersionIs(int major)
InitializeDriverInformation
virtual void InitializeDriverInformation()
DRIVER_VENDOR_NVIDIA
@ DRIVER_VENDOR_NVIDIA
Definition: vtkOpenGLExtensionManager.h:343
DRIVER_VENDOR_ATI
@ DRIVER_VENDOR_ATI
Definition: vtkOpenGLExtensionManager.h:342
GetDriverGLVersion
virtual const char * GetDriverGLVersion()
Definition: vtkOpenGLExtensionManager.h:301
DriverIsMesa
virtual bool DriverIsMesa()
vtkObject::New
static vtkObject * New()
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkRenderingOpenGLModule.h
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
DriverGLRendererHasToken
virtual bool DriverGLRendererHasToken(const char *str)
vtkOpenGLExtensionManager
vtkOpenGLExtensionManager()
DriverVersionMinor
int DriverVersionMinor
Definition: vtkOpenGLExtensionManager.h:337
ExtensionsString
char * ExtensionsString
Definition: vtkOpenGLExtensionManager.h:325
GetDriverGLRenderer
virtual const char * GetDriverGLRenderer()
Definition: vtkOpenGLExtensionManager.h:302
SetRenderWindow
virtual void SetRenderWindow(vtkRenderWindow *renwin)
DriverIsMicrosoft
virtual bool DriverIsMicrosoft()
DriverVersionPatch
int DriverVersionPatch
Definition: vtkOpenGLExtensionManager.h:338
DriverGLVersion
std::string DriverGLVersion
Definition: vtkOpenGLExtensionManager.h:330
GetRenderWindow
vtkRenderWindow * GetRenderWindow()
ExtensionSupported
virtual int ExtensionSupported(const char *name)
LoadExtension
virtual void LoadExtension(const char *name)
GetDriverVersionMajor
virtual int GetDriverVersionMajor()
Definition: vtkOpenGLExtensionManager.h:238
LoadCorePromotedExtension
virtual void LoadCorePromotedExtension(const char *name)
DriverGLVersionPatch
int DriverGLVersionPatch
Definition: vtkOpenGLExtensionManager.h:333
vtkObject::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
DRIVER_VENDOR_MESA
@ DRIVER_VENDOR_MESA
Definition: vtkOpenGLExtensionManager.h:345
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkOpenGLExtensionManager
Interface class for querying and using OpenGL extensions.
GetDriverGLVersionPatch
virtual int GetDriverGLVersionPatch()
Definition: vtkOpenGLExtensionManager.h:249
Update
virtual void Update()
DRIVER_VENDOR_INTEL
@ DRIVER_VENDOR_INTEL
Definition: vtkOpenGLExtensionManager.h:344
DriverGLRenderer
std::string DriverGLRenderer
Definition: vtkOpenGLExtensionManager.h:335
~vtkOpenGLExtensionManager
virtual ~vtkOpenGLExtensionManager()
SafeLoadExtension
virtual int SafeLoadExtension(const char *name)
DriverGLVendorIdType
DriverGLVendorIdType
Definition: vtkOpenGLExtensionManager.h:340
DriverGLRendererHas
virtual bool DriverGLRendererHas(const char *str)
GetDriverGLVersionMinor
virtual int GetDriverGLVersionMinor()
Definition: vtkOpenGLExtensionManager.h:248
GetProcAddress
virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(const char *fname)
ReadOpenGLExtensions
virtual void ReadOpenGLExtensions()
IgnoreDriverBugs
bool IgnoreDriverBugs
Definition: vtkOpenGLExtensionManager.h:349
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
OwnRenderWindow
int OwnRenderWindow
Definition: vtkOpenGLExtensionManager.h:324
vtkWeakPointer.h
GetDriverGLVendor
virtual const char * GetDriverGLVendor()
Definition: vtkOpenGLExtensionManager.h:300
DriverVersionAtLeast
virtual bool DriverVersionAtLeast(int major)
DriverIsNvidia
virtual bool DriverIsNvidia()
vtkGetStringMacro
vtkGetStringMacro(ExtensionsString)
vtkObject.h
GetDriverVersionMinor
virtual int GetDriverVersionMinor()
Definition: vtkOpenGLExtensionManager.h:239
vtkBooleanMacro
vtkBooleanMacro(IgnoreDriverBugs, bool)
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
DRIVER_VENDOR_UNKNOWN
@ DRIVER_VENDOR_UNKNOWN
Definition: vtkOpenGLExtensionManager.h:341
DriverGLVersionMajor
int DriverGLVersionMajor
Definition: vtkOpenGLExtensionManager.h:331
DriverGLVersionMinor
int DriverGLVersionMinor
Definition: vtkOpenGLExtensionManager.h:332
vtkX3D::description
@ description
Definition: vtkX3D.h:322
DriverGLRendererIs
virtual bool DriverGLRendererIs(const char *str)
DRIVER_VENDOR_MICROSOFT
@ DRIVER_VENDOR_MICROSOFT
Definition: vtkOpenGLExtensionManager.h:346
LoadSupportedExtension
virtual int LoadSupportedExtension(const char *name)
GetDriverVersionPatch
virtual int GetDriverVersionPatch()
Definition: vtkOpenGLExtensionManager.h:240
vtkgl::void
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:89
GetIgnoreDriverBugs
bool GetIgnoreDriverBugs(const char *description)
DriverGLVendor
std::string DriverGLVendor
Definition: vtkOpenGLExtensionManager.h:334
DriverIsIntel
virtual bool DriverIsIntel()
DriverGLRendererIsOSMesa
virtual bool DriverGLRendererIsOSMesa()
vtkgl::string
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
vtkWeakPointer< vtkRenderWindow >
int
int
Definition: vtkVectorOperators.h:164
GetDriverGLVersionMajor
virtual int GetDriverGLVersionMajor()
Definition: vtkOpenGLExtensionManager.h:247
DriverIsATI
virtual bool DriverIsATI()
VTKRENDERINGOPENGL_EXPORT
#define VTKRENDERINGOPENGL_EXPORT
Definition: vtkRenderingOpenGLModule.h:15
BuildTime
vtkTimeStamp BuildTime
Definition: vtkOpenGLExtensionManager.h:327
DriverGLVersionIs
virtual bool DriverGLVersionIs(int major, int minor, int patch)
DriverVersionMajor
int DriverVersionMajor
Definition: vtkOpenGLExtensionManager.h:336
DriverGLVendorId
DriverGLVendorIdType DriverGLVendorId
Definition: vtkOpenGLExtensionManager.h:348