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 "vtkRenderingOpenGL2Module.h" // For export macro
32 #include "vtkRenderWindow.h"
33 #include <string> // for ivar
34 #include <map> // for ivar
35 #include <set> // for ivar
36 #include "vtkType.h" // for ivar
37 
38 class vtkIdList;
42 class vtkShaderProgram;
43 class vtkStdString;
44 class vtkTexture;
45 class vtkTextureObject;
48 
49 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
50 {
51 public:
53  void PrintSelf(ostream& os, vtkIndent indent);
54 
59  void Render();
60 
64  virtual const char *GetRenderingBackend();
65 
67 
70  static void SetGlobalMaximumNumberOfMultiSamples(int val);
71  static int GetGlobalMaximumNumberOfMultiSamples();
73 
77  virtual void StereoUpdate();
78 
80 
83  virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
84  virtual int GetPixelData(int x,int y,int x2,int y2, int front,
86  virtual int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
87  int front);
88  virtual int SetPixelData(int x,int y,int x2,int y2,
89  vtkUnsignedCharArray *data, int front);
91 
93 
96  virtual float *GetRGBAPixelData(int x,int y,int x2,int y2,int front);
97  virtual int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
99  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
100  int front, int blend=0);
101  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
102  int front, int blend=0);
103  virtual void ReleaseRGBAPixelData(float *data);
104  virtual unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
105  int front);
106  virtual int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
108  virtual int SetRGBACharPixelData(int x, int y, int x2, int y2,
109  unsigned char *data, int front,
110  int blend=0);
111  virtual int SetRGBACharPixelData(int x,int y,int x2,int y2,
112  vtkUnsignedCharArray *data, int front,
113  int blend=0);
115 
117 
120  virtual float *GetZbufferData( int x1, int y1, int x2, int y2 );
121  virtual int GetZbufferData( int x1, int y1, int x2, int y2, float* z );
122  virtual int GetZbufferData( int x1, int y1, int x2, int y2,
123  vtkFloatArray* z );
124  virtual int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer );
125  virtual int SetZbufferData( int x1, int y1, int x2, int y2,
126  vtkFloatArray *buffer );
128 
129 
133  void ActivateTexture(vtkTextureObject *);
134 
138  void DeactivateTexture(vtkTextureObject *);
139 
143  int GetTextureUnitForTexture(vtkTextureObject *);
144 
148  int GetDepthBufferSize();
149 
154  int GetColorBufferSizes(int *rgba);
155 
157 
160  virtual void SetSize(int a[2]);
161  virtual void SetSize(int,int);
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  vtkGetMacro(FrameBufferObject, unsigned int);
262 
267  vtkTextureUnitManager *GetTextureUnitManager();
268 
273  virtual void WaitForCompletion();
274 
278  virtual void DrawPixels(int x1, int y1, int x2, int y2,
279  int numComponents, int dataType, void *data);
280 
285  virtual void DrawPixels(
286  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
287  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
288  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
289 
294  virtual void DrawPixels(
295  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
296 
300  virtual float GetMaximumHardwareLineWidth() {
301  return this->MaximumHardwareLineWidth; };
302 
309  virtual bool IsPointSpriteBugPresent()
310  {
311  return 0;
312  }
313 
319  int GetDefaultTextureInternalFormat(
320  int vtktype, int numComponents,
321  bool needInteger, bool needFloat);
322 
329  {
330  return this->OpenGLSupportMessage;
331  }
332 
333  // Create and bind offscreen rendering buffers without destroying the current
334  // OpenGL context. This allows to temporary switch to offscreen rendering
335  // (ie. to make a screenshot even if the window is hidden).
336  // Return if the creation was successful (1) or not (0).
337  // Note: This function requires that the device supports OpenGL framebuffer extension.
338  // The function has no effect if OffScreenRendering is ON.
339  virtual int SetUseOffScreenBuffers(bool offScreen);
340  virtual bool GetUseOffScreenBuffers();
341 
345  virtual int SupportsOpenGL();
346 
353  virtual void Initialize(void) {};
354 
355  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
356 
358  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
359  = this->Resources.find(cb);
360  if (it == this->Resources.end())
361  {
362  this->Resources.insert(cb);
363  }
364  }
365 
367  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
368  = this->Resources.find(cb);
369  if (it != this->Resources.end())
370  {
371  this->Resources.erase(it);
372  }
373  }
374 
384  virtual void PushContext() { this->MakeCurrent(); }
385  virtual void PopContext() {}
386 
387 protected:
390 
392 
393  // used in testing for opengl support
394  // in the SupportsOpenGL() method
398 
399  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
400  void InitializeTextureInternalFormats();
401 
402  std::map<const vtkTextureObject *, int> TextureResourceIds;
403 
404  virtual int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
405  int GetRGBAPixelData(int x, int y, int x2, int y2, int front, float* data);
406  int GetRGBACharPixelData(int x, int y, int x2, int y2, int front,
407  unsigned char* data);
408 
418  int CreateHardwareOffScreenWindow(int width, int height);
419 
420  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
421  void BindHardwareOffScreenBuffers();
422 
428  void DestroyHardwareOffScreenWindow();
429 
430  void UnbindHardwareOffScreenBuffers();
431  void DestroyHardwareOffScreenBuffers();
432 
436  int OffScreenUseFrameBuffer;
437 
439 
442  int NumberOfFrameBuffers;
443  unsigned int TextureObjects[4]; // really GLuint
444  unsigned int FrameBufferObject; // really GLuint
445  unsigned int DepthRenderBufferObject; // really GLuint
446  int HardwareBufferSize[2];
447  bool HardwareOffScreenBuffersBind;
449 
453  virtual void CreateAWindow() = 0;
454 
458  virtual void DestroyWindow() = 0;
459 
464  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
465 
469  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
470 
471 
475  void SaveGLState();
476 
480  void RestoreGLState();
481 
482  std::map<std::string, int> GLStateIntegers;
483 
484  unsigned int BackLeftBuffer;
485  unsigned int BackRightBuffer;
486  unsigned int FrontLeftBuffer;
487  unsigned int FrontRightBuffer;
488  unsigned int FrontBuffer;
489  unsigned int BackBuffer;
490 
491  #ifndef VTK_LEGACY_REMOVE
492 
496  unsigned int LastGraphicError;
497  #endif
498 
502  int OwnContext;
503 
504  vtkTimeStamp ContextCreationTime;
505 
506  vtkTextureUnitManager *TextureUnitManager;
507 
509 
510  bool Initialized; // ensure glewinit has been called
511 
513 
514 private:
515  vtkOpenGLRenderWindow(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
516  void operator=(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
517 };
518 
519 #endif
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
virtual int SetUseOffScreenBuffers(bool)
Create and bind offscreen rendering buffers without destroying the current OpenGL context...
manage Shader Programs within a context
virtual unsigned char * GetPixelData(int x, int y, int x2, int y2, int front)=0
Get the pixel data of an image, transmitted as RGBRGBRGB.
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 ...
virtual int GetColorBufferSizes(int *rgba)=0
Get the size of the color buffer.
#define VTK_UNICODE_STRING
Definition: vtkType.h:81
virtual int SetRGBAPixelData(int x, int y, int x2, int y2, float *, int front, int blend=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248
virtual void SetSize(int, int)
Set/Get the size of the window in screen coordinates in pixels.
virtual unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
std::map< const vtkTextureObject *, int > TextureResourceIds
a simple class to control print indentation
Definition: vtkIndent.h:39
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
virtual void MakeCurrent()=0
Attempt to make this window the current graphics context for the calling thread.
virtual int GetDepthBufferSize()=0
This method should be defined by the subclass.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
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.
virtual float * GetRGBAPixelData(int x, int y, int x2, int y2, int front)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
handles properties associated with a texture map
Definition: vtkTexture.h:70
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
virtual void PushContext()
Ability to push and pop this window&#39;s context as the current context.
dynamic, self-adjusting array of unsigned char
allocate/free texture units.
vtkOpenGLShaderCache * ShaderCache
abstracts an OpenGL texture object.
create a window for renderers to draw into
OpenGL rendering window.
virtual const char * GetRenderingBackend()
What rendering backend has the user requested.
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
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 void Render()
Ask each renderer owned by this RenderWindow to render its image and synchronize this process...
virtual int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front)=0
Set/Get the pixel data of an image, transmitted as RGBRGBRGB.
virtual int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0)=0
Same as Get/SetPixelData except that the image also contains an alpha component.
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
The ShaderProgram uses one or more Shader objects.