VTK  9.1.20220518
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 =========================================================================*/
57 #ifndef vtkOpenGLRenderWindow_h
58 #define vtkOpenGLRenderWindow_h
59 
60 #include "vtkDeprecation.h" // for VTK_DEPRECATED_IN_9_1_0
61 #include "vtkRect.h" // for vtkRecti
62 #include "vtkRenderWindow.h"
63 #include "vtkRenderingOpenGL2Module.h" // For export macro
64 #include "vtkType.h" // for ivar
65 #include <map> // for ivar
66 #include <set> // for ivar
67 #include <string> // for ivar
68 
69 class vtkIdList;
72 class vtkOpenGLHardwareSupport;
77 class vtkShaderProgram;
78 class vtkStdString;
79 class vtkTexture;
80 class vtkTextureObject;
83 class vtkOpenGLState;
84 
85 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
86 {
87 public:
89  void PrintSelf(ostream& os, vtkIndent indent) override;
90 
94  void Start(void) override;
95 
100  void Frame() override;
101 
105  const char* GetRenderingBackend() override;
106 
108 
114 
116 
121  unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
123  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
125  int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
127  int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
129 
131 
134  float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
136  int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
138  int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
139  int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
140  int right = 0) override;
141  void ReleaseRGBAPixelData(float* data) override;
142  unsigned char* GetRGBACharPixelData(
143  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, vtkUnsignedCharArray* data, int right = 0) override;
146  int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
147  int blend = 0, int right = 0) override;
148  int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
149  int blend = 0, int right = 0) override;
151 
153 
156  float* GetZbufferData(int x1, int y1, int x2, int y2) override;
157  int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
158  int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
159  int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
160  int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
162 
167 
172 
177 
181  int GetDepthBufferSize() override;
182 
187 
192  int GetColorBufferSizes(int* rgba) override;
193 
199  int GetColorBufferInternalFormat(int attachmentPoint);
200 
204  virtual void OpenGLInit();
205 
206  // Initialize the state of OpenGL that VTK wants for this window
207  virtual void OpenGLInitState();
208 
209  // Initialize VTK for rendering in a new OpenGL context
210  virtual void OpenGLInitContext();
211 
217  void GetOpenGLVersion(int& major, int& minor);
218 
220  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
221  unsigned int GetBackLeftBuffer();
222  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
223  unsigned int GetBackRightBuffer();
224  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
225  unsigned int GetFrontLeftBuffer();
226  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
227  unsigned int GetFrontRightBuffer();
228  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
229  unsigned int GetBackBuffer();
230  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1, now always returns 0")
231  unsigned int GetFrontBuffer();
233 
237  virtual vtkMTimeType GetContextCreationTime();
238 
242  vtkOpenGLShaderCache* GetShaderCache();
243 
248 
250 
253  vtkGetObjectMacro(RenderFramebuffer, vtkOpenGLFramebufferObject);
254  VTK_DEPRECATED_IN_9_1_0("Removed in 9.1")
255  vtkOpenGLFramebufferObject* GetOffScreenFramebuffer() { return this->RenderFramebuffer; }
257 
261  vtkGetObjectMacro(DisplayFramebuffer, vtkOpenGLFramebufferObject);
262 
268 
273  void WaitForCompletion() override;
274 
278  virtual void DrawPixels(
279  int x1, int y1, int x2, int y2, int numComponents, int dataType, void* data);
280 
285  virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin,
286  int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents,
287  int dataType, void* data);
288 
293  virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void* data);
294 
298  virtual float GetMaximumHardwareLineWidth() { return this->MaximumHardwareLineWidth; }
299 
306  virtual bool IsPointSpriteBugPresent() { return false; }
307 
314  int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB);
315 
321  std::string GetOpenGLSupportMessage() { return this->OpenGLSupportMessage; }
322 
326  int SupportsOpenGL() override;
327 
331  const char* ReportCapabilities() override;
332 
339  virtual void Initialize(void) {}
340 
341  std::set<vtkGenericOpenGLResourceFreeCallback*> Resources;
342 
344  {
345  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
346  if (it == this->Resources.end())
347  {
348  this->Resources.insert(cb);
349  }
350  }
351 
353  {
354  std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
355  if (it != this->Resources.end())
356  {
357  this->Resources.erase(it);
358  }
359  }
360 
370  virtual void PushContext() { this->MakeCurrent(); }
371  virtual void PopContext() {}
372 
378 
388  virtual bool SetSwapControl(int) { return false; }
389 
390  // Get the state object used to keep track of
391  // OpenGL state
392  virtual vtkOpenGLState* GetState() { return this->State; }
393 
394  // Get a VBO that can be shared by many
395  // It consists of normalized display
396  // coordinates for a quad and tcoords
398 
399  // Activate and return thje texture unit for a generic 2d 64x64
400  // float greyscale noise texture ranging from 0 to 1. The texture is
401  // generated using PerlinNoise. This textur eunit will automatically
402  // be deactivated at the end of the render process.
404 
408  void End() override;
409 
413  void Render() override;
414 
419  void StereoMidpoint() override;
420 
421  // does VTKs framebuffer require resolving for reading pixels
423 
429 
434 
438  void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX,
439  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
440 
442 
446  void BlitToRenderFramebuffer(bool includeDepth);
447  void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX,
448  int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
450 
456  {
457  BlitToHardware, // hardware buffers
458  BlitToCurrent, // currently bound draw framebuffer
459  NoBlit // no blit, GUI or external code will handle the blit
460  };
461 
463 
467  vtkSetClampMacro(FrameBlitMode, FrameBlitModes, BlitToHardware, NoBlit);
468  vtkGetMacro(FrameBlitMode, FrameBlitModes);
469  void SetFrameBlitModeToBlitToHardware() { this->SetFrameBlitMode(BlitToHardware); }
470  void SetFrameBlitModeToBlitToCurrent() { this->SetFrameBlitMode(BlitToCurrent); }
471  void SetFrameBlitModeToNoBlit() { this->SetFrameBlitMode(NoBlit); }
473 
475 
478  vtkSetMacro(FramebufferFlipY, bool);
479  vtkGetMacro(FramebufferFlipY, bool);
480  vtkBooleanMacro(FramebufferFlipY, bool);
482 
484  // copy depth values from a source framebuffer to a destination framebuffer
485  // using texture maps to do the copy. The source framebufferobject must be texture
486  // backed. This method is designed to work around issues with trying to blit depth
487  // values between framebuffers that have different depth formats.
488 
489  // blit entire source texture to active viewport
491 
492  // blit specified source texels to active viewport
493  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2);
494 
495  // blit specified source texels to specified viewport
496  virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2,
497  int destX, int destY, int destX2, int destY2);
499 
500 protected:
503 
504  // blits the display buffers to the appropriate hardware buffers
506 
507  // when frame is called, at the end blit to the hardware buffers
509 
510  // a FSQ we use to resolve MSAA that handles gamma
512 
513  // a FSQ we use to blit depth values
515 
516  // a FSQ we use to flip framebuffer texture
518 
519  // flip quad helpers Y tcoord
521 
522  // resolve and flip renderframebuffer as needed
523  // when copying to displayframebuffer. Returns
524  // true if the color buffer was copied.
526 
527  // used in testing for opengl support
528  // in the SupportsOpenGL() method
532 
533  virtual int ReadPixels(
534  const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right = 0);
535 
544  int CreateFramebuffers(int width, int height);
547 
548  // used when we need to resolve a multisampled
549  // framebuffer
551 
555  virtual void CreateAWindow() = 0;
556 
560  virtual void DestroyWindow() = 0;
561 
565  void SaveGLState();
566 
571 
572  std::map<std::string, int> GLStateIntegers;
573 
578 
580 
582 
583  bool Initialized; // ensure glewinit has been called
584  bool GlewInitValid; // Did glewInit initialize with a valid state?
585 
587 
589 
590  // used for fast quad rendering
592 
593  // noise texture
595 
597 
598  // keep track of in case we need to recreate the framebuffer
600 
601  int ScreenSize[2];
602 
603 private:
605  void operator=(const vtkOpenGLRenderWindow&) = delete;
606 
607  // Keeping `State` private so the only way to access it is through
608  // `this->GetState()`.
609  vtkOpenGLState* State;
610 };
611 
612 #endif
dynamic, self-adjusting array of float
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
OpenGL buffer object.
Internal class which encapsulates OpenGL FramebufferObject.
Class to make rendering a full screen quad easier.
OpenGL rendering window.
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...
vtkOpenGLBufferObject * GetTQuad2DVBO()
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.
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
bool GetUsingSRGBColorSpace()
Is this window/fo in sRGB colorspace.
void Start(void) override
Begin the rendering process.
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.
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.
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
virtual void Initialize(void)
Initialize the rendering window.
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.
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.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:108
abstracts an OpenGL texture object.
allocate/free texture units.
handles properties associated with a texture map
Definition: vtkTexture.h:178
record modification and/or execution time
Definition: vtkTimeStamp.h:55
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
virtual void MakeCurrent()
Make the window current.
Definition: vtkWindow.h:246
@ height
Definition: vtkX3D.h:260
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496
int vtkTypeBool
Definition: vtkABI.h:69
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_DEPRECATED_IN_9_1_0(reason)
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287