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;
44 
45 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject : public vtkObject
46 {
47 public:
48  static vtkFrameBufferObject* New();
50  void PrintSelf(ostream& os, vtkIndent indent);
51 
53 
57  void SetContext(vtkOpenGLRenderWindow *context);
58  vtkOpenGLRenderWindow *GetContext();
60 
62 
68  bool Start(int width, int height, bool shaderSupportsTextureInt);
69  bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt);
71 
73 
78  void RenderQuad(int minX, int maxX, int minY, int maxY,
81 
83  void Bind();
84 
87  void UnBind();
88 
90 
91  void SetActiveBuffer(unsigned int index)
92  {
93  this->SetActiveBuffers(1, &index);
94  }
96 
101  void SetActiveBuffers(int numbuffers, unsigned int indices[]);
102 
104 
112  void SetColorBuffer(
113  unsigned int index,
114  vtkTextureObject *texture,
115  unsigned int zslice=0);
117 
118  vtkTextureObject *GetColorBuffer(unsigned int index);
119  void RemoveColorBuffer(unsigned int index);
120  void RemoveAllColorBuffers();
121 
123 
124  void SetDepthBuffer(vtkTextureObject *depthTexture);
125  void RemoveDepthBuffer();
127 
129 
131  vtkSetMacro(DepthBufferNeeded,bool);
132  vtkGetMacro(DepthBufferNeeded,bool);
134 
136 
141  void SetNumberOfRenderTargets(unsigned int);
142  vtkGetMacro(NumberOfRenderTargets,unsigned int);
144 
148  unsigned int GetMaximumNumberOfActiveTargets();
149 
153  unsigned int GetMaximumNumberOfRenderTargets();
154 
156 
157  vtkGetVector2Macro(LastSize,int);
159 
162  static bool IsSupported(vtkOpenGLRenderWindow *renWin);
163 
166  int CheckFrameBufferStatus(unsigned int mode);
167 
168 protected:
170 
171  static
172  bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin);
174 
175  // gen buffer (occurs when context is set)
176  void CreateFBO();
177 
178  // delete buffer (occurs during destruction or context swicth)
179  void DestroyFBO();
180 
181  // create texture or renderbuffer and attach
182  // if user provided a texture just use that
183  // mode specifies DRAW or READ
184  void CreateDepthBuffer(int width, int height, unsigned int mode);
185 
186  // create textures for each target and attach
187  // if user provided textures use those, if the user
188  // provides any then they need to provide all
189  // mode specifies DRAW or READ
190  void CreateColorBuffers(
191  int width,
192  int height,
193  unsigned int mode,
194  bool shaderSupportsTextureInt);
195 
196  // detach and delete our reference(s)
197  void DestroyDepthBuffer();
198  void DestroyColorBuffers();
199 
200  // glDrawBuffers
201  void ActivateBuffers();
202 
204  void DisplayFrameBufferAttachments();
205 
207  void DisplayFrameBufferAttachment(unsigned int uattachment);
208 
210  void DisplayDrawBuffers();
211 
213  void DisplayReadBuffer();
214 
216  void DisplayBuffer(int value);
217 
220 
222 
223  bool DepthBufferNeeded;
224  bool ColorBuffersDirty;
225  unsigned int FBOIndex;
226  int PreviousFBOIndex;
227  unsigned int DepthBuffer;
228  unsigned int NumberOfRenderTargets;
229  int LastSize[2];
230  std::vector<unsigned int> UserZSlices;
231  std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
232  std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
233  std::vector<unsigned int> ActiveBuffers;
234  vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
235  bool DepthBufferDirty;
236 
237 private:
238  vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented.
239  void operator=(const vtkFrameBufferObject&); // Not implemented.
240 };
241 
242 #endif
OpenGL rendering window.
abstract base class for most VTK objects
Definition: vtkObject.h:61
void SetActiveBuffer(unsigned int index)
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
The VertexArrayObject class uses, or emulates, vertex array objects.
abstracts an OpenGL pixel buffer object.
internal class which encapsulates OpenGL frame buffer object. Not to be used directly.
abstracts an OpenGL texture object.
create a window for renderers to draw into
vtkWeakPointer< vtkOpenGLRenderWindow > Context
static vtkObject * New()
The ShaderProgram uses one or more Shader objects.