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 =========================================================================*/
45 #ifndef vtkFrameBufferObject2_h
46 #define vtkFrameBufferObject2_h
47 
48 #include "vtkObject.h"
49 #include "vtkRenderingOpenGLModule.h" // For export macro
50 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
51 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
52 
59 #ifdef NDEBUG
60 # define vtkCheckFrameBufferStatusMacro(mode)
61 # define vtkStaticCheckFrameBufferStatusMacro(mode)
62 #else
63 # define vtkCheckFrameBufferStatusMacroImpl(macro, mode) \
64 { \
65 const char *eStr; \
66 bool ok = vtkFrameBufferObject2::GetFrameBufferStatus(mode, eStr); \
67 if (!ok) \
68 { \
69  macro( \
70  << "OpenGL ERROR. The FBO is incomplete : " << eStr); \
71 } \
72  }
73 # define vtkCheckFrameBufferStatusMacro(mode) \
74  vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
75 # define vtkStaticCheckFrameBufferStatusMacro(mode) \
76  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
77 #endif
78 
79 class vtkRenderWindow;
80 class vtkTextureObject;
81 class vtkRenderbuffer;
85 
86 class VTKRENDERINGOPENGL_EXPORT vtkFrameBufferObject2 : public vtkObject
87 {
88 public:
89  static vtkFrameBufferObject2* New();
91  void PrintSelf(ostream& os, vtkIndent indent);
92 
94 
101  void SetContext(vtkRenderWindow *context);
102  vtkRenderWindow *GetContext();
104 
109  static bool IsSupported(vtkRenderWindow *renWin);
110 
117  void Bind(unsigned int mode);
118 
124  void UnBind(unsigned int mode);
125 
133  void SaveCurrentBindings();
134 
136 
143  void SaveCurrentBuffers();
144  void RestorePreviousBuffers(unsigned int mode);
146 
150  void AddColorAttachment(
151  unsigned int mode,
152  unsigned int attId,
153  vtkTextureObject* tex);
154 
155  void AddTexColorAttachment(
156  unsigned int mode,
157  unsigned int attId,
158  unsigned int handle);
159 
160  void RemoveTexColorAttachments(unsigned int mode, unsigned int num);
161  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
162  { this->AddTexColorAttachment(mode, attId, 0U); }
163 
167  void AddColorAttachment(
168  unsigned int mode,
169  unsigned int attId,
170  vtkRenderbuffer* tex);
171 
172  void AddRenColorAttachment(
173  unsigned int mode,
174  unsigned int attId,
175  unsigned int handle);
176 
177  void RemoveRenColorAttachments(unsigned int mode, unsigned int num);
178  void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
179  { this->AddRenColorAttachment(mode, attId, 0U); }
180 
182 
185  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
186  void AddTexDepthAttachment(unsigned int mode, unsigned int handle);
187  void RemoveTexDepthAttachment(unsigned int mode)
188  { this->AddTexDepthAttachment(mode, 0U); }
190 
192 
195  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
196  void AddRenDepthAttachment(unsigned int mode, unsigned int handle);
197  void RemoveRenDepthAttachment(unsigned int mode)
198  { this->AddRenDepthAttachment(mode, 0U); }
200 
202 
205  void ActivateDrawBuffer(unsigned int id);
206  void ActivateReadBuffer(unsigned int id);
207  void DeactivateReadBuffer();
209 
211 
215  void ActivateDrawBuffers(unsigned int n);
216  void ActivateDrawBuffers(unsigned int *ids, int n);
217  void DeactivateDrawBuffers();
219 
226  static
227  void InitializeViewport(int width, int height);
228 
234  int CheckFrameBufferStatus(unsigned int mode);
235 
242  static
243  bool GetFrameBufferStatus(
244  unsigned int mode,
245  const char *&desc);
246 
253  static
254  int Blit(
255  int srcExt[4],
256  int destExt[4],
257  unsigned int bits,
258  unsigned int mapping);
259 
268  vtkPixelBufferObject *DownloadColor1(
269  int extent[4],
270  int vtkType,
271  int channel);
272 
273  vtkPixelBufferObject *DownloadColor3(
274  int extent[4],
275  int vtkType);
276 
277  vtkPixelBufferObject *DownloadColor4(
278  int extent[4],
279  int vtkType);
280 
286  vtkPixelBufferObject *DownloadDepth(
287  int extent[4],
288  int vtkType);
289 
297  vtkPixelBufferObject *Download(
298  int extent[4],
299  int vtkType,
300  int nComps,
301  int oglType,
302  int oglFormat);
303 
304  static
305  void Download(
306  int extent[4],
307  int vtkType,
308  int nComps,
309  int oglType,
310  int oglFormat,
311  vtkPixelBufferObject *pbo);
312 
313 protected:
317  static
318  bool LoadRequiredExtensions(vtkRenderWindow *renWin);
319 
320  // gen buffer (occurs when context is set)
321  void CreateFBO();
322 
323  // delete buffer (occurs during destruction or context swicth)
324  void DestroyFBO();
325 
326 
330  int GetOpenGLType(int vtkType);
331 
334 
336 
337  unsigned int FBOIndex;
338  unsigned int PreviousDrawFBO;
339  unsigned int PreviousReadFBO;
340  unsigned int DepthBuffer;
341  unsigned int PreviousDrawBuffer;
342  unsigned int PreviousReadBuffer;
343 
344 private:
345  vtkFrameBufferObject2(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
346  void operator=(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
347 
348  friend class vtkRenderbuffer; // needs access to LoadRequiredExtentsions
349 
350 };
351 
352 #endif
OpenGL rendering window.
void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
void RemoveRenDepthAttachment(unsigned int mode)
Directly assign/remove a renderbuffer to depth attachments.
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWeakPointer< vtkRenderWindow > Context
a simple class to control print indentation
Definition: vtkIndent.h:39
abstracts an OpenGL pixel buffer object.
Interface class for querying and using OpenGL extensions.
abstracts an OpenGL texture object.
create a window for renderers to draw into
Storage for FBO's.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
void RemoveTexDepthAttachment(unsigned int mode)
Directly assign/remove a texture/renderbuffer to depth attachments.
Interface to OpenGL framebuffer object.