vtkOpenGLRenderWindow.h 9.97 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1 2
/*=========================================================================

Mathieu Malaterre's avatar
Mathieu Malaterre committed
3 4
  Program:   Visualization Toolkit
  Module:    vtkOpenGLRenderWindow.h
Will Schroeder's avatar
Will Schroeder committed
5

Mathieu Malaterre's avatar
Mathieu Malaterre committed
6 7 8
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Will Schroeder's avatar
Will Schroeder committed
9

Mathieu Malaterre's avatar
Mathieu Malaterre committed
10 11 12
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13 14 15 16 17

=========================================================================*/
// .NAME vtkOpenGLRenderWindow - OpenGL rendering window
// .SECTION Description
// vtkOpenGLRenderWindow is a concrete implementation of the abstract class
Ken Martin's avatar
Ken Martin committed
18 19 20
// vtkRenderWindow. vtkOpenGLRenderer interfaces to the OpenGL graphics
// library. Application programmers should normally use vtkRenderWindow
// instead of the OpenGL specific version.
Will Schroeder's avatar
Will Schroeder committed
21

22 23
#ifndef vtkOpenGLRenderWindow_h
#define vtkOpenGLRenderWindow_h
Will Schroeder's avatar
Will Schroeder committed
24

25
#include "vtkRenderingOpenGLModule.h" // For export macro
26
#include "vtkRenderWindow.h"
27
#include "vtkOpenGL.h" // Needed for GLuint.
Will Schroeder's avatar
Will Schroeder committed
28

29
class vtkIdList;
30
class vtkOpenGLExtensionManager;
31
class vtkOpenGLHardwareSupport;
32
class vtkTextureUnitManager;
Burlen Loring's avatar
Burlen Loring committed
33
class vtkStdString;
34

35
class VTKRENDERINGOPENGL_EXPORT vtkOpenGLRenderWindow : public vtkRenderWindow
Will Schroeder's avatar
Will Schroeder committed
36 37
{
public:
38
  vtkTypeMacro(vtkOpenGLRenderWindow, vtkRenderWindow);
39
  void PrintSelf(ostream& os, vtkIndent indent);
40

41 42 43 44 45
  // Description:
  // Set/Get the maximum number of multisamples
  static void SetGlobalMaximumNumberOfMultiSamples(int val);
  static int  GetGlobalMaximumNumberOfMultiSamples();

Ken Martin's avatar
Ken Martin committed
46 47
  // Description:
  // Update system if needed due to stereo rendering.
Will Schroeder's avatar
Will Schroeder committed
48 49 50
  virtual void StereoUpdate();

  // Description:
51
  // Set/Get the pixel data of an image, transmitted as RGBRGB...
Will Schroeder's avatar
Will Schroeder committed
52
  virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
53
  virtual int GetPixelData(int x,int y,int x2,int y2, int front,
54 55
                           vtkUnsignedCharArray *data);
  virtual int SetPixelData(int x,int y,int x2,int y2,unsigned char *data,
Lisa Avila's avatar
Lisa Avila committed
56
                           int front);
57 58
  virtual int SetPixelData(int x,int y,int x2,int y2,
                           vtkUnsignedCharArray *data, int front);
Will Schroeder's avatar
Will Schroeder committed
59 60

  // Description:
61
  // Set/Get the pixel data of an image, transmitted as RGBARGBA...
Will Schroeder's avatar
Will Schroeder committed
62
  virtual float *GetRGBAPixelData(int x,int y,int x2,int y2,int front);
63
  virtual int GetRGBAPixelData(int x,int y,int x2,int y2, int front,
Lisa Avila's avatar
Lisa Avila committed
64
                               vtkFloatArray* data);
65 66 67
  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, float *data,
                               int front, int blend=0);
  virtual int SetRGBAPixelData(int x,int y,int x2,int y2, vtkFloatArray *data,
Lisa Avila's avatar
Lisa Avila committed
68
                               int front, int blend=0);
69
  virtual void ReleaseRGBAPixelData(float *data);
