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
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)
int * GetLastSize(bool forceUpdate)
Additional overload which lets the user decide whether the returned size should be the currently cach...
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.
virtual void GetLastSize(int size[2])
virtual int * GetLastSize()
Dimensions in pixels of the framebuffer.
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)
virtual void GetLastSize(int &width, int &height)
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)
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)
abstract interface to OpenGL FBOs
a simple class to control print indentation
Definition: vtkIndent.h:40
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
@ size
Definition: vtkX3D.h:253