VTK
dox/Rendering/OpenGL/vtkPixelBufferObject.h
Go to the documentation of this file.
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 "vtkRenderingOpenGLModule.h" // For export macro
00037 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00038 
00039 class vtkRenderWindow;
00040 class vtkOpenGLExtensionManager;
00041 
00042 class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
00043 {
00044 public:
00045 
00046   //BTX
00047   // Usage values.
00048   enum
00049   {
00050     StreamDraw=0,
00051     StreamRead,
00052     StreamCopy,
00053     StaticDraw,
00054     StaticRead,
00055     StaticCopy,
00056     DynamicDraw,
00057     DynamicRead,
00058     DynamicCopy,
00059     NumberOfUsages
00060   };
00061   //ETX
00062 
00063   static vtkPixelBufferObject* New();
00064   vtkTypeMacro(vtkPixelBufferObject, vtkObject);
00065   void PrintSelf(ostream& os, vtkIndent indent);
00066 
00068 
00072   void SetContext(vtkRenderWindow* context);
00073   vtkRenderWindow* GetContext();
00075 
00077 
00088   vtkGetMacro(Usage,int);
00089   vtkSetMacro(Usage,int);
00091 
00093 
00100   bool Upload1D(int type, void* data,
00101     unsigned int numtuples, int comps, vtkIdType increment)
00102     {
00103     unsigned int newdims[3];
00104     newdims[0] = numtuples;
00105     newdims[1] = 1;
00106     newdims[2] = 1;
00107     vtkIdType newinc[3];
00108     newinc[0] = increment;
00109     newinc[1] = 0;
00110     newinc[2] = 0;
00111     return this->Upload3D(type, data, newdims, comps, newinc,0,0);
00112     }
00114 
00116 
00121   bool Upload2D(int type, void* data,
00122     unsigned int dims[2],
00123     int comps,
00124     vtkIdType increments[2])
00125     {
00126     unsigned int newdims[3];
00127     newdims[0] = dims[0];
00128     newdims[1] = dims[1];
00129     newdims[2] = 1;
00130     vtkIdType newinc[3];
00131     newinc[0] = increments[0];
00132     newinc[1] = increments[1];
00133     newinc[2] = 0;
00134     return this->Upload3D(type, data, newdims, comps, newinc,0,0);
00135     }
00137 
00139 
00144   bool Upload3D(int type, void* data,
00145                 unsigned int dims[3], int comps,
00146                 vtkIdType increments[3],
00147                 int components,
00148                 int *componentList);
00150 
00152 
00155   vtkGetMacro(Type, int);
00156   vtkSetMacro(Type, int);
00158 
00160 
00161   vtkGetMacro(Components, int);
00162   vtkSetMacro(Components, int);
00164 
00166 
00168   vtkGetMacro(Size, unsigned int);
00169   vtkSetMacro(Size, unsigned int);
00170   void SetSize(unsigned int nTups, int nComps);
00172 
00174 
00175   vtkGetMacro(Handle, unsigned int);
00177 
00179 
00181   bool Download1D(
00182     int type, void* data,
00183     unsigned int dim,
00184     int numcomps, vtkIdType increment)
00185     {
00186     unsigned int newdims[3];
00187     newdims[0] = dim;
00188     newdims[1] = 1;
00189     newdims[2] = 1;
00190     vtkIdType newincrements[3];
00191     newincrements[0] = increment;
00192     newincrements[1] = 0;
00193     newincrements[2] = 0;
00194     return this->Download3D(type, data, newdims, numcomps, newincrements);
00195     }
00197 
00199 
00201   bool Download2D(
00202     int type, void* data,
00203     unsigned int dims[2],
00204     int numcomps, vtkIdType increments[2])
00205     {
00206     unsigned int newdims[3];
00207     newdims[0] = dims[0];
00208     newdims[1] = dims[1];
00209     newdims[2] = 1;
00210     vtkIdType newincrements[3];
00211     newincrements[0] = increments[0];
00212     newincrements[1] = increments[1];
00213     newincrements[2] =  0;
00214     return this->Download3D(type, data, newdims, numcomps, newincrements);
00215     }
00217 
00219 
00221   bool Download3D(int type, void* data,
00222     unsigned int dims[3],
00223     int numcomps, vtkIdType increments[3]);
00225 
00227 
00228   void BindToPackedBuffer()
00229     { this->Bind(PACKED_BUFFER); }
00231 
00232   void BindToUnPackedBuffer()
00233     { this->Bind(UNPACKED_BUFFER); }
00234 
00236   void UnBind();
00237 
00239 
00241   void *MapPackedBuffer()
00242     { return this->MapBuffer(PACKED_BUFFER); }
00244 
00245   void *MapPackedBuffer(int type, unsigned int numtuples, int comps)
00246     { return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER); }
00247 
00248   void *MapPackedBuffer(unsigned int numbytes)
00249     { return this->MapBuffer(numbytes, PACKED_BUFFER); }
00250 
00251   void *MapUnpackedBuffer()
00252     { return this->MapBuffer(UNPACKED_BUFFER); }
00253 
00254   void *MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
00255     { return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER); }
00256 
00257   void *MapUnpackedBuffer(unsigned int numbytes)
00258     { return this->MapBuffer(numbytes, UNPACKED_BUFFER); }
00259 
00261 
00263   void UnmapUnpackedBuffer()
00264     { this->UnmapBuffer(UNPACKED_BUFFER); }
00266 
00267   void UnmapPackedBuffer()
00268     { this->UnmapBuffer(PACKED_BUFFER); }
00269 
00270 //BTX
00271   // PACKED_BUFFER for download APP<-PBO
00272   // UNPACKED_BUFFER for upload APP->PBO
00273   enum BufferType{
00274     UNPACKED_BUFFER=0,
00275     PACKED_BUFFER
00276   };
00277 
00279   void Bind(BufferType buffer);
00280 
00282 
00286   void *MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
00287   void *MapBuffer(unsigned int numbytes, BufferType mode);
00288   void *MapBuffer(BufferType mode);
00290 
00293   void UnmapBuffer(BufferType mode);
00294 
00296 
00298   void Allocate(
00299         int vtkType,
00300         unsigned int numtuples,
00301         int comps,
00302         BufferType mode);
00304 
00306 
00307   void Allocate(
00308         unsigned int nbytes,
00309         BufferType mode);
00311 
00313   void ReleaseMemory();
00314 
00317   static bool IsSupported(vtkRenderWindow* renWin);
00318 
00319 //ETX
00320 //BTX
00321 protected:
00322   vtkPixelBufferObject();
00323   ~vtkPixelBufferObject();
00324 
00327   bool LoadRequiredExtensions(vtkRenderWindow* renWin);
00328 
00330   void CreateBuffer();
00331 
00333   void DestroyBuffer();
00334 
00335   int Usage;
00336   unsigned int BufferTarget; // GLenum
00337   int Type;
00338   int Components;
00339   unsigned int Size;
00340   vtkWeakPointer<vtkRenderWindow> Context;
00341   unsigned int Handle;
00342 private:
00343   vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented.
00344   void operator=(const vtkPixelBufferObject&); // Not implemented.
00345   //ETX
00346 };
00347 
00348 #endif