VTK
dox/Rendering/OpenGL/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 "vtkRenderingOpenGLModule.h" // For export macro
00029 #include "vtkObject.h"
00030 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
00031 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00032 //BTX
00033 #include <vector> // for the lists of logical buffers.
00034 //ETX
00035 
00036 class vtkRenderWindow;
00037 class vtkTextureObject;
00038 class vtkOpenGLExtensionManager;
00039 
00040 class VTKRENDERINGOPENGL_EXPORT vtkFrameBufferObject : public vtkObject
00041 {
00042 public:
00043   static vtkFrameBufferObject* New();
00044   vtkTypeMacro(vtkFrameBufferObject, vtkObject);
00045   void PrintSelf(ostream& os, vtkIndent indent);
00046 
00048 
00052   void SetContext(vtkRenderWindow *context);
00053   vtkRenderWindow *GetContext();
00055 
00057 
00063   bool Start(int width,
00064              int height,
00065              bool shaderSupportsTextureInt);
00066   bool StartNonOrtho(int width,
00067                      int height,
00068                      bool shaderSupportsTextureInt);
00070 
00072 
00077   void RenderQuad(int minX,
00078                   int maxX,
00079                   int minY,
00080                   int maxY);
00082 
00085   void Bind();
00086 
00089   void UnBind();
00090 
00092 
00093   void SetActiveBuffer(unsigned int index)
00094     {
00095       this->SetActiveBuffers(1, &index);
00096     }
00098 
00100 
00102   void SetActiveBuffers(int numbuffers,
00103                         unsigned int indices[]);
00105 
00106   // All user specified texture objects must match the FBO dimensions
00107   // and must have been created by the time Start() gets called.
00108   // If texture is a 3D texture, zslice identifies the zslice that will be
00109   // attached to the color buffer.
00110   // .SECTION Caveat
00111   // Currently, 1D textures are not supported.
00112   void SetColorBuffer(unsigned int index,
00113                       vtkTextureObject *texture,
00114                       unsigned int zslice=0);
00115 
00116   vtkTextureObject *GetColorBuffer(unsigned int index);
00117   void RemoveColorBuffer(unsigned int index);
00118   void RemoveAllColorBuffers();
00119 
00121 
00122   void SetDepthBuffer(vtkTextureObject *depthTexture);
00123   void RemoveDepthBuffer();
00125 
00127 
00129   vtkSetMacro(DepthBufferNeeded,bool);
00130   vtkGetMacro(DepthBufferNeeded,bool);
00132 
00134 
00135   void SetNumberOfRenderTargets(unsigned int);
00136   vtkGetMacro(NumberOfRenderTargets,unsigned int);
00138 
00142   unsigned int GetMaximumNumberOfActiveTargets();
00143 
00147   unsigned int GetMaximumNumberOfRenderTargets();
00148 
00150 
00151   vtkGetVector2Macro(LastSize,int);
00153 
00155   static bool IsSupported(vtkRenderWindow *renWin);
00156 
00157 //BTX
00158 protected:
00160   void CheckFrameBufferStatus();
00161 
00163   void DisplayFrameBufferAttachments();
00164 
00166   void DisplayFrameBufferAttachment(unsigned int uattachment);
00167 
00169   void DisplayDrawBuffers();
00170 
00172   void DisplayReadBuffer();
00173 
00175   void DisplayBuffer(int value);
00176 
00177   vtkFrameBufferObject();
00178   ~vtkFrameBufferObject();
00179 
00180   vtkWeakPointer<vtkRenderWindow> Context;
00181 
00182   bool DepthBufferNeeded;
00183   bool ColorBuffersDirty;
00184   unsigned int FBOIndex;
00185   int PreviousFBOIndex; // -1: no previous FBO
00186   unsigned int DepthBuffer;
00187 
00188   unsigned int NumberOfRenderTargets;
00189   // TODO: add support for stencil buffer.
00190 
00191   int LastSize[2];
00192 
00193   void CreateFBO();
00194   void DestroyFBO();
00195   void Create(int width,
00196               int height);
00197   void CreateBuffers(int width,
00198                      int height);
00199   void CreateColorBuffers(int width,
00200                           int height,
00201                           bool shaderSupportsTextureInt);
00202   void Destroy();
00203   void DestroyBuffers();
00204   void DestroyColorBuffers();
00205   void ActivateBuffers();
00206 
00208   bool LoadRequiredExtensions(vtkOpenGLExtensionManager *manager);
00209 
00210   std::vector<unsigned int> UserZSlices;
00211   std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers;
00212   std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers;
00213   std::vector<unsigned int> ActiveBuffers;
00214   vtkSmartPointer<vtkTextureObject> UserDepthBuffer;
00215   bool DepthBufferDirty;
00216 private:
00217   vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented.
00218   void operator=(const vtkFrameBufferObject&); // Not implemented.
00219 //ETX
00220 };
00221 
00222 #endif