70
  virtual unsigned char *GetRGBACharPixelData(int x,int y,int x2,int y2,
71
                                              int front);
72
  virtual int GetRGBACharPixelData(int x,int y,int x2,int y2, int front,
73 74 75
                                   vtkUnsignedCharArray *data);
  virtual int SetRGBACharPixelData(int x, int y, int x2, int y2,
                                   unsigned char *data, int front,
76
                                   int blend=0);
77
  virtual int SetRGBACharPixelData(int x,int y,int x2,int y2,
78
                                   vtkUnsignedCharArray *data, int front,
79
                                   int blend=0);
Will Schroeder's avatar
Will Schroeder committed
80 81 82 83

  // Description:
  // Set/Get the zbuffer data from an image
  virtual float *GetZbufferData( int x1, int y1, int x2, int y2 );
84
  virtual int GetZbufferData( int x1, int y1, int x2, int y2, float* z );
Lisa Avila's avatar
Lisa Avila committed
85 86
  virtual int GetZbufferData( int x1, int y1, int x2, int y2,
                              vtkFloatArray* z );
87
  virtual int SetZbufferData( int x1, int y1, int x2, int y2, float *buffer );
Lisa Avila's avatar
Lisa Avila committed
88 89
  virtual int SetZbufferData( int x1, int y1, int x2, int y2,
                              vtkFloatArray *buffer );
90

91
  // Description:
92
  // Register a texture name with this render window.
93
  void RegisterTextureResource (GLuint id);
94 95 96 97

  // Description:
  // Get the size of the depth buffer.
  int GetDepthBufferSize();
98 99 100 101 102

  // Description:
  // Get the size of the color buffer.
  // Returns 0 if not able to determine otherwise sets R G B and A into buffer.
  int GetColorBufferSizes(int *rgba);
103

104 105 106 107
  // Description:
  // Initialize OpenGL for this window.
  virtual void OpenGLInit();

108 109 110 111 112 113
  // Initialize the state of OpenGL that VTK wants for this window
  virtual void OpenGLInitState();

  // Initialize VTK for rendering in a new OpenGL context
  virtual void OpenGLInitContext();

114 115 116
  // Description:
  // Return the OpenGL name of the back left buffer.
  // It is GL_BACK_LEFT if GL is bound to the window-system-provided
117
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT if GL is bound to an
118 119 120
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetBackLeftBuffer();
121

122 123 124
  // Description:
  // Return the OpenGL name of the back right buffer.
  // It is GL_BACK_RIGHT if GL is bound to the window-system-provided
125
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT+1 if GL is bound to an
126 127 128
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetBackRightBuffer();
129

130 131 132
  // Description:
  // Return the OpenGL name of the front left buffer.
  // It is GL_FRONT_LEFT if GL is bound to the window-system-provided
133
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT if GL is bound to an
134 135 136
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetFrontLeftBuffer();
137

138 139 140 141 142 143 144
  // Description:
  // Return the OpenGL name of the front right buffer.
  // It is GL_FRONT_RIGHT if GL is bound to the window-system-provided
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT+1 if GL is bound to an
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetFrontRightBuffer();
145

146 147 148 149 150 151 152
  // Description:
  // Return the OpenGL name of the back left buffer.
  // It is GL_BACK if GL is bound to the window-system-provided
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT if GL is bound to an
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetBackBuffer();
153

154 155 156 157 158 159 160
  // Description:
  // Return the OpenGL name of the front left buffer.
  // It is GL_FRONT if GL is bound to the window-system-provided
  // framebuffer. It is vtkgl::COLOR_ATTACHMENT0_EXT if GL is bound to an
  // application-created framebuffer object (GPU-based offscreen rendering)
  // It is used by vtkOpenGLCamera.
  unsigned int GetFrontBuffer();
161

162 163
  // Description:
  // Get the time when the OpenGL context was created.
164
  virtual unsigned long GetContextCreationTime();
165 166 167 168 169 170

  // Description:
  // Returns the extension manager. A new one will be created if one hasn't
  // already been set up.
  vtkOpenGLExtensionManager* GetExtensionManager();

