VTK
dox/Rendering/vtkFrameBufferObject.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkFrameBufferObject.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00025 #ifndef __vtkFrameBufferObject_h
00026 #define __vtkFrameBufferObject_h
00027 
00028 #include "vtkObject.h"
00029 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
00030 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00031 //BTX
00032 #include <vector> // for the lists of logical buffers.
00033 //ETX
00034 
00035 class vtkRenderWindow;
00036 class vtkTextureObject;
00037 class vtkOpenGLExtensionManager;
00038 
00039 class VTK_RENDERING_EXPORT vtkFrameBufferObject : public vtkObject
00040 {
00041 public:
00042   static vtkFrameBufferObject* New();
00043   vtkTypeMacro(vtkFrameBufferObject, vtkObject);
00044   void PrintSelf(ostream& os, vtkIndent indent);
00045 
00047 
00051   void SetContext(vtkRenderWindow *context);
00052   vtkRenderWindow *GetContext();
00054 
00056 
00062   bool Start(int width,
00063              int height,
00064              bool shaderSupportsTextureInt);
00065   bool StartNonOrtho(int width,
00066                      int height,
00067                      bool shaderSupportsTextureInt);
00069 
00071 
00076   void RenderQuad(int minX,
00077                   int maxX,
00078                   int minY,
00079                   int maxY);
00081 
00084   void Bind();
00085 
00088   void UnBind();
00089 
00091 
00092   void SetActiveBuffer(unsigned int index)
00093     {
00094       this->SetActiveBuffers(1, &index);
00095     }
00097   
00099 
00101   void SetActiveBuffers(int numbuffers,
00102                         unsigned int indices[]);
00104 
00105   // All user specified texture objects must match the FBO dimensions
00106   // and must have been created by the time Start() gets called.
00107   // If texture is a 3D texture, zslice identifies the zslice that will be
00108   // attached to the color buffer.
00109   // .SECTION Caveat
00110   // Currently, 1D textures are not supported.
00111   void SetColorBuffer(unsigned int index,
00112                       vtkTextureObject *texture,
00113                       unsigned int zslice=0);
00114 
00115   vtkTextureObject *GetColorBuffer(unsigned int index);
00116   void RemoveColorBuffer(unsigned int index);
00117   void RemoveAllColorBuffers();
00118 
00120 
00121   void SetDepthBuffer(vtkTextureObject *depthTexture);
00122   void RemoveDepthBuffer();
00124 
00126 
00128   vtkSetMacro(DepthBufferNeeded,bool);
00129   vtkGetMacro(DepthBufferNeeded,bool);
00131 
00133 
00134   void SetNumberOfRenderTargets(unsigned int);
00135   vtkGetMacro(NumberOfRenderTargets,unsigned int);
00137 
00141   unsigned int GetMaximumNumberOfActiveTargets();
00142 
00146   unsigned int GetMaximumNumberOfRenderTargets();
00147   
00149 
00150   vtkGetVector2Macro(LastSize,int);
00152 
00154   static bool IsSupported(vtkRenderWindow *renWin);
00155 
00156 //BTX
00157 protected:
00159   void CheckFrameBufferStatus();
00160   
00162   void DisplayFrameBufferAttachments();
00163   
00165   void DisplayFrameBufferAttachment(unsigned int uattachment);
00166   
00168   void DisplayDrawBuffers();
00169   
00171   void DisplayReadBuffer();
00172   
00174   void DisplayBuffer(int value);
00175   
00176   vtkFrameBufferObject();
00177   ~vtkFrameBufferObject();
00178 
00179   vtkWeakPointer<vtkRenderWindow> Context;
00180 
00181   bool DepthBufferNeeded;
00182   bool ColorBuffersDirty;
00183   unsigned int FBOIndex;
00184   int PreviousFBOIndex; // -1: no previous FBO
00185   unsigned int DepthBuffer;
00186 
00187   unsigned int NumberOfRenderTargets;
00188   // TODO: add support for stencil buffer.
00189  
00190   int LastSize[2];
00191  
00192   void CreateFBO();
00193   void DestroyFBO();
00194   void Create(int width,
00195               int height);
00196   void CreateBuffers(int width,
00197                      int height);
00198   void CreateColorBuffers(int width,
00199                           int height,
00200                           bool shaderSupportsTextureInt);
00201   void Destroy();
00202   void DestroyBuffers();
00203   void DestroyColorBuffers();
00204   void ActivateBuffers();
00205 
00207   bool LoadRequiredExtensions(vtkOpenGLExtensionManager *manager);
00208 
00209   std::vector<unsigned int> UserZSlices;
00210   std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
00211   std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
00212   std::vector<unsigned int> ActiveBuffers;
00213   vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
00214   bool DepthBufferDirty;
00215 private:
00216   vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented.
00217   void operator=(const vtkFrameBufferObject&); // Not implemented.
00218 //ETX
00219 };
00220 
00221 #endif