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 =========================================================================*/
28 #ifndef vtkOpenGLRenderWindow_h
29 #define vtkOpenGLRenderWindow_h
30 
31 #include "vtkRect.h" // for vtkRecti
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderingOpenGL2Module.h" // For export macro
34 #include "vtkType.h" // for ivar
35 #include <map> // for ivar
36 #include <set> // for ivar
37 #include <string> // for ivar
38 
39 class vtkIdList;
41 class vtkOpenGLHardwareSupport;
45 class vtkShaderProgram;
46 class vtkStdString;
47 class vtkTexture;
48 class vtkTextureObject;
51 class vtkOpenGLState;
52 
53 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
54 {
55 public:
57  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
62  const char *GetRenderingBackend() override;
63 
65 
68  static void SetGlobalMaximumNumberOfMultiSamples(int val);
69  static int GetGlobalMaximumNumberOfMultiSamples();
71 
73 
76  unsigned char *GetPixelData(int x,int y,int x2,int y2,int front,int right)
77  override;
78  int GetPixelData(int x,int y,int x2,int y2, int front,
79  vtkUnsignedCharArray *data, int right) override;
80  int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
81  int front, int right) override;
82  int SetPixelData(int x,int y,int x2,int y2,
83  vtkUnsignedCharArray *data, int front, int right)
84  override;
86 
88 
91  float *GetRGBAPixelData(int x,int y,int x2,int y2,int front,int right=0)
92  override;
93  int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
94  vtkFloatArray* data, int right=0) override;
95  int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
96  int front, int blend=0, int right=0) override;
97  int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
98  int front, int blend=0, int right=0) override;
99  void ReleaseRGBAPixelData(float *data) override;
100  unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
101  int front, int right=0) override;
102  int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
103  vtkUnsignedCharArray *data, int right=0)
104  override;
105  int SetRGBACharPixelData(int x, int y, int x2, int y2,
106  unsigned char *data, int front,
107  int blend=0, int right=0) override;
108  int SetRGBACharPixelData(int x,int y,int x2,int y2,
109  vtkUnsignedCharArray *data, int front,
110  int blend=0,int right=0) override;
112 
114 
117  float *GetZbufferData( int x1, int y1, int x2, int y2 ) override;
118  int GetZbufferData( int x1, int y1, int x2, int y2, float* z ) override;
119  int GetZbufferData( int x1, int y1, int x2, int y2,
120  vtkFloatArray* z ) override;
121  int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer ) override;
122  int SetZbufferData( int x1, int y1, int x2, int y2,
123  vtkFloatArray *buffer ) override;
125 
126 
130  void ActivateTexture(vtkTextureObject *);
131 
135  void DeactivateTexture(vtkTextureObject *);
136 
140  int GetTextureUnitForTexture(vtkTextureObject *);
141 
145  int GetDepthBufferSize() override;
146 
150  bool GetUsingSRGBColorSpace();
151 
156  int GetColorBufferSizes(int *rgba) override;
157 
163  int GetColorBufferInternalFormat(int attachmentPoint);
164 
166 
169  void SetSize(int a[2]) override;
170  void SetSize(int,int) override;
172 
176  virtual void OpenGLInit();
177 
178  // Initialize the state of OpenGL that VTK wants for this window
179  virtual void OpenGLInitState();
180 
181  // Initialize VTK for rendering in a new OpenGL context
182  virtual void OpenGLInitContext();
183 
189  void GetOpenGLVersion(int &major, int &minor);
190 
198  unsigned int GetBackLeftBuffer();
199 
207  unsigned int GetBackRightBuffer();
208 
216  unsigned int GetFrontLeftBuffer();
217 
225  unsigned int GetFrontRightBuffer();
226 
234  unsigned int GetBackBuffer();
235 
243  unsigned int GetFrontBuffer();
244 
248  virtual vtkMTimeType GetContextCreationTime();
249 
251 
254  vtkGetObjectMacro(ShaderCache,vtkOpenGLShaderCache);
256 
258 
261  vtkGetObjectMacro(VBOCache,vtkOpenGLVertexBufferObjectCache);
263 
265 
268  vtkGetMacro(FrameBufferObject, unsigned int);
270 
275  vtkTextureUnitManager *GetTextureUnitManager();
276 
281  void WaitForCompletion() override;
282 
286  virtual void DrawPixels(int x1, int y1, int x2, int y2,
287  int numComponents, int dataType, void *data);
288 
293  virtual void DrawPixels(
294  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
295  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
296  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
297 
302  virtual void DrawPixels(
303  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
304 
308  virtual float GetMaximumHardwareLineWidth() {
309  return this->MaximumHardwareLineWidth; };
310 
317  virtual bool IsPointSpriteBugPresent()
318  {
319  return 0;
320  }
321 
327  int GetDefaultTextureInternalFormat(
328  int vtktype, int numComponents,
329  bool needInteger, bool needFloat, bool needSRGB);
330 
337  {
338  return this->OpenGLSupportMessage;
339  }
340 
341  // Create and bind offscreen rendering buffers without destroying the current
342  // OpenGL context. This allows to temporary switch to offscreen rendering
343  // (ie. to make a screenshot even if the window is hidden).
344  // Return if the creation was successful (1) or not (0).
345  // Note: This function requires that the device supports OpenGL framebuffer extension.
346  // The function has no effect if OffScreenRendering is ON.
347  int SetUseOffScreenBuffers(bool offScreen) override;
348  bool GetUseOffScreenBuffers() override;
349 
353  int SupportsOpenGL() override;
354 
358  const char *ReportCapabilities() override;
359 
366  virtual void Initialize(void) {};
367 
368  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
369 
371  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
372  = this->Resources.find(cb);
373  if (it == this->Resources.end())
374  {
375  this->Resources.insert(cb);
376  }
377  }
378 
380  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
381  = this->Resources.find(cb);
382  if (it != this->Resources.end())
383  {
384  this->Resources.erase(it);
385  }
386  }
387 
397  virtual void PushContext() { this->MakeCurrent(); }
398  virtual void PopContext() {}
399 
404  bool InitializeFromCurrentContext() override;
405 
413  vtkGetMacro(DefaultFrameBufferId, unsigned int);
414 
424  virtual bool SetSwapControl(int ) { return false; }
425 
426  // Get the state object used to keep track of
427  // OpenGL state
429  return this->State; }
430 
431  // Get a VBO that can be shared by many
432  // It consists of normalized display
433  // coordinates for a quad and tcoords
434  vtkOpenGLBufferObject *GetTQuad2DVBO();
435 
436  // Activate and return thje texture unit for a generic 2d 64x64
437  // float greyscale noise texture ranging from 0 to 1. The texture is
438  // generated using PerlinNoise. This textur eunit will automatically
439  // be deactivated at the end of the render process.
440  int GetNoiseTextureUnit();
441 
446  void StereoUpdate() override;
447 
452  void StereoMidpoint() override;
453 
457  void Render() override;
458 
459 protected:
461  ~vtkOpenGLRenderWindow() override;
462 
465 
467 
468  // used in testing for opengl support
469  // in the SupportsOpenGL() method
473 
474  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
475  void InitializeTextureInternalFormats();
476 
477  std::map<const vtkTextureObject *, int> TextureResourceIds;
478 
479  virtual int ReadPixels(const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right=0);
480 
490  int CreateHardwareOffScreenWindow(int width, int height);
491 
492  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
493  void BindHardwareOffScreenBuffers();
494 
500  void DestroyHardwareOffScreenWindow();
501 
502  void UnbindHardwareOffScreenBuffers();
503  void DestroyHardwareOffScreenBuffers();
504 
509 
511 
515  unsigned int TextureObjects[4]; // really GLuint
516  unsigned int FrameBufferObject; // really GLuint
517  unsigned int DepthRenderBufferObject; // really GLuint
518  int HardwareBufferSize[2];
521 
525  virtual void CreateAWindow() = 0;
526 
530  virtual void DestroyWindow() = 0;
531 
536  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
537 
541  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
542 
543 
547  void SaveGLState();
548 
552  void RestoreGLState();
553 
554  std::map<std::string, int> GLStateIntegers;
555 
556  unsigned int BackLeftBuffer;
557  unsigned int BackRightBuffer;
558  unsigned int FrontLeftBuffer;
559  unsigned int FrontRightBuffer;
560  unsigned int FrontBuffer;
561  unsigned int BackBuffer;
562  unsigned int DefaultFrameBufferId;
563 
568 
570 
572 
574 
575  bool Initialized; // ensure glewinit has been called
576  bool GlewInitValid; // Did glewInit initialize with a valid state?
577 
579 
581 
582  // used for fast quad rendering
584 
585  // noise texture
587 
588 private:
590  void operator=(const vtkOpenGLRenderWindow&) = delete;
591 };
592 
593 #endif
vtkWindow::SetSize
virtual void SetSize(int, int)
vtkOpenGLRenderWindow::GetMaximumHardwareLineWidth
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
Definition: vtkOpenGLRenderWindow.h:308
vtkOpenGLRenderWindow::RegisterGraphicsResources
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:370
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkOpenGLRenderWindow::NumberOfFrameBuffers
int NumberOfFrameBuffers
Variables used by the framebuffer-based offscreen method.
Definition: vtkOpenGLRenderWindow.h:514
vtkOpenGLRenderWindow::DefaultFrameBufferId
unsigned int DefaultFrameBufferId
Definition: vtkOpenGLRenderWindow.h:562
vtkRenderWindow::GetUseOffScreenBuffers
virtual bool GetUseOffScreenBuffers()
Definition: vtkRenderWindow.h:687
vtkOpenGLRenderWindow::MaximumHardwareLineWidth
float MaximumHardwareLineWidth
Definition: vtkOpenGLRenderWindow.h:578
vtkRenderWindow::GetColorBufferSizes
virtual int GetColorBufferSizes(int *rgba)=0
Get the size of the color buffer.
vtkRenderWindow::GetDepthBufferSize
virtual int GetDepthBufferSize()=0
This method should be defined by the subclass.
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkOpenGLRenderWindow::SetSwapControl
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
Definition: vtkOpenGLRenderWindow.h:424
vtkX3D::data
Definition: vtkX3D.h:315
vtkOpenGLRenderWindow::TextureResourceIds
std::map< const vtkTextureObject *, int > TextureResourceIds
Definition: vtkOpenGLRenderWindow.h:477
vtkRenderWindow::GetRGBAPixelData
virtual float * GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
vtkOpenGLRenderWindow::GetOpenGLSupportMessage
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
Definition: vtkOpenGLRenderWindow.h:336
VTK_UNICODE_STRING
#define VTK_UNICODE_STRING
Definition: vtkType.h:85
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkRenderWindow::SetUseOffScreenBuffers
virtual int SetUseOffScreenBuffers(bool)
Create and bind offscreen rendering buffers without destroying the current OpenGL context.
Definition: vtkRenderWindow.h:686
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:41
vtkRenderWindow.h
vtkOpenGLRenderWindow::UnregisterGraphicsResources
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:379
vtkOpenGLRenderWindow::DrawPixelsTextureObject
vtkTextureObject * DrawPixelsTextureObject
Definition: vtkOpenGLRenderWindow.h:573
vtkOpenGLRenderWindow::FrameBufferObject
unsigned int FrameBufferObject
Definition: vtkOpenGLRenderWindow.h:516
vtkOpenGLRenderWindow::TextureUnitManager
vtkTextureUnitManager * TextureUnitManager
Definition: vtkOpenGLRenderWindow.h:571
vtkOpenGLRenderWindow::OffScreenUseFrameBuffer
int OffScreenUseFrameBuffer
Flag telling if a framebuffer-based offscreen is currently in use.
Definition: vtkOpenGLRenderWindow.h:508
vtkOpenGLRenderWindow::FrontRightBuffer
unsigned int FrontRightBuffer
Definition: vtkOpenGLRenderWindow.h:559
vtkOpenGLRenderWindow::OpenGLSupportMessage
std::string OpenGLSupportMessage
Definition: vtkOpenGLRenderWindow.h:472
vtkOpenGLRenderWindow::PopContext
virtual void PopContext()
Definition: vtkOpenGLRenderWindow.h:398
vtkOpenGLRenderWindow::FrontBuffer
unsigned int FrontBuffer
Definition: vtkOpenGLRenderWindow.h:560
vtkOpenGLRenderWindow::GlewInitValid
bool GlewInitValid
Definition: vtkOpenGLRenderWindow.h:576
vtkType.h
vtkOpenGLRenderWindow::ContextCreationTime
vtkTimeStamp ContextCreationTime
Definition: vtkOpenGLRenderWindow.h:569
vtkTexture
handles properties associated with a texture map
Definition: vtkTexture.h:71
vtkOpenGLRenderWindow::OpenGLSupportResult
int OpenGLSupportResult
Definition: vtkOpenGLRenderWindow.h:471
vtkTextureUnitManager
allocate/free texture units.
Definition: vtkTextureUnitManager.h:38
vtkOpenGLRenderWindow::ShaderCache
vtkOpenGLShaderCache * ShaderCache
Definition: vtkOpenGLRenderWindow.h:463
vtkRenderWindow::StereoMidpoint
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye.
vtkOpenGLRenderWindow::HardwareOffScreenBuffersBind
bool HardwareOffScreenBuffersBind
Definition: vtkOpenGLRenderWindow.h:519
vtkX3D::height
Definition: vtkX3D.h:254
vtkOpenGLRenderWindow::VBOCache
vtkOpenGLVertexBufferObjectCache * VBOCache
Definition: vtkOpenGLRenderWindow.h:464
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:47
vtkOpenGLRenderWindow::OwnContext
int OwnContext
Flag telling if the context has been created here or was inherited.
Definition: vtkOpenGLRenderWindow.h:567
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:25
vtkRect.h
vtkRenderWindow::GetZbufferData
virtual float * GetZbufferData(int x, int y, int x2, int y2)=0
Set/Get the zbuffer data from the frame buffer.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:44
vtkRenderWindow::Render
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process.
vtkRenderWindow::SetPixelData
virtual int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int right=0)=0
Set/Get the pixel data of an image, transmitted as RGBRGBRGB.
vtkOpenGLRenderWindow::Capabilities
char * Capabilities
Definition: vtkOpenGLRenderWindow.h:580
vtkOpenGLRenderWindow::FrontLeftBuffer
unsigned int FrontLeftBuffer
Definition: vtkOpenGLRenderWindow.h:558
vtkOpenGLRenderWindow::NoiseTextureObject
vtkTextureObject * NoiseTextureObject
Definition: vtkOpenGLRenderWindow.h:586
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkRenderWindow::WaitForCompletion
virtual void WaitForCompletion()=0
Block the thread until the actual rendering is finished().
vtkOpenGLRenderWindow::GetState
virtual vtkOpenGLState * GetState()
Definition: vtkOpenGLRenderWindow.h:428
vtkRenderWindow::MakeCurrent
void MakeCurrent() override=0
Attempt to make this window the current graphics context for the calling thread.
vtkOpenGLShaderCache
manage Shader Programs within a context
Definition: vtkOpenGLShaderCache.h:35
vtkRenderWindow::ReportCapabilities
virtual const char * ReportCapabilities()
Get report of capabilities for the render window.
Definition: vtkRenderWindow.h:618
vtkOpenGLRenderWindow::IsPointSpriteBugPresent
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
Definition: vtkOpenGLRenderWindow.h:317
vtkOpenGLRenderWindow::Initialized
bool Initialized
Definition: vtkOpenGLRenderWindow.h:575
vtkX3D::string
Definition: vtkX3D.h:490
vtkRenderWindow::SetZbufferData
virtual int SetZbufferData(int x, int y, int x2, int y2, float *z)=0
vtkRenderWindow::SetRGBAPixelData
virtual int SetRGBAPixelData(int x, int y, int x2, int y2, float *, int front, int blend=0, int right=0)=0
vtkWindow::GetPixelData
virtual unsigned char * GetPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
Get the pixel data of an image, transmitted as RGBRGBRGB.
vtkOpenGLRenderWindow::OpenGLSupportTested
bool OpenGLSupportTested
Definition: vtkOpenGLRenderWindow.h:470
vtkRenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkOpenGLRenderWindow::BackRightBuffer
unsigned int BackRightBuffer
Definition: vtkOpenGLRenderWindow.h:557
vtkRenderWindow::GetRGBACharPixelData
virtual unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
vtkOpenGLVertexBufferObjectCache
manage vertex buffer objects shared within a context
Definition: vtkOpenGLVertexBufferObjectCache.h:38
vtkRenderWindow::StereoUpdate
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
vtkOpenGLRenderWindow::GLStateIntegers
std::map< std::string, int > GLStateIntegers
Definition: vtkOpenGLRenderWindow.h:554
vtkRenderWindow::ReleaseRGBAPixelData
virtual void ReleaseRGBAPixelData(float *data)=0
vtkOpenGLRenderWindow::BackLeftBuffer
unsigned int BackLeftBuffer
Definition: vtkOpenGLRenderWindow.h:556
vtkRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkRenderWindow.h:623
vtkRecti
Definition: vtkRect.h:323
vtkRenderWindow::SetRGBACharPixelData
virtual int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0)=0
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:53
vtkOpenGLRenderWindow::State
vtkOpenGLState * State
Definition: vtkOpenGLRenderWindow.h:466
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:87
vtkRenderWindow::InitializeFromCurrentContext
virtual bool InitializeFromCurrentContext()
Initialize the render window from the information associated with the currently activated OpenGL cont...
Definition: vtkRenderWindow.h:573
vtkRenderWindow::GetRenderingBackend
virtual const char * GetRenderingBackend()
What rendering backend has the user requested.
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkOpenGLRenderWindow::TQuad2DVBO
vtkOpenGLBufferObject * TQuad2DVBO
Definition: vtkOpenGLRenderWindow.h:583
vtkOpenGLRenderWindow::DepthRenderBufferObject
unsigned int DepthRenderBufferObject
Definition: vtkOpenGLRenderWindow.h:517
vtkOpenGLRenderWindow::BackBuffer
unsigned int BackBuffer
Definition: vtkOpenGLRenderWindow.h:561
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:67
vtkOpenGLRenderWindow::PushContext
virtual void PushContext()
Ability to push and pop this window's context as the current context.
Definition: vtkOpenGLRenderWindow.h:397
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302