VTK
dox/Rendering/OpenGL/vtkFrameBufferObject2.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkFrameBufferObject2.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 =========================================================================*/
00044 #ifndef __vtkFrameBufferObject2_h
00045 #define __vtkFrameBufferObject2_h
00046 
00047 #include "vtkObject.h"
00048 #include "vtkRenderingOpenGLModule.h" // For export macro
00049 #include "vtkSmartPointer.h" // needed for vtkSmartPointer.
00050 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00051 
00053 
00057 #ifdef NDEBUG
00058 # define vtkCheckFrameBufferStatusMacro(mode)
00059 # define vtkStaticCheckFrameBufferStatusMacro(mode)
00060 #else
00061 # define vtkCheckFrameBufferStatusMacroImpl(macro, mode)           \
00062 {                                                                  \
00063 const char *eStr;                                                  \
00064 bool ok = vtkFrameBufferObject2::GetFrameBufferStatus(mode, eStr); \
00065 if (!ok)                                                           \
00066   {                                                                \
00067   macro(                                                           \
00068     << "OpenGL ERROR. The FBO is incomplete : " << eStr);          \
00069   }                                                                \
00070  }
00071 # define vtkCheckFrameBufferStatusMacro(mode) \
00072     vtkCheckFrameBufferStatusMacroImpl(vtkErrorMacro, mode)
00073 # define vtkStaticCheckFrameBufferStatusMacro(mode) \
00074     vtkCheckFrameBufferStatusMacroImpl(vtkGenericWarningMacro, mode)
00075 #endif
00076 
00077 
00078 class vtkRenderWindow;
00079 class vtkTextureObject;
00080 class vtkRenderbuffer;
00081 class vtkPixelBufferObject;
00082 class vtkOpenGLExtensionManager;
00083 class vtkOpenGLRenderWindow;
00084 
00085 class VTKRENDERINGOPENGL_EXPORT vtkFrameBufferObject2 : public vtkObject
00086 {
00087 public:
00088   static vtkFrameBufferObject2* New();
00089   vtkTypeMacro(vtkFrameBufferObject2, vtkObject);
00090   void PrintSelf(ostream& os, vtkIndent indent);
00091 
00093 
00097   void SetContext(vtkRenderWindow *context);
00098   vtkRenderWindow *GetContext();
00100 
00103   static bool IsSupported(vtkRenderWindow *renWin);
00104 
00109   void Bind(unsigned int mode);
00110 
00114   void UnBind(unsigned int mode);
00115 
00120   void SaveCurrentBindings();
00121 
00123 
00126   void SaveCurrentBuffers();
00127   void RestorePreviousBuffers(unsigned int mode);
00129 
00131 
00132   void AddColorAttachment(
00133         unsigned int mode,
00134         unsigned int attId,
00135         vtkTextureObject* tex);
00137 
00138   void AddTexColorAttachment(
00139         unsigned int mode,
00140         unsigned int attId,
00141         unsigned int handle);
00142 
00143   void RemoveTexColorAttachments(unsigned int mode, unsigned int num);
00144   void RemoveTexColorAttachment(unsigned int mode, unsigned int attId)
00145     { this->AddTexColorAttachment(mode, attId, 0U); }
00146 
00148 
00149   void AddColorAttachment(
00150         unsigned int mode,
00151         unsigned int attId,
00152         vtkRenderbuffer* tex);
00154 
00155   void AddRenColorAttachment(
00156         unsigned int mode,
00157         unsigned int attId,
00158         unsigned int handle);
00159 
00160   void RemoveRenColorAttachments(unsigned int mode, unsigned int num);
00161   void RemoveRenColorAttachment(unsigned int mode, unsigned int attId)
00162     { this->AddRenColorAttachment(mode, attId, 0U); }
00163 
00165 
00166   void AddDepthAttachment(unsigned int mode, vtkTextureObject* tex);
00167   void AddTexDepthAttachment(unsigned int mode, unsigned int handle);
00168   void RemoveTexDepthAttachment(unsigned int mode)
00169     { this->AddTexDepthAttachment(mode, 0U); }
00171 
00173 
00174   void AddDepthAttachment(unsigned int mode, vtkRenderbuffer* tex);
00175   void AddRenDepthAttachment(unsigned int mode, unsigned int handle);
00176   void RemoveRenDepthAttachment(unsigned int mode)
00177     { this->AddRenDepthAttachment(mode, 0U); }
00179 
00181 
00182   void ActivateDrawBuffer(unsigned int id);
00183   void ActivateReadBuffer(unsigned int id);
00184   void DeactivateReadBuffer();
00186 
00188 
00189   void ActivateDrawBuffers(unsigned int n);
00190   void ActivateDrawBuffers(unsigned int *ids, int n);
00191   void DeactivateDrawBuffers();
00193 
00195 
00199   static
00200   void InitializeViewport(int width, int height);
00202 
00205   int CheckFrameBufferStatus(unsigned int mode);
00206 
00208 
00211   static
00212   bool GetFrameBufferStatus(
00213         unsigned int mode,
00214         const char *&desc);
00216 
00218 
00221   static
00222   int Blit(
00223         int srcExt[4],
00224         int destExt[4],
00225         unsigned int bits,
00226         unsigned int mapping);
00228 
00230 
00236   vtkPixelBufferObject *DownloadColor1(
00237         int extent[4],
00238         int vtkType,
00239         int channel);
00241 
00242   vtkPixelBufferObject *DownloadColor3(
00243         int extent[4],
00244         int vtkType);
00245 
00246   vtkPixelBufferObject *DownloadColor4(
00247         int extent[4],
00248         int vtkType);
00249 
00251 
00254   vtkPixelBufferObject *DownloadDepth(
00255         int extent[4],
00256         int vtkType);
00258 
00260 
00264   vtkPixelBufferObject *Download(
00265         int extent[4],
00266         int vtkType,
00267         int nComps,
00268         int oglType,
00269         int oglFormat);
00271 
00272   static
00273   void Download(
00274         int extent[4],
00275         int vtkType,
00276         int nComps,
00277         int oglType,
00278         int oglFormat,
00279         vtkPixelBufferObject *pbo);
00280 
00281 //BTX
00282 protected:
00284 
00285   static
00286   bool LoadRequiredExtensions(vtkRenderWindow *renWin);
00288 
00289   // gen buffer (occurs when context is set)
00290   void CreateFBO();
00291 
00292   // delete buffer (occurs during destruction or context swicth)
00293   void DestroyFBO();
00294 
00295 
00297   int GetOpenGLType(int vtkType);
00298 
00299   vtkFrameBufferObject2();
00300   ~vtkFrameBufferObject2();
00301 
00302   vtkWeakPointer<vtkRenderWindow> Context;
00303 
00304   unsigned int FBOIndex;
00305   unsigned int PreviousDrawFBO;
00306   unsigned int PreviousReadFBO;
00307   unsigned int DepthBuffer;
00308   unsigned int PreviousDrawBuffer;
00309   unsigned int PreviousReadBuffer;
00310 
00311 private:
00312   vtkFrameBufferObject2(const vtkFrameBufferObject2&); // Not implemented.
00313   void operator=(const vtkFrameBufferObject2&); // Not implemented.
00314 
00315   friend class vtkRenderbuffer; // needs access to LoadRequiredExtentsions
00316 //ETX
00317 };
00318 
00319 #endif