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:
91  void PrintSelf(ostream& os, vtkIndent indent);
92 
94 
101  void SetContext(vtkRenderWindow *context);
104 
109  static bool IsSupported(vtkRenderWindow *renWin);
110 
117  void Bind(unsigned int mode);
118 
124  void UnBind(unsigned int mode);
125 
134 
136 
144  void RestorePreviousBuffers(unsigned int mode);
146 
151  unsigned int mode,
152  unsigned int attId,
153  vtkTextureObject* tex);
154 
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 
168  unsigned int mode,
169  unsigned int attId,
170  vtkRenderbuffer* tex);
171 
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);
209 
211 
215  void ActivateDrawBuffers(unsigned int n);
216  void ActivateDrawBuffers(unsigned int *ids, int n);
219 
226  static
227  void InitializeViewport(int width, int height);
228 
234  int CheckFrameBufferStatus(unsigned int mode);
235 
242  static
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 
269  int extent[4],
270  int vtkType,
271  int channel);
272 
274  int extent[4],
275  int vtkType);
276 
278  int extent[4],
279  int vtkType);
280 
287  int extent[4],
288  int vtkType);
289 
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
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
Interface to OpenGL framebuffer object.
void RestorePreviousBuffers(unsigned int mode)
static bool GetFrameBufferStatus(unsigned int mode, const char *&desc)
Validate the current FBO configuration (attachments, formats, etc) return false if the FBO is incompl...
vtkPixelBufferObject * DownloadColor4(int extent[4], int vtkType)
vtkPixelBufferObject * DownloadColor3(int extent[4], int vtkType)
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void AddRenDepthAttachment(unsigned int mode, unsigned int handle)
void AddDepthAttachment(unsigned int mode, vtkRenderbuffer *tex)
Directly assign/remove a renderbuffer to depth attachments.
vtkPixelBufferObject * DownloadColor1(int extent[4], int vtkType, int channel)
Download data from the read color attachment of the currently bound FBO into the retruned PBO.
void ActivateDrawBuffer(unsigned int id)
Select a single specific draw or read buffer (zero based)
void RemoveTexDepthAttachment(unsigned int mode)
int CheckFrameBufferStatus(unsigned int mode)
Validate the current FBO configuration (attachments, formats, etc) prints detected errors to vtkError...
static int Blit(int srcExt[4], int destExt[4], unsigned int bits, unsigned int mapping)
Copy from the currently bound READ FBO to the currently bound DRAW FBO.
void AddDepthAttachment(unsigned int mode, vtkTextureObject *tex)
Directly assign/remove a texture/renderbuffer to depth attachments.
void AddTexDepthAttachment(unsigned int mode, unsigned int handle)
void ActivateDrawBuffers(unsigned int n)
Select n consecutive write attachments.
int GetOpenGLType(int vtkType)
Given a vtk type get a compatible open gl type.
void AddTexColorAttachment(unsigned int mode, unsigned int attId, unsigned int handle)
static vtkFrameBufferObject2 * New()
static void InitializeViewport(int width, int height)
Set up ortho viewport with scissor, lighting, blend, and depth disabled.
void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
void ActivateReadBuffer(unsigned int id)
void AddRenColorAttachment(unsigned int mode, unsigned int attId, unsigned int handle)
void Bind(unsigned int mode)
Bind FBO to FRAMEBUFFER, DRAW_FRAMEBUFFER or READ_FRAMEBUFFER The current binding is not saved,...
vtkPixelBufferObject * Download(int extent[4], int vtkType, int nComps, int oglType, int oglFormat)
Download data from the read buffer of the current FBO.
static void Download(int extent[4], int vtkType, int nComps, int oglType, int oglFormat, vtkPixelBufferObject *pbo)
vtkWeakPointer< vtkRenderWindow > Context
void UnBind(unsigned int mode)
Bind saved FBO (see SaveCurrentBindings) for DRAW or READ (see glBindFramebuffer) If no bindings were...
static bool LoadRequiredExtensions(vtkRenderWindow *renWin)
Load all necessary extensions.
void AddColorAttachment(unsigned int mode, unsigned int attId, vtkTextureObject *tex)
Directly assign/remove a texture to color attachments.
static bool IsSupported(vtkRenderWindow *renWin)
Returns if the context supports the required extensions.
void SaveCurrentBuffers()
Store the current draw and read buffers.
void ActivateDrawBuffers(unsigned int *ids, int n)
vtkRenderWindow * GetContext()
void SaveCurrentBindings()
Store the current framebuffer bindings.
void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
void RemoveRenDepthAttachment(unsigned int mode)
void RemoveRenColorAttachments(unsigned int mode, unsigned int num)
void AddColorAttachment(unsigned int mode, unsigned int attId, vtkRenderbuffer *tex)
Directly assign/remove a renderbuffer to color attachments.
vtkPixelBufferObject * DownloadDepth(int extent[4], int vtkType)
Download data from the depth attachment of the currently bound FBO.
void SetContext(vtkRenderWindow *context)
Get/Set the context.
void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
Interface class for querying and using OpenGL extensions.
OpenGL rendering window.
abstracts an OpenGL pixel buffer object.
create a window for renderers to draw into
Storage for FBO's.
abstracts an OpenGL texture object.
@ mode
Definition: vtkX3D.h:247
@ extent
Definition: vtkX3D.h:345
@ height
Definition: vtkX3D.h:254