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) 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 
271  void InitializeViewport(int width, int height);
272 
274  // activate deactivate draw/read buffers (color buffers)
275  void ActivateDrawBuffers(unsigned int n);
276  void ActivateDrawBuffers(unsigned int *ids, int n);
277  void ActivateDrawBuffer(unsigned int id);
278  void ActivateReadBuffer(unsigned int id);
279  void ActivateBuffer(unsigned int id) {
280  this->ActivateDrawBuffer(id);
281  this->ActivateReadBuffer(id); }
282  void DeactivateDrawBuffers();
283  void DeactivateReadBuffer();
285 
296  void RenderQuad(int minX, int maxX, int minY, int maxY,
298 
300 
305  void AddColorAttachment(
306  unsigned int mode,
307  unsigned int attId,
308  vtkTextureObject* tex,
309  unsigned int zslice = 0,
310  unsigned int format = 0,
311  unsigned int mipmapLevel = 0);
312  void AddColorAttachment(
313  unsigned int mode,
314  unsigned int attId,
315  vtkRenderbuffer* tex);
316  void RemoveColorAttachment(unsigned int mode, unsigned int index);
317  void RemoveColorAttachments(unsigned int mode, unsigned int num);
319 
323  int GetNumberOfColorAttachments(unsigned int mode);
324 
326 
330  this->AddDepthAttachment(this->GetBothMode()); }
331  void AddDepthAttachment(unsigned int mode);
332  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
333  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
334  void RemoveDepthAttachment(unsigned int mode);
336 
338 
343  bool PopulateFramebuffer(int width, int height);
344  bool PopulateFramebuffer(
345  int width,
346  int height,
347  bool useTextures,
348  int numberOfColorAttachments,
349  int colorDataType,
350  bool wantDepthAttachment,
351  int depthBitplanes,
352  int multisamples);
354 
360  unsigned int GetMaximumNumberOfActiveTargets();
361 
367  unsigned int GetMaximumNumberOfRenderTargets();
368 
370 
373  int *GetLastSize() override
374  {
375  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer " << this->LastSize);
376  return this->LastSize;
377  }
378  void GetLastSize(int &_arg1, int &_arg2) override
379  {
380  _arg1 = this->LastSize[0];
381  _arg2 = this->LastSize[1];
382  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1 << "," << _arg2 << ")");
383  }
384  void GetLastSize (int _arg[2]) override
385  {
386  this->GetLastSize (_arg[0], _arg[1]);
387  }
389 
395  return true; }
396 
401  int CheckFrameBufferStatus(unsigned int mode);
402 
406  virtual void ReleaseGraphicsResources(vtkWindow *win);
407 
414  static
415  bool GetFrameBufferStatus(
416  unsigned int mode,
417  const char *&desc);
418 
425  static int Blit(
426  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
427 
436  vtkPixelBufferObject *DownloadColor1(
437  int extent[4],
438  int vtkType,
439  int channel);
440 
441  vtkPixelBufferObject *DownloadColor3(
442  int extent[4],
443  int vtkType);
444 
445  vtkPixelBufferObject *DownloadColor4(
446  int extent[4],
447  int vtkType);
448 
454  vtkPixelBufferObject *DownloadDepth(
455  int extent[4],
456  int vtkType);
457 
465  vtkPixelBufferObject *Download(
466  int extent[4],
467  int vtkType,
468  int nComps,
469  int oglType,
470  int oglFormat);
471 
472  static
473  void Download(
474  int extent[4],
475  int vtkType,
476  int nComps,
477  int oglType,
478  int oglFormat,
479  vtkPixelBufferObject *pbo);
480 
481  // returns the mode values for draw/read/both
482  // Can be used in cases where you do not
483  // want to have OpenGL code mixed in.
484  static unsigned int GetDrawMode();
485  static unsigned int GetReadMode();
486  static unsigned int GetBothMode();
487 
491  void Resize(int width, int height);
492 
493  // Deprecated
494  void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
495  { this->RemoveColorAttachments(mode, num); }
496  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
497  { this->RemoveColorAttachment(mode, attId); }
498  void RemoveRenDepthAttachment(unsigned int mode)
499  { this->RemoveDepthAttachment(mode); }
500  void RemoveTexDepthAttachment(unsigned int mode)
501  { this->RemoveDepthAttachment(mode); }
502 
503 protected:
504  void SetColorBuffer(unsigned int mode,
505  unsigned int index, vtkTextureObject *texture,
506  unsigned int zslice=0, unsigned int format=0, unsigned int mipmapLevel=0);
507  void SetColorBuffer(unsigned int mode,
508  unsigned int index, vtkRenderbuffer *rb);
509  void SetDepthBuffer(unsigned int mode, vtkTextureObject *depthTexture);
510  void SetDepthBuffer(unsigned int mode, vtkRenderbuffer *depthBuffer);
511 
515  void Attach();
516 
520  void AttachColorBuffer(unsigned int mode, unsigned int index);
521  void AttachDepthBuffer(unsigned int mode);
522 
526  static
528  return true; };
529 
531 
532  // gen buffer (occurs when context is set)
533  void CreateFBO();
534 
535  // delete buffer (occurs during destruction or context swicth)
536  void DestroyFBO();
537 
538  // detach and delete our reference(s)
539  void DestroyDepthBuffer(vtkWindow *win);
540  void DestroyColorBuffers(vtkWindow *win);
541 
542  // glDrawBuffers
543  void ActivateBuffers();
544 
545  // examine attachments to see if they have the same size
546  void UpdateSize();
547 
551  void DisplayFrameBufferAttachments();
552 
556  void DisplayFrameBufferAttachment(unsigned int uattachment);
557 
561  void DisplayDrawBuffers();
562 
566  void DisplayReadBuffer();
567 
571  void DisplayBuffer(int value);
572 
576  int GetOpenGLType(int vtkType);
577 
579  ~vtkOpenGLFramebufferObject() override;
580 
582 
583  unsigned int FBOIndex;
584 
585  unsigned int PreviousDrawFBO;
586  unsigned int PreviousReadFBO;
589  unsigned int PreviousDrawBuffer;
590  unsigned int PreviousReadBuffer;
593 
594  int LastSize[2];
595  std::vector<unsigned int> ActiveBuffers;
596 
597  vtkFOInfo *DrawDepthBuffer;
598  vtkFOInfo *ReadDepthBuffer;
599  std::map<unsigned int, vtkFOInfo *> DrawColorBuffers;
600  std::map<unsigned int, vtkFOInfo *> ReadColorBuffers;
601 
602 private:
604  void operator=(const vtkOpenGLFramebufferObject&) = delete;
605 };
606 
607 #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.
std::map< unsigned int, vtkFOInfo * > ReadColorBuffers
vtkWeakPointer< vtkOpenGLRenderWindow > Context
std::map< unsigned int, vtkFOInfo * > DrawColorBuffers
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:37
void RemoveTexDepthAttachment(unsigned int mode)
abstract interface to OpenGL FBOs
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:39
void RestorePreviousBindingsAndBuffers()
Store/Restore the current framebuffer bindings and buffers.
The VertexArrayObject class uses, or emulates, vertex array objects.
const char * GetClassName() const
Return the class name as a string.
void RestorePreviousBindingsAndBuffers(unsigned int mode)
Store/Restore the current framebuffer bindings and buffers.
std::vector< unsigned int > ActiveBuffers
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.