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
vtkFrameBufferObject
internal class which encapsulates OpenGL frame buffer object. Not to be used directly.
Definition: vtkFrameBufferObject.h:46
vtkFrameBufferObject::ResourceCallback
vtkGenericOpenGLResourceFreeCallback * ResourceCallback
Definition: vtkFrameBufferObject.h:216
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkFrameBufferObject::SetActiveBuffer
void SetActiveBuffer(unsigned int index)
Choose the buffers to render into.
Definition: vtkFrameBufferObject.h:108
vtkSmartPointer< vtkTextureObject >
vtkFrameBufferObjectBase::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
vtkFrameBufferObjectBase
abstract interface to OpenGL FBOs
Definition: vtkFrameBufferObjectBase.h:32
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkX3D::height
@ height
Definition: vtkX3D.h:254
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:44
vtkGenericOpenGLResourceFreeCallback
Definition: vtkOpenGLResourceFreeCallback.h:25
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkSmartPointer.h
vtkWeakPointer.h
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkFrameBufferObject::Context
vtkWeakPointer< vtkOpenGLRenderWindow > Context
Definition: vtkFrameBufferObject.h:274
vtkFrameBufferObjectBase.h
vtkX3D::mode
@ mode
Definition: vtkX3D.h:247
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:38
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:86
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:35
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:43
vtkWeakPointer< vtkOpenGLRenderWindow >