VTK  9.7.1
vtkOpenGLFramebufferObject.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
120 #ifndef vtkOpenGLFramebufferObject_h
121 #define vtkOpenGLFramebufferObject_h
122 
123 /* Dec 2018 this class has been cleaned up such that
124  * AddColorAttachment and AddDepthAttachment no longer
125  * take a mode argument. The mode is determined by how
126  * the framebuffer is bound. If you are using these methods
127  * and need to support both the old and new signatures you
128  * can check for the following define in your code.
129  */
130 #define VTK_UPDATED_FRAMEBUFFER
131 
138 #ifdef NDEBUG
139 #define vtkCheckFrameBufferStatusMacro(mode)
140 #define vtkStaticCheckFrameBufferStatusMacro(mode)
141 #else
142 #define vtkCheckFrameBufferStatusMacroImpl(macro, mode) \
143  do \
144  { \
145  const char* eStr; \
146  bool ok = vtkOpenGLFramebufferObject::GetFrameBufferStatus(mode, eStr); \
147  if (!ok) \
148  { \
149  macro(<< "OpenGL ERROR. The FBO is incomplete : " << eStr); \
150  } \
151  } while (false)
152 #define vtkCheckFrameBufferStatusMacro(mode) vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
153 #define vtkStaticCheckFrameBufferStatusMacro(mode) \
154  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
155 #endif
156 
158 #include "vtkRenderingOpenGL2Module.h" // For export macro
159 #include <map> // for the maps
160 #include <vector> // for the lists of logical buffers.
161 
162 VTK_ABI_NAMESPACE_BEGIN
163 class vtkFOInfo;
168 class vtkRenderWindow;
169 class vtkRenderbuffer;
170 class vtkShaderProgram;
171 class vtkTextureObject;
172 class vtkWindow;
173 
174 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFramebufferObject : public vtkFrameBufferObjectBase
175 {
176 public:
179  void PrintSelf(ostream& os, vtkIndent indent) override;
180 
182 
189  void SetContext(vtkRenderWindow* context);
190  vtkOpenGLRenderWindow* GetContext();
192 
196  void Bind();
197  void Bind(unsigned int mode);
198 
202  void UnBind();
203  void UnBind(unsigned int mode);
204 
206 
209  void SaveCurrentBindingsAndBuffers();
210  void SaveCurrentBindingsAndBuffers(unsigned int mode);
211  void RestorePreviousBindingsAndBuffers();
212  void RestorePreviousBindingsAndBuffers(unsigned int mode);
214 
216 
225  bool Start(int width, int height);
226  bool StartNonOrtho(int width, int height);
228 
233  void InitializeViewport(int width, int height);
234 
236  // activate deactivate draw/read buffers (color buffers)
237  void ActivateDrawBuffers(unsigned int n);
238  void ActivateDrawBuffers(unsigned int* ids, int n);
239  void ActivateDrawBuffer(unsigned int id);
240  void ActivateReadBuffer(unsigned int id);
241  void ActivateBuffer(unsigned int id)
242  {
243  this->ActivateDrawBuffer(id);
244  this->ActivateReadBuffer(id);
245  }
246  void DeactivateDrawBuffers();
247  void DeactivateReadBuffer();
249 
250  vtkGetMacro(ActiveReadBuffer, unsigned int);
251  unsigned int GetActiveDrawBuffer(unsigned int id);
252 
263  void RenderQuad(int minX, int maxX, int minY, int maxY, vtkShaderProgram* program,
265 
267 
270  void AddColorAttachment(unsigned int attId, vtkTextureObject* tex, unsigned int zslice = 0,
271  unsigned int format = 0, unsigned int mipmapLevel = 0);
272  void AddColorAttachment(unsigned int attId, vtkRenderbuffer* tex);
273  void RemoveColorAttachment(unsigned int index);
274  void RemoveColorAttachments(unsigned int num);
276 
281  vtkTextureObject* GetColorAttachmentAsTextureObject(unsigned int num);
282 
286  int GetNumberOfColorAttachments();
287 
289 
292  void AddDepthAttachment();
293  void AddDepthAttachment(vtkTextureObject* tex);
294  void AddDepthAttachment(vtkRenderbuffer* tex);
295  void RemoveDepthAttachment();
296  vtkTextureObject* GetDepthAttachmentAsTextureObject();
298 
300 
305  bool PopulateFramebuffer(int width, int height);
306  bool PopulateFramebuffer(int width, int height, bool useTextures, int numberOfColorAttachments,
307  int colorDataType, bool wantDepthAttachment, int depthBitplanes, int multisamples,
308  bool wantStencilAttachment = false);
310 
316  unsigned int GetMaximumNumberOfActiveTargets();
317 
323  unsigned int GetMaximumNumberOfRenderTargets();
324 
326 
329  int* GetLastSize() override
330  {
331  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer "
332  << this->LastSize);
333  return this->LastSize;
334  }
335  void GetLastSize(int& _arg1, int& _arg2) override
336  {
337  _arg1 = this->LastSize[0];
338  _arg2 = this->LastSize[1];
339  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1
340  << "," << _arg2 << ")");
341  }
342  void GetLastSize(int _arg[2]) override { this->GetLastSize(_arg[0], _arg[1]); }
344 
349  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
350 
355  int CheckFrameBufferStatus(unsigned int mode);
356 
360  virtual void ReleaseGraphicsResources(vtkWindow* win);
361 
368  static bool GetFrameBufferStatus(unsigned int mode, const char*& desc);
369 
370  vtkGetMacro(FBOIndex, unsigned int);
371 
378  static int Blit(
379  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
380 
389  vtkPixelBufferObject* DownloadColor1(int extent[4], int vtkType, int channel);
390 
391  vtkPixelBufferObject* DownloadColor3(int extent[4], int vtkType);
392 
393  vtkPixelBufferObject* DownloadColor4(int extent[4], int vtkType);
394 
400  vtkPixelBufferObject* DownloadDepth(int extent[4], int vtkType);
401 
409  vtkPixelBufferObject* Download(
410  int extent[4], int vtkType, int nComps, int oglType, int oglFormat);
411 
412  static void Download(
413  int extent[4], int vtkType, int nComps, int oglType, int oglFormat, vtkPixelBufferObject* pbo);
414 
415  // returns the mode values for draw/read/both
416  // Can be used in cases where you do not
417  // want to have OpenGL code mixed in.
418  static unsigned int GetDrawMode();
419  static unsigned int GetReadMode();
420  static unsigned int GetBothMode();
421 
425  void Resize(int width, int height);
426 
427  int GetMultiSamples();
428 
429 protected:
433  void AttachColorBuffer(unsigned int index);
434  void AttachDepthBuffer();
435 
439  static bool LoadRequiredExtensions(vtkOpenGLRenderWindow*) { return true; }
440 
442 
443  // gen buffer (occurs when context is set)
444  void CreateFBO();
445 
446  // delete buffer (occurs during destruction or context switch)
447  void DestroyFBO();
448 
449  // detach and delete our reference(s)
450  void DestroyDepthBuffer(vtkWindow* win);
451  void DestroyColorBuffers(vtkWindow* win);
452 
453  // glDrawBuffers
454  void ActivateBuffers();
455 
456  // examine attachments to see if they have the same size
457  void UpdateSize();
458 
462  void DisplayFrameBufferAttachments();
463 
467  void DisplayFrameBufferAttachment(unsigned int uattachment);
468 
472  void DisplayDrawBuffers();
473 
477  void DisplayReadBuffer();
478 
482  void DisplayBuffer(int value);
483 
487  int GetOpenGLType(int vtkType);
488 
490  ~vtkOpenGLFramebufferObject() override;
491 
493 
494  unsigned int FBOIndex;
495 
500 
501  int LastSize[2];
502  std::vector<unsigned int> ActiveBuffers;
503  unsigned int ActiveReadBuffer;
504 
505  vtkFOInfo* DepthBuffer;
506  std::map<unsigned int, vtkFOInfo*> ColorBuffers;
507 
508 private:
510  void operator=(const vtkOpenGLFramebufferObject&) = delete;
511 };
512 
513 VTK_ABI_NAMESPACE_END
514 #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:41
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:28
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.