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 =========================================================================*/
00029 #ifndef __vtkPixelBufferObject_h
00030 #define __vtkPixelBufferObject_h
00031 
00032 #include "vtkRenderingOpenGLModule.h" // For export macro
00033 #include "vtkObject.h"
00034 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
00035 
00036 class vtkRenderWindow;
00037 class vtkOpenGLExtensionManager;
00038 
00039 class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
00040 {
00041 public:
00042 
00043   //BTX
00044   // Usage values.
00045   enum
00046   {
00047     StreamDraw=0,
00048     StreamRead,
00049     StreamCopy,
00050     StaticDraw,
00051     StaticRead,
00052     StaticCopy,
00053     DynamicDraw,
00054     DynamicRead,
00055     DynamicCopy,
00056     NumberOfUsages
00057   };
00058   //ETX
00059 
00060   static vtkPixelBufferObject* New();
00061   vtkTypeMacro(vtkPixelBufferObject, vtkObject);
00062   void PrintSelf(ostream& os, vtkIndent indent);
00063 
00065 
00069   void SetContext(vtkRenderWindow* context);
00070   vtkRenderWindow* GetContext();
00072 
00074 
00085   vtkGetMacro(Usage,int);
00086   vtkSetMacro(Usage,int);
00088 
00090 
00096   bool Upload1D(int type, void* data,
00097     unsigned int numtuples, int comps, vtkIdType increment)
00098     {
00099     unsigned int newdims[3];
00100     newdims[0] = numtuples;
00101     newdims[1] = 1;
00102     newdims[2] = 1;
00103     vtkIdType newinc[3];
00104     newinc[0] = increment;
00105     newinc[1] = 0;
00106     newinc[2] = 0;
00107     return this->Upload3D(type, data, newdims, comps, newinc,0,0);
00108     }
00110 
00112 
00117   bool Upload2D(int type, void* data,
00118     unsigned int dims[2],
00119     int comps,
00120     vtkIdType increments[2])
00121     {
00122     unsigned int newdims[3];
00123     newdims[0] = dims[0];
00124     newdims[1] = dims[1];
00125     newdims[2] = 1;
00126     vtkIdType newinc[3];
00127     newinc[0] = increments[0];
00128     newinc[1] = increments[1];
00129     newinc[2] = 0;
00130     return this->Upload3D(type, data, newdims, comps, newinc,0,0);
00131     }
00133 
00135 
00140   bool Upload3D(int type, void* data,
00141                 unsigned int dims[3], int comps,
00142                 vtkIdType increments[3],
00143                 int components,
00144                 int *componentList);
00146 
00148 
00151   vtkGetMacro(Type, int);
00153 
00155 
00157   vtkGetMacro(Size, unsigned int);
00159 
00161 
00162   vtkGetMacro(Handle, unsigned int);
00164 
00166 
00168   bool Download1D(
00169     int type, void* data,
00170     unsigned int dim,
00171     int numcomps, vtkIdType increment)
00172     {
00173     unsigned int newdims[3];
00174     newdims[0] = dim;
00175     newdims[1] = 1;
00176     newdims[2] = 1;
00177     vtkIdType newincrements[3];
00178     newincrements[0] = increment;
00179     newincrements[1] = 0;
00180     newincrements[2] = 0;
00181     return this->Download3D(type, data, newdims, numcomps, newincrements);
00182     }
00184 
00186 
00188   bool Download2D(
00189     int type, void* data,
00190     unsigned int dims[2],
00191     int numcomps, vtkIdType increments[2])
00192     {
00193     unsigned int newdims[3];
00194     newdims[0] = dims[0];
00195     newdims[1] = dims[1];
00196     newdims[2] = 1;
00197     vtkIdType newincrements[3];
00198     newincrements[0] = increments[0];
00199     newincrements[1] = increments[1];
00200     newincrements[2] =  0;
00201     return this->Download3D(type, data, newdims, numcomps, newincrements);
00202     }
00204 
00206 
00208   bool Download3D(int type, void* data,
00209     unsigned int dims[3],
00210     int numcomps, vtkIdType increments[3]);
00212 
00214 
00215   void BindToPackedBuffer()
00216     { this->Bind(PACKED_BUFFER); }
00218 
00219   void BindToUnPackedBuffer()
00220     { this->Bind(UNPACKED_BUFFER); }
00221 
00223   void UnBind();
00224 
00225 //BTX
00226   // We can't use just PACKED because this is a cygwin macro defined as
00227   // __attribute__((packed))
00228   enum BufferType{
00229     PACKED_BUFFER,
00230     UNPACKED_BUFFER
00231   };
00232 
00234   void Bind(BufferType buffer);
00235 
00237 
00238   void Allocate(unsigned int size,
00239                 int type);
00241 
00243   void ReleaseMemory();
00244 
00246   static bool IsSupported(vtkRenderWindow* renWin);
00247 
00248 //ETX
00249 //BTX
00250 protected:
00251   vtkPixelBufferObject();
00252   ~vtkPixelBufferObject();
00253 
00256   bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
00257 
00259   void CreateBuffer();
00260 
00262   void DestroyBuffer();
00263 
00264   int Usage;
00265   unsigned int BufferTarget; // GLenum
00266   int Type;
00267   unsigned int Size;
00268   vtkWeakPointer<vtkRenderWindow> Context;
00269   unsigned int Handle;
00270 private:
00271   vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented.
00272   void operator=(const vtkPixelBufferObject&); // Not implemented.
00273   //ETX
00274 };
00275 
00276 #endif
00277 
00278