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 =========================================================================*/
28 #ifndef vtkFrameBufferObject_h
29 #define vtkFrameBufferObject_h
30 
31 #include "vtkObject.h"
32 #include "vtkRenderingOpenGL2Module.h" // For export macro
33 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
34 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
35 #include <vector> // for the lists of logical buffers.
36 
37 
38 class vtkRenderWindow;
39 class vtkTextureObject;
42 class vtkShaderProgram;
43 namespace vtkgl
44 {
45 class VertexArrayObject;
46 }
47 
48 
49 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject : public vtkObject
50 {
51 public:
52  static vtkFrameBufferObject* New();
54  void PrintSelf(ostream& os, vtkIndent indent);
55 
57 
61  void SetContext(vtkOpenGLRenderWindow *context);
62  vtkOpenGLRenderWindow *GetContext();
64 
66 
72  bool Start(int width, int height, bool shaderSupportsTextureInt);
73  bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt);
75 
77 
82  void RenderQuad(int minX, int maxX, int minY, int maxY,
85 
87  void Bind();
88 
91  void UnBind();
92 
94 
95  void SetActiveBuffer(unsigned int index)
96  {
97  this->SetActiveBuffers(1, &index);
98  }
100 
105  void SetActiveBuffers(int numbuffers, unsigned int indices[]);
106 
108 
116  void SetColorBuffer(
117  unsigned int index,
119  unsigned int zslice=0);
121 
122  vtkTextureObject *GetColorBuffer(unsigned int index);
123  void RemoveColorBuffer(unsigned int index);
124  void RemoveAllColorBuffers();
125 
127 
128  void SetDepthBuffer(vtkTextureObject *depthTexture);
129  void RemoveDepthBuffer();
131 
133 
135  vtkSetMacro(DepthBufferNeeded,bool);
136  vtkGetMacro(DepthBufferNeeded,bool);
138 
140 
145  void SetNumberOfRenderTargets(unsigned int);
146  vtkGetMacro(NumberOfRenderTargets,unsigned int);
148 
152  unsigned int GetMaximumNumberOfActiveTargets();
153 
157  unsigned int GetMaximumNumberOfRenderTargets();
158 
160 
161  vtkGetVector2Macro(LastSize,int);
163 
166  static bool IsSupported(vtkOpenGLRenderWindow *renWin);
167 
170  int CheckFrameBufferStatus(unsigned int mode);
171 
172 protected:
174 
175  static
176  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
178 
179  // gen buffer (occurs when context is set)
180  void CreateFBO();
181 
182  // delete buffer (occurs during destruction or context swicth)
183  void DestroyFBO();
184 
185  // create texture or renderbuffer and attach
186  // if user provided a texture just use that
187  // mode specifies DRAW or READ
188  void CreateDepthBuffer(int width, int height, unsigned int mode);
189 
190  // create textures for each target and attach
191  // if user provided textures use those, if the user
192  // provides any then they need to provide all
193  // mode specifies DRAW or READ
194  void CreateColorBuffers(
195  int width,
196  int height,
197  unsigned int mode,
198  bool shaderSupportsTextureInt);
199 
200  // detach and delete our reference(s)
201  void DestroyDepthBuffer();
202  void DestroyColorBuffers();
203 
204  // glDrawBuffers
205  void ActivateBuffers();
206 
208  void DisplayFrameBufferAttachments();
209 
211  void DisplayFrameBufferAttachment(unsigned int uattachment);
212 
214  void DisplayDrawBuffers();
215 
217  void DisplayReadBuffer();
218 
220  void DisplayBuffer(int value);
221 
224 
226 
227  bool DepthBufferNeeded;
228  bool ColorBuffersDirty;
229  unsigned int FBOIndex;
230  int PreviousFBOIndex;
231  unsigned int DepthBuffer;
232  unsigned int NumberOfRenderTargets;
233  int LastSize[2];
234  std::vector<unsigned int> UserZSlices;
235  std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
236  std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
237  std::vector<unsigned int> ActiveBuffers;
238  vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
239  bool DepthBufferDirty;
240 
241 private:
242  vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented.
243  void operator=(const vtkFrameBufferObject&); // Not implemented.
244 };
245 
246 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:61
GLuint index
Definition: vtkgl.h:11983
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
void SetActiveBuffer(unsigned int index)
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
GLint GLint GLsizei GLsizei height
Definition: vtkgl.h:11316
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
GLint GLint GLsizei width
Definition: vtkgl.h:11316
Definition: vtkgl.h:11267
abstracts an OpenGL pixel buffer object.
The VertexArrayObject class uses, or emulates, vertex array objects.
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: vtkgl.h:11315
internal class which encapsulates OpenGL frame buffer object. Not to be used directly.
abstracts an OpenGL texture object.
#define vtkGetVector2Macro(name, type)
Definition: vtkSetGet.h:260
create a window for renderers to draw into
vtkWeakPointer< vtkOpenGLRenderWindow > Context
GLuint program
Definition: vtkgl.h:13011
static vtkObject * New()
GLenum GLuint texture
Definition: vtkgl.h:12500
GLenum mode
Definition: vtkgl.h:12325
The ShaderProgram uses one or more Shader objects.
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69