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 
148 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject
149 {
150 public:
151  vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject);
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 
168  vtkGetStringMacro(ExtensionsString);
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);
315  vtkSetMacro(IgnoreDriverBugs, bool);
316  vtkBooleanMacro(IgnoreDriverBugs, bool);
318 
319 //BTX
320 protected:
322  virtual ~vtkOpenGLExtensionManager();
323 
326 
328 
329  // driver specific info
340  {
347  };
350 
351  virtual void InitializeDriverInformation();
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 
367 //ETX
368 };
369 
370 #endif // vtkOpenGLExtensionManager_h
virtual bool DriverGLVersionIs(int major, int minor, int patch)
vtkTimeStamp BuildTime
virtual bool DriverGLRendererHasToken(const char *str)
abstract base class for most VTK objects
Definition: vtkObject.h:61
virtual void InitializeDriverInformation()
int DriverVersionMajor
std::string DriverGLVersion
record modification and/or execution time
Definition: vtkTimeStamp.h:34
int DriverVersionMinor
virtual int GetDriverVersionMajor()
vtkRenderWindow * GetRenderWindow()
char * ExtensionsString
virtual void SetRenderWindow(vtkRenderWindow *renwin)
int DriverVersionPatch
virtual void Update()
virtual bool DriverIsMesa()
virtual ~vtkOpenGLExtensionManager()
virtual int ExtensionSupported(const char *name)
virtual bool DriverIsMicrosoft()
virtual int GetDriverGLVersionPatch()
vtkOpenGLExtensionManager()
std::string DriverGLRenderer
virtual void LoadCorePromotedExtension(const char *name)
virtual void LoadExtension(const char *name)
virtual const char * GetDriverGLRenderer()
int DriverGLVersionPatch
virtual bool DriverGLRendererHas(const char *str)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual const char * GetDriverGLVendor()
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual void ReadOpenGLExtensions()
virtual int SafeLoadExtension(const char *name)
virtual int GetDriverGLVersionMinor()
virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(const char *fname)
int OwnRenderWindow
Interface class for querying and using OpenGL extensions.
virtual bool DriverGLRendererIs(const char *str)
vtkWeakPointer< vtkRenderWindow > RenderWindow
bool IgnoreDriverBugs
virtual bool DriverIsNvidia()
create a window for renderers to draw into
virtual int GetDriverVersionMinor()
std::string DriverGLVendor
virtual bool DriverGLRendererIsOSMesa()
virtual bool DriverVersionAtLeast(int major)
virtual int GetDriverGLVersionMajor()
bool GetIgnoreDriverBugs(const char *description)
static vtkObject * New()
virtual int GetDriverVersionPatch()
virtual bool DriverIsATI()
int DriverGLVersionMajor
int DriverGLVersionMinor
DriverGLVendorIdType DriverGLVendorId
virtual bool DriverIsIntel()
virtual bool DriverVersionIs(int major)
virtual void LoadAsARBExtension(const char *name)
virtual const char * GetDriverGLVersion()
virtual int LoadSupportedExtension(const char *name)