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 
58  virtual const char *GetRenderingBackend();
59 
61 
64  static void SetGlobalMaximumNumberOfMultiSamples(int val);
65  static int GetGlobalMaximumNumberOfMultiSamples();
67 
71  virtual void StereoUpdate();
72 
74 
77  virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
78  virtual int GetPixelData(int x,int y,int x2,int y2, int front,
80  virtual int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
81  int front);
82  virtual int SetPixelData(int x,int y,int x2,int y2,
83  vtkUnsignedCharArray *data, int front);
85 
87 
90  virtual float *GetRGBAPixelData(int x,int y,int x2,int y2,int front);
91  virtual int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
93  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
94  int front, int blend=0);
95  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
96  int front, int blend=0);
97  virtual void ReleaseRGBAPixelData(float *data);
98  virtual unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
99  int front);
100  virtual int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
102  virtual int SetRGBACharPixelData(int x, int y, int x2, int y2,
103  unsigned char *data, int front,
104  int blend=0);
105  virtual int SetRGBACharPixelData(int x,int y,int x2,int y2,
106  vtkUnsignedCharArray *data, int front,
107  int blend=0);
109 
111 
114  virtual float *GetZbufferData( int x1, int y1, int x2, int y2 );
115  virtual int GetZbufferData( int x1, int y1, int x2, int y2, float* z );
116  virtual int GetZbufferData( int x1, int y1, int x2, int y2,
117  vtkFloatArray* z );
118  virtual int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer );
119  virtual int SetZbufferData( int x1, int y1, int x2, int y2,
120  vtkFloatArray *buffer );
122 
123 
127  void ActivateTexture(vtkTextureObject *);
128 
132  void DeactivateTexture(vtkTextureObject *);
133 
137  int GetTextureUnitForTexture(vtkTextureObject *);
138 
142  int GetDepthBufferSize();
143 
148  int GetColorBufferSizes(int *rgba);
149 
151 
154  virtual void SetSize(int a[2]);
155  virtual void SetSize(int,int);
157 
161  virtual void OpenGLInit();
162 
163  // Initialize the state of OpenGL that VTK wants for this window
164  virtual void OpenGLInitState();
165 
166  // Initialize VTK for rendering in a new OpenGL context
167  virtual void OpenGLInitContext();
168 
170 
173  static bool GetContextSupportsOpenGL32();
174  void SetContextSupportsOpenGL32(bool val);
176 
182  void GetOpenGLVersion(int &major, int &minor);
183 
191  unsigned int GetBackLeftBuffer();
192 
200  unsigned int GetBackRightBuffer();
201 
209  unsigned int GetFrontLeftBuffer();
210 
218  unsigned int GetFrontRightBuffer();
219 
227  unsigned int GetBackBuffer();
228 
236  unsigned int GetFrontBuffer();
237 
241  virtual vtkMTimeType GetContextCreationTime();
242 
244 
247  vtkGetObjectMacro(ShaderCache,vtkOpenGLShaderCache);
249 
251 
254  vtkGetMacro(FrameBufferObject, unsigned int);
256 
261  vtkTextureUnitManager *GetTextureUnitManager();
262 
267  virtual void WaitForCompletion();
268 
272  virtual void DrawPixels(int x1, int y1, int x2, int y2,
273  int numComponents, int dataType, void *data);
274 
279  virtual void DrawPixels(
280  int dstXmin, int dstYmin, int dstXmax, int dstYmax,
281  int srcXmin, int srcYmin, int srcXmax, int srcYmax,
282  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
283 
288  virtual void DrawPixels(
289  int srcWidth, int srcHeight, int numComponents, int dataType, void *data);
290 
294  virtual float GetMaximumHardwareLineWidth() {
295  return this->MaximumHardwareLineWidth; };
296 
303  virtual bool IsPointSpriteBugPresent()
304  {
305  return 0;
306  }
307 
313  int GetDefaultTextureInternalFormat(
314  int vtktype, int numComponents,
315  bool needInteger, bool needFloat);
316 
323  {
324  return this->OpenGLSupportMessage;
325  }
326 
327  // Create and bind offscreen rendering buffers without destroying the current
328  // OpenGL context. This allows to temporary switch to offscreen rendering
329  // (ie. to make a screenshot even if the window is hidden).
330  // Return if the creation was successful (1) or not (0).
331  // Note: This function requires that the device supports OpenGL framebuffer extension.
332  // The function has no effect if OffScreenRendering is ON.
333  virtual int SetUseOffScreenBuffers(bool offScreen);
334  virtual bool GetUseOffScreenBuffers();
335 
339  virtual int SupportsOpenGL();
340 
347  virtual void Initialize(void) {};
348 
349  std::set<vtkGenericOpenGLResourceFreeCallback *> Resources;
350 
352  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
353  = this->Resources.find(cb);
354  if (it == this->Resources.end())
355  {
356  this->Resources.insert(cb);
357  }
358  }
359 
361  std::set<vtkGenericOpenGLResourceFreeCallback *>::iterator it
362  = this->Resources.find(cb);
363  if (it != this->Resources.end())
364  {
365  this->Resources.erase(it);
366  }
367  }
368 
378  virtual void PushContext() { this->MakeCurrent(); }
379  virtual void PopContext() {}
380 
381 protected:
384 
386 
387  // used in testing for opengl support
388  // in the SupportsOpenGL() method
392 
393  int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
394  void InitializeTextureInternalFormats();
395 
396  std::map<const vtkTextureObject *, int> TextureResourceIds;
397 
398  virtual int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
399  int GetRGBAPixelData(int x, int y, int x2, int y2, int front, float* data);
400  int GetRGBACharPixelData(int x, int y, int x2, int y2, int front,
401  unsigned char* data);
402 
412  int CreateHardwareOffScreenWindow(int width, int height);
413 
414  int CreateHardwareOffScreenBuffers(int width, int height, bool bind = false);
415  void BindHardwareOffScreenBuffers();
416 
422  void DestroyHardwareOffScreenWindow();
423 
424  void UnbindHardwareOffScreenBuffers();
425  void DestroyHardwareOffScreenBuffers();
426 
430  int OffScreenUseFrameBuffer;
431 
433 
436  int NumberOfFrameBuffers;
437  unsigned int TextureObjects[4]; // really GLuint
438  unsigned int FrameBufferObject; // really GLuint
439  unsigned int DepthRenderBufferObject; // really GLuint
440  int HardwareBufferSize[2];
441  bool HardwareOffScreenBuffersBind;
443 
447  virtual void CreateAWindow() = 0;
448 
452  virtual void DestroyWindow() = 0;
453 
458  virtual void ReleaseGraphicsResources(vtkRenderWindow *);
459 
463  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
464 
465 
469  void SaveGLState();
470 
474  void RestoreGLState();
475 
476  std::map<std::string, int> GLStateIntegers;
477 
478  unsigned int BackLeftBuffer;
479  unsigned int BackRightBuffer;
480  unsigned int FrontLeftBuffer;
481  unsigned int FrontRightBuffer;
482  unsigned int FrontBuffer;
483  unsigned int BackBuffer;
484 
485  #ifndef VTK_LEGACY_REMOVE
486 
490  unsigned int LastGraphicError;
491  #endif
492 
496  int OwnContext;
497 
498  vtkTimeStamp ContextCreationTime;
499 
500  vtkTextureUnitManager *TextureUnitManager;
501 
503 
504  bool Initialized; // ensure glewinit has been called
505 
507 
508 private:
509  vtkOpenGLRenderWindow(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
510  void operator=(const vtkOpenGLRenderWindow&) VTK_DELETE_FUNCTION;
511 };
512 
513 #endif
vtkWindow::SetSize
virtual void SetSize(int, int)
vtkOpenGLRenderWindow::GetMaximumHardwareLineWidth
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
Definition: vtkOpenGLRenderWindow.h:294
vtkOpenGLRenderWindow::RegisterGraphicsResources
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:351
vtkRenderWindow::SetRGBACharPixelData
virtual int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0)=0
vtkRenderWindow::GetUseOffScreenBuffers
virtual bool GetUseOffScreenBuffers()
Definition: vtkRenderWindow.h:724
vtkOpenGLRenderWindow::MaximumHardwareLineWidth
float MaximumHardwareLineWidth
Definition: vtkOpenGLRenderWindow.h:506
vtkRenderWindow::GetColorBufferSizes
virtual int GetColorBufferSizes(int *rgba)=0
Get the size of the color buffer.
vtkRenderWindow::GetDepthBufferSize
virtual int GetDepthBufferSize()=0
This method should be defined by the subclass.
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkX3D::data
Definition: vtkX3D.h:315
vtkRenderWindow::SetRGBAPixelData
virtual int SetRGBAPixelData(int x, int y, int x2, int y2, float *, int front, int blend=0)=0
vtkOpenGLRenderWindow::TextureResourceIds
std::map< const vtkTextureObject *, int > TextureResourceIds
Definition: vtkOpenGLRenderWindow.h:396
vtkOpenGLRenderWindow::GetOpenGLSupportMessage
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
Definition: vtkOpenGLRenderWindow.h:322
VTK_UNICODE_STRING
#define VTK_UNICODE_STRING
Definition: vtkType.h:81
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkRenderWindow::SetUseOffScreenBuffers
virtual int SetUseOffScreenBuffers(bool)
Create and bind offscreen rendering buffers without destroying the current OpenGL context.
Definition: vtkRenderWindow.h:723
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:41
vtkRenderWindow.h
vtkOpenGLRenderWindow::UnregisterGraphicsResources
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
Definition: vtkOpenGLRenderWindow.h:360
vtkOpenGLRenderWindow::DrawPixelsTextureObject
vtkTextureObject * DrawPixelsTextureObject
Definition: vtkOpenGLRenderWindow.h:502
vtkOpenGLRenderWindow::OpenGLSupportMessage
std::string OpenGLSupportMessage
Definition: vtkOpenGLRenderWindow.h:391
vtkOpenGLRenderWindow::PopContext
virtual void PopContext()
Definition: vtkOpenGLRenderWindow.h:379
vtkMTimeType
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248
vtkType.h
vtkTexture
handles properties associated with a texture map
Definition: vtkTexture.h:70
vtkOpenGLRenderWindow::OpenGLSupportResult
int OpenGLSupportResult
Definition: vtkOpenGLRenderWindow.h:390
vtkTextureUnitManager
allocate/free texture units.
Definition: vtkTextureUnitManager.h:38
vtkOpenGLRenderWindow::ShaderCache
vtkOpenGLShaderCache * ShaderCache
Definition: vtkOpenGLRenderWindow.h:385
vtkX3D::height
Definition: vtkX3D.h:254
vtkOpenGLHardwareSupport
OpenGL rendering window.
Definition: vtkOpenGLHardwareSupport.h:37
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:44
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:25
vtkRenderWindow::GetZbufferData
virtual float * GetZbufferData(int x, int y, int x2, int y2)=0
Set/Get the zbuffer data from the frame buffer.
vtkRenderWindow::GetRGBACharPixelData
virtual unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front)=0
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkRenderWindow::WaitForCompletion
virtual void WaitForCompletion()=0
Block the thread until the actual rendering is finished().
vtkOpenGLShaderCache
manage Shader Programs within a context
Definition: vtkOpenGLShaderCache.h:34
vtkOpenGLRenderWindow::IsPointSpriteBugPresent
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
Definition: vtkOpenGLRenderWindow.h:303
vtkRenderWindow::SetPixelData
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.
vtkWindow::GetPixelData
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.
vtkOpenGLRenderWindow::Initialized
bool Initialized
Definition: vtkOpenGLRenderWindow.h:504
vtkX3D::string
Definition: vtkX3D.h:490
vtkRenderWindow::SetZbufferData
virtual int SetZbufferData(int x, int y, int x2, int y2, float *z)=0
vtkOpenGLRenderWindow::OpenGLSupportTested
bool OpenGLSupportTested
Definition: vtkOpenGLRenderWindow.h:389
vtkRenderWindow::MakeCurrent
virtual void MakeCurrent()=0
Attempt to make this window the current graphics context for the calling thread.
vtkRenderWindow::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkRenderWindow::StereoUpdate
virtual void StereoUpdate()
Update the system, if needed, due to stereo rendering.
vtkOpenGLRenderWindow::GLStateIntegers
std::map< std::string, int > GLStateIntegers
Definition: vtkOpenGLRenderWindow.h:476
vtkRenderWindow::ReleaseRGBAPixelData
virtual void ReleaseRGBAPixelData(float *data)=0
vtkRenderWindow::SupportsOpenGL
virtual int SupportsOpenGL()
Does this render window support OpenGL? 0-false, 1-true.
Definition: vtkRenderWindow.h:651
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:38
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:86
vtkRenderWindow::GetRenderingBackend
virtual const char * GetRenderingBackend()
What rendering backend has the user requested.
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
vtkOpenGLRenderWindow::PushContext
virtual void PushContext()
Ability to push and pop this window's context as the current context.
Definition: vtkOpenGLRenderWindow.h:378
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:35
vtkOpenGLRenderWindow::LastGraphicError
unsigned int LastGraphicError
Definition: vtkOpenGLRenderWindow.h:490
vtkRenderWindow::GetRGBAPixelData
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.