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:
51  static vtkFrameBufferObject* New();
53  void PrintSelf(ostream& os, vtkIndent indent);
54 
56 
63  void SetContext(vtkOpenGLRenderWindow *context);
64  vtkOpenGLRenderWindow *GetContext();
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 
133  void SetColorBuffer(
134  unsigned int index,
135  vtkTextureObject *texture,
136  unsigned int zslice=0);
137 
138  vtkTextureObject *GetColorBuffer(unsigned int index);
139  void RemoveColorBuffer(unsigned int index);
140  void RemoveAllColorBuffers();
141 
143 
146  void SetDepthBuffer(vtkTextureObject *depthTexture);
147  void RemoveDepthBuffer();
149 
151 
155  vtkSetMacro(DepthBufferNeeded,bool);
156  vtkGetMacro(DepthBufferNeeded,bool);
158 
160 
167  void SetNumberOfRenderTargets(unsigned int);
168  vtkGetMacro(NumberOfRenderTargets,unsigned int);
170 
176  unsigned int GetMaximumNumberOfActiveTargets();
177 
183  unsigned int GetMaximumNumberOfRenderTargets();
184 
186 
189  vtkGetVector2Macro(LastSize,int);
191 
196  static bool IsSupported(vtkOpenGLRenderWindow *renWin);
197 
202  int CheckFrameBufferStatus(unsigned int mode);
203 
207  virtual void ReleaseGraphicsResources(vtkWindow *win);
208 
209 protected:
213  static
214  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
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
233  void CreateColorBuffers(
234  int width,
235  int height,
236  unsigned int mode,
237  bool shaderSupportsTextureInt);
238 
239  // detach and delete our reference(s)
240  void DestroyDepthBuffer();
241  void DestroyColorBuffers();
242 
243  // glDrawBuffers
244  void ActivateBuffers();
245 
249  void DisplayFrameBufferAttachments();
250 
254  void DisplayFrameBufferAttachment(unsigned int uattachment);
255 
259  void DisplayDrawBuffers();
260 
264  void DisplayReadBuffer();
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
OpenGL rendering window.
void SetActiveBuffer(unsigned int index)
Choose the buffers to render into.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
abstract interface to OpenGL FBOs
a simple class to control print indentation
Definition: vtkIndent.h:39
The VertexArrayObject class uses, or emulates, vertex array objects.
abstracts an OpenGL pixel buffer object.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
internal class which encapsulates OpenGL frame buffer object.
abstracts an OpenGL texture object.
create a window for renderers to draw into
vtkWeakPointer< vtkOpenGLRenderWindow > Context
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
The ShaderProgram uses one or more Shader objects.