VTK
vtkFrameBufferObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFrameBufferObject.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 =========================================================================*/
29 #ifndef vtkFrameBufferObject_h
30 #define vtkFrameBufferObject_h
31 
33 #include "vtkRenderingOpenGL2Module.h" // For export macro
34 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
35 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
36 #include <vector> // for the lists of logical buffers.
37 
38 
39 class vtkRenderWindow;
40 class vtkTextureObject;
43 class vtkShaderProgram;
46 class vtkWindow;
47 
48 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject : public vtkFrameBufferObjectBase
49 {
50 public:
53  void PrintSelf(ostream& os, vtkIndent indent);
54 
56 
66 
68 
77  bool Start(int width, int height, bool shaderSupportsTextureInt);
78  bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt);
80 
91  void RenderQuad(int minX, int maxX, int minY, int maxY,
93 
97  void Bind();
98 
103  void UnBind();
104 
108  void SetActiveBuffer(unsigned int index)
109  {
110  this->SetActiveBuffers(1, &index);
111  }
112 
120  void SetActiveBuffers(int numbuffers, unsigned int indices[]);
121 
134  unsigned int index,
135  vtkTextureObject *texture,
136  unsigned int zslice=0);
137 
139  void RemoveColorBuffer(unsigned int index);
141 
143 
146  void SetDepthBuffer(vtkTextureObject *depthTexture);
149 
151 
155  vtkSetMacro(DepthBufferNeeded,bool);
156  vtkGetMacro(DepthBufferNeeded,bool);
158 
160 
167  void SetNumberOfRenderTargets(unsigned int);
168  vtkGetMacro(NumberOfRenderTargets,unsigned int);
170 
177 
184 
186 
189  vtkGetVector2Macro(LastSize,int);
191 
196  static bool IsSupported(vtkOpenGLRenderWindow *renWin);
197 
202  int CheckFrameBufferStatus(unsigned int mode);
203 
208 
209 protected:
213  static
215 
217 
218  // gen buffer (occurs when context is set)
219  void CreateFBO();
220 
221  // delete buffer (occurs during destruction or context swicth)
222  void DestroyFBO();
223 
224  // create texture or renderbuffer and attach
225  // if user provided a texture just use that
226  // mode specifies DRAW or READ
227  void CreateDepthBuffer(int width, int height, unsigned int mode);
228 
229  // create textures for each target and attach
230  // if user provided textures use those, if the user
231  // provides any then they need to provide all
232  // mode specifies DRAW or READ
234  int width,
235  int height,
236  unsigned int mode,
237  bool shaderSupportsTextureInt);
238 
239  // detach and delete our reference(s)
242 
243  // glDrawBuffers
245 
250 
254  void DisplayFrameBufferAttachment(unsigned int uattachment);
255 
260 
265 
269  void DisplayBuffer(int value);
270 
273 
275 
276  bool DepthBufferNeeded;
277  bool ColorBuffersDirty;
278  unsigned int FBOIndex;
279  int PreviousFBOIndex;
280  unsigned int DepthBuffer;
281  unsigned int NumberOfRenderTargets;
282  int LastSize[2];
283  std::vector<unsigned int> UserZSlices;
284  std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
285  std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
286  std::vector<unsigned int> ActiveBuffers;
287  vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
288  bool DepthBufferDirty;
289 
290 private:
291  vtkFrameBufferObject(const vtkFrameBufferObject&) VTK_DELETE_FUNCTION;
292  void operator=(const vtkFrameBufferObject&) VTK_DELETE_FUNCTION;
293 };
294 
295 #endif
vtkFrameBufferObject
internal class which encapsulates OpenGL frame buffer object.
Definition: vtkFrameBufferObject.h:47
vtkFrameBufferObject::SetActiveBuffers
void SetActiveBuffers(int numbuffers, unsigned int indices[])
User provided color buffers are attached by index to color buffers.
vtkFrameBufferObject::DestroyColorBuffers
void DestroyColorBuffers()
vtkFrameBufferObject::ResourceCallback
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
Definition: vtkFrameBufferObject.h:216
vtkFrameBufferObject::RenderQuad
void RenderQuad(int minX, int maxX, int minY, int maxY, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
Renders a quad at the given location with pixel coordinates.
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkFrameBufferObject::DisplayBuffer
void DisplayBuffer(int value)
Display any buffer (convert value into string).
vtkFrameBufferObject::CreateDepthBuffer
void CreateDepthBuffer(int width, int height, unsigned int mode)
vtkFrameBufferObject::CheckFrameBufferStatus
int CheckFrameBufferStatus(unsigned int mode)
Validate the current FBO configuration (attachments, formats, etc) prints detected errors to vtkError...
vtkFrameBufferObject::SetActiveBuffer
void SetActiveBuffer(unsigned int index)
Choose the buffers to render into.
Definition: vtkFrameBufferObject.h:108
vtkFrameBufferObject::CreateFBO
void CreateFBO()
vtkSmartPointer< vtkTextureObject >
vtkFrameBufferObject::DisplayReadBuffer
void DisplayReadBuffer()
Display the read buffer.
vtkFrameBufferObject::UnBind
void UnBind()
Restore the previous draw framebuffer if saved, else bind the default buffer.
vtkFrameBufferObject::RemoveColorBuffer
void RemoveColorBuffer(unsigned int index)
vtkFrameBufferObjectBase
abstract interface to OpenGL FBOs
Definition: vtkFrameBufferObjectBase.h:33
vtkFrameBufferObject::DestroyFBO
void DestroyFBO()
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
vtkFrameBufferObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkFrameBufferObject::IsSupported
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Returns if the context supports the required extensions.
vtkFrameBufferObject::StartNonOrtho
bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt)
vtkFrameBufferObject::DisplayFrameBufferAttachment
void DisplayFrameBufferAttachment(unsigned int uattachment)
Display a given attachment for the current framebuffer object.
vtkFrameBufferObject::Bind
void Bind()
Make the draw frame buffer active (uses FRAMEBUFFER).
vtkX3D::height
@ height
Definition: vtkX3D.h:254
vtkFrameBufferObject::Start
bool Start(int width, int height, bool shaderSupportsTextureInt)
User must take care that width/height match the dimensions of the user defined texture attachments.
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:45
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:26
vtkFrameBufferObject::DisplayFrameBufferAttachments
void DisplayFrameBufferAttachments()
Display all the attachments of the current framebuffer object.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:41
vtkFrameBufferObject::SetColorBuffer
void SetColorBuffer(unsigned int index, vtkTextureObject *texture, unsigned int zslice=0)
Insert a color buffer into the list of available color buffers.
vtkFrameBufferObject::ActivateBuffers
void ActivateBuffers()
vtkFrameBufferObject::DestroyDepthBuffer
void DestroyDepthBuffer()
vtkSmartPointer.h
vtkFrameBufferObject::GetContext
vtkOpenGLRenderWindow * GetContext()
vtkWeakPointer.h
vtkFrameBufferObject::LoadRequiredExtensions
static bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
Load all necessary extensions.
vtkFrameBufferObject::GetMaximumNumberOfRenderTargets
unsigned int GetMaximumNumberOfRenderTargets()
Returns the maximum number of render targets available.
vtkFrameBufferObject::GetColorBuffer
vtkTextureObject * GetColorBuffer(unsigned int index)
vtkFrameBufferObject::RemoveAllColorBuffers
void RemoveAllColorBuffers()
vtkFrameBufferObject::~vtkFrameBufferObject
~vtkFrameBufferObject()
vtkFrameBufferObject::DisplayDrawBuffers
void DisplayDrawBuffers()
Display the draw buffers.
vtkFrameBufferObject::GetMaximumNumberOfActiveTargets
unsigned int GetMaximumNumberOfActiveTargets()
Returns the maximum number of targets that can be rendered to at one time.
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkFrameBufferObject::Context
vtkWeakPointer< vtkOpenGLRenderWindow > Context
Definition: vtkFrameBufferObject.h:274
vtkFrameBufferObject::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources(vtkWindow *win)
Deactivate and UnBind.
vtkFrameBufferObject::SetNumberOfRenderTargets
void SetNumberOfRenderTargets(unsigned int)
Set/Get the number of render targets to render into at once.
vtkFrameBufferObjectBase.h
vtkFrameBufferObject::New
static vtkFrameBufferObject * New()
vtkFrameBufferObject::SetDepthBuffer
void SetDepthBuffer(vtkTextureObject *depthTexture)
Set the texture to use as depth buffer.
vtkFrameBufferObject::CreateColorBuffers
void CreateColorBuffers(int width, int height, unsigned int mode, bool shaderSupportsTextureInt)
vtkX3D::mode
@ mode
Definition: vtkX3D.h:247
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:39
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:87
vtkFrameBufferObject::RemoveDepthBuffer
void RemoveDepthBuffer()
vtkFrameBufferObject::SetContext
void SetContext(vtkOpenGLRenderWindow *context)
Get/Set the context.
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:44
vtkWeakPointer< vtkOpenGLRenderWindow >
vtkFrameBufferObject::vtkFrameBufferObject
vtkFrameBufferObject()