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 
53 #include "vtkRenderingOpenGLModule.h" // For export macro
54 // #include "vtkOpenGLExtensionManager.h"
55 // #include "vtkgl.h"
56 // \endcode
57 // The vtkgl.h include file contains all the constants and function
58 // pointers required for using OpenGL extensions in a portable and
59 // namespace safe way. vtkgl.h is built from parsed glext.h, glxext.h, and
60 // wglext.h files. Snapshots of these files are distributed with VTK,
61 // but you can also set CMake options to use other files.
62 //
63 // To use an OpenGL extension, you first need to make an instance of
64 // vtkOpenGLExtensionManager and give it a vtkRenderWindow. You can then
65 // query the vtkOpenGLExtensionManager to see if the extension is supported
66 // with the ExtensionSupported method. Valid names for extensions are
67 // given in the OpenGL extension registry at
68 // http://www.opengl.org/registry/ .
69 // You can also grep vtkgl.h (which will be in the binary build directory
70 // if VTK is not installed) for appropriate names. There are also
71 // special extensions GL_VERSION_X_X (where X_X is replaced with a major
72 // and minor version, respectively) which contain all the constants and
73 // functions for OpenGL versions for which the gl.h header file is of an
74 // older version than the driver.
75 //
76 // \code
77 // if ( !extensions->ExtensionSupported("GL_VERSION_1_2")
78 // || !extensions->ExtensionSupported("GL_ARB_multitexture") ) {
79 // {
80 // vtkErrorMacro("Required extensions not supported!");
81 // }
82 // \endcode
83 //
84 // Once you have verified that the extensions you want exist, before you
85 // use them you have to load them with the LoadExtension method.
86 //
87 // \code
88 // extensions->LoadExtension("GL_VERSION_1_2");
89 // extensions->LoadExtension("GL_ARB_multitexture");
90 // \endcode
91 //
92 // Alternatively, you can use the LoadSupportedExtension method, which checks
93 // whether the requested extension is supported and, if so, loads it. The
94 // LoadSupportedExtension method will not raise any errors or warnings if it
95 // fails, so it is important for callers to pay attention to the return value.
96 //
97 // \code
98 // if ( extensions->LoadSupportedExtension("GL_VERSION_1_2")
99 // && extensions->LoadSupportedExtension("GL_ARB_multitexture") ) {
100 // {
101 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
102 // }
103 // else
104 // {
105 // vtkErrorMacro("Required extensions could not be loaded!");
106 // }
107 // \endcode
108 //
109 // Once you have queried and loaded all of the extensions you need, you can
110 // delete the vtkOpenGLExtensionManager. To use a constant of an extension,
111 // simply replace the "GL_" prefix with "vtkgl::". Likewise, replace the
112 // "gl" prefix of functions with "vtkgl::". In rare cases, an extension will
113 // add a type. In this case, add vtkgl:: to the type (i.e. vtkgl::GLchar).
114 //
115 // \code
116 // extensions->Delete();
117 // ...
118 // vtkgl::ActiveTexture(vtkgl::TEXTURE0_ARB);
119 // \endcode
120 //
121 // For wgl extensions, replace the "WGL_" and "wgl" prefixes with
122 // "vtkwgl::". For glX extensions, replace the "GLX_" and "glX" prefixes
123 // with "vtkglX::".
124 //
125 
126 #ifndef vtkOpenGLExtensionManager_h
127 #define vtkOpenGLExtensionManager_h
128 
129 #include "vtkObject.h"
130 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
131 #include <string> // needed for std::string
132 
133 class vtkRenderWindow;
134 
135 extern "C" {
136 #ifdef _WIN32
137 #include "vtkOpenGL.h" // Needed for WINAPI
138  typedef int (WINAPI *vtkOpenGLExtensionManagerFunctionPointer)(void);
139 #else
140  typedef void (*vtkOpenGLExtensionManagerFunctionPointer)(void);
141 #endif
142 }
143 
144 class VTKRENDERINGOPENGL_EXPORT vtkOpenGLExtensionManager : public vtkObject
145 {
146 public:
147  vtkTypeMacro(vtkOpenGLExtensionManager, vtkObject);
148  static vtkOpenGLExtensionManager *New();
149  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
150 
152 
157  virtual void SetRenderWindow(vtkRenderWindow *renwin);
159 
163  virtual void Update();
164 
166 
172 
176  virtual int ExtensionSupported(const char *name);
177 
182  virtual vtkOpenGLExtensionManagerFunctionPointer GetProcAddress(
183  const char *fname);
184 
191  virtual void LoadExtension(const char *name);
192 
200  virtual int LoadSupportedExtension(const char *name);
201 
202 
271  virtual void LoadCorePromotedExtension(const char *name);
272 
277  virtual void LoadAsARBExtension(const char *name);
278 
283  virtual int GetDriverVersionMajor(){ return this->DriverVersionMajor; }
284  virtual int GetDriverVersionMinor(){ return this->DriverVersionMinor; }
285  virtual int GetDriverVersionPatch(){ return this->DriverVersionPatch; }
286 
292  virtual int GetDriverGLVersionMajor(){ return this->DriverGLVersionMajor; }
293  virtual int GetDriverGLVersionMinor(){ return this->DriverGLVersionMinor; }
294  virtual int GetDriverGLVersionPatch(){ return this->DriverGLVersionPatch; }
295 
297 
302  virtual bool DriverIsATI();
303  virtual bool DriverIsNvidia();
304  virtual bool DriverIsIntel();
305  virtual bool DriverIsMesa();
306  virtual bool DriverIsMicrosoft();
308 
310 
313  virtual bool DriverVersionIs(int major);
314  virtual bool DriverVersionIs(int major, int minor);
315  virtual bool DriverVersionIs(int major, int minor, int patch);
317 
319 
323  virtual bool DriverVersionAtLeast(int major);
324  virtual bool DriverVersionAtLeast(int major, int minor);
325  virtual bool DriverVersionAtLeast(int major, int minor, int patch);
327 
329 
335  virtual bool DriverGLVersionIs(int major, int minor, int patch);
336  virtual bool DriverGLVersionIs(int major, int minor);
338 
340 
346  virtual bool DriverGLRendererIs(const char *str);
347  virtual bool DriverGLRendererHas(const char *str);
348  virtual bool DriverGLRendererHasToken(const char *str);
350 
354  virtual bool DriverGLRendererIsOSMesa();
355 
360  virtual const char *GetDriverGLVendor(){ return this->DriverGLVendor.c_str(); }
361  virtual const char *GetDriverGLVersion(){ return this->DriverGLVersion.c_str(); }
362  virtual const char *GetDriverGLRenderer(){ return this->DriverGLRenderer.c_str(); }
363 
365 
375  bool GetIgnoreDriverBugs(const char *description);
379 
380 protected:
382  ~vtkOpenGLExtensionManager() VTK_OVERRIDE;
383 
386 
388 
389  // driver specific info
390  std::string DriverGLVersion;
394  std::string DriverGLVendor;
395  std::string DriverGLRenderer;
400  {
407  };
410 
411  virtual void InitializeDriverInformation();
412 
413  virtual void ReadOpenGLExtensions();
414 
421  virtual int SafeLoadExtension(const char *name);
422 
423 private:
424  vtkOpenGLExtensionManager(const vtkOpenGLExtensionManager&) VTK_DELETE_FUNCTION;
425  void operator=(const vtkOpenGLExtensionManager&) VTK_DELETE_FUNCTION;
426 
428 
429 };
430 
431 #endif // vtkOpenGLExtensionManager_h
virtual bool DriverGLVersionIs(int major, int minor, int patch)
Test for the driver&#39;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:53
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:32
int DriverVersionMinor
virtual int GetDriverVersionMajor()
Return the driver&#39;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&#39;s for common implementors of rendering drivers.
virtual int ExtensionSupported(const char *name)
Returns true if the extension is supported, false otherwise.
virtual bool DriverIsMicrosoft()
Test&#39;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:33
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
~vtkOpenGLExtensionManager() VTK_OVERRIDE
bool IgnoreDriverBugs
virtual bool DriverIsNvidia()
Test&#39;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&#39;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&#39;s for common implementors of rendering drivers.
int DriverGLVersionMajor
int DriverGLVersionMinor
DriverGLVendorIdType DriverGLVendorId
virtual bool DriverIsIntel()
Test&#39;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.