VTK
vtkOpenGLRenderWindow.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLRenderWindow.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
25 #ifndef vtkOpenGLRenderWindow_h
26 #define vtkOpenGLRenderWindow_h
27 
28 #include "vtkRect.h" // for vtkRecti
29 #include "vtkRenderWindow.h"
30 #include "vtkRenderingOpenGL2Module.h" // For export macro
31 #include "vtkType.h" // for ivar
32 #include <map> // for ivar
33 #include <set> // for ivar
34 #include <string> // for ivar
35 
36 class vtkIdList;
41 class vtkShaderProgram;
42 class vtkStdString;
43 class vtkTexture;
44 class vtkTextureObject;
47 
48 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
49 {
50 public:
52  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
53 
57  const char *GetRenderingBackend() VTK_OVERRIDE;
58 
60 
63  static void SetGlobalMaximumNumberOfMultiSamples(int val);
64  static int GetGlobalMaximumNumberOfMultiSamples();
66 
70  void StereoUpdate() VTK_OVERRIDE;
71 
73 
76  unsigned char *GetPixelData(int x,int y,int x2,int y2,int front) VTK_OVERRIDE;
77  int GetPixelData(int x,int y,int x2,int y2, int front,
78  vtkUnsignedCharArray *data) VTK_OVERRIDE;
79  int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
80  int front) VTK_OVERRIDE;
81  int SetPixelData(int x,int y,int x2,int y2,
82  vtkUnsignedCharArray *data, int front) VTK_OVERRIDE;
84 
86 
89  float *GetRGBAPixelData(int x,int y,int x2,int y2,int front) VTK_OVERRIDE;
90  int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
91  vtkFloatArray* data) VTK_OVERRIDE;
92  int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
93  int front, int blend=0) VTK_OVERRIDE;
94  int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
95  int front, int blend=0) VTK_OVERRIDE;
96  void ReleaseRGBAPixelData(float *data) VTK_OVERRIDE;
97  unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
98  int front) VTK_OVERRIDE;
99  int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
100  vtkUnsignedCharArray *data) VTK_OVERRIDE;
101  int SetRGBACharPixelData(int x, int y, int x2, int y2,
102  unsigned char *data, int front,
103  int blend=0) VTK_OVERRIDE;
104  int SetRGBACharPixelData(int x,int y,int x2,int y2,
105  vtkUnsignedCharArray *data, int front,
106  int blend=0) VTK_OVERRIDE;
108 
110 
113  float *GetZbufferData( int x1, int y1, int x2, int y2 ) VTK_OVERRIDE;
114  int GetZbufferData( int x1, int y1, int x2, int y2, float* z ) VTK_OVERRIDE;
115  int GetZbufferData( int x1, int y1, int x2, int y2,
116  vtkFloatArray* z ) VTK_OVERRIDE;
117  int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer ) VTK_OVERRIDE;
118  int SetZbufferData( int x1, int y1, int x2, int y2,
119  vtkFloatArray *buffer ) VTK_OVERRIDE;
121 
122 
126  void ActivateTexture(vtkTextureObject *);
127 
131  void DeactivateTexture(vtkTextureObject *);
132 
136  int GetTextureUnitForTexture(vtkTextureObject *);
137 
141  int GetDepthBufferSize() VTK_OVERRIDE;
142 
147  int GetColorBufferSizes(int *rgba) VTK_OVERRIDE;
148 
150 
153  void SetSize(int a[2]) VTK_OVERRIDE;
154  void SetSize(int,int) VTK_OVERRIDE;
156 
160  virtual void OpenGLInit();
161 
162  // Initialize the state of OpenGL that VTK wants for this window
163  virtual void OpenGLInitState();
164 
165  // Initialize VTK for rendering in a new OpenGL context
166  virtual void OpenGLInitContext();
167 
169 
172  static bool GetContextSupportsOpenGL32();
173  void SetContextSupportsOpenGL32(bool val);
175 
181  void GetOpenGLVersion(int &major, int &minor);
182 
190  unsigned int GetBackLeftBuffer();
191 
199  unsigned int GetBackRightBuffer();
200 
208  unsigned int GetFrontLeftBuffer();
209 
217  unsigned int GetFrontRightBuffer();
218 
226  unsigned int GetBackBuffer();
227 
235  unsigned int GetFrontBuffer();
236 
240  virtual vtkMTimeType GetContextCreationTime();
241 
243 
246  vtkGetObjectMacro(ShaderCache,vtkOpenGLShaderCache);
248 
250 
253  vtkGetObjectMacro(VBOCache,vtkOpenGLVertexBufferObjectCache);
255 
257 
260  vtkGetMacro(FrameBufferObject, unsigned int);
262 
267  vtkTextureUnitManager *GetTextureUnitManager();
268 
273  void WaitForCompletion() VTK_OVERRIDE;
274 
278  virtual void DrawPixels(int x1, int y1, int x2, int y2,
279  int numComponents, int dataType, void *data);
280 
285  virtual void DrawPixels(
286  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
287  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
288  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
289 
294  virtual void DrawPixels(
295  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
296 
300  virtual float GetMaximumHardwareLineWidth() {
301  return this->MaximumHardwareLineWidth; };
302 
309  virtual bool IsPointSpriteBugPresent()
310  {
311  return 0;
312  }
313 
319  int GetDefaultTextureInternalFormat(
320  int vtktype, int numComponents,
321  bool needInteger, bool needFloat);
322 
329  {
330  return this->OpenGLSupportMessage;
331  }
332 
333  // Create and bind offscreen rendering buffers without destroying the current
334  // OpenGL context. This allows to temporary switch to offscreen rendering
335  // (ie. to make a screenshot even if the window is hidden).
336  // Return if the creation was successful (1) or not (0).
337  // Note: This function requires that the device supports OpenGL framebuffer extension.
338  // The function has no effect if OffScreenRendering is ON.
339  int SetUseOffScreenBuffers(bool offScreen) VTK_OVERRIDE;
340  bool GetUseOffScreenBuffers() VTK_OVERRIDE;
341 
345  int SupportsOpenGL() VTK_OVERRIDE;
346 
350  const char *ReportCapabilities() VTK_OVERRIDE;
351 
358  virtual void Initialize(void) {};
359 
360  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
361 
363  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
364  = this->Resources.find(cb);
365  if (it == this->Resources.end())
366  {
367  this->Resources.insert(cb);
368  }
369  }
370 
372  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
373  = this->Resources.find(cb);
374  if (it != this->Resources.end())
375  {
376  this->Resources.erase(it);
377  }
378  }
379 
389  virtual void PushContext() { this->MakeCurrent(); }
390  virtual void PopContext() {}
391 
396  bool InitializeFromCurrentContext() VTK_OVERRIDE;
397 
405  vtkGetMacro(DefaultFrameBufferId, unsigned int);
406 
407 protected:
409  ~vtkOpenGLRenderWindow() VTK_OVERRIDE;
410 
413 
414  // used in testing for opengl support
415  // in the SupportsOpenGL() method
419 
420  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
421  void InitializeTextureInternalFormats();
422 
423  std::map<const vtkTextureObject *, int> TextureResourceIds;
424 
425  virtual int ReadPixels(const vtkRecti& rect, int front, int glFormat, int glType, void* data);
426 
436  int CreateHardwareOffScreenWindow(int width, int height);
437 
438  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
439  void BindHardwareOffScreenBuffers();
440 
446  void DestroyHardwareOffScreenWindow();
447 
448  void UnbindHardwareOffScreenBuffers();
449  void DestroyHardwareOffScreenBuffers();
450 
454  int OffScreenUseFrameBuffer;
455 
457 
460  int NumberOfFrameBuffers;
461  unsigned int TextureObjects[4]; // really GLuint
462  unsigned int FrameBufferObject; // really GLuint
463  unsigned int DepthRenderBufferObject; // really GLuint
464  int HardwareBufferSize[2];
465  bool HardwareOffScreenBuffersBind;
467 
471  virtual void CreateAWindow() = 0;
472 
476  virtual void DestroyWindow() = 0;
477 
482  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
483 
487  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
488 
489 
493  void SaveGLState();
494 
498  void RestoreGLState();
499 
500  std::map<std::string, int> GLStateIntegers;
501 
502  unsigned int BackLeftBuffer;
503  unsigned int BackRightBuffer;
504  unsigned int FrontLeftBuffer;
505  unsigned int FrontRightBuffer;
506  unsigned int FrontBuffer;
507  unsigned int BackBuffer;
508  unsigned int DefaultFrameBufferId;
509 
510  #ifndef VTK_LEGACY_REMOVE
511 
515  unsigned int LastGraphicError;
516  #endif
517 
521  int OwnContext;
522 
523  vtkTimeStamp ContextCreationTime;
524 
525  vtkTextureUnitManager *TextureUnitManager;
526 
528 
529  bool Initialized; // ensure glewinit has been called
530  bool GlewInitValid; // Did glewInit initialize with a valid state?
531 
533 
535 
536 private:
537  vtkOpenGLRenderWindow(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
538  void operator=(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
539 };
540 
541 #endif
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
virtual int SetUseOffScreenBuffers(bool)
Create and bind offscreen rendering buffers without destroying the current OpenGL context...
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
manage Shader Programs within a context
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
record modification and/or execution time
Definition: vtkTimeStamp.h:32
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
manage vertex buffer objects shared within a context
#define VTK_UNICODE_STRING
Definition: vtkType.h:85
virtual const char * ReportCapabilities()
Get report of capabilities for the render window.
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
std::map< const vtkTextureObject *, int > TextureResourceIds
a simple class to control print indentation
Definition: vtkIndent.h:33
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkTextureObject * DrawPixelsTextureObject
list of point or cell ids
Definition: vtkIdList.h:30
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
handles properties associated with a texture map
Definition: vtkTexture.h:64
virtual void PushContext()
Ability to push and pop this window&#39;s context as the current context.
dynamic, self-adjusting array of unsigned char
allocate/free texture units.
vtkOpenGLShaderCache * ShaderCache
abstracts an OpenGL texture object.
create a window for renderers to draw into
OpenGL rendering window.
virtual bool InitializeFromCurrentContext()
Initialize the render window from the information associated with the currently activated OpenGL cont...
virtual const char * GetRenderingBackend()
What rendering backend has the user requested.
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
virtual bool GetUseOffScreenBuffers()
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
std::map< std::string, int > GLStateIntegers
void MakeCurrent() override=0
Attempt to make this window the current graphics context for the calling thread.
vtkOpenGLVertexBufferObjectCache * VBOCache
The ShaderProgram uses one or more Shader objects.