VTK  9.0.1
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;
39 class vtkOpenGLHardwareSupport;
43 class vtkShaderProgram;
44 class vtkStdString;
45 class vtkTexture;
46 class vtkTextureObject;
49 class vtkOpenGLState;
50 
51 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
52 {
53 public:
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
60  void Start(void) override;
61 
66  void Frame() override;
67 
71  const char* GetRenderingBackend() override;
72 
74 
77  static void SetGlobalMaximumNumberOfMultiSamples(int val);
78  static int GetGlobalMaximumNumberOfMultiSamples();
80 
82 
85  unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
86  int GetPixelData(
87  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
88  int SetPixelData(
89  int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
90  int SetPixelData(
91  int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
93 
95 
98  float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
99  int GetRGBAPixelData(
100  int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
101  int SetRGBAPixelData(
102  int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
103  int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
104  int right = 0) override;
105  void ReleaseRGBAPixelData(float* data) override;
106  unsigned char* GetRGBACharPixelData(
107  int x, int y, int x2, int y2, int front, int right = 0) override;
109  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
110  int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
111  int blend = 0, int right = 0) override;
112  int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
113  int blend = 0, int right = 0) override;
115 
117 
120  float* GetZbufferData(int x1, int y1, int x2, int y2) override;
121  int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
122  int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* z) override;
123  int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
124  int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
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 
174  void SetSize(int width, int height) override;
175  void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
177 
181  virtual void OpenGLInit();
182 
183  // Initialize the state of OpenGL that VTK wants for this window
184  virtual void OpenGLInitState();
185 
186  // Initialize VTK for rendering in a new OpenGL context
187  virtual void OpenGLInitContext();
188 
194  void GetOpenGLVersion(int& major, int& minor);
195 
203  unsigned int GetBackLeftBuffer();
204 
212  unsigned int GetBackRightBuffer();
213 
221  unsigned int GetFrontLeftBuffer();
222 
230  unsigned int GetFrontRightBuffer();
231 
236  unsigned int GetBackBuffer();
237 
242  unsigned int GetFrontBuffer();
243 
247  virtual vtkMTimeType GetContextCreationTime();
248 
252  vtkOpenGLShaderCache* GetShaderCache();
253 
257  vtkOpenGLVertexBufferObjectCache* GetVBOCache();
258 
260 
263  vtkGetObjectMacro(OffScreenFramebuffer, vtkOpenGLFramebufferObject);
265 
270  vtkTextureUnitManager* GetTextureUnitManager();
271 
276  void WaitForCompletion() override;
277 
281  virtual void DrawPixels(
282  int x1, int y1, int x2, int y2, int numComponents, int dataType, void* data);
283 
288  virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin,
289  int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents,
290  int dataType, void* data);
291 
296  virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void* data);
297 
301  virtual float GetMaximumHardwareLineWidth() { return this->MaximumHardwareLineWidth; }
302 
309  virtual bool IsPointSpriteBugPresent() { return 0; }
310 
316  int GetDefaultTextureInternalFormat(
317  int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB);
318 
324  std::string GetOpenGLSupportMessage() { return this->OpenGLSupportMessage; }
325 
329  int SupportsOpenGL() override;
330 
334  const char* ReportCapabilities() override;
335 
342  virtual void Initialize(void) {}
343 
344  std::set<vtkGenericOpenGLResourceFreeCallback*> Resources;
345 
347  {
348  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
349  if (it == this->Resources.end())
350  {
351  this->Resources.insert(cb);
352  }
353  }
354 
356  {
357  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
358  if (it != this->Resources.end())
359  {
360  this->Resources.erase(it);
361  }
362  }
363 
373  virtual void PushContext() { this->MakeCurrent(); }
374  virtual void PopContext() {}
375 
380  bool InitializeFromCurrentContext() override;
381 
389  vtkGetMacro(DefaultFrameBufferId, unsigned int);
390 
400  virtual bool SetSwapControl(int) { return false; }
401 
402  // Get the state object used to keep track of
403  // OpenGL state
404  virtual vtkOpenGLState* GetState() { return this->State; }
405 
406  // Get a VBO that can be shared by many
407  // It consists of normalized display
408  // coordinates for a quad and tcoords
409  vtkOpenGLBufferObject* GetTQuad2DVBO();
410 
411  // Activate and return thje texture unit for a generic 2d 64x64
412  // float greyscale noise texture ranging from 0 to 1. The texture is
413  // generated using PerlinNoise. This textur eunit will automatically
414  // be deactivated at the end of the render process.
415  int GetNoiseTextureUnit();
416 
420  void End() override;
421 
425  void Render() override;
426 
431  void StereoMidpoint() override;
432 
433  // does VTKs framebuffer require resolving for reading pixels
434  bool GetBufferNeedsResolving();
435 
440  void ReleaseGraphicsResources(vtkWindow*) override;
441 
442 protected:
444  ~vtkOpenGLRenderWindow() override;
445 
446  // used in testing for opengl support
447  // in the SupportsOpenGL() method
451 
452  virtual int ReadPixels(
453  const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right = 0);
454 
463  int CreateOffScreenFramebuffer(int width, int height);
465 
469  virtual void CreateAWindow() = 0;
470 
474  virtual void DestroyWindow() = 0;
475 
479  void SaveGLState();
480 
484  void RestoreGLState();
485 
486  std::map<std::string, int> GLStateIntegers;
487 
488  unsigned int BackLeftBuffer;
489  unsigned int BackRightBuffer;
490  unsigned int FrontLeftBuffer;
491  unsigned int FrontRightBuffer;
492  unsigned int DefaultFrameBufferId;
493 
498 
500 
502 
503  bool Initialized; // ensure glewinit has been called
504  bool GlewInitValid; // Did glewInit initialize with a valid state?
505 
507 
509 
510  // used for fast quad rendering
512 
513  // noise texture
515 
517 
518  // keep track of in case we need to recreate the framebuffer
520 
521  int ScreenSize[2];
522 
523 private:
525  void operator=(const vtkOpenGLRenderWindow&) = delete;
526 
527  // Keeping `State` private so the only way to access it is through
528  // `this->GetState()`.
529  vtkOpenGLState* State;
530 };
531 
532 #endif
vtkRenderWindow::SetPixelData
virtual int SetPixelData(int, int, int, int, unsigned char *, int, int=0)
Set/Get the pixel data of an image, transmitted as RGBRGBRGB.
Definition: vtkRenderWindow.h:427
vtkOpenGLRenderWindow::SetSize
void SetSize(int a[2]) override
Definition: vtkOpenGLRenderWindow.h:175
vtkOpenGLRenderWindow::GetMaximumHardwareLineWidth
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
Definition: vtkOpenGLRenderWindow.h:301
vtkOpenGLRenderWindow::RegisterGraphicsResources
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:346
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkOpenGLRenderWindow::DefaultFrameBufferId
unsigned int DefaultFrameBufferId
Definition: vtkOpenGLRenderWindow.h:492
vtkOpenGLRenderWindow::MaximumHardwareLineWidth
float MaximumHardwareLineWidth
Definition: vtkOpenGLRenderWindow.h:506
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
vtkOpenGLRenderWindow::SetSwapControl
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
Definition: vtkOpenGLRenderWindow.h:400
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkOpenGLRenderWindow::GetOpenGLSupportMessage
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
Definition: vtkOpenGLRenderWindow.h:324
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkOpenGLRenderWindow::LastMultiSamples
int LastMultiSamples
Definition: vtkOpenGLRenderWindow.h:519
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkOpenGLFramebufferObject
Internal class which encapsulates OpenGL FramebufferObject.
Definition: vtkOpenGLFramebufferObject.h:181
vtkRenderWindow.h
vtkOpenGLRenderWindow::UnregisterGraphicsResources
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:355
vtkOpenGLRenderWindow::DrawPixelsTextureObject
vtkTextureObject * DrawPixelsTextureObject
Definition: vtkOpenGLRenderWindow.h:501
vtkRenderWindow::SetRGBACharPixelData
virtual int SetRGBACharPixelData(int, int, int, int, unsigned char *, int, int=0, int=0)
Definition: vtkRenderWindow.h:478
vtkOpenGLRenderWindow::FrontRightBuffer
unsigned int FrontRightBuffer
Definition: vtkOpenGLRenderWindow.h:491
vtkRenderWindow::WaitForCompletion
virtual void WaitForCompletion()
Block the thread until the actual rendering is finished().
Definition: vtkRenderWindow.h:188
vtkOpenGLRenderWindow::OpenGLSupportMessage
std::string OpenGLSupportMessage
Definition: vtkOpenGLRenderWindow.h:450
vtkRenderWindow::SetZbufferData
virtual int SetZbufferData(int, int, int, int, float *)
Definition: vtkRenderWindow.h:505
vtkOpenGLRenderWindow::PopContext
virtual void PopContext()
Definition: vtkOpenGLRenderWindow.h:374
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkRenderWindow::GetZbufferData
virtual float * GetZbufferData(int, int, int, int)
Set/Get the zbuffer data from the frame buffer.
Definition: vtkRenderWindow.h:496
vtkOpenGLRenderWindow::GlewInitValid
bool GlewInitValid
Definition: vtkOpenGLRenderWindow.h:504
vtkType.h
vtkWindow::SetSize
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels).
vtkWindow::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources(vtkWindow *)
Release any graphics resources that are being consumed by this texture.
Definition: vtkWindow.h:173
vtkOpenGLRenderWindow::ContextCreationTime
vtkTimeStamp ContextCreationTime
Definition: vtkOpenGLRenderWindow.h:499
vtkTexture
handles properties associated with a texture map
Definition: vtkTexture.h:65
vtkOpenGLRenderWindow::OpenGLSupportResult
int OpenGLSupportResult
Definition: vtkOpenGLRenderWindow.h:449
vtkTextureUnitManager
allocate/free texture units.
Definition: vtkTextureUnitManager.h:38
vtkRenderWindow::GetRGBACharPixelData
virtual unsigned char * GetRGBACharPixelData(int, int, int, int, int, int=0)
Definition: vtkRenderWindow.h:468
vtkRenderWindow::StereoMidpoint
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye.
vtkX3D::height
@ height
Definition: vtkX3D.h:260
vtkRenderWindow::ReleaseRGBAPixelData
virtual void ReleaseRGBAPixelData(float *)
Definition: vtkRenderWindow.h:467
vtkRenderWindow::GetColorBufferSizes
virtual int GetColorBufferSizes(int *)
Get the size of the color buffer.
Definition: vtkRenderWindow.h:699
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:44
vtkOpenGLRenderWindow::OwnContext
int OwnContext
Flag telling if the context has been created here or was inherited.
Definition: vtkOpenGLRenderWindow.h:497
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:25
vtkRenderWindow::MakeCurrent
void MakeCurrent() override
Attempt to make this window the current graphics context for the calling thread.
Definition: vtkRenderWindow.h:651
vtkRect.h
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkRenderWindow::Render
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process.
vtkOpenGLRenderWindow::Capabilities
char * Capabilities
Definition: vtkOpenGLRenderWindow.h:508
vtkOpenGLRenderWindow::FrontLeftBuffer
unsigned int FrontLeftBuffer
Definition: vtkOpenGLRenderWindow.h:490
vtkOpenGLRenderWindow::NoiseTextureObject
vtkTextureObject * NoiseTextureObject
Definition: vtkOpenGLRenderWindow.h:514
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkOpenGLRenderWindow::GetState
virtual vtkOpenGLState * GetState()
Definition: vtkOpenGLRenderWindow.h:404
vtkRenderWindow::GetRGBAPixelData
virtual float * GetRGBAPixelData(int, int, int, int, int, int=0)
Same as Get/SetPixelData except that the image also contains an alpha component.
Definition: vtkRenderWindow.h:447
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:677
vtkOpenGLRenderWindow::IsPointSpriteBugPresent
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
Definition: vtkOpenGLRenderWindow.h:309
vtkRenderWindow::Frame
virtual void Frame()
A termination method performed at the end of the rendering process to do things like swapping buffers...
Definition: vtkRenderWindow.h:182
vtkRenderWindow::GetDepthBufferSize
virtual int GetDepthBufferSize()
This method should be defined by the subclass.
Definition: vtkRenderWindow.h:693
vtkRenderWindow::End
virtual void End()
Update the system, if needed, at end of render process.
Definition: vtkRenderWindow.h:171
vtkOpenGLRenderWindow::FirstRenderTime
double FirstRenderTime
Definition: vtkOpenGLRenderWindow.h:516
vtkOpenGLRenderWindow::Initialized
bool Initialized
Definition: vtkOpenGLRenderWindow.h:503
vtkRenderWindow::Start
virtual void Start()
Start the rendering process for a frame.
Definition: vtkRenderWindow.h:166
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkOpenGLRenderWindow::OpenGLSupportTested
bool OpenGLSupportTested
Definition: vtkOpenGLRenderWindow.h:448
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:489
vtkOpenGLVertexBufferObjectCache
manage vertex buffer objects shared within a context
Definition: vtkOpenGLVertexBufferObjectCache.h:38
vtkOpenGLRenderWindow::GLStateIntegers
std::map< std::string, int > GLStateIntegers
Definition: vtkOpenGLRenderWindow.h:486
vtkWindow::GetPixelData
virtual unsigned char * GetPixelData(int, int, int, int, int, int=0)
Get the pixel data of an image, transmitted as RGBRGBRGB.
Definition: vtkWindow.h:188
vtkOpenGLRenderWindow::BackLeftBuffer
unsigned int BackLeftBuffer
Definition: vtkOpenGLRenderWindow.h:488
vtkRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkRenderWindow.h:682
vtkRenderWindow::SetRGBAPixelData
virtual int SetRGBAPixelData(int, int, int, int, float *, int, int=0, int=0)
Definition: vtkRenderWindow.h:457
vtkRecti
Definition: vtkRect.h:312
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:51
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:93
vtkRenderWindow::InitializeFromCurrentContext
virtual bool InitializeFromCurrentContext()
Initialize the render window from the information associated with the currently activated OpenGL cont...
Definition: vtkRenderWindow.h:632
vtkOpenGLRenderWindow::OffScreenFramebuffer
vtkOpenGLFramebufferObject * OffScreenFramebuffer
Definition: vtkOpenGLRenderWindow.h:464
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:34
vtkOpenGLRenderWindow::TQuad2DVBO
vtkOpenGLBufferObject * TQuad2DVBO
Definition: vtkOpenGLRenderWindow.h:511
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:79
vtkOpenGLRenderWindow::PushContext
virtual void PushContext()
Ability to push and pop this window's context as the current context.
Definition: vtkOpenGLRenderWindow.h:373
vtkOpenGLRenderWindow::Resources
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
Definition: vtkOpenGLRenderWindow.h:344
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkOpenGLRenderWindow::Initialize
virtual void Initialize(void)
Initialize the rendering window.
Definition: vtkOpenGLRenderWindow.h:342
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293