VTK
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 "vtkRect.h" // for vtkRecti
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderingOpenGL2Module.h" // For export macro
34 #include "vtkType.h" // for ivar
35 #include <map> // for ivar
36 #include <set> // for ivar
37 #include <string> // for ivar
38 
39 class vtkIdList;
44 class vtkShaderProgram;
45 class vtkStdString;
46 class vtkTexture;
47 class vtkTextureObject;
50 
51 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
52 {
53 public:
55  void PrintSelf(ostream& os, vtkIndent indent) override;
56 
60  const char *GetRenderingBackend() override;
61 
63 
66  static void SetGlobalMaximumNumberOfMultiSamples(int val);
67  static int GetGlobalMaximumNumberOfMultiSamples();
69 
71 
74  unsigned char *GetPixelData(int x,int y,int x2,int y2,int front,int right)
75  override;
76  int GetPixelData(int x,int y,int x2,int y2, int front,
77  vtkUnsignedCharArray *data, int right) override;
78  int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
79  int front, int right) override;
80  int SetPixelData(int x,int y,int x2,int y2,
81  vtkUnsignedCharArray *data, int front, int right)
82  override;
84 
86 
89  float *GetRGBAPixelData(int x,int y,int x2,int y2,int front,int right=0)
90  override;
91  int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
92  vtkFloatArray* data, int right=0) override;
93  int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
94  int front, int blend=0, int right=0) override;
95  int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
96  int front, int blend=0, int right=0) override;
97  void ReleaseRGBAPixelData(float *data) override;
98  unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
99  int front, int right=0) override;
100  int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
101  vtkUnsignedCharArray *data, int right=0)
102  override;
103  int SetRGBACharPixelData(int x, int y, int x2, int y2,
104  unsigned char *data, int front,
105  int blend=0, int right=0) override;
106  int SetRGBACharPixelData(int x,int y,int x2,int y2,
107  vtkUnsignedCharArray *data, int front,
108  int blend=0,int right=0) override;
110 
112 
115  float *GetZbufferData( int x1, int y1, int x2, int y2 ) override;
116  int GetZbufferData( int x1, int y1, int x2, int y2, float* z ) override;
117  int GetZbufferData( int x1, int y1, int x2, int y2,
118  vtkFloatArray* z ) override;
119  int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer ) override;
120  int SetZbufferData( int x1, int y1, int x2, int y2,
121  vtkFloatArray *buffer ) override;
123 
124 
128  void ActivateTexture(vtkTextureObject *);
129 
133  void DeactivateTexture(vtkTextureObject *);
134 
138  int GetTextureUnitForTexture(vtkTextureObject *);
139 
143  int GetDepthBufferSize() override;
144 
148  bool GetUsingSRGBColorSpace();
149 
154  int GetColorBufferSizes(int *rgba) override;
155 
157 
160  void SetSize(int a[2]) override;
161  void SetSize(int,int) override;
163 
167  virtual void OpenGLInit();
168 
169  // Initialize the state of OpenGL that VTK wants for this window
170  virtual void OpenGLInitState();
171 
172  // Initialize VTK for rendering in a new OpenGL context
173  virtual void OpenGLInitContext();
174 
176 
179  static bool GetContextSupportsOpenGL32();
180  void SetContextSupportsOpenGL32(bool val);
182 
188  void GetOpenGLVersion(int &major, int &minor);
189 
197  unsigned int GetBackLeftBuffer();
198 
206  unsigned int GetBackRightBuffer();
207 
215  unsigned int GetFrontLeftBuffer();
216 
224  unsigned int GetFrontRightBuffer();
225 
233  unsigned int GetBackBuffer();
234 
242  unsigned int GetFrontBuffer();
243 
247  virtual vtkMTimeType GetContextCreationTime();
248 
250 
253  vtkGetObjectMacro(ShaderCache,vtkOpenGLShaderCache);
255 
257 
260  vtkGetObjectMacro(VBOCache,vtkOpenGLVertexBufferObjectCache);
262 
264 
267  vtkGetMacro(FrameBufferObject, unsigned int);
269 
274  vtkTextureUnitManager *GetTextureUnitManager();
275 
280  void WaitForCompletion() override;
281 
285  virtual void DrawPixels(int x1, int y1, int x2, int y2,
286  int numComponents, int dataType, void *data);
287 
292  virtual void DrawPixels(
293  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
294  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
295  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
296 
301  virtual void DrawPixels(
302  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
303 
307  virtual float GetMaximumHardwareLineWidth() {
308  return this->MaximumHardwareLineWidth; };
309 
316  virtual bool IsPointSpriteBugPresent()
317  {
318  return 0;
319  }
320 
326  int GetDefaultTextureInternalFormat(
327  int vtktype, int numComponents,
328  bool needInteger, bool needFloat, bool needSRGB);
329 
336  {
337  return this->OpenGLSupportMessage;
338  }
339 
340  // Create and bind offscreen rendering buffers without destroying the current
341  // OpenGL context. This allows to temporary switch to offscreen rendering
342  // (ie. to make a screenshot even if the window is hidden).
343  // Return if the creation was successful (1) or not (0).
344  // Note: This function requires that the device supports OpenGL framebuffer extension.
345  // The function has no effect if OffScreenRendering is ON.
346  int SetUseOffScreenBuffers(bool offScreen) override;
347  bool GetUseOffScreenBuffers() override;
348 
352  int SupportsOpenGL() override;
353 
357  const char *ReportCapabilities() override;
358 
365  virtual void Initialize(void) {};
366 
367  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
368 
370  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
371  = this->Resources.find(cb);
372  if (it == this->Resources.end())
373  {
374  this->Resources.insert(cb);
375  }
376  }
377 
379  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
380  = this->Resources.find(cb);
381  if (it != this->Resources.end())
382  {
383  this->Resources.erase(it);
384  }
385  }
386 
396  virtual void PushContext() { this->MakeCurrent(); }
397  virtual void PopContext() {}
398 
403  bool InitializeFromCurrentContext() override;
404 
412  vtkGetMacro(DefaultFrameBufferId, unsigned int);
413 
423  virtual bool SetSwapControl(int ) { return false; }
424 
425 protected:
427  ~vtkOpenGLRenderWindow() override;
428 
431 
432  // used in testing for opengl support
433  // in the SupportsOpenGL() method
437 
438  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
439  void InitializeTextureInternalFormats();
440 
441  std::map<const vtkTextureObject *, int> TextureResourceIds;
442 
443  virtual int ReadPixels(const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right=0);
444 
454  int CreateHardwareOffScreenWindow(int width, int height);
455 
456  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
457  void BindHardwareOffScreenBuffers();
458 
464  void DestroyHardwareOffScreenWindow();
465 
466  void UnbindHardwareOffScreenBuffers();
467  void DestroyHardwareOffScreenBuffers();
468 
472  int OffScreenUseFrameBuffer;
473 
475 
478  int NumberOfFrameBuffers;
479  unsigned int TextureObjects[4]; // really GLuint
480  unsigned int FrameBufferObject; // really GLuint
481  unsigned int DepthRenderBufferObject; // really GLuint
482  int HardwareBufferSize[2];
483  bool HardwareOffScreenBuffersBind;
485 
489  virtual void CreateAWindow() = 0;
490 
494  virtual void DestroyWindow() = 0;
495 
500  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
501 
505  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
506 
507 
511  void SaveGLState();
512 
516  void RestoreGLState();
517 
518  std::map<std::string, int> GLStateIntegers;
519 
520  unsigned int BackLeftBuffer;
521  unsigned int BackRightBuffer;
522  unsigned int FrontLeftBuffer;
523  unsigned int FrontRightBuffer;
524  unsigned int FrontBuffer;
525  unsigned int BackBuffer;
526  unsigned int DefaultFrameBufferId;
527 
528  #ifndef VTK_LEGACY_REMOVE
529 
533  unsigned int LastGraphicError;
534  #endif
535 
539  int OwnContext;
540 
541  vtkTimeStamp ContextCreationTime;
542 
543  vtkTextureUnitManager *TextureUnitManager;
544 
546 
547  bool Initialized; // ensure glewinit has been called
548  bool GlewInitValid; // Did glewInit initialize with a valid state?
549 
551 
553 
554 private:
556  void operator=(const vtkOpenGLRenderWindow&) = delete;
557 };
558 
559 #endif
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
virtual unsigned char * GetPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
Get the pixel data of an image, transmitted as RGBRGBRGB.
virtual int SetUseOffScreenBuffers(bool)
Create and bind offscreen rendering buffers without destroying the current OpenGL context...
virtual int SetRGBAPixelData(int x, int y, int x2, int y2, float *, int front, int blend=0, int right=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
manage Shader Programs within a context
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
record modification and/or execution time
Definition: vtkTimeStamp.h:35
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
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
virtual int GetColorBufferSizes(int *rgba)=0
Get the size of the color buffer.
#define VTK_UNICODE_STRING
Definition: vtkType.h:85
virtual int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int right=0)=0
Set/Get the pixel data of an image, transmitted as RGBRGBRGB.
virtual void SetSize(int, int)
Set/Get the size of the window in screen coordinates in pixels.
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 int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
std::map< const vtkTextureObject *, int > TextureResourceIds
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual float * GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
The VertexArrayObject class uses, or emulates, vertex array objects.
virtual void ReleaseRGBAPixelData(float *data)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
vtkTextureObject * DrawPixelsTextureObject
list of point or cell ids
Definition: vtkIdList.h:36
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int GetDepthBufferSize()=0
This method should be defined by the subclass.
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual int SetZbufferData(int x, int y, int x2, int y2, float *z)=0
Set/Get the zbuffer data from the frame buffer.
handles properties associated with a texture map
Definition: vtkTexture.h:71
virtual void PushContext()
Ability to push and pop this window&#39;s context as the current context.
virtual unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
dynamic, self-adjusting array of unsigned char
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
allocate/free texture units.
vtkOpenGLShaderCache * ShaderCache
abstracts an OpenGL texture object.
create a window for renderers to draw into
OpenGL rendering window.
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.
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
virtual float * GetZbufferData(int x, int y, int x2, int y2)=0
Set/Get the zbuffer data from the frame buffer.
virtual bool GetUseOffScreenBuffers()
virtual void WaitForCompletion()=0
Block the thread until the actual rendering is finished().
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
std::map< std::string, int > GLStateIntegers
void MakeCurrent() override=0
Attempt to make this window the current graphics context for the calling thread.
vtkOpenGLVertexBufferObjectCache * VBOCache
The ShaderProgram uses one or more Shader objects.