VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPixelBufferObject.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 =========================================================================*/ 00032 #ifndef vtkPixelBufferObject_h 00033 #define vtkPixelBufferObject_h 00034 00035 #include "vtkObject.h" 00036 #include "vtkRenderingOpenGL2Module.h" // For export macro 00037 #include "vtkWeakPointer.h" // needed for vtkWeakPointer. 00038 00039 class vtkRenderWindow; 00040 class vtkOpenGLExtensionManager; 00041 00042 class VTKRENDERINGOPENGL2_EXPORT vtkPixelBufferObject : public vtkObject 00043 { 00044 public: 00045 00046 // Usage values. 00047 enum 00048 { 00049 StreamDraw=0, 00050 StreamRead, 00051 StreamCopy, 00052 StaticDraw, 00053 StaticRead, 00054 StaticCopy, 00055 DynamicDraw, 00056 DynamicRead, 00057 DynamicCopy, 00058 NumberOfUsages 00059 }; 00060 00061 static vtkPixelBufferObject* New(); 00062 vtkTypeMacro(vtkPixelBufferObject, vtkObject); 00063 void PrintSelf(ostream& os, vtkIndent indent); 00064 00066 00070 void SetContext(vtkRenderWindow* context); 00071 vtkRenderWindow* GetContext(); 00073 00075 00086 vtkGetMacro(Usage,int); 00087 vtkSetMacro(Usage,int); 00089 00091 00098 bool Upload1D(int type, void* data, 00099 unsigned int numtuples, int comps, vtkIdType increment) 00100 { 00101 unsigned int newdims[3]; 00102 newdims[0] = numtuples; 00103 newdims[1] = 1; 00104 newdims[2] = 1; 00105 vtkIdType newinc[3]; 00106 newinc[0] = increment; 00107 newinc[1] = 0; 00108 newinc[2] = 0; 00109 return this->Upload3D(type, data, newdims, comps, newinc,0,0); 00110 } 00112 00114 00119 bool Upload2D(int type, void* data, 00120 unsigned int dims[2], 00121 int comps, 00122 vtkIdType increments[2]) 00123 { 00124 unsigned int newdims[3]; 00125 newdims[0] = dims[0]; 00126 newdims[1] = dims[1]; 00127 newdims[2] = 1; 00128 vtkIdType newinc[3]; 00129 newinc[0] = increments[0]; 00130 newinc[1] = increments[1]; 00131 newinc[2] = 0; 00132 return this->Upload3D(type, data, newdims, comps, newinc,0,0); 00133 } 00135 00137 00142 bool Upload3D(int type, void* data, 00143 unsigned int dims[3], int comps, 00144 vtkIdType increments[3], 00145 int components, 00146 int *componentList); 00148 00150 00153 vtkGetMacro(Type, int); 00154 vtkSetMacro(Type, int); 00156 00158 00159 vtkGetMacro(Components, int); 00160 vtkSetMacro(Components, int); 00162 00164 00166 vtkGetMacro(Size, unsigned int); 00167 vtkSetMacro(Size, unsigned int); 00168 void SetSize(unsigned int nTups, int nComps); 00170 00172 00173 vtkGetMacro(Handle, unsigned int); 00175 00177 00179 bool Download1D( 00180 int type, void* data, 00181 unsigned int dim, 00182 int numcomps, vtkIdType increment) 00183 { 00184 unsigned int newdims[3]; 00185 newdims[0] = dim; 00186 newdims[1] = 1; 00187 newdims[2] = 1; 00188 vtkIdType newincrements[3]; 00189 newincrements[0] = increment; 00190 newincrements[1] = 0; 00191 newincrements[2] = 0; 00192 return this->Download3D(type, data, newdims, numcomps, newincrements); 00193 } 00195 00197 00199 bool Download2D( 00200 int type, void* data, 00201 unsigned int dims[2], 00202 int numcomps, vtkIdType increments[2]) 00203 { 00204 unsigned int newdims[3]; 00205 newdims[0] = dims[0]; 00206 newdims[1] = dims[1]; 00207 newdims[2] = 1; 00208 vtkIdType newincrements[3]; 00209 newincrements[0] = increments[0]; 00210 newincrements[1] = increments[1]; 00211 newincrements[2] = 0; 00212 return this->Download3D(type, data, newdims, numcomps, newincrements); 00213 } 00215 00217 00219 bool Download3D(int type, void* data, 00220 unsigned int dims[3], 00221 int numcomps, vtkIdType increments[3]); 00223 00225 00226 void BindToPackedBuffer() 00227 { this->Bind(PACKED_BUFFER); } 00229 00230 void BindToUnPackedBuffer() 00231 { this->Bind(UNPACKED_BUFFER); } 00232 00234 void UnBind(); 00235 00237 00239 void *MapPackedBuffer() 00240 { return this->MapBuffer(PACKED_BUFFER); } 00242 00243 void *MapPackedBuffer(int type, unsigned int numtuples, int comps) 00244 { return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER); } 00245 00246 void *MapPackedBuffer(unsigned int numbytes) 00247 { return this->MapBuffer(numbytes, PACKED_BUFFER); } 00248 00249 void *MapUnpackedBuffer() 00250 { return this->MapBuffer(UNPACKED_BUFFER); } 00251 00252 void *MapUnpackedBuffer(int type, unsigned int numtuples, int comps) 00253 { return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER); } 00254 00255 void *MapUnpackedBuffer(unsigned int numbytes) 00256 { return this->MapBuffer(numbytes, UNPACKED_BUFFER); } 00257 00259 00261 void UnmapUnpackedBuffer() 00262 { this->UnmapBuffer(UNPACKED_BUFFER); } 00264 00265 void UnmapPackedBuffer() 00266 { this->UnmapBuffer(PACKED_BUFFER); } 00267 00268 // PACKED_BUFFER for download APP<-PBO 00269 // UNPACKED_BUFFER for upload APP->PBO 00270 enum BufferType{ 00271 UNPACKED_BUFFER=0, 00272 PACKED_BUFFER 00273 }; 00274 00276 void Bind(BufferType buffer); 00277 00279 00283 void *MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode); 00284 void *MapBuffer(unsigned int numbytes, BufferType mode); 00285 void *MapBuffer(BufferType mode); 00287 00290 void UnmapBuffer(BufferType mode); 00291 00293 00295 void Allocate( 00296 int vtkType, 00297 unsigned int numtuples, 00298 int comps, 00299 BufferType mode); 00301 00303 00304 void Allocate( 00305 unsigned int nbytes, 00306 BufferType mode); 00308 00310 void ReleaseMemory(); 00311 00314 static bool IsSupported(vtkRenderWindow* renWin); 00315 00316 protected: 00317 vtkPixelBufferObject(); 00318 ~vtkPixelBufferObject(); 00319 00322 bool LoadRequiredExtensions(vtkRenderWindow* renWin); 00323 00325 void CreateBuffer(); 00326 00328 void DestroyBuffer(); 00329 00330 int Usage; 00331 unsigned int BufferTarget; // GLenum 00332 int Type; 00333 int Components; 00334 unsigned int Size; 00335 vtkWeakPointer<vtkRenderWindow> Context; 00336 unsigned int Handle; 00337 private: 00338 vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented. 00339 void operator=(const vtkPixelBufferObject&); // Not implemented. 00340 }; 00341 00342 #endif