VTK  9.2.6
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 "vtkDeprecation.h" // for VTK_DEPRECATED_IN_9_1_0
32 #include "vtkRect.h" // for vtkRecti
33 #include "vtkRenderWindow.h"
34 #include "vtkRenderingOpenGL2Module.h" // For export macro
35 #include "vtkType.h" // for ivar
36 #include <map> // for ivar
37 #include <set> // for ivar
38 #include <string> // for ivar
39 
40 class vtkIdList;
43 class vtkOpenGLHardwareSupport;
48 class vtkShaderProgram;
49 class vtkStdString;
50 class vtkTexture;
51 class vtkTextureObject;
54 class vtkOpenGLState;
55 
56 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
57 {
58 public:
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
65  void Start(void) override;
66 
71  void Frame() override;
72 
76  const char* GetRenderingBackend() override;
77 
79 
82  static void SetGlobalMaximumNumberOfMultiSamples(int val);
83  static int GetGlobalMaximumNumberOfMultiSamples();
85 
87 
92  unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
93  int GetPixelData(
94  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
95  int SetPixelData(
96  int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
97  int SetPixelData(
98  int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
100 
102 
105  float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
106  int GetRGBAPixelData(
107  int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
108  int SetRGBAPixelData(
109  int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
110  int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
111  int right = 0) override;
112  void ReleaseRGBAPixelData(float* data) override;
113  unsigned char* GetRGBACharPixelData(
114  int x, int y, int x2, int y2, int front, int right = 0) override;
116  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
117  int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
118  int blend = 0, int right = 0) override;
119  int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
120  int blend = 0, int right = 0) override;
122 
124 
127  float* GetZbufferData(int x1, int y1, int x2, int y2) override;
128  int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
129  int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
130  int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
131  int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
133 
137  void ActivateTexture(vtkTextureObject*);
138 
142  void DeactivateTexture(vtkTextureObject*);
143 
147  int GetTextureUnitForTexture(vtkTextureObject*);
148 
152  int GetDepthBufferSize() override;
153 
157  bool GetUsingSRGBColorSpace();
158 
163  int GetColorBufferSizes(int* rgba) override;
164 
170  int GetColorBufferInternalFormat(int attachmentPoint);
171 
175  virtual void OpenGLInit();
176 
177  // Initialize the state of OpenGL that VTK wants for this window
178  virtual void OpenGLInitState();
179 
180  // Initialize VTK for rendering in a new OpenGL context
181  virtual void OpenGLInitContext();
182 
188  void GetOpenGLVersion(int& major, int& minor);
189 
191  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
192  unsigned int GetBackLeftBuffer();
193  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
194  unsigned int GetBackRightBuffer();
195  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
196  unsigned int GetFrontLeftBuffer();
197  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
198  unsigned int GetFrontRightBuffer();
199  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
200  unsigned int GetBackBuffer();
201  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
202  unsigned int GetFrontBuffer();
204 
208  virtual vtkMTimeType GetContextCreationTime();
209 
213  vtkOpenGLShaderCache* GetShaderCache();
214 
218  vtkOpenGLVertexBufferObjectCache* GetVBOCache();
219 
221 
224  vtkGetObjectMacro(RenderFramebuffer, vtkOpenGLFramebufferObject);
225  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1")
226  vtkOpenGLFramebufferObject* GetOffScreenFramebuffer() { return this->RenderFramebuffer; }
228 
232  vtkGetObjectMacro(DisplayFramebuffer, vtkOpenGLFramebufferObject);
233 
238  vtkTextureUnitManager* GetTextureUnitManager();
239 
244  void WaitForCompletion() override;
245 
249  virtual void DrawPixels(
250  int x1, int y1, int x2, int y2, int numComponents, int dataType, void* data);
251 
256  virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin,
257  int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents,
258  int dataType, void* data);
259 
264  virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void* data);
265 
269  virtual float GetMaximumHardwareLineWidth() { return this->MaximumHardwareLineWidth; }
270 
277  virtual bool IsPointSpriteBugPresent() { return false; }
278 
284  int GetDefaultTextureInternalFormat(
285  int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB);
286 
292  std::string GetOpenGLSupportMessage() { return this->OpenGLSupportMessage; }
293 
297  int SupportsOpenGL() override;
298 
302  const char* ReportCapabilities() override;
303 
310  virtual void Initialize(void) {}
311 
312  std::set<vtkGenericOpenGLResourceFreeCallback*> Resources;
313 
315  {
316  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
317  if (it == this->Resources.end())
318  {
319  this->Resources.insert(cb);
320  }
321  }
322 
324  {
325  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
326  if (it != this->Resources.end())
327  {
328  this->Resources.erase(it);
329  }
330  }
331 
341  virtual void PushContext() { this->MakeCurrent(); }
342  virtual void PopContext() {}
343 
348  bool InitializeFromCurrentContext() override;
349 
359  virtual bool SetSwapControl(int) { return false; }
360 
361  // Get the state object used to keep track of
362  // OpenGL state
363  virtual vtkOpenGLState* GetState() { return this->State; }
364 
365  // Get a VBO that can be shared by many
366  // It consists of normalized display
367  // coordinates for a quad and tcoords
368  vtkOpenGLBufferObject* GetTQuad2DVBO();
369 
370  // Activate and return thje texture unit for a generic 2d 64x64
371  // float greyscale noise texture ranging from 0 to 1. The texture is
372  // generated using PerlinNoise. This textur eunit will automatically
373  // be deactivated at the end of the render process.
374  int GetNoiseTextureUnit();
375 
379  void End() override;
380 
384  void Render() override;
385 
390  void StereoMidpoint() override;
391 
392  // does VTKs framebuffer require resolving for reading pixels
393  bool GetBufferNeedsResolving();
394 
399  void ReleaseGraphicsResources(vtkWindow*) override;
400 
404  void BlitDisplayFramebuffer();
405 
409  void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX,
410  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
411 
413 
417  void BlitToRenderFramebuffer(bool includeDepth);
418  void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX,
419  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
421 
427  {
428  BlitToHardware, // hardware buffers
429  BlitToCurrent, // currently bound draw framebuffer
430  NoBlit // no blit, GUI or external code will handle the blit
431  };
432 
434 
438  vtkSetClampMacro(FrameBlitMode, FrameBlitModes, BlitToHardware, NoBlit);
439  vtkGetMacro(FrameBlitMode, FrameBlitModes);
440  void SetFrameBlitModeToBlitToHardware() { this->SetFrameBlitMode(BlitToHardware); }
441  void SetFrameBlitModeToBlitToCurrent() { this->SetFrameBlitMode(BlitToCurrent); }
442  void SetFrameBlitModeToNoBlit() { this->SetFrameBlitMode(NoBlit); }
444 
446 
449  vtkSetMacro(FramebufferFlipY, bool);
450  vtkGetMacro(FramebufferFlipY, bool);
451  vtkBooleanMacro(FramebufferFlipY, bool);
453 
455  // copy depth values from a source framebuffer to a destination framebuffer
456  // using texture maps to do the copy. The source framebufferobject must be texture
457  // backed. This method is designed to work around issues with trying to blit depth
458  // values between framebuffers that have different depth formats.
459 
460  // blit entire source texture to active viewport
461  virtual void TextureDepthBlit(vtkTextureObject* source);
462 
463  // blit specified source texels to active viewport
464  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2);
465 
466  // blit specified source texels to specified viewport
467  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2,
468  int destX, int destY, int destX2, int destY2);
470 
471 protected:
473  ~vtkOpenGLRenderWindow() override;
474 
475  // blits the display buffers to the appropriate hardware buffers
476  virtual void BlitDisplayFramebuffersToHardware();
477 
478  // when frame is called, at the end blit to the hardware buffers
480 
481  // a FSQ we use to resolve MSAA that handles gamma
483 
484  // a FSQ we use to blit depth values
486 
487  // a FSQ we use to flip framebuffer texture
489 
490  // flip quad helpers Y tcoord
492 
493  // resolve and flip renderframebuffer as needed
494  // when copying to displayframebuffer. Returns
495  // true if the color buffer was copied.
496  virtual bool ResolveFlipRenderFramebuffer();
497 
498  // used in testing for opengl support
499  // in the SupportsOpenGL() method
503 
504  virtual int ReadPixels(
505  const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right = 0);
506 
515  int CreateFramebuffers(int width, int height);
518 
519  // used when we need to resolve a multisampled
520  // framebuffer
522 
526  virtual void CreateAWindow() = 0;
527 
531  virtual void DestroyWindow() = 0;
532 
536  void SaveGLState();
537 
541  void RestoreGLState();
542 
543  std::map<std::string, int> GLStateIntegers;
544 
549 
551 
553 
554  bool Initialized; // ensure glewinit has been called
555  bool GlewInitValid; // Did glewInit initialize with a valid state?
556 
558 
560 
561  // used for fast quad rendering
563 
564  // noise texture
566 
568 
569  // keep track of in case we need to recreate the framebuffer
571 
572  int ScreenSize[2];
573 
574 private:
576  void operator=(const vtkOpenGLRenderWindow&) = delete;
577 
578  // Keeping `State` private so the only way to access it is through
579  // `this->GetState()`.
580  vtkOpenGLState* State;
581 };
582 
583 #endif
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
OpenGL rendering window.
vtkOpenGLFramebufferObject * ResolveFramebuffer
virtual void Start()
Start the rendering process for a frame.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
#define VTK_DEPRECATED_IN_9_1_0(reason)
vtkTypeBool OwnContext
Flag telling if the context has been created here or was inherited.
virtual int GetDepthBufferSize()
This method should be defined by the subclass.
virtual float * GetZbufferData(int, int, int, int)
Set/Get the zbuffer data from the frame buffer.
void SetFrameBlitModeToBlitToHardware()
SetGet how to handle blits at the end of a Frame() call.
virtual unsigned char * GetPixelData(int, int, int, int, int, int=0)
Get the pixel data of an image, transmitted as RGBRGBRGB.
Definition: vtkWindow.h:195
virtual int SetPixelData(int, int, int, int, unsigned char *, int, int=0)
Set/Get the pixel data of an image, transmitted as RGBRGBRGB.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
manage Shader Programs within a context
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual int GetColorBufferSizes(int *)
Get the size of the color buffer.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
void SetFrameBlitModeToBlitToCurrent()
SetGet how to handle blits at the end of a Frame() call.
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkOpenGLQuadHelper * FlipQuad
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
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process...
int vtkTypeBool
Definition: vtkABI.h:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
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.
OpenGL state storage.
virtual int SetZbufferData(int, int, int, int, float *)
Set/Get the zbuffer data from the frame buffer.
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkTextureObject * DrawPixelsTextureObject
list of point or cell ids
Definition: vtkIdList.h:33
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void WaitForCompletion()
Block the thread until the actual rendering is finished().
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
handles properties associated with a texture map
Definition: vtkTexture.h:68
virtual void ReleaseRGBAPixelData(float *)
Same as Get/SetPixelData except that the image also contains an alpha component.
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:246
virtual void PushContext()
Ability to push and pop this window's context as the current context.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Internal class which encapsulates OpenGL FramebufferObject.
vtkTextureObject * NoiseTextureObject
dynamic, self-adjusting array of unsigned char
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
allocate/free texture units.
abstracts an OpenGL texture object.
virtual int SetRGBAPixelData(int, int, int, int, float *, int, int=0, int=0)
Same as Get/SetPixelData except that the image also contains an alpha component.
create a window for renderers to draw into
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.
void SetFrameBlitModeToNoBlit()
SetGet how to handle blits at the end of a Frame() call.
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
virtual unsigned char * GetRGBACharPixelData(int, int, int, int, int, int=0)
Same as Get/SetPixelData except that the image also contains an alpha component.
virtual void StereoMidpoint()
Intermediate method performs operations required between the rendering of the left and right eye...
vtkOpenGLQuadHelper * DepthBlitQuad
Class to make rendering a full screen quad easier.
FrameBlitModes
Define how the resulting image should be blitted when at the end of the Frame() call if SwapBuffers i...
vtkOpenGLFramebufferObject * RenderFramebuffer
virtual void End()
Update the system, if needed, at end of render process.
virtual float * GetRGBAPixelData(int, int, int, int, int, int=0)
Same as Get/SetPixelData except that the image also contains an alpha component.
vtkOpenGLBufferObject * TQuad2DVBO
OpenGL buffer object.
virtual vtkOpenGLState * GetState()
virtual void Initialize(void)
Initialize the rendering window.
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
std::map< std::string, int > GLStateIntegers
virtual void ReleaseGraphicsResources(vtkWindow *)
Release any graphics resources that are being consumed by this texture.
Definition: vtkWindow.h:180
vtkOpenGLQuadHelper * ResolveQuad
virtual void Frame()
A termination method performed at the end of the rendering process to do things like swapping buffers...
vtkOpenGLFramebufferObject * DisplayFramebuffer
The ShaderProgram uses one or more Shader objects.
virtual int SetRGBACharPixelData(int, int, int, int, unsigned char *, int, int=0, int=0)
Same as Get/SetPixelData except that the image also contains an alpha component.