VTK
|
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 =========================================================================*/ 00028 #ifndef vtkFrameBufferObject_h 00029 #define vtkFrameBufferObject_h 00030 00031 #include "vtkObject.h" 00032 #include "vtkRenderingOpenGL2Module.h" // For export macro 00033 #include "vtkSmartPointer.h" // needed for vtkSmartPointer. 00034 #include "vtkWeakPointer.h" // needed for vtkWeakPointer. 00035 #include <vector> // for the lists of logical buffers. 00036 00037 00038 class vtkRenderWindow; 00039 class vtkTextureObject; 00040 class vtkPixelBufferObject; 00041 class vtkOpenGLRenderWindow; 00042 class vtkShaderProgram; 00043 namespace vtkgl 00044 { 00045 class VertexArrayObject; 00046 } 00047 00048 00049 class VTKRENDERINGOPENGL2_EXPORT vtkFrameBufferObject : public vtkObject 00050 { 00051 public: 00052 static vtkFrameBufferObject* New(); 00053 vtkTypeMacro(vtkFrameBufferObject, vtkObject); 00054 void PrintSelf(ostream& os, vtkIndent indent); 00055 00057 00061 void SetContext(vtkOpenGLRenderWindow *context); 00062 vtkOpenGLRenderWindow *GetContext(); 00064 00066 00072 bool Start(int width, int height, bool shaderSupportsTextureInt); 00073 bool StartNonOrtho(int width, int height, bool shaderSupportsTextureInt); 00075 00077 00082 void RenderQuad(int minX, int maxX, int minY, int maxY, 00083 vtkShaderProgram *program, vtkgl::VertexArrayObject *vao); 00085 00087 void Bind(); 00088 00091 void UnBind(); 00092 00094 00095 void SetActiveBuffer(unsigned int index) 00096 { 00097 this->SetActiveBuffers(1, &index); 00098 } 00100 00105 void SetActiveBuffers(int numbuffers, unsigned int indices[]); 00106 00108 00116 void SetColorBuffer( 00117 unsigned int index, 00118 vtkTextureObject *texture, 00119 unsigned int zslice=0); 00121 00122 vtkTextureObject *GetColorBuffer(unsigned int index); 00123 void RemoveColorBuffer(unsigned int index); 00124 void RemoveAllColorBuffers(); 00125 00127 00128 void SetDepthBuffer(vtkTextureObject *depthTexture); 00129 void RemoveDepthBuffer(); 00131 00133 00135 vtkSetMacro(DepthBufferNeeded,bool); 00136 vtkGetMacro(DepthBufferNeeded,bool); 00138 00140 00145 void SetNumberOfRenderTargets(unsigned int); 00146 vtkGetMacro(NumberOfRenderTargets,unsigned int); 00148 00152 unsigned int GetMaximumNumberOfActiveTargets(); 00153 00157 unsigned int GetMaximumNumberOfRenderTargets(); 00158 00160 00161 vtkGetVector2Macro(LastSize,int); 00163 00166 static bool IsSupported(vtkOpenGLRenderWindow *renWin); 00167 00170 int CheckFrameBufferStatus(unsigned int mode); 00171 00172 protected: 00174 00175 static 00176 bool LoadRequiredExtensions(vtkOpenGLRenderWindow *renWin); 00178 00179 // gen buffer (occurs when context is set) 00180 void CreateFBO(); 00181 00182 // delete buffer (occurs during destruction or context swicth) 00183 void DestroyFBO(); 00184 00185 // create texture or renderbuffer and attach 00186 // if user provided a texture just use that 00187 // mode specifies DRAW or READ 00188 void CreateDepthBuffer(int width, int height, unsigned int mode); 00189 00190 // create textures for each target and attach 00191 // if user provided textures use those, if the user 00192 // provides any then they need to provide all 00193 // mode specifies DRAW or READ 00194 void CreateColorBuffers( 00195 int width, 00196 int height, 00197 unsigned int mode, 00198 bool shaderSupportsTextureInt); 00199 00200 // detach and delete our reference(s) 00201 void DestroyDepthBuffer(); 00202 void DestroyColorBuffers(); 00203 00204 // glDrawBuffers 00205 void ActivateBuffers(); 00206 00208 void DisplayFrameBufferAttachments(); 00209 00211 void DisplayFrameBufferAttachment(unsigned int uattachment); 00212 00214 void DisplayDrawBuffers(); 00215 00217 void DisplayReadBuffer(); 00218 00220 void DisplayBuffer(int value); 00221 00222 vtkFrameBufferObject(); 00223 ~vtkFrameBufferObject(); 00224 00225 vtkWeakPointer<vtkOpenGLRenderWindow> Context; 00226 00227 bool DepthBufferNeeded; 00228 bool ColorBuffersDirty; 00229 unsigned int FBOIndex; 00230 int PreviousFBOIndex; 00231 unsigned int DepthBuffer; 00232 unsigned int NumberOfRenderTargets; 00233 int LastSize[2]; 00234 std::vector<unsigned int> UserZSlices; 00235 std::vector<vtkSmartPointer<vtkTextureObject> > UserColorBuffers; 00236 std::vector<vtkSmartPointer<vtkTextureObject> > ColorBuffers; 00237 std::vector<unsigned int> ActiveBuffers; 00238 vtkSmartPointer<vtkTextureObject> UserDepthBuffer; 00239 bool DepthBufferDirty; 00240 00241 private: 00242 vtkFrameBufferObject(const vtkFrameBufferObject&); // Not implemented. 00243 void operator=(const vtkFrameBufferObject&); // Not implemented. 00244 }; 00245 00246 #endif