VTK
vtkOpenGLFramebufferObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLFramebufferObject.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 =========================================================================*/
135 #ifndef vtkOpenGLFramebufferObject_h
136 #define vtkOpenGLFramebufferObject_h
137 
144 #ifdef NDEBUG
145 # define vtkCheckFrameBufferStatusMacro(mode)
146 # define vtkStaticCheckFrameBufferStatusMacro(mode)
147 #else
148 # define vtkCheckFrameBufferStatusMacroImpl(macro, mode) \
149 { \
150 const char *eStr; \
151 bool ok = vtkOpenGLFramebufferObject::GetFrameBufferStatus(mode, eStr); \
152 if (!ok) \
153 { \
154  macro( \
155  << "OpenGL ERROR. The FBO is incomplete : " << eStr); \
156 } \
157  }
158 # define vtkCheckFrameBufferStatusMacro(mode) \
159  vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
160 # define vtkStaticCheckFrameBufferStatusMacro(mode) \
161  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
162 #endif
163 
164 
166 #include "vtkRenderingOpenGL2Module.h" // For export macro
167 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
168 #include <vector> // for the lists of logical buffers.
169 #include <map> // for the maps
170 
171 class vtkFOInfo;
176 class vtkRenderWindow;
177 class vtkRenderbuffer;
178 class vtkShaderProgram;
179 class vtkTextureObject;
180 class vtkWindow;
181 
182 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFramebufferObject : public vtkFrameBufferObjectBase
183 {
184 public:
187  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
188 
190 
197  void SetContext(vtkRenderWindow *context);
198  vtkOpenGLRenderWindow *GetContext();
200 
204  void Bind();
205  void Bind(unsigned int mode);
206 
210  void UnBind();
211  void UnBind(unsigned int mode);
212 
214 
217  void SaveCurrentBindings();
218  void SaveCurrentBindings(unsigned int mode);
220  this->SaveCurrentBuffers();
221  this->SaveCurrentBindings();
222  }
223  void SaveCurrentBindingsAndBuffers(unsigned int mode) {
224  this->SaveCurrentBuffers(mode);
225  this->SaveCurrentBindings(mode);
226  }
227  void RestorePreviousBindings();
228  void RestorePreviousBindings(unsigned int mode);
230  this->RestorePreviousBindings();
231  this->RestorePreviousBuffers();
232  }
233  void RestorePreviousBindingsAndBuffers(unsigned int mode) {
234  this->RestorePreviousBindings(mode);
235  this->RestorePreviousBuffers(mode);
236  }
238 
240 
247  void SaveCurrentBuffers();
248  void SaveCurrentBuffers(unsigned int mode);
249  void RestorePreviousBuffers();
250  void RestorePreviousBuffers(unsigned int mode);
252 
254 
263  bool Start(int width, int height);
264  bool StartNonOrtho(int width, int height);
266 
273  static
274  void InitializeViewport(int width, int height);
275 
277  // activate deactivate draw/read buffers (color buffers)
278  void ActivateDrawBuffers(unsigned int n);
279  void ActivateDrawBuffers(unsigned int *ids, int n);
280  void ActivateDrawBuffer(unsigned int id);
281  void ActivateReadBuffer(unsigned int id);
282  void ActivateBuffer(unsigned int id) {
283  this->ActivateDrawBuffer(id);
284  this->ActivateReadBuffer(id); }
285  void DeactivateDrawBuffers();
286  void DeactivateReadBuffer();
288 
299  void RenderQuad(int minX, int maxX, int minY, int maxY,
301 
303 
308  void AddColorAttachment(
309  unsigned int mode,
310  unsigned int attId,
311  vtkTextureObject* tex,
312  unsigned int zslice = 0);
313  void AddColorAttachment(
314  unsigned int mode,
315  unsigned int attId,
316  vtkRenderbuffer* tex);
317  void RemoveColorAttachment(unsigned int mode, unsigned int index);
318  void RemoveColorAttachments(unsigned int mode, unsigned int num);
320 
324  int GetNumberOfColorAttachments(unsigned int mode);
325 
327 
331  this->AddDepthAttachment(this->GetBothMode()); }
332  void AddDepthAttachment(unsigned int mode);
333  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
334  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
335  void RemoveDepthAttachment(unsigned int mode);
337 
339 
344  bool PopulateFramebuffer(int width, int height);
345  bool PopulateFramebuffer(
346  int width,
347  int height,
348  bool useTextures,
349  int numberOfColorAttachments,
350  int colorDataType,
351  bool wantDepthAttachment,
352  int depthBitplanes,
353  int multisamples);
355 
361  unsigned int GetMaximumNumberOfActiveTargets();
362 
368  unsigned int GetMaximumNumberOfRenderTargets();
369 
371 
374  int *GetLastSize() VTK_OVERRIDE
375  {
376  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer " << this->LastSize);
377  return this->LastSize;
378  }
379  void GetLastSize(int &_arg1, int &_arg2) VTK_OVERRIDE
380  {
381  _arg1 = this->LastSize[0];
382  _arg2 = this->LastSize[1];
383  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1 << "," << _arg2 << ")");
384  }
385  void GetLastSize (int _arg[2]) VTK_OVERRIDE
386  {
387  this->GetLastSize (_arg[0], _arg[1]);
388  }
390 
396  return true; }
397 
402  int CheckFrameBufferStatus(unsigned int mode);
403 
407  virtual void ReleaseGraphicsResources(vtkWindow *win);
408 
415  static
416  bool GetFrameBufferStatus(
417  unsigned int mode,
418  const char *&desc);
419 
426  static int Blit(
427  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
428 
437  vtkPixelBufferObject *DownloadColor1(
438  int extent[4],
439  int vtkType,
440  int channel);
441 
442  vtkPixelBufferObject *DownloadColor3(
443  int extent[4],
444  int vtkType);
445 
446  vtkPixelBufferObject *DownloadColor4(
447  int extent[4],
448  int vtkType);
449 
455  vtkPixelBufferObject *DownloadDepth(
456  int extent[4],
457  int vtkType);
458 
466  vtkPixelBufferObject *Download(
467  int extent[4],
468  int vtkType,
469  int nComps,
470  int oglType,
471  int oglFormat);
472 
473  static
474  void Download(
475  int extent[4],
476  int vtkType,
477  int nComps,
478  int oglType,
479  int oglFormat,
480  vtkPixelBufferObject *pbo);
481 
482  // returns the mode values for draw/read/both
483  // Can be used in cases where you do not
484  // want to have OpenGL code mixed in.
485  static unsigned int GetDrawMode();
486  static unsigned int GetReadMode();
487  static unsigned int GetBothMode();
488 
492  void Resize(int width, int height);
493 
494  // Deprecated
495  void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
496  { this->RemoveColorAttachments(mode, num); }
497  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
498  { this->RemoveColorAttachment(mode, attId); }
499  void RemoveRenDepthAttachment(unsigned int mode)
500  { this->RemoveDepthAttachment(mode); }
501  void RemoveTexDepthAttachment(unsigned int mode)
502  { this->RemoveDepthAttachment(mode); }
503 
504 protected:
505  void SetColorBuffer(unsigned int mode,
506  unsigned int index, vtkTextureObject *texture,
507  unsigned int zslice=0);
508  void SetColorBuffer(unsigned int mode,
509  unsigned int index, vtkRenderbuffer *rb);
510  void SetDepthBuffer(unsigned int mode, vtkTextureObject *depthTexture);
511  void SetDepthBuffer(unsigned int mode, vtkRenderbuffer *depthBuffer);
512 
516  void Attach();
517 
521  void AttachColorBuffer(unsigned int mode, unsigned int index);
522  void AttachDepthBuffer(unsigned int mode);
523 
527  static
529  return true; };
530 
532 
533  // gen buffer (occurs when context is set)
534  void CreateFBO();
535 
536  // delete buffer (occurs during destruction or context swicth)
537  void DestroyFBO();
538 
539  // detach and delete our reference(s)
540  void DestroyDepthBuffer(vtkWindow *win);
541  void DestroyColorBuffers(vtkWindow *win);
542 
543  // glDrawBuffers
544  void ActivateBuffers();
545 
546  // examine attachments to see if they have the same size
547  void UpdateSize();
548 
552  void DisplayFrameBufferAttachments();
553 
557  void DisplayFrameBufferAttachment(unsigned int uattachment);
558 
562  void DisplayDrawBuffers();
563 
567  void DisplayReadBuffer();
568 
572  void DisplayBuffer(int value);
573 
577  int GetOpenGLType(int vtkType);
578 
580  ~vtkOpenGLFramebufferObject() VTK_OVERRIDE;
581 
583 
584  unsigned int FBOIndex;
585 
586  unsigned int PreviousDrawFBO;
587  unsigned int PreviousReadFBO;
588  bool DrawBindingSaved;
589  bool ReadBindingSaved;
590  unsigned int PreviousDrawBuffer;
591  unsigned int PreviousReadBuffer;
592  bool DrawBufferSaved;
593  bool ReadBufferSaved;
594 
595  int LastSize[2];
596  std::vector<unsigned int> ActiveBuffers;
597 
598  vtkFOInfo *DrawDepthBuffer;
599  vtkFOInfo *ReadDepthBuffer;
600  std::map<unsigned int, vtkFOInfo *> DrawColorBuffers;
601  std::map<unsigned int, vtkFOInfo *> ReadColorBuffers;
602 
603 private:
604  vtkOpenGLFramebufferObject(const vtkOpenGLFramebufferObject&) VTK_DELETE_FUNCTION;
605  void operator=(const vtkOpenGLFramebufferObject&) VTK_DELETE_FUNCTION;
606 };
607 
608 #endif
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *)
Returns if the context supports the required extensions.
void AddDepthAttachment()
Directly assign/remove a texture/renderbuffer to depth attachments.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
virtual int * GetLastSize()=0
Dimensions in pixels of the framebuffer.
void RemoveRenDepthAttachment(unsigned int mode)
void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
static bool LoadRequiredExtensions(vtkOpenGLRenderWindow *)
Load all necessary extensions.
void GetLastSize(int &_arg1, int &_arg2) override
Dimensions in pixels of the framebuffer.
void SaveCurrentBindingsAndBuffers(unsigned int mode)
Store/Restore the current framebuffer bindings and buffers.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
void RemoveTexDepthAttachment(unsigned int mode)
abstract interface to OpenGL FBOs
const char * GetClassName() const
Return the class name as a string.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:33
void RestorePreviousBindingsAndBuffers()
Store/Restore the current framebuffer bindings and buffers.
The VertexArrayObject class uses, or emulates, vertex array objects.
a weak reference to a vtkObject.
void RestorePreviousBindingsAndBuffers(unsigned int mode)
Store/Restore the current framebuffer bindings and buffers.
abstracts an OpenGL pixel buffer object.
Internal class which encapsulates OpenGL FramebufferObject.
void GetLastSize(int _arg[2]) override
Dimensions in pixels of the framebuffer.
abstracts an OpenGL texture object.
create a window for renderers to draw into
void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
Storage for FBO&#39;s.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void SaveCurrentBindingsAndBuffers()
Store/Restore the current framebuffer bindings and buffers.
int * GetLastSize() override
Dimensions in pixels of the framebuffer.
The ShaderProgram uses one or more Shader objects.