VTK
vtkFrameBufferObject2.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFrameBufferObject2.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 =========================================================================*/
44 #ifndef vtkFrameBufferObject2_h
45 #define vtkFrameBufferObject2_h
46 
47 #include "vtkObject.h"
48 #include "vtkRenderingOpenGL2Module.h" // For export macro
49 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
50 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
51 
53 
57 #ifdef NDEBUG
58 # define vtkCheckFrameBufferStatusMacro(mode)
59 # define vtkStaticCheckFrameBufferStatusMacro(mode)
60 #else
61 # define vtkCheckFrameBufferStatusMacroImpl(macro, mode) \
62 { \
63 const char *eStr; \
64 bool ok = vtkFrameBufferObject2::GetFrameBufferStatus(mode, eStr); \
65 if (!ok) \
66  { \
67  macro( \
68  << "OpenGL ERROR. The FBO is incomplete : " << eStr); \
69  } \
70  }
71 # define vtkCheckFrameBufferStatusMacro(mode) \
72  vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
73 # define vtkStaticCheckFrameBufferStatusMacro(mode) \
74  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
75 #endif
76 
77 
78 class vtkRenderWindow;
79 class vtkTextureObject;
80 class vtkRenderbuffer;
83 
84 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkObject
85 {
86 public:
87  static vtkFrameBufferObject2* New();
89  void PrintSelf(ostream& os, vtkIndent indent);
90 
92 
96  void SetContext(vtkRenderWindow *context);
97  vtkRenderWindow *GetContext();
99 
102  static bool IsSupported(vtkRenderWindow *renWin);
103 
108  void Bind(unsigned int mode);
109 
113  void UnBind(unsigned int mode);
114 
119  void SaveCurrentBindings();
120 
122 
125  void SaveCurrentBuffers();
126  void RestorePreviousBuffers(unsigned int mode);
128 
130 
131  void AddColorAttachment(
132  unsigned int mode,
133  unsigned int attId,
134  vtkTextureObject* tex);
136 
137  void AddTexColorAttachment(
138  unsigned int mode,
139  unsigned int attId,
140  unsigned int handle);
141 
142  void RemoveTexColorAttachments(unsigned int mode, unsigned int num);
143  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
144  { this->AddTexColorAttachment(mode, attId, 0U); }
145 
147 
148  void AddColorAttachment(
149  unsigned int mode,
150  unsigned int attId,
151  vtkRenderbuffer* tex);
153 
154  void AddRenColorAttachment(
155  unsigned int mode,
156  unsigned int attId,
157  unsigned int handle);
158 
159  void RemoveRenColorAttachments(unsigned int mode, unsigned int num);
160  void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
161  { this->AddRenColorAttachment(mode, attId, 0U); }
162 
164 
165  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
166  void AddTexDepthAttachment(unsigned int mode, unsigned int handle);
167  void RemoveTexDepthAttachment(unsigned int mode)
168  { this->AddTexDepthAttachment(mode, 0U); }
170 
172 
173  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
174  void AddRenDepthAttachment(unsigned int mode, unsigned int handle);
175  void RemoveRenDepthAttachment(unsigned int mode)
176  { this->AddRenDepthAttachment(mode, 0U); }
178 
180 
181  void ActivateDrawBuffer(unsigned int id);
182  void ActivateReadBuffer(unsigned int id);
183  void DeactivateReadBuffer();
185 
187 
188  void ActivateDrawBuffers(unsigned int n);
189  void ActivateDrawBuffers(unsigned int *ids, int n);
190  void DeactivateDrawBuffers();
192 
194 
198  static
199  void InitializeViewport(int width, int height);
201 
204  int CheckFrameBufferStatus(unsigned int mode);
205 
207 
210  static
211  bool GetFrameBufferStatus(
212  unsigned int mode,
213  const char *&desc);
215 
217 
220  static
221  int Blit(
222  int srcExt[4],
223  int destExt[4],
224  unsigned int bits,
225  unsigned int mapping);
227 
229 
235  vtkPixelBufferObject *DownloadColor1(
236  int extent[4],
237  int vtkType,
238  int channel);
240 
241  vtkPixelBufferObject *DownloadColor3(
242  int extent[4],
243  int vtkType);
244 
245  vtkPixelBufferObject *DownloadColor4(
246  int extent[4],
247  int vtkType);
248 
250 
253  vtkPixelBufferObject *DownloadDepth(
254  int extent[4],
255  int vtkType);
257 
259 
263  vtkPixelBufferObject *Download(
264  int extent[4],
265  int vtkType,
266  int nComps,
267  int oglType,
268  int oglFormat);
270 
271  static
272  void Download(
273  int extent[4],
274  int vtkType,
275  int nComps,
276  int oglType,
277  int oglFormat,
278  vtkPixelBufferObject *pbo);
279 
280 //BTX
281 protected:
283 
284  static
285  bool LoadRequiredExtensions(vtkRenderWindow *renWin);
287 
288  // gen buffer (occurs when context is set)
289  void CreateFBO();
290 
291  // delete buffer (occurs during destruction or context swicth)
292  void DestroyFBO();
293 
294 
296  int GetOpenGLType(int vtkType);
297 
300 
302 
303  unsigned int FBOIndex;
304  unsigned int PreviousDrawFBO;
305  unsigned int PreviousReadFBO;
306  unsigned int DepthBuffer;
307  unsigned int PreviousDrawBuffer;
308  unsigned int PreviousReadBuffer;
309 
310 private:
311  vtkFrameBufferObject2(const vtkFrameBufferObject2&); // Not implemented.
312  void operator=(const vtkFrameBufferObject2&); // Not implemented.
313 
314  friend class vtkRenderbuffer; // needs access to LoadRequiredExtentsions
315 //ETX
316 };
317 
318 #endif
OpenGL rendering window.
void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
void RemoveRenDepthAttachment(unsigned int mode)
abstract base class for most VTK objects
Definition: vtkObject.h:61
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
abstracts an OpenGL pixel buffer object.
abstracts an OpenGL texture object.
create a window for renderers to draw into
Storage for FBO's.
static vtkObject * New()
void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
void RemoveTexDepthAttachment(unsigned int mode)
Interface to OpenGL framebuffer object.