VTK  9.2.6
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 =========================================================================*/
132 #ifndef vtkOpenGLFramebufferObject_h
133 #define vtkOpenGLFramebufferObject_h
134 
135 /* Dec 2018 this class has been cleaned up such that
136  * AddColorAttachment and AddDepthAttachment no longer
137  * take a mode argument. The mode is determined by how
138  * the framebuffer is bound. If you are using these methods
139  * and need to support both the old and new signatures you
140  * can check for the following define in your code.
141  */
142 #define VTK_UPDATED_FRAMEBUFFER
143 
150 #ifdef NDEBUG
151 #define vtkCheckFrameBufferStatusMacro(mode)
152 #define vtkStaticCheckFrameBufferStatusMacro(mode)
153 #else
154 #define vtkCheckFrameBufferStatusMacroImpl(macro, mode) \
155  { \
156  const char* eStr; \
157  bool ok = vtkOpenGLFramebufferObject::GetFrameBufferStatus(mode, eStr); \
158  if (!ok) \
159  { \
160  macro(<< "OpenGL ERROR. The FBO is incomplete : " << eStr); \
161  } \
162  }
163 #define vtkCheckFrameBufferStatusMacro(mode) vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
164 #define vtkStaticCheckFrameBufferStatusMacro(mode) \
165  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
166 #endif
167 
169 #include "vtkRenderingOpenGL2Module.h" // For export macro
170 #include <map> // for the maps
171 #include <vector> // for the lists of logical buffers.
172 
173 class vtkFOInfo;
178 class vtkRenderWindow;
179 class vtkRenderbuffer;
180 class vtkShaderProgram;
181 class vtkTextureObject;
182 class vtkWindow;
183 
184 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFramebufferObject : public vtkFrameBufferObjectBase
185 {
186 public:
189  void PrintSelf(ostream& os, vtkIndent indent) override;
190 
192 
199  void SetContext(vtkRenderWindow* context);
200  vtkOpenGLRenderWindow* GetContext();
202 
206  void Bind();
207  void Bind(unsigned int mode);
208 
212  void UnBind();
213  void UnBind(unsigned int mode);
214 
216 
219  void SaveCurrentBindingsAndBuffers();
220  void SaveCurrentBindingsAndBuffers(unsigned int mode);
221  void RestorePreviousBindingsAndBuffers();
222  void RestorePreviousBindingsAndBuffers(unsigned int mode);
224 
226 
235  bool Start(int width, int height);
236  bool StartNonOrtho(int width, int height);
238 
243  void InitializeViewport(int width, int height);
244 
246  // activate deactivate draw/read buffers (color buffers)
247  void ActivateDrawBuffers(unsigned int n);
248  void ActivateDrawBuffers(unsigned int* ids, int n);
249  void ActivateDrawBuffer(unsigned int id);
250  void ActivateReadBuffer(unsigned int id);
251  void ActivateBuffer(unsigned int id)
252  {
253  this->ActivateDrawBuffer(id);
254  this->ActivateReadBuffer(id);
255  }
256  void DeactivateDrawBuffers();
257  void DeactivateReadBuffer();
259 
260  vtkGetMacro(ActiveReadBuffer, unsigned int);
261  unsigned int GetActiveDrawBuffer(unsigned int id);
262 
273  void RenderQuad(int minX, int maxX, int minY, int maxY, vtkShaderProgram* program,
275 
277 
280  void AddColorAttachment(unsigned int attId, vtkTextureObject* tex, unsigned int zslice = 0,
281  unsigned int format = 0, unsigned int mipmapLevel = 0);
282  void AddColorAttachment(unsigned int attId, vtkRenderbuffer* tex);
283  void RemoveColorAttachment(unsigned int index);
284  void RemoveColorAttachments(unsigned int num);
286 
291  vtkTextureObject* GetColorAttachmentAsTextureObject(unsigned int num);
292 
296  int GetNumberOfColorAttachments();
297 
299 
302  void AddDepthAttachment();
303  void AddDepthAttachment(vtkTextureObject* tex);
304  void AddDepthAttachment(vtkRenderbuffer* tex);
305  void RemoveDepthAttachment();
306  vtkTextureObject* GetDepthAttachmentAsTextureObject();
308 
310 
315  bool PopulateFramebuffer(int width, int height);
316  bool PopulateFramebuffer(int width, int height, bool useTextures, int numberOfColorAttachments,
317  int colorDataType, bool wantDepthAttachment, int depthBitplanes, int multisamples,
318  bool wantStencilAttachment = false);
320 
326  unsigned int GetMaximumNumberOfActiveTargets();
327 
333  unsigned int GetMaximumNumberOfRenderTargets();
334 
336 
339  int* GetLastSize() override
340  {
341  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer "
342  << this->LastSize);
343  return this->LastSize;
344  }
345  void GetLastSize(int& _arg1, int& _arg2) override
346  {
347  _arg1 = this->LastSize[0];
348  _arg2 = this->LastSize[1];
349  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1
350  << "," << _arg2 << ")");
351  }
352  void GetLastSize(int _arg[2]) override { this->GetLastSize(_arg[0], _arg[1]); }
354 
359  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
360 
365  int CheckFrameBufferStatus(unsigned int mode);
366 
370  virtual void ReleaseGraphicsResources(vtkWindow* win);
371 
378  static bool GetFrameBufferStatus(unsigned int mode, const char*& desc);
379 
380  vtkGetMacro(FBOIndex, unsigned int);
381 
388  static int Blit(
389  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
390 
399  vtkPixelBufferObject* DownloadColor1(int extent[4], int vtkType, int channel);
400 
401  vtkPixelBufferObject* DownloadColor3(int extent[4], int vtkType);
402 
403  vtkPixelBufferObject* DownloadColor4(int extent[4], int vtkType);
404 
410  vtkPixelBufferObject* DownloadDepth(int extent[4], int vtkType);
411 
419  vtkPixelBufferObject* Download(
420  int extent[4], int vtkType, int nComps, int oglType, int oglFormat);
421 
422  static void Download(
423  int extent[4], int vtkType, int nComps, int oglType, int oglFormat, vtkPixelBufferObject* pbo);
424 
425  // returns the mode values for draw/read/both
426  // Can be used in cases where you do not
427  // want to have OpenGL code mixed in.
428  static unsigned int GetDrawMode();
429  static unsigned int GetReadMode();
430  static unsigned int GetBothMode();
431 
435  void Resize(int width, int height);
436 
437  int GetMultiSamples();
438 
439 protected:
443  void AttachColorBuffer(unsigned int index);
444  void AttachDepthBuffer();
445 
449  static bool LoadRequiredExtensions(vtkOpenGLRenderWindow*) { return true; }
450 
452 
453  // gen buffer (occurs when context is set)
454  void CreateFBO();
455 
456  // delete buffer (occurs during destruction or context switch)
457  void DestroyFBO();
458 
459  // detach and delete our reference(s)
460  void DestroyDepthBuffer(vtkWindow* win);
461  void DestroyColorBuffers(vtkWindow* win);
462 
463  // glDrawBuffers
464  void ActivateBuffers();
465 
466  // examine attachments to see if they have the same size
467  void UpdateSize();
468 
472  void DisplayFrameBufferAttachments();
473 
477  void DisplayFrameBufferAttachment(unsigned int uattachment);
478 
482  void DisplayDrawBuffers();
483 
487  void DisplayReadBuffer();
488 
492  void DisplayBuffer(int value);
493 
497  int GetOpenGLType(int vtkType);
498 
500  ~vtkOpenGLFramebufferObject() override;
501 
503 
504  unsigned int FBOIndex;
505 
510 
511  int LastSize[2];
512  std::vector<unsigned int> ActiveBuffers;
513  unsigned int ActiveReadBuffer;
514 
515  vtkFOInfo* DepthBuffer;
516  std::map<unsigned int, vtkFOInfo*> ColorBuffers;
517 
518 private:
520  void operator=(const vtkOpenGLFramebufferObject&) = delete;
521 };
522 
523 #endif
OpenGL rendering window.
static bool IsSupported(vtkOpenGLRenderWindow *)
Returns if the context supports the required extensions.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
static bool LoadRequiredExtensions(vtkOpenGLRenderWindow *)
Load all necessary extensions.
void GetLastSize(int &_arg1, int &_arg2) override
Dimensions in pixels of the framebuffer.
std::map< unsigned int, vtkFOInfo * > ColorBuffers
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
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
The VertexArrayObject class uses, or emulates, vertex array objects.
const char * GetClassName() const
Return the class name as a string.
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
Storage for FBO's.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
int * GetLastSize() override
Dimensions in pixels of the framebuffer.
The ShaderProgram uses one or more Shader objects.