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
abstract interface to OpenGL FBOs
internal class which encapsulates OpenGL frame buffer object.
bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt)
unsigned int GetMaximumNumberOfRenderTargets()
Returns the maximum number of render targets available.
virtual void ReleaseGraphicsResources(vtkWindow *win)
Deactivate and UnBind.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
void DisplayFrameBufferAttachments()
Display all the attachments of the current framebuffer object.
void SetColorBuffer(unsigned int index, vtkTextureObject *texture, unsigned int zslice=0)
Insert a color buffer into the list of available color buffers.
bool Start(int width, int height, bool shaderSupportsTextureInt)
User must take care that width/height match the dimensions of the user defined texture attachments.
void SetNumberOfRenderTargets(unsigned int)
Set/Get the number of render targets to render into at once.
void DisplayBuffer(int value)
Display any buffer (convert value into string).
void RemoveColorBuffer(unsigned int index)
vtkOpenGLRenderWindow * GetContext()
void UnBind()
Restore the previous draw framebuffer if saved, else bind the default buffer.
unsigned int GetMaximumNumberOfActiveTargets()
Returns the maximum number of targets that can be rendered to at one time.
static bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin)
Load all necessary extensions.
vtkWeakPointer< vtkOpenGLRenderWindow > Context
void DisplayReadBuffer()
Display the read buffer.
void CreateColorBuffers(int width, int height, unsigned int mode, bool shaderSupportsTextureInt)
void SetActiveBuffer(unsigned int index)
Choose the buffers to render into.
void SetActiveBuffers(int numbuffers, unsigned int indices[])
User provided color buffers are attached by index to color buffers.
vtkTextureObject * GetColorBuffer(unsigned int index)
void DisplayFrameBufferAttachment(unsigned int uattachment)
Display a given attachment for the current framebuffer object.
int CheckFrameBufferStatus(unsigned int mode)
Validate the current FBO configuration (attachments, formats, etc) prints detected errors to vtkError...
static vtkFrameBufferObject * New()
void SetDepthBuffer(vtkTextureObject *depthTexture)
Set the texture to use as depth buffer.
void SetContext(vtkOpenGLRenderWindow *context)
Get/Set the context.
void Bind()
Make the draw frame buffer active (uses FRAMEBUFFER).
void CreateDepthBuffer(int width, int height, unsigned int mode)
void RenderQuad(int minX, int maxX, int minY, int maxY, vtkShaderProgram *program, vtkOpenGLVertexArrayObject *vao)
Renders a quad at the given location with pixel coordinates.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
void DisplayDrawBuffers()
Display the draw buffers.
static bool IsSupported(vtkOpenGLRenderWindow *renWin)
Returns if the context supports the required extensions.
a simple class to control print indentation
Definition: vtkIndent.h:40
OpenGL rendering window.
The VertexArrayObject class uses, or emulates, vertex array objects.
abstracts an OpenGL pixel buffer object.
create a window for renderers to draw into
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ mode
Definition: vtkX3D.h:247
@ value
Definition: vtkX3D.h:220
@ height
Definition: vtkX3D.h:254
@ index
Definition: vtkX3D.h:246
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.