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 =========================================================================*/ 00029 #ifndef __vtkPixelBufferObject_h 00030 #define __vtkPixelBufferObject_h 00031 00032 #include "vtkObject.h" 00033 #include "vtkWeakPointer.h" // needed for vtkWeakPointer. 00034 00035 class vtkRenderWindow; 00036 class vtkOpenGLExtensionManager; 00037 00038 class VTK_RENDERING_EXPORT vtkPixelBufferObject : public vtkObject 00039 { 00040 public: 00041 00042 //BTX 00043 // Usage values. 00044 enum 00045 { 00046 StreamDraw=0, 00047 StreamRead, 00048 StreamCopy, 00049 StaticDraw, 00050 StaticRead, 00051 StaticCopy, 00052 DynamicDraw, 00053 DynamicRead, 00054 DynamicCopy, 00055 NumberOfUsages 00056 }; 00057 //ETX 00058 00059 static vtkPixelBufferObject* New(); 00060 vtkTypeMacro(vtkPixelBufferObject, vtkObject); 00061 void PrintSelf(ostream& os, vtkIndent indent); 00062 00064 00068 void SetContext(vtkRenderWindow* context); 00069 vtkRenderWindow* GetContext(); 00071 00073 00084 vtkGetMacro(Usage,int); 00085 vtkSetMacro(Usage,int); 00087 00089 00095 bool Upload1D(int type, void* data, 00096 unsigned int numtuples, int comps, vtkIdType increment) 00097 { 00098 unsigned int newdims[3]; 00099 newdims[0] = numtuples; 00100 newdims[1] = 1; 00101 newdims[2] = 1; 00102 vtkIdType newinc[3]; 00103 newinc[0] = increment; 00104 newinc[1] = 0; 00105 newinc[2] = 0; 00106 return this->Upload3D(type, data, newdims, comps, newinc,0,0); 00107 } 00109 00111 00116 bool Upload2D(int type, void* data, 00117 unsigned int dims[2], 00118 int comps, 00119 vtkIdType increments[2]) 00120 { 00121 unsigned int newdims[3]; 00122 newdims[0] = dims[0]; 00123 newdims[1] = dims[1]; 00124 newdims[2] = 1; 00125 vtkIdType newinc[3]; 00126 newinc[0] = increments[0]; 00127 newinc[1] = increments[1]; 00128 newinc[2] = 0; 00129 return this->Upload3D(type, data, newdims, comps, newinc,0,0); 00130 } 00132 00134 00139 bool Upload3D(int type, void* data, 00140 unsigned int dims[3], int comps, 00141 vtkIdType increments[3], 00142 int components, 00143 int *componentList); 00145 00147 00150 vtkGetMacro(Type, int); 00152 00154 00156 vtkGetMacro(Size, unsigned int); 00158 00160 00161 vtkGetMacro(Handle, unsigned int); 00163 00165 00167 bool Download1D( 00168 int type, void* data, 00169 unsigned int dim, 00170 int numcomps, vtkIdType increment) 00171 { 00172 unsigned int newdims[3]; 00173 newdims[0] = dim; 00174 newdims[1] = 1; 00175 newdims[2] = 1; 00176 vtkIdType newincrements[3]; 00177 newincrements[0] = increment; 00178 newincrements[1] = 0; 00179 newincrements[2] = 0; 00180 return this->Download3D(type, data, newdims, numcomps, newincrements); 00181 } 00183 00185 00187 bool Download2D( 00188 int type, void* data, 00189 unsigned int dims[2], 00190 int numcomps, vtkIdType increments[2]) 00191 { 00192 unsigned int newdims[3]; 00193 newdims[0] = dims[0]; 00194 newdims[1] = dims[1]; 00195 newdims[2] = 1; 00196 vtkIdType newincrements[3]; 00197 newincrements[0] = increments[0]; 00198 newincrements[1] = increments[1]; 00199 newincrements[2] = 0; 00200 return this->Download3D(type, data, newdims, numcomps, newincrements); 00201 } 00203 00205 00207 bool Download3D(int type, void* data, 00208 unsigned int dims[3], 00209 int numcomps, vtkIdType increments[3]); 00211 00213 00214 void BindToPackedBuffer() 00215 { this->Bind(PACKED_BUFFER); } 00217 00218 void BindToUnPackedBuffer() 00219 { this->Bind(UNPACKED_BUFFER); } 00220 00222 void UnBind(); 00223 00224 //BTX 00225 // We can't use just PACKED because this is a cygwin macro defined as 00226 // __attribute__((packed)) 00227 enum BufferType{ 00228 PACKED_BUFFER, 00229 UNPACKED_BUFFER 00230 }; 00231 00233 void Bind(BufferType buffer); 00234 00236 00237 void Allocate(unsigned int size, 00238 int type); 00240 00242 void ReleaseMemory(); 00243 00245 static bool IsSupported(vtkRenderWindow* renWin); 00246 00247 //ETX 00248 //BTX 00249 protected: 00250 vtkPixelBufferObject(); 00251 ~vtkPixelBufferObject(); 00252 00255 bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr); 00256 00258 void CreateBuffer(); 00259 00261 void DestroyBuffer(); 00262 00263 int Usage; 00264 unsigned int BufferTarget; // GLenum 00265 int Type; 00266 unsigned int Size; 00267 vtkWeakPointer<vtkRenderWindow> Context; 00268 unsigned int Handle; 00269 private: 00270 vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented. 00271 void operator=(const vtkPixelBufferObject&); // Not implemented. 00272 //ETX 00273 }; 00274 00275 #endif 00276 00277