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  }
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  void AddColorAttachment(
311  unsigned int mode,
312  unsigned int attId,
313  vtkRenderbuffer* tex);
314  void RemoveColorAttachment(unsigned int mode, unsigned int index);
315  void RemoveColorAttachments(unsigned int mode, unsigned int num);
317 
321  int GetNumberOfColorAttachments(unsigned int mode);
322 
324 
328  this->AddDepthAttachment(this->GetBothMode()); }
329  void AddDepthAttachment(unsigned int mode);
330  void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
331  void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
332  void RemoveDepthAttachment(unsigned int mode);
334 
336 
341  bool PopulateFramebuffer(int width, int height);
342  bool PopulateFramebuffer(
343  int width,
344  int height,
345  bool useTextures,
346  int numberOfColorAttachments,
347  int colorDataType,
348  bool wantDepthAttachment,
349  int depthBitplanes,
350  int multisamples);
352 
358  unsigned int GetMaximumNumberOfActiveTargets();
359 
365  unsigned int GetMaximumNumberOfRenderTargets();
366 
368 
371  int *GetLastSize() override
372  {
373  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer " << this->LastSize);
374  return this->LastSize;
375  }
376  void GetLastSize(int &_arg1, int &_arg2) override
377  {
378  _arg1 = this->LastSize[0];
379  _arg2 = this->LastSize[1];
380  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1 << "," << _arg2 << ")");
381  }
382  void GetLastSize (int _arg[2]) override
383  {
384  this->GetLastSize (_arg[0], _arg[1]);
385  }
387 
393  return true; }
394 
399  int CheckFrameBufferStatus(unsigned int mode);
400 
404  virtual void ReleaseGraphicsResources(vtkWindow *win);
405 
412  static
413  bool GetFrameBufferStatus(
414  unsigned int mode,
415  const char *&desc);
416 
423  static int Blit(
424  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
425 
434  vtkPixelBufferObject *DownloadColor1(
435  int extent[4],
436  int vtkType,
437  int channel);
438 
439  vtkPixelBufferObject *DownloadColor3(
440  int extent[4],
441  int vtkType);
442 
443  vtkPixelBufferObject *DownloadColor4(
444  int extent[4],
445  int vtkType);
446 
452  vtkPixelBufferObject *DownloadDepth(
453  int extent[4],
454  int vtkType);
455 
463  vtkPixelBufferObject *Download(
464  int extent[4],
465  int vtkType,
466  int nComps,
467  int oglType,
468  int oglFormat);
469 
470  static
471  void Download(
472  int extent[4],
473  int vtkType,
474  int nComps,
475  int oglType,
476  int oglFormat,
477  vtkPixelBufferObject *pbo);
478 
479  // returns the mode values for draw/read/both
480  // Can be used in cases where you do not
481  // want to have OpenGL code mixed in.
482  static unsigned int GetDrawMode();
483  static unsigned int GetReadMode();
484  static unsigned int GetBothMode();
485 
489  void Resize(int width, int height);
490 
491  // Deprecated
492  void RemoveTexColorAttachments(unsigned int mode, unsigned int num)
493  { this->RemoveColorAttachments(mode, num); }
494  void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
495  { this->RemoveColorAttachment(mode, attId); }
496  void RemoveRenDepthAttachment(unsigned int mode)
497  { this->RemoveDepthAttachment(mode); }
498  void RemoveTexDepthAttachment(unsigned int mode)
499  { this->RemoveDepthAttachment(mode); }
500 
501 protected:
502  void SetColorBuffer(unsigned int mode,
503  unsigned int index, vtkTextureObject *texture,
504  unsigned int zslice=0);
505  void SetColorBuffer(unsigned int mode,
506  unsigned int index, vtkRenderbuffer *rb);
507  void SetDepthBuffer(unsigned int mode, vtkTextureObject *depthTexture);
508  void SetDepthBuffer(unsigned int mode, vtkRenderbuffer *depthBuffer);
509 
513  void Attach();
514 
518  void AttachColorBuffer(unsigned int mode, unsigned int index);
519  void AttachDepthBuffer(unsigned int mode);
520 
524  static
526  return true; };
527 
528  vtkGenericOpenGLResourceFreeCallback *ResourceCallback;
529 
530  // gen buffer (occurs when context is set)
531  void CreateFBO();
532 
533  // delete buffer (occurs during destruction or context swicth)
534  void DestroyFBO();
535 
536  // detach and delete our reference(s)
537  void DestroyDepthBuffer(vtkWindow *win);
538  void DestroyColorBuffers(vtkWindow *win);
539 
540  // glDrawBuffers
541  void ActivateBuffers();
542 
543  // examine attachments to see if they have the same size
544  void UpdateSize();
545 
549  void DisplayFrameBufferAttachments();
550 
554  void DisplayFrameBufferAttachment(unsigned int uattachment);
555 
559  void DisplayDrawBuffers();
560 
564  void DisplayReadBuffer();
565 
569  void DisplayBuffer(int value);
570 
574  int GetOpenGLType(int vtkType);
575 
577  ~vtkOpenGLFramebufferObject() override;
578 
580 
581  unsigned int FBOIndex;
582 
583  unsigned int PreviousDrawFBO;
584  unsigned int PreviousReadFBO;
587  unsigned int PreviousDrawBuffer;
588  unsigned int PreviousReadBuffer;
591 
592  int LastSize[2];
593  std::vector<unsigned int> ActiveBuffers;
594 
595  vtkFOInfo *DrawDepthBuffer;
596  vtkFOInfo *ReadDepthBuffer;
597  std::map<unsigned int, vtkFOInfo *> DrawColorBuffers;
598  std::map<unsigned int, vtkFOInfo *> ReadColorBuffers;
599 
600 private:
602  void operator=(const vtkOpenGLFramebufferObject&) = delete;
603 };
604 
605 #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.
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: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.
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'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.