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 
49 #include "vtkRenderingOpenGL2Module.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;
84 
85 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject2 : public vtkFrameBufferObjectBase
86 {
87 public:
90  void PrintSelf(ostream& os, vtkIndent indent);
91 
93 
100  void SetContext(vtkRenderWindow *context);
103 
108  static bool IsSupported(vtkRenderWindow *renWin);
109 
116  void Bind(unsigned int mode);
117 
123  void UnBind(unsigned int mode);
124 
133 
135 
143  void RestorePreviousBuffers(unsigned int mode);
145 
150  unsigned int mode,
151  unsigned int attId,
152  vtkTextureObject* tex);
153 
155  unsigned int mode,
156  unsigned int attId,
157  unsigned int handle);
158 
159  void RemoveTexColorAttachments(unsigned int mode, unsigned int num);
160  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
161  { this->AddTexColorAttachment(mode, attId, 0U); }
162 
167  unsigned int mode,
168  unsigned int attId,
169  vtkRenderbuffer* tex);
170 
172  unsigned int mode,
173  unsigned int attId,
174  unsigned int handle);
175 
176  void RemoveRenColorAttachments(unsigned int mode, unsigned int num);
177  void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
178  { this->AddRenColorAttachment(mode, attId, 0U); }
179 
181 
184  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
185  void AddTexDepthAttachment(unsigned int mode, unsigned int handle);
186  void RemoveTexDepthAttachment(unsigned int mode)
187  { this->AddTexDepthAttachment(mode, 0U); }
189 
191 
194  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
195  void AddRenDepthAttachment(unsigned int mode, unsigned int handle);
196  void RemoveRenDepthAttachment(unsigned int mode)
197  { this->AddRenDepthAttachment(mode, 0U); }
199 
201 
204  void ActivateDrawBuffer(unsigned int id);
205  void ActivateReadBuffer(unsigned int id);
208 
210 
214  void ActivateDrawBuffers(unsigned int n);
215  void ActivateDrawBuffers(unsigned int *ids, int n);
218 
225  static
226  void InitializeViewport(int width, int height);
227 
233  int CheckFrameBufferStatus(unsigned int mode);
234 
241  static
243  unsigned int mode,
244  const char *&desc);
245 
252  static
253  int Blit(
254  int srcExt[4],
255  int destExt[4],
256  unsigned int bits,
257  unsigned int mapping);
258 
268  int extent[4],
269  int vtkType,
270  int channel);
271 
273  int extent[4],
274  int vtkType);
275 
277  int extent[4],
278  int vtkType);
279 
286  int extent[4],
287  int vtkType);
288 
297  int extent[4],
298  int vtkType,
299  int nComps,
300  int oglType,
301  int oglFormat);
302 
303  static
304  void Download(
305  int extent[4],
306  int vtkType,
307  int nComps,
308  int oglType,
309  int oglFormat,
310  vtkPixelBufferObject *pbo);
311 
313 
320  virtual int* GetLastSize();
321  virtual void GetLastSize(int &width, int &height);
322  virtual void GetLastSize(int size[2]);
324 
331  int* GetLastSize(bool forceUpdate);
332 
333 protected:
337  static
339 
340  // gen buffer (occurs when context is set)
341  void CreateFBO();
342 
343  // delete buffer (occurs during destruction or context swicth)
344  void DestroyFBO();
345 
349  int GetOpenGLType(int vtkType);
350 
353 
355 
356  unsigned int FBOIndex;
357  unsigned int PreviousDrawFBO;
358  unsigned int PreviousReadFBO;
359  unsigned int PreviousDrawBuffer;
360  unsigned int PreviousReadBuffer;
361  int LastViewportSize[2];
362 
363 private:
367  inline void QueryViewportSize();
368 
369  vtkFrameBufferObject2(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
370  void operator=(const vtkFrameBufferObject2&) VTK_DELETE_FUNCTION;
371 
372  friend class vtkRenderbuffer; // needs access to LoadRequiredExtentsions
373 
374 };
375 
376 #endif
vtkFrameBufferObject2::GetOpenGLType
int GetOpenGLType(int vtkType)
Given a vtk type get a compatible open gl type.
vtkFrameBufferObject2::RemoveTexDepthAttachment
void RemoveTexDepthAttachment(unsigned int mode)
Definition: vtkFrameBufferObject2.h:186
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:196
vtkFrameBufferObject2::CreateFBO
void CreateFBO()
vtkFrameBufferObject2::GetLastSize
virtual int * GetLastSize()
Dimensions in pixels of the framebuffer.
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)
vtkFrameBufferObjectBase
abstract interface to OpenGL FBOs
Definition: vtkFrameBufferObjectBase.h:33
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:177
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)
vtkFrameBufferObject2::DeactivateReadBuffer
void DeactivateReadBuffer()
vtkFrameBufferObject2::GetLastSize
virtual void GetLastSize(int size[2])
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::ActivateDrawBuffer
void ActivateDrawBuffer(unsigned int id)
Select a single specific draw or read buffer (zero based)
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)
vtkX3D::size
@ size
Definition: vtkX3D.h:253
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::GetContext
vtkRenderWindow * GetContext()
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,...
vtkFrameBufferObjectBase.h
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:160
vtkFrameBufferObject2::GetLastSize
int * GetLastSize(bool forceUpdate)
Additional overload which lets the user decide whether the returned size should be the currently cach...
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::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
vtkFrameBufferObject2::GetLastSize
virtual void GetLastSize(int &width, int &height)