VTK  9.2.20230606
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 =========================================================================*/
67 #ifndef vtkOpenGLRenderWindow_h
68 #define vtkOpenGLRenderWindow_h
69 
70 #include "vtkRect.h" // for vtkRecti
71 #include "vtkRenderWindow.h"
72 #include "vtkRenderingOpenGL2Module.h" // For export macro
73 #include "vtkType.h" // for ivar
74 #include <map> // for ivar
75 #include <set> // for ivar
76 #include <string> // for ivar
77 
78 VTK_ABI_NAMESPACE_BEGIN
79 class vtkIdList;
82 class vtkOpenGLHardwareSupport;
87 class vtkShaderProgram;
88 class vtkTexture;
89 class vtkTextureObject;
92 class vtkOpenGLState;
93 
94 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
95 {
96 public:
98  void PrintSelf(ostream& os, vtkIndent indent) override;
99 
103  void Start() override;
104 
109  void Frame() override;
110 
114  const char* GetRenderingBackend() override;
115 
117 
123 
125 
130  unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
132  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
134  int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
136  int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
138 
140 
143  float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
145  int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
147  int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
148  int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
149  int right = 0) override;
150  void ReleaseRGBAPixelData(float* data) override;
151  unsigned char* GetRGBACharPixelData(
152  int x, int y, int x2, int y2, int front, int right = 0) override;
154  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
155  int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
156  int blend = 0, int right = 0) override;
157  int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
158  int blend = 0, int right = 0) override;
160 
162 
165  float* GetZbufferData(int x1, int y1, int x2, int y2) override;
166  int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
167  int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
168  int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
169  int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
171 
176 
181 
186 
190  int GetDepthBufferSize() override;
191 
196 
201  int GetColorBufferSizes(int* rgba) override;
202 
208  int GetColorBufferInternalFormat(int attachmentPoint);
209 
213  virtual void OpenGLInit();
214 
215  // Initialize the state of OpenGL that VTK wants for this window
216  virtual void OpenGLInitState();
217 
218  // Initialize VTK for rendering in a new OpenGL context
219  virtual void OpenGLInitContext();
220 
226  void GetOpenGLVersion(int& major, int& minor);
227 
232 
237 
242 
244 
247  vtkGetObjectMacro(RenderFramebuffer, vtkOpenGLFramebufferObject);
249 
253  vtkGetObjectMacro(DisplayFramebuffer, vtkOpenGLFramebufferObject);
254 
260 
265  void WaitForCompletion() override;
266 
270  virtual void DrawPixels(
271  int x1, int y1, int x2, int y2, int numComponents, int dataType, void* data);
272 
277  virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin,
278  int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents,
279  int dataType, void* data);
280 
285  virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void* data);
286 
290  virtual float GetMaximumHardwareLineWidth() { return this->MaximumHardwareLineWidth; }
291 
298  virtual bool IsPointSpriteBugPresent() { return false; }
299 
306  int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB);
307 
313  std::string GetOpenGLSupportMessage() { return this->OpenGLSupportMessage; }
314 
318  int SupportsOpenGL() override;
319 
323  const char* ReportCapabilities() override;
324 
331  virtual void Initialize() {}
332 
333  std::set<vtkGenericOpenGLResourceFreeCallback*> Resources;
334 
336  {
337  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
338  if (it == this->Resources.end())
339  {
340  this->Resources.insert(cb);
341  }
342  }
343 
345  {
346  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
347  if (it != this->Resources.end())
348  {
349  this->Resources.erase(it);
350  }
351  }
352 
362  virtual void PushContext() { this->MakeCurrent(); }
363  virtual void PopContext() {}
364 
370 
380  virtual bool SetSwapControl(int) { return false; }
381 
382  // Get the state object used to keep track of
383  // OpenGL state
384  virtual vtkOpenGLState* GetState() { return this->State; }
385 
386  // Get a VBO that can be shared by many
387  // It consists of normalized display
388  // coordinates for a quad and tcoords
390 
391  // Activate and return thje texture unit for a generic 2d 64x64
392  // float greyscale noise texture ranging from 0 to 1. The texture is
393  // a hard-coded blue noise texture. This texture unit will automatically
394  // be deactivated at the end of the render process.
396 
400  void End() override;
401 
405  void Render() override;
406 
411  void StereoMidpoint() override;
412 
413  // does VTKs framebuffer require resolving for reading pixels
415 
421 
426 
430  void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX,
431  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
432 
434 
438  void BlitToRenderFramebuffer(bool includeDepth);
439  void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX,
440  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
442 
448  {
449  BlitToHardware, // hardware buffers
450  BlitToCurrent, // currently bound draw framebuffer
451  NoBlit // no blit, GUI or external code will handle the blit
452  };
453 
455 
459  vtkSetClampMacro(FrameBlitMode, FrameBlitModes, BlitToHardware, NoBlit);
460  vtkGetMacro(FrameBlitMode, FrameBlitModes);
461  void SetFrameBlitModeToBlitToHardware() { this->SetFrameBlitMode(BlitToHardware); }
462  void SetFrameBlitModeToBlitToCurrent() { this->SetFrameBlitMode(BlitToCurrent); }
463  void SetFrameBlitModeToNoBlit() { this->SetFrameBlitMode(NoBlit); }
465 
467 
470  vtkSetMacro(FramebufferFlipY, bool);
471  vtkGetMacro(FramebufferFlipY, bool);
472  vtkBooleanMacro(FramebufferFlipY, bool);
474 
476  // copy depth values from a source framebuffer to a destination framebuffer
477  // using texture maps to do the copy. The source framebufferobject must be texture
478  // backed. This method is designed to work around issues with trying to blit depth
479  // values between framebuffers that have different depth formats.
480 
481  // blit entire source texture to active viewport
483 
484  // blit specified source texels to active viewport
485  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2);
486 
487  // blit specified source texels to specified viewport
488  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2,
489  int destX, int destY, int destX2, int destY2);
491 
492 protected:
495 
496  // blits the display buffers to the appropriate hardware buffers
498 
499  // when frame is called, at the end blit to the hardware buffers
501 
502  // a FSQ we use to resolve MSAA that handles gamma
504 
505  // a FSQ we use to blit depth values
507 
508  // a FSQ we use to flip framebuffer texture
510 
511  // a FSQ we use to read depth component on platforms with OpenGL ES implementations
512  // because `glReadPixels` cannot be used to read GL_DEPTH_COMPONENT
514 
515  // flip quad helpers Y tcoord
517 
518  // resolve and flip renderframebuffer as needed
519  // when copying to displayframebuffer. Returns
520  // true if the color buffer was copied.
522 
523  // On GLES, the depth attachment buffer cannot be downloaded from
524  // the GPU with `glReadPixels`.
525  // This method reads the depth buffer bits.
526  // The depth attachment size can be 8,16,24 or 32. The values are split into 4 8-bit numbers.
527  // These are stored in the form of an RGBA color attachment in DepthFrameBuffer.
528  // `glReadPixels` can read that RGBA format and reconstruct full 8,16,24 or 32-bit integer
529  // followed by scaling down to 0-1.
530  bool ReadDepthComponent(int depthSize);
531 
532  // used in testing for opengl support
533  // in the SupportsOpenGL() method
537 
538  virtual int ReadPixels(
539  const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right = 0);
540 
549  int CreateFramebuffers(int width, int height);
552 
553  // used when we need to resolve a multisampled
554  // framebuffer
556 
557  // used when we need to read depth component
558  // with OpenGL ES 3
560 
564  virtual void CreateAWindow() = 0;
565 
569  virtual void DestroyWindow() = 0;
570 
574  void SaveGLState();
575 
580 
581  std::map<std::string, int> GLStateIntegers;
582 
587 
589 
591 
592  bool Initialized; // ensure glewinit has been called
593  bool GlewInitValid; // Did glewInit initialize with a valid state?
594 
596 
598 
599  // used for fast quad rendering
601 
602  // noise texture
604 
606 
607  // keep track of in case we need to recreate the framebuffer
609 
610  int ScreenSize[2];
611 
612 private:
614  void operator=(const vtkOpenGLRenderWindow&) = delete;
615 
616  // Keeping `State` private so the only way to access it is through
617  // `this->GetState()`.
618  vtkOpenGLState* State;
619 };
620 
621 VTK_ABI_NAMESPACE_END
622 #endif
dynamic, self-adjusting array of float
list of point or cell ids
Definition: vtkIdList.h:144
a simple class to control print indentation
Definition: vtkIndent.h:120
OpenGL buffer object.
Internal class which encapsulates OpenGL FramebufferObject.
Class to make rendering a full screen quad easier.
OpenGL rendering window.
void Start() override
Begin the rendering process.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
int GetColorBufferInternalFormat(int attachmentPoint)
Get the internal format of current attached texture or render buffer.
int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin, int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function, but it allows for scaling the data and using only part...
vtkOpenGLFramebufferObject * DisplayFramebuffer
std::map< std::string, int > GLStateIntegers
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
int GetRGBAPixelData(int x, int y, int x2, int y2, int front, vtkFloatArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
bool ReadDepthComponent(int depthSize)
vtkOpenGLBufferObject * GetTQuad2DVBO()
vtkOpenGLQuadHelper * DepthReadQuad
virtual void DrawPixels(int x1, int y1, int x2, int y2, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function.
int SetRGBAPixelData(int x, int y, int x2, int y2, float *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
int GetTextureUnitForTexture(vtkTextureObject *)
Get the texture unit for a given texture object.
virtual void Initialize()
Initialize the rendering window.
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
FrameBlitModes
Define how the resulting image should be blitted when at the end of the Frame() call if SwapBuffers i...
virtual void TextureDepthBlit(vtkTextureObject *source)
vtkTypeBool OwnContext
Flag telling if the context has been created here or was inherited.
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
Set/Get the zbuffer data from an image.
virtual void TextureDepthBlit(vtkTextureObject *source, int srcX, int srcY, int srcX2, int srcY2, int destX, int destY, int destX2, int destY2)
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkTextureObject * NoiseTextureObject
vtkOpenGLFramebufferObject * ResolveFramebuffer
int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void End() override
Update the system, if needed, at end of render process.
unsigned char * GetPixelData(int x, int y, int x2, int y2, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
void BlitToRenderFramebuffer(bool includeDepth)
Blit the currently bound read buffer to the renderbuffer.
static void SetGlobalMaximumNumberOfMultiSamples(int val)
Set/Get the maximum number of multisamples.
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
vtkTextureUnitManager * GetTextureUnitManager()
Returns its texture unit manager object.
int GetDefaultTextureInternalFormat(int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB)
Get a mapping of vtk data types to native texture formats for this window we put this on the RenderWi...
void ActivateTexture(vtkTextureObject *)
Activate a texture unit for this texture.
vtkTextureObject * DrawPixelsTextureObject
vtkOpenGLFramebufferObject * DepthFramebuffer
bool GetUsingSRGBColorSpace()
Is this window/fo in sRGB colorspace.
int GetColorBufferSizes(int *rgba) override
Get the size of the color buffer.
int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void Render() override
Handle opengl specific code and calls superclass.
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int bufferMode, int interpolation)
Blit a display buffer into a currently bound draw destination.
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
void ReleaseRGBAPixelData(float *data) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
const char * GetRenderingBackend() override
What rendering backend has the user requested.
virtual void OpenGLInitContext()
vtkOpenGLQuadHelper * DepthBlitQuad
virtual void TextureDepthBlit(vtkTextureObject *source, int srcX, int srcY, int srcX2, int srcY2)
void WaitForCompletion() override
Block the thread until the actual rendering is finished().
virtual bool ResolveFlipRenderFramebuffer()
virtual void PushContext()
Ability to push and pop this window's context as the current context.
vtkOpenGLVertexBufferObjectCache * GetVBOCache()
Returns the VBO Cache.
float * GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkOpenGLQuadHelper * FlipQuad
virtual void OpenGLInitState()
vtkOpenGLFramebufferObject * RenderFramebuffer
static int GetGlobalMaximumNumberOfMultiSamples()
Set/Get the maximum number of multisamples.
virtual void CreateAWindow()=0
Create a not-off-screen window.
void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int bufferMode, int interpolation)
Blit the currently bound read buffer to the renderbuffer.
virtual int ReadPixels(const vtkRecti &rect, int front, int glFormat, int glType, void *data, int right=0)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
virtual vtkMTimeType GetContextCreationTime()
Get the time when the OpenGL context was created.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
int SetPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
int GetDepthBufferSize() override
Get the size of the depth buffer.
void SetFrameBlitModeToBlitToCurrent()
SetGet how to handle blits at the end of a Frame() call.
bool InitializeFromCurrentContext() override
Initialize the render window from the information associated with the currently activated OpenGL cont...
virtual vtkOpenGLState * GetState()
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
vtkOpenGLBufferObject * TQuad2DVBO
~vtkOpenGLRenderWindow() override
void SetFrameBlitModeToNoBlit()
SetGet how to handle blits at the end of a Frame() call.
int CreateFramebuffers(int width, int height)
Create the offScreen framebuffer Return if the creation was successful or not.
vtkOpenGLShaderCache * GetShaderCache()
Returns an Shader Cache object.
virtual void OpenGLInit()
Initialize OpenGL for this window.
int SetZbufferData(int x1, int y1, int x2, int y2, float *buffer) override
Set/Get the zbuffer data from an image.
void BlitDisplayFramebuffer()
Blit a display framebuffer into a currently bound draw destination.
virtual void BlitDisplayFramebuffersToHardware()
void DeactivateTexture(vtkTextureObject *)
Deactivate a previously activated texture.
void RestoreGLState()
Restore OpenGL state at end of the rendering.
void GetOpenGLVersion(int &major, int &minor)
Get the major and minor version numbers of the OpenGL context we are using ala 3.2,...
void SaveGLState()
Query and save OpenGL state.
int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
int GetRGBACharPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
float * GetZbufferData(int x1, int y1, int x2, int y2) override
Set/Get the zbuffer data from an image.
void SetFrameBlitModeToBlitToHardware()
SetGet how to handle blits at the end of a Frame() call.
int GetPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB...
virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function.
vtkOpenGLQuadHelper * ResolveQuad
manage Shader Programs within a context
OpenGL state storage.
The VertexArrayObject class uses, or emulates, vertex array objects.
manage vertex buffer objects shared within a context
create a window for renderers to draw into
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
allocate/free texture units.
handles properties associated with a texture map
Definition: vtkTexture.h:179
record modification and/or execution time
Definition: vtkTimeStamp.h:56
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition: vtkWindow.h:40
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:247
@ height
Definition: vtkX3D.h:266
@ data
Definition: vtkX3D.h:327
@ string
Definition: vtkX3D.h:502
int vtkTypeBool
Definition: vtkABI.h:71
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:282