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
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
OpenGL rendering window.
int OwnContext
Flag telling if the context has been created here or was inherited.
virtual void Start()
Start the rendering process for a frame.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
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.
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
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:293
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:32
void MakeCurrent() override
Attempt to make this window the current graphics context for the calling thread.
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
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...
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
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.
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
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:33
The VertexArrayObject class uses, or emulates, vertex array objects.
vtkTextureObject * DrawPixelsTextureObject
list of point or cell ids
Definition: vtkIdList.h:30
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().
vtkOpenGLFramebufferObject * OffScreenFramebuffer
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
handles properties associated with a texture map
Definition: vtkTexture.h:65
virtual void ReleaseRGBAPixelData(float *)
Same as Get/SetPixelData except that the image also contains an alpha component.
virtual void PushContext()
Ability to push and pop this window&#39;s context as the current context.
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 SetSize(int a[2]) override
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
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...
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:173
virtual void Frame()
A termination method performed at the end of the rendering process to do things like swapping buffers...
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.