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
vtkFrameBufferObject2::GetOpenGLType
int GetOpenGLType(int vtkType)
Given a vtk type get a compatible open gl type.
vtkFrameBufferObject2::PreviousDrawBuffer
unsigned int PreviousDrawBuffer
Definition: vtkFrameBufferObject2.h:341
vtkFrameBufferObject2::RemoveTexDepthAttachment
void RemoveTexDepthAttachment(unsigned int mode)
Definition: vtkFrameBufferObject2.h:187
vtkFrameBufferObject2::AddDepthAttachment
void AddDepthAttachment(unsigned int mode, vtkRenderbuffer *tex)
Directly assign/remove a renderbuffer to depth attachments.
vtkFrameBufferObject2::InitializeViewport
static void InitializeViewport(int width, int height)
Set up ortho viewport with scissor, lighting, blend, and depth disabled.
vtkFrameBufferObject2::AddRenColorAttachment
void AddRenColorAttachment(unsigned int mode, unsigned int attId, unsigned int handle)
vtkFrameBufferObject2::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkFrameBufferObject2::vtkFrameBufferObject2
vtkFrameBufferObject2()
vtkFrameBufferObject2::RemoveRenDepthAttachment
void RemoveRenDepthAttachment(unsigned int mode)
Definition: vtkFrameBufferObject2.h:197
vtkFrameBufferObject2::CreateFBO
void CreateFBO()
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkFrameBufferObject2::RestorePreviousBuffers
void RestorePreviousBuffers(unsigned int mode)
vtkFrameBufferObject2::UnBind
void UnBind(unsigned int mode)
Bind saved FBO (see SaveCurrentBindings) for DRAW or READ (see glBindFramebuffer) If no bindings were...
vtkFrameBufferObject2::Download
vtkPixelBufferObject * Download(int extent[4], int vtkType, int nComps, int oglType, int oglFormat)
Download data from the read buffer of the current FBO.
vtkFrameBufferObject2::AddTexDepthAttachment
void AddTexDepthAttachment(unsigned int mode, unsigned int handle)
vtkFrameBufferObject2::AddTexColorAttachment
void AddTexColorAttachment(unsigned int mode, unsigned int attId, unsigned int handle)
vtkFrameBufferObject2::DeactivateDrawBuffers
void DeactivateDrawBuffers()
vtkFrameBufferObject2::RemoveRenColorAttachment
void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
Definition: vtkFrameBufferObject2.h:178
vtkFrameBufferObject2::AddColorAttachment
void AddColorAttachment(unsigned int mode, unsigned int attId, vtkRenderbuffer *tex)
Directly assign/remove a renderbuffer to color attachments.
vtkFrameBufferObject2::DownloadColor3
vtkPixelBufferObject * DownloadColor3(int extent[4], int vtkType)
vtkOpenGLExtensionManager
Interface class for querying and using OpenGL extensions.
vtkFrameBufferObject2::DeactivateReadBuffer
void DeactivateReadBuffer()
vtkFrameBufferObject2::RemoveRenColorAttachments
void RemoveRenColorAttachments(unsigned int mode, unsigned int num)
vtkX3D::height
@ height
Definition: vtkX3D.h:254
vtkFrameBufferObject2::ActivateDrawBuffers
void ActivateDrawBuffers(unsigned int n)
Select n consecutive write attachments.
vtkFrameBufferObject2::New
static vtkFrameBufferObject2 * New()
vtkFrameBufferObject2::SaveCurrentBuffers
void SaveCurrentBuffers()
Store the current draw and read buffers.
vtkFrameBufferObject2::ActivateDrawBuffers
void ActivateDrawBuffers(unsigned int *ids, int n)
vtkFrameBufferObject2::PreviousReadFBO
unsigned int PreviousReadFBO
Definition: vtkFrameBufferObject2.h:339
vtkFrameBufferObject2::ActivateDrawBuffer
void ActivateDrawBuffer(unsigned int id)
Select a single specific draw or read buffer (zero based)
vtkFrameBufferObject2::DepthBuffer
unsigned int DepthBuffer
Definition: vtkFrameBufferObject2.h:340
vtkFrameBufferObject2::FBOIndex
unsigned int FBOIndex
Definition: vtkFrameBufferObject2.h:337
vtkFrameBufferObject2::LoadRequiredExtensions
static bool LoadRequiredExtensions(vtkRenderWindow *renWin)
Load all necessary extensions.
vtkFrameBufferObject2::GetFrameBufferStatus
static bool GetFrameBufferStatus(unsigned int mode, const char *&desc)
Validate the current FBO configuration (attachments, formats, etc) return false if the FBO is incompl...
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:44
vtkFrameBufferObject2::~vtkFrameBufferObject2
~vtkFrameBufferObject2()
vtkFrameBufferObject2::AddRenDepthAttachment
void AddRenDepthAttachment(unsigned int mode, unsigned int handle)
vtkSmartPointer.h
vtkFrameBufferObject2::CheckFrameBufferStatus
int CheckFrameBufferStatus(unsigned int mode)
Validate the current FBO configuration (attachments, formats, etc) prints detected errors to vtkError...
vtkFrameBufferObject2::RemoveTexColorAttachments
void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
vtkFrameBufferObject2::DownloadColor4
vtkPixelBufferObject * DownloadColor4(int extent[4], int vtkType)
vtkWeakPointer.h
vtkFrameBufferObject2::ActivateReadBuffer
void ActivateReadBuffer(unsigned int id)
vtkFrameBufferObject2::SaveCurrentBindings
void SaveCurrentBindings()
Store the current framebuffer bindings.
vtkFrameBufferObject2::Context
vtkWeakPointer< vtkRenderWindow > Context
Definition: vtkFrameBufferObject2.h:335
vtkFrameBufferObject2::GetContext
vtkRenderWindow * GetContext()
vtkObject.h
vtkFrameBufferObject2::SetContext
void SetContext(vtkRenderWindow *context)
Get/Set the context.
vtkFrameBufferObject2::Download
static void Download(int extent[4], int vtkType, int nComps, int oglType, int oglFormat, vtkPixelBufferObject *pbo)
vtkFrameBufferObject2::AddColorAttachment
void AddColorAttachment(unsigned int mode, unsigned int attId, vtkTextureObject *tex)
Directly assign/remove a texture to color attachments.
vtkFrameBufferObject2::DownloadColor1
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.
vtkFrameBufferObject2::DestroyFBO
void DestroyFBO()
vtkFrameBufferObject2::Bind
void Bind(unsigned int mode)
Bind FBO to FRAMEBUFFER, DRAW_FRAMEBUFFER or READ_FRAMEBUFFER The current binding is not saved,...
vtkFrameBufferObject2::AddDepthAttachment
void AddDepthAttachment(unsigned int mode, vtkTextureObject *tex)
Directly assign/remove a texture/renderbuffer to depth attachments.
vtkFrameBufferObject2::Blit
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.
vtkFrameBufferObject2::RemoveTexColorAttachment
void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
Definition: vtkFrameBufferObject2.h:161
vtkFrameBufferObject2::PreviousDrawFBO
unsigned int PreviousDrawFBO
Definition: vtkFrameBufferObject2.h:338
vtkX3D::mode
@ mode
Definition: vtkX3D.h:247
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:42
vtkX3D::extent
@ extent
Definition: vtkX3D.h:345
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:87
vtkFrameBufferObject2
Interface to OpenGL framebuffer object.
Definition: vtkFrameBufferObject2.h:87
vtkFrameBufferObject2::PreviousReadBuffer
unsigned int PreviousReadBuffer
Definition: vtkFrameBufferObject2.h:342
vtkFrameBufferObject2::IsSupported
static bool IsSupported(vtkRenderWindow *renWin)
Returns if the context supports the required extensions.
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:44
vtkWeakPointer< vtkRenderWindow >
vtkFrameBufferObject2::DownloadDepth
vtkPixelBufferObject * DownloadDepth(int extent[4], int vtkType)
Download data from the depth attachment of the currently bound FBO.
vtkRenderbuffer
Storage for FBO's.
Definition: vtkRenderbuffer.h:33