171
  // Description:
172 173
  // Returns an Hardware Support object. A new one will be created if one
  // hasn't already been set up.
174
  vtkOpenGLHardwareSupport* GetHardwareSupport();
175

176 177 178 179 180 181
  //BTX
  // Description:
  // Returns its texture unit manager object. A new one will be created if one
  // hasn't already been set up.
  vtkTextureUnitManager *GetTextureUnitManager();
  //ETX
182

183 184 185 186
  // Description:
  // Block the thread until the actual rendering is finished().
  // Useful for measurement only.
  virtual void WaitForCompletion();
187

188 189 190
protected:
  vtkOpenGLRenderWindow();
  ~vtkOpenGLRenderWindow();
191

192
  long OldMonitorSetting;
193
  vtkIdList *TextureResourceIds;
194

195 196 197
  int GetPixelData(int x, int y, int x2, int y2, int front, unsigned char* data);
  int GetRGBAPixelData(int x, int y, int x2, int y2, int front, float* data);
  int GetRGBACharPixelData(int x, int y, int x2, int y2, int front,
Lisa Avila's avatar
Lisa Avila committed
198
                           unsigned char* data);
199

200 201 202 203 204 205 206 207 208
  // Description:
  // Create an offScreen window based on OpenGL framebuffer extension.
  // Return if the creation was successful or not.
  // \pre positive_width: width>0
  // \pre positive_height: height>0
  // \pre not_initialized: !OffScreenUseFrameBuffer
  // \post valid_result: (result==0 || result==1)
  //                     && (result implies OffScreenUseFrameBuffer)
  int CreateHardwareOffScreenWindow(int width, int height);
209

210 211 212 213 214
  // Description:
  // Destroy an offscreen window based on OpenGL framebuffer extension.
  // \pre initialized: OffScreenUseFrameBuffer
  // \post destroyed: !OffScreenUseFrameBuffer
  void DestroyHardwareOffScreenWindow();
215

216 217 218
  // Description:
  // Flag telling if a framebuffer-based offscreen is currently in use.
  int OffScreenUseFrameBuffer;
219

220 221 222 223 224 225
  // Description:
  // Variables used by the framebuffer-based offscreen method.
  int NumberOfFrameBuffers;
  unsigned int TextureObjects[4]; // really GLuint
  unsigned int FrameBufferObject; // really GLuint
  unsigned int DepthRenderBufferObject; // really GLuint
226

227 228
  // Description:
  // Create a not-off-screen window.
229
  virtual void CreateAWindow() = 0;
230

231 232
  // Description:
  // Destroy a not-off-screen window.
233
  virtual void DestroyWindow() = 0;
234

235 236 237
  // Description:
  // Set the texture unit manager.
  void SetTextureUnitManager(vtkTextureUnitManager *textureUnitManager);
238

239 240 241
  unsigned int BackLeftBuffer;
  unsigned int BackRightBuffer;
  unsigned int FrontLeftBuffer;
242 243 244
  unsigned int FrontRightBuffer;
  unsigned int FrontBuffer;
  unsigned int BackBuffer;
245

246 247 248 249
  // Description:
  // Flag telling if the context has been created here or was inherited.
  int OwnContext;

250
  vtkTimeStamp ContextCreationTime;
251

252
  vtkTextureUnitManager *TextureUnitManager;
253

254 255 256
private:
  vtkOpenGLRenderWindow(const vtkOpenGLRenderWindow&);  // Not implemented.
  void operator=(const vtkOpenGLRenderWindow&);  // Not implemented.
257 258

  void SetExtensionManager(vtkOpenGLExtensionManager*);
259 260
  void SetHardwareSupport(vtkOpenGLHardwareSupport * renderWindow);

261
  vtkOpenGLExtensionManager* ExtensionManager;
262
  vtkOpenGLHardwareSupport* HardwareSupport;
Will Schroeder's avatar
Will Schroeder committed
263 264 265
};

#endif