VTK  9.3.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  { \
144  const char* eStr; \
145  bool ok = vtkOpenGLFramebufferObject::GetFrameBufferStatus(mode, eStr); \
146  if (!ok) \
147  { \
148  macro(<< "OpenGL ERROR. The FBO is incomplete : " << eStr); \
149  } \
150  }
151 #define vtkCheckFrameBufferStatusMacro(mode) vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
152 #define vtkStaticCheckFrameBufferStatusMacro(mode) \
153  vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
154 #endif
155 
157 #include "vtkRenderingOpenGL2Module.h" // For export macro
158 #include <map> // for the maps
159 #include <vector> // for the lists of logical buffers.
160 
161 VTK_ABI_NAMESPACE_BEGIN
162 class vtkFOInfo;
167 class vtkRenderWindow;
168 class vtkRenderbuffer;
169 class vtkShaderProgram;
170 class vtkTextureObject;
171 class vtkWindow;
172 
173 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLFramebufferObject : public vtkFrameBufferObjectBase
174 {
175 public:
178  void PrintSelf(ostream& os, vtkIndent indent) override;
179 
181 
188  void SetContext(vtkRenderWindow* context);
189  vtkOpenGLRenderWindow* GetContext();
191 
195  void Bind();
196  void Bind(unsigned int mode);
197 
201  void UnBind();
202  void UnBind(unsigned int mode);
203 
205 
208  void SaveCurrentBindingsAndBuffers();
209  void SaveCurrentBindingsAndBuffers(unsigned int mode);
210  void RestorePreviousBindingsAndBuffers();
211  void RestorePreviousBindingsAndBuffers(unsigned int mode);
213 
215 
224  bool Start(int width, int height);
225  bool StartNonOrtho(int width, int height);
227 
232  void InitializeViewport(int width, int height);
233 
235  // activate deactivate draw/read buffers (color buffers)
236  void ActivateDrawBuffers(unsigned int n);
237  void ActivateDrawBuffers(unsigned int* ids, int n);
238  void ActivateDrawBuffer(unsigned int id);
239  void ActivateReadBuffer(unsigned int id);
240  void ActivateBuffer(unsigned int id)
241  {
242  this->ActivateDrawBuffer(id);
243  this->ActivateReadBuffer(id);
244  }
245  void DeactivateDrawBuffers();
246  void DeactivateReadBuffer();
248 
249  vtkGetMacro(ActiveReadBuffer, unsigned int);
250  unsigned int GetActiveDrawBuffer(unsigned int id);
251 
262  void RenderQuad(int minX, int maxX, int minY, int maxY, vtkShaderProgram* program,
264 
266 
269  void AddColorAttachment(unsigned int attId, vtkTextureObject* tex, unsigned int zslice = 0,
270  unsigned int format = 0, unsigned int mipmapLevel = 0);
271  void AddColorAttachment(unsigned int attId, vtkRenderbuffer* tex);
272  void RemoveColorAttachment(unsigned int index);
273  void RemoveColorAttachments(unsigned int num);
275 
280  vtkTextureObject* GetColorAttachmentAsTextureObject(unsigned int num);
281 
285  int GetNumberOfColorAttachments();
286 
288 
291  void AddDepthAttachment();
292  void AddDepthAttachment(vtkTextureObject* tex);
293  void AddDepthAttachment(vtkRenderbuffer* tex);
294  void RemoveDepthAttachment();
295  vtkTextureObject* GetDepthAttachmentAsTextureObject();
297 
299 
304  bool PopulateFramebuffer(int width, int height);
305  bool PopulateFramebuffer(int width, int height, bool useTextures, int numberOfColorAttachments,
306  int colorDataType, bool wantDepthAttachment, int depthBitplanes, int multisamples,
307  bool wantStencilAttachment = false);
309 
315  unsigned int GetMaximumNumberOfActiveTargets();
316 
322  unsigned int GetMaximumNumberOfRenderTargets();
323 
325 
328  int* GetLastSize() override
329  {
330  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize pointer "
331  << this->LastSize);
332  return this->LastSize;
333  }
334  void GetLastSize(int& _arg1, int& _arg2) override
335  {
336  _arg1 = this->LastSize[0];
337  _arg2 = this->LastSize[1];
338  vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning LastSize (" << _arg1
339  << "," << _arg2 << ")");
340  }
341  void GetLastSize(int _arg[2]) override { this->GetLastSize(_arg[0], _arg[1]); }
343 
348  static bool IsSupported(vtkOpenGLRenderWindow*) { return true; }
349 
354  int CheckFrameBufferStatus(unsigned int mode);
355 
359  virtual void ReleaseGraphicsResources(vtkWindow* win);
360 
367  static bool GetFrameBufferStatus(unsigned int mode, const char*& desc);
368 
369  vtkGetMacro(FBOIndex, unsigned int);
370 
377  static int Blit(
378  const int srcExt[4], const int destExt[4], unsigned int bits, unsigned int mapping);
379 
388  vtkPixelBufferObject* DownloadColor1(int extent[4], int vtkType, int channel);
389 
390  vtkPixelBufferObject* DownloadColor3(int extent[4], int vtkType);
391 
392  vtkPixelBufferObject* DownloadColor4(int extent[4], int vtkType);
393 
399  vtkPixelBufferObject* DownloadDepth(int extent[4], int vtkType);
400 
408  vtkPixelBufferObject* Download(
409  int extent[4], int vtkType, int nComps, int oglType, int oglFormat);
410 
411  static void Download(
412  int extent[4], int vtkType, int nComps, int oglType, int oglFormat, vtkPixelBufferObject* pbo);
413 
414  // returns the mode values for draw/read/both
415  // Can be used in cases where you do not
416  // want to have OpenGL code mixed in.
417  static unsigned int GetDrawMode();
418  static unsigned int GetReadMode();
419  static unsigned int GetBothMode();
420 
424  void Resize(int width, int height);
425 
426  int GetMultiSamples();
427 
428 protected:
432  void AttachColorBuffer(unsigned int index);
433  void AttachDepthBuffer();
434 
438  static bool LoadRequiredExtensions(vtkOpenGLRenderWindow*) { return true; }
439 
441 
442  // gen buffer (occurs when context is set)
443  void CreateFBO();
444 
445  // delete buffer (occurs during destruction or context switch)
446  void DestroyFBO();
447 
448  // detach and delete our reference(s)
449  void DestroyDepthBuffer(vtkWindow* win);
450  void DestroyColorBuffers(vtkWindow* win);
451 
452  // glDrawBuffers
453  void ActivateBuffers();
454 
455  // examine attachments to see if they have the same size
456  void UpdateSize();
457 
461  void DisplayFrameBufferAttachments();
462 
466  void DisplayFrameBufferAttachment(unsigned int uattachment);
467 
471  void DisplayDrawBuffers();
472 
476  void DisplayReadBuffer();
477 
481  void DisplayBuffer(int value);
482 
486  int GetOpenGLType(int vtkType);
487 
489  ~vtkOpenGLFramebufferObject() override;
490 
492 
493  unsigned int FBOIndex;
494 
499 
500  int LastSize[2];
501  std::vector<unsigned int> ActiveBuffers;
502  unsigned int ActiveReadBuffer;
503 
504  vtkFOInfo* DepthBuffer;
505  std::map<unsigned int, vtkFOInfo*> ColorBuffers;
506 
507 private:
509  void operator=(const vtkOpenGLFramebufferObject&) = delete;
510 };
511 
512 VTK_ABI_NAMESPACE_END
513 #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:27
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.