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 =========================================================================*/
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;
37 class vtkOpenGLHardwareSupport;
41 class vtkShaderProgram;
42 class vtkStdString;
43 class vtkTexture;
44 class vtkTextureObject;
47 
48 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
49 {
50 public:
52  void PrintSelf(ostream& os, vtkIndent indent) override;
53 
57  const char *GetRenderingBackend() override;
58 
60 
63  static void SetGlobalMaximumNumberOfMultiSamples(int val);
64  static int GetGlobalMaximumNumberOfMultiSamples();
66 
68 
71  unsigned char *GetPixelData(int x,int y,int x2,int y2,int front,int right)
72  override;
73  int GetPixelData(int x,int y,int x2,int y2, int front,
74  vtkUnsignedCharArray *data, int right) override;
75  int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
76  int front, int right) override;
77  int SetPixelData(int x,int y,int x2,int y2,
78  vtkUnsignedCharArray *data, int front, int right)
79  override;
81 
83 
86  float *GetRGBAPixelData(int x,int y,int x2,int y2,int front,int right=0)
87  override;
88  int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
89  vtkFloatArray* data, int right=0) override;
90  int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
91  int front, int blend=0, int right=0) override;
92  int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
93  int front, int blend=0, int right=0) override;
94  void ReleaseRGBAPixelData(float *data) override;
95  unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
96  int front, int right=0) override;
97  int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
98  vtkUnsignedCharArray *data, int right=0)
99  override;
100  int SetRGBACharPixelData(int x, int y, int x2, int y2,
101  unsigned char *data, int front,
102  int blend=0, int right=0) override;
103  int SetRGBACharPixelData(int x,int y,int x2,int y2,
104  vtkUnsignedCharArray *data, int front,
105  int blend=0,int right=0) override;
107 
109 
112  float *GetZbufferData( int x1, int y1, int x2, int y2 ) override;
113  int GetZbufferData( int x1, int y1, int x2, int y2, float* z ) override;
114  int GetZbufferData( int x1, int y1, int x2, int y2,
115  vtkFloatArray* z ) override;
116  int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer ) override;
117  int SetZbufferData( int x1, int y1, int x2, int y2,
118  vtkFloatArray *buffer ) override;
120 
121 
125  void ActivateTexture(vtkTextureObject *);
126 
130  void DeactivateTexture(vtkTextureObject *);
131 
135  int GetTextureUnitForTexture(vtkTextureObject *);
136 
140  int GetDepthBufferSize() override;
141 
145  bool GetUsingSRGBColorSpace();
146 
151  int GetColorBufferSizes(int *rgba) override;
152 
154 
157  void SetSize(int a[2]) override;
158  void SetSize(int,int) override;
160 
164  virtual void OpenGLInit();
165 
166  // Initialize the state of OpenGL that VTK wants for this window
167  virtual void OpenGLInitState();
168 
169  // Initialize VTK for rendering in a new OpenGL context
170  virtual void OpenGLInitContext();
171 
173 
176  static bool GetContextSupportsOpenGL32();
177  void SetContextSupportsOpenGL32(bool val);
179 
185  void GetOpenGLVersion(int &major, int &minor);
186 
194  unsigned int GetBackLeftBuffer();
195 
203  unsigned int GetBackRightBuffer();
204 
212  unsigned int GetFrontLeftBuffer();
213 
221  unsigned int GetFrontRightBuffer();
222 
230  unsigned int GetBackBuffer();
231 
239  unsigned int GetFrontBuffer();
240 
244  virtual vtkMTimeType GetContextCreationTime();
245 
247 
250  vtkGetObjectMacro(ShaderCache,vtkOpenGLShaderCache);
252 
254 
257  vtkGetObjectMacro(VBOCache,vtkOpenGLVertexBufferObjectCache);
259 
261 
264  vtkGetMacro(FrameBufferObject, unsigned int);
266 
271  vtkTextureUnitManager *GetTextureUnitManager();
272 
277  void WaitForCompletion() override;
278 
282  virtual void DrawPixels(int x1, int y1, int x2, int y2,
283  int numComponents, int dataType, void *data);
284 
289  virtual void DrawPixels(
290  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
291  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
292  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
293 
298  virtual void DrawPixels(
299  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
300 
304  virtual float GetMaximumHardwareLineWidth() {
305  return this->MaximumHardwareLineWidth; };
306 
313  virtual bool IsPointSpriteBugPresent()
314  {
315  return 0;
316  }
317 
323  int GetDefaultTextureInternalFormat(
324  int vtktype, int numComponents,
325  bool needInteger, bool needFloat, bool needSRGB);
326 
333  {
334  return this->OpenGLSupportMessage;
335  }
336 
337  // Create and bind offscreen rendering buffers without destroying the current
338  // OpenGL context. This allows to temporary switch to offscreen rendering
339  // (ie. to make a screenshot even if the window is hidden).
340  // Return if the creation was successful (1) or not (0).
341  // Note: This function requires that the device supports OpenGL framebuffer extension.
342  // The function has no effect if OffScreenRendering is ON.
343  int SetUseOffScreenBuffers(bool offScreen) override;
344  bool GetUseOffScreenBuffers() override;
345 
349  int SupportsOpenGL() override;
350 
354  const char *ReportCapabilities() override;
355 
362  virtual void Initialize(void) {};
363 
364  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
365 
367  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
368  = this->Resources.find(cb);
369  if (it == this->Resources.end())
370  {
371  this->Resources.insert(cb);
372  }
373  }
374 
376  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
377  = this->Resources.find(cb);
378  if (it != this->Resources.end())
379  {
380  this->Resources.erase(it);
381  }
382  }
383 
393  virtual void PushContext() { this->MakeCurrent(); }
394  virtual void PopContext() {}
395 
400  bool InitializeFromCurrentContext() override;
401 
409  vtkGetMacro(DefaultFrameBufferId, unsigned int);
410 
420  virtual bool SetSwapControl(int ) { return false; }
421 
422 protected:
424  ~vtkOpenGLRenderWindow() override;
425 
428 
429  // used in testing for opengl support
430  // in the SupportsOpenGL() method
434 
435  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
436  void InitializeTextureInternalFormats();
437 
438  std::map<const vtkTextureObject *, int> TextureResourceIds;
439 
440  virtual int ReadPixels(const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right=0);
441 
451  int CreateHardwareOffScreenWindow(int width, int height);
452 
453  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
454  void BindHardwareOffScreenBuffers();
455 
461  void DestroyHardwareOffScreenWindow();
462 
463  void UnbindHardwareOffScreenBuffers();
464  void DestroyHardwareOffScreenBuffers();
465 
470 
472 
476  unsigned int TextureObjects[4]; // really GLuint
477  unsigned int FrameBufferObject; // really GLuint
478  unsigned int DepthRenderBufferObject; // really GLuint
479  int HardwareBufferSize[2];
482 
486  virtual void CreateAWindow() = 0;
487 
491  virtual void DestroyWindow() = 0;
492 
497  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
498 
502  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
503 
504 
508  void SaveGLState();
509 
513  void RestoreGLState();
514 
515  std::map<std::string, int> GLStateIntegers;
516 
517  unsigned int BackLeftBuffer;
518  unsigned int BackRightBuffer;
519  unsigned int FrontLeftBuffer;
520  unsigned int FrontRightBuffer;
521  unsigned int FrontBuffer;
522  unsigned int BackBuffer;
523  unsigned int DefaultFrameBufferId;
524 
529 
531 
533 
535 
536  bool Initialized; // ensure glewinit has been called
537  bool GlewInitValid; // Did glewInit initialize with a valid state?
538 
540 
542 
543 private:
545  void operator=(const vtkOpenGLRenderWindow&) = delete;
546 };
547 
548 #endif
OpenGL rendering window.
int OwnContext
Flag telling if the context has been created here or was inherited.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
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.
int OffScreenUseFrameBuffer
Flag telling if a framebuffer-based offscreen is currently in use.
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
int NumberOfFrameBuffers
Variables used by the framebuffer-based offscreen method.
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
bool HardwareOffScreenBuffersBind
Variables used by the framebuffer-based offscreen method.
record modification and/or execution time
Definition: vtkTimeStamp.h:32
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
vtkTextureUnitManager * TextureUnitManager
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:33
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
unsigned int FrameBufferObject
Variables used by the framebuffer-based offscreen method.
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 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:65
virtual void PushContext()
Ability to push and pop this window'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
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.
unsigned int DepthRenderBufferObject
Variables used by the framebuffer-based offscreen method.
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.