VTK  9.0.2
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 
80 
82 
85  unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
87  int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
89  int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
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;
100  int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
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 
131 
136 
141 
145  int GetDepthBufferSize() override;
146 
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 
248 
253 
258 
260 
263  vtkGetObjectMacro(OffScreenFramebuffer, vtkOpenGLFramebufferObject);
265 
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 
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 
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
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.
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
435 
441 
442 protected:
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 
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
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:36
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
OpenGL buffer object.
Internal class which encapsulates OpenGL FramebufferObject.
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...
void SetSize(int a[2]) override
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
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...
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
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
int GetTextureUnitForTexture(vtkTextureObject *)
Get the texture unit for a given texture object.
int OwnContext
Flag telling if the context has been created here or was inherited.
int CreateOffScreenFramebuffer(int width, int height)
Create the offScreen framebuffer Return if the creation was successful or not.
unsigned int GetBackRightBuffer()
Return the OpenGL name of the back right buffer.
vtkOpenGLFramebufferObject * OffScreenFramebuffer
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkTextureObject * NoiseTextureObject
unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0) override
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...
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.
unsigned int GetBackBuffer()
Return the OpenGL name of the back left buffer.
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 RGBRGBRGB.
int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0) override
void Render() override
Handle opengl specific code and calls superclass.
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
void SetSize(int width, int height) override
Set the size (width and height) of the rendering window in screen coordinates (in pixels).
unsigned int GetFrontRightBuffer()
Return the OpenGL name of the front right buffer.
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
unsigned int GetFrontBuffer()
Return the OpenGL name of the front left buffer.
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
const char * GetRenderingBackend() override
What rendering backend has the user requested.
virtual void OpenGLInitContext()
unsigned int GetBackLeftBuffer()
Return the OpenGL name of the back left buffer.
void WaitForCompletion() override
Block the thread until the actual rendering is finished().
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...
virtual void OpenGLInitState()
static int GetGlobalMaximumNumberOfMultiSamples()
virtual void CreateAWindow()=0
Create a not-off-screen window.
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.
unsigned int GetFrontLeftBuffer()
Return the OpenGL name of the front left buffer.
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
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
int GetDepthBufferSize() override
Get the size of the depth buffer.
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.
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
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
int GetRGBACharPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right=0) override
float * GetZbufferData(int x1, int y1, int x2, int y2) override
Set/Get the zbuffer data from an image.
int GetPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right) override
virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function.
int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *z) override
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
void MakeCurrent() override
Attempt to make this window the current graphics context for the calling thread.
The ShaderProgram uses one or more Shader objects.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:35
abstracts an OpenGL texture object.
allocate/free texture units.
handles properties associated with a texture map
Definition: vtkTexture.h:66
record modification and/or execution time
Definition: vtkTimeStamp.h:33
dynamic, self-adjusting array of unsigned char
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
@ height
Definition: vtkX3D.h:260
@ data
Definition: vtkX3D.h:321
@ string
Definition: vtkX3D.h:496
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293