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 
56 #include "vtkRenderingOpenGLModule.h" // For export macro
57 // #include "vtkOpenGLExtensionManager.h"
58 // #include "vtkgl.h"
59 // \endcode
60 // The vtkgl.h include file contains all the constants and function
61 // pointers required for using OpenGL extensions in a portable and
62 // namespace safe way. vtkgl.h is built from parsed glext.h, glxext.h, and
63 // wglext.h files. Snapshots of these files are distributed with VTK,
64 // but you can also set CMake options to use other files.
65 //
66 // To use an OpenGL extension, you first need to make an instance of
67 // vtkOpenGLExtensionManager and give it a vtkRenderWindow. You can then
68 // query the vtkOpenGLExtensionManager to see if the extension is supported
69 // with the ExtensionSupported method. Valid names for extensions are
70 // given in the OpenGL extension registry at
71 // http://www.opengl.org/registry/ .
72 // You can also grep vtkgl.h (which will be in the binary build directory
73 // if VTK is not installed) for appropriate names. There are also
74 // special extensions GL_VERSION_X_X (where X_X is replaced with a major
75 // and minor version, respectively) which contain all the constants and
76 // functions for OpenGL versions for which the gl.h header file is of an
77 // older version than the driver.
78 //
79 // \code
80 // if ( !extensions->ExtensionSupported("GL_VERSION_1_2")
81 // || !extensions->ExtensionSupported("GL_ARB_multitexture") ) {
82 // {
83 // vtkErrorMacro("Required extensions not supported!");
84 // }
85 // \endcode
86 //
87 // Once you have verified that the extensions you want exist, before you
88 // use them you have to load them with the LoadExtension method.
89 //
90 // \code
91 // extensions->LoadExtension("GL_VERSION_1_2");
92 // extensions->LoadExtension("GL_ARB_multitexture");
93 // \endcode
94 //
95 // Alternatively, you can use the LoadSupportedExtension method, which checks
96 // whether the requested extension is supported and, if so, loads it. The
97 // LoadSupportedExtension method will not raise any errors or warnings if it
98 // fails, so it is important for callers to pay attention to the return value.
99 //
100 // \code
101 // if ( extensions->LoadSupportedExtension("GL_VERSION_1_2")
102 // && extensions->LoadSupportedExtension("GL_ARB_multitexture") ) {
103 // {
104 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
105 // }
106 // else
107 // {
108 // vtkErrorMacro("Required extensions could not be loaded!");
109 // }
110 // \endcode
111 //
112 // Once you have queried and loaded all of the extensions you need, you can
113 // delete the vtkOpenGLExtensionManager. To use a constant of an extension,
114 // simply replace the "GL_" prefix with "vtkgl::". Likewise, replace the
115 // "gl" prefix of functions with "vtkgl::". In rare cases, an extension will
116 // add a type. In this case, add vtkgl:: to the type (i.e. vtkgl::GLchar).
117 //
118 // \code
119 // extensions->Delete();
120 // ...
121 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
122 // \endcode
123 //
124 // For wgl extensions, replace the "WGL_" and "wgl" prefixes with
125 // "vtkwgl::". For glX extensions, replace the "GLX_" and "glX" prefixes
126 // with "vtkglX::".
127 //
128 
129 #ifndef vtkOpenGLExtensionManager_h
130 #define vtkOpenGLExtensionManager_h
131 
132 #include "vtkObject.h"
133 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
134 #include <string> // needed for std::string
135 
136 class vtkRenderWindow;
137 
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 
147 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject
148 {
149 public:
150  vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject);
151  static vtkOpenGLExtensionManager *New();
152  void PrintSelf(ostream &os, vtkIndent indent);
153 
155 
160  virtual void SetRenderWindow(vtkRenderWindow *renwin);
162 
166  virtual void Update();
167 
169 
175 
179  virtual int ExtensionSupported(const char *name);
180 
185  virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(
186  const char *fname);
187 
194  virtual void LoadExtension(const char *name);
195 
203  virtual int LoadSupportedExtension(const char *name);
204 
205 
274  virtual void LoadCorePromotedExtension(const char *name);
275 
280  virtual void LoadAsARBExtension(const char *name);
281 
286  virtual int GetDriverVersionMajor(){ return this->DriverVersionMajor; }
287  virtual int GetDriverVersionMinor(){ return this->DriverVersionMinor; }
288  virtual int GetDriverVersionPatch(){ return this->DriverVersionPatch; }
289 
295  virtual int GetDriverGLVersionMajor(){ return this->DriverGLVersionMajor; }
296  virtual int GetDriverGLVersionMinor(){ return this->DriverGLVersionMinor; }
297  virtual int GetDriverGLVersionPatch(){ return this->DriverGLVersionPatch; }
298 
300 
305  virtual bool DriverIsATI();
306  virtual bool DriverIsNvidia();
307  virtual bool DriverIsIntel();
308  virtual bool DriverIsMesa();
309  virtual bool DriverIsMicrosoft();
311 
313 
316  virtual bool DriverVersionIs(int major);
317  virtual bool DriverVersionIs(int major, int minor);
318  virtual bool DriverVersionIs(int major, int minor, int patch);
320 
322 
326  virtual bool DriverVersionAtLeast(int major);
327  virtual bool DriverVersionAtLeast(int major, int minor);
328  virtual bool DriverVersionAtLeast(int major, int minor, int patch);
330 
332 
338  virtual bool DriverGLVersionIs(int major, int minor, int patch);
339  virtual bool DriverGLVersionIs(int major, int minor);
341 
343 
349  virtual bool DriverGLRendererIs(const char *str);
350  virtual bool DriverGLRendererHas(const char *str);
351  virtual bool DriverGLRendererHasToken(const char *str);
353 
357  virtual bool DriverGLRendererIsOSMesa();
358 
363  virtual const char *GetDriverGLVendor(){ return this->DriverGLVendor.c_str(); }
364  virtual const char *GetDriverGLVersion(){ return this->DriverGLVersion.c_str(); }
365  virtual const char *GetDriverGLRenderer(){ return this->DriverGLRenderer.c_str(); }
366 
368 
378  bool GetIgnoreDriverBugs(const char *description);
382 
383 protected:
385  virtual ~vtkOpenGLExtensionManager();
386 
389 
391 
392  // driver specific info
403  {
410  };
413 
414  virtual void InitializeDriverInformation();
415 
416  virtual void ReadOpenGLExtensions();
417 
424  virtual int SafeLoadExtension(const char *name);
425 
426 private:
427  vtkOpenGLExtensionManager(const vtkOpenGLExtensionManager&) VTK_DELETE_FUNCTION;
428  void operator=(const vtkOpenGLExtensionManager&) VTK_DELETE_FUNCTION;
429 
431 
432 };
433 
434 #endif // vtkOpenGLExtensionManager_h
virtual bool DriverGLVersionIs(int major, int minor, int patch)
Test for the driver's GL version as reported in its GL_VERSION string.
vtkTimeStamp BuildTime
virtual bool DriverGLRendererHasToken(const char *str)
Test for a specific renderer.
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void InitializeDriverInformation()
int DriverVersionMajor
std::string DriverGLVersion
record modification and/or execution time
Definition: vtkTimeStamp.h:35
int DriverVersionMinor
virtual int GetDriverVersionMajor()
Return the driver's version parts.
vtkRenderWindow * GetRenderWindow()
char * ExtensionsString
virtual void SetRenderWindow(vtkRenderWindow *renwin)
int DriverVersionPatch
virtual void Update()
Updates the extensions string.
virtual bool DriverIsMesa()
Test's for common implementors of rendering drivers.
virtual ~vtkOpenGLExtensionManager()
virtual int ExtensionSupported(const char *name)
Returns true if the extension is supported, false otherwise.
virtual bool DriverIsMicrosoft()
Test's for common implementors of rendering drivers.
virtual int GetDriverGLVersionPatch()
vtkOpenGLExtensionManager()
std::string DriverGLRenderer
virtual void LoadCorePromotedExtension(const char *name)
Loads all the functions associated with the given core-promoted extension into the appropriate static...
virtual void LoadExtension(const char *name)
Loads all the functions associated with the given extension into the appropriate static members of vt...
virtual const char * GetDriverGLRenderer()
int DriverGLVersionPatch
virtual bool DriverGLRendererHas(const char *str)
Test for a specific renderer.
virtual const char * GetDriverGLVendor()
Get the OpenGL version, vendor and renderer strings.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void ReadOpenGLExtensions()
a weak reference to a vtkObject.
virtual int SafeLoadExtension(const char *name)
Wrap around the generated vtkgl::LoadExtension to deal with OpenGL 1.2 and its optional part GL_ARB_i...
virtual int GetDriverGLVersionMinor()
virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(const char *fname)
Returns a function pointer to the OpenGL extension function with the given name.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
int OwnRenderWindow
Interface class for querying and using OpenGL extensions.
virtual bool DriverGLRendererIs(const char *str)
Test for a specific renderer.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
vtkWeakPointer< vtkRenderWindow > RenderWindow
bool IgnoreDriverBugs
virtual bool DriverIsNvidia()
Test's for common implementors of rendering drivers.
create a window for renderers to draw into
virtual int GetDriverVersionMinor()
std::string DriverGLVendor
virtual bool DriverGLRendererIsOSMesa()
Test for Mesa's offscreen renderer.
virtual bool DriverVersionAtLeast(int major)
Test for driver version greater than or equal to the named version.
virtual int GetDriverGLVersionMajor()
Get GL API version that the driver provides.
bool GetIgnoreDriverBugs(const char *description)
When set known driver bugs are ignored during driver feature detection.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual int GetDriverVersionPatch()
virtual bool DriverIsATI()
Test's for common implementors of rendering drivers.
int DriverGLVersionMajor
int DriverGLVersionMinor
DriverGLVendorIdType DriverGLVendorId
virtual bool DriverIsIntel()
Test's for common implementors of rendering drivers.
virtual bool DriverVersionIs(int major)
Test for a specific driver version.
virtual void LoadAsARBExtension(const char *name)
Similar to LoadCorePromotedExtension().
virtual const char * GetDriverGLVersion()
virtual int LoadSupportedExtension(const char *name)
Returns true if the extension is supported and loaded successfully, false otherwise.