VTK
vtkPixelBufferObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPixelBufferObject.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
32 #ifndef vtkPixelBufferObject_h
33 #define vtkPixelBufferObject_h
34 
35 #include "vtkObject.h"
36 #include "vtkRenderingOpenGLModule.h" // For export macro
37 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
38 
39 class vtkRenderWindow;
41 
42 class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
43 {
44 public:
45 
46  //BTX
47  // Usage values.
48  enum
49  {
50  StreamDraw=0,
59  NumberOfUsages
60  };
61  //ETX
62 
63  static vtkPixelBufferObject* New();
65  void PrintSelf(ostream& os, vtkIndent indent);
66 
68 
72  void SetContext(vtkRenderWindow* context);
73  vtkRenderWindow* GetContext();
75 
77 
88  vtkGetMacro(Usage,int);
89  vtkSetMacro(Usage,int);
91 
93 
100  bool Upload1D(int type, void* data,
101  unsigned int numtuples, int comps, vtkIdType increment)
102  {
103  unsigned int newdims[3];
104  newdims[0] = numtuples;
105  newdims[1] = 1;
106  newdims[2] = 1;
107  vtkIdType newinc[3];
108  newinc[0] = increment;
109  newinc[1] = 0;
110  newinc[2] = 0;
111  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
112  }
114 
116 
121  bool Upload2D(int type, void* data,
122  unsigned int dims[2],
123  int comps,
124  vtkIdType increments[2])
125  {
126  unsigned int newdims[3];
127  newdims[0] = dims[0];
128  newdims[1] = dims[1];
129  newdims[2] = 1;
130  vtkIdType newinc[3];
131  newinc[0] = increments[0];
132  newinc[1] = increments[1];
133  newinc[2] = 0;
134  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
135  }
137 
139 
144  bool Upload3D(int type, void* data,
145  unsigned int dims[3], int comps,
146  vtkIdType increments[3],
147  int components,
148  int *componentList);
150 
152 
155  vtkGetMacro(Type, int);
156  vtkSetMacro(Type, int);
158 
160 
161  vtkGetMacro(Components, int);
162  vtkSetMacro(Components, int);
164 
166 
168  vtkGetMacro(Size, unsigned int);
169  vtkSetMacro(Size, unsigned int);
170  void SetSize(unsigned int nTups, int nComps);
172 
174 
175  vtkGetMacro(Handle, unsigned int);
177 
179 
182  int type, void* data,
183  unsigned int dim,
184  int numcomps, vtkIdType increment)
185  {
186  unsigned int newdims[3];
187  newdims[0] = dim;
188  newdims[1] = 1;
189  newdims[2] = 1;
190  vtkIdType newincrements[3];
191  newincrements[0] = increment;
192  newincrements[1] = 0;
193  newincrements[2] = 0;
194  return this->Download3D(type, data, newdims, numcomps, newincrements);
195  }
197 
199 
202  int type, void* data,
203  unsigned int dims[2],
204  int numcomps, vtkIdType increments[2])
205  {
206  unsigned int newdims[3];
207  newdims[0] = dims[0];
208  newdims[1] = dims[1];
209  newdims[2] = 1;
210  vtkIdType newincrements[3];
211  newincrements[0] = increments[0];
212  newincrements[1] = increments[1];
213  newincrements[2] = 0;
214  return this->Download3D(type, data, newdims, numcomps, newincrements);
215  }
217 
219 
221  bool Download3D(int type, void* data,
222  unsigned int dims[3],
223  int numcomps, vtkIdType increments[3]);
225 
227 
229  { this->Bind(PACKED_BUFFER); }
231 
233  { this->Bind(UNPACKED_BUFFER); }
234 
236  void UnBind();
237 
239 
242  { return this->MapBuffer(PACKED_BUFFER); }
244 
245  void *MapPackedBuffer(int type, unsigned int numtuples, int comps)
246  { return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER); }
247 
248  void *MapPackedBuffer(unsigned int numbytes)
249  { return this->MapBuffer(numbytes, PACKED_BUFFER); }
250 
252  { return this->MapBuffer(UNPACKED_BUFFER); }
253 
254  void *MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
255  { return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER); }
256 
257  void *MapUnpackedBuffer(unsigned int numbytes)
258  { return this->MapBuffer(numbytes, UNPACKED_BUFFER); }
259 
261 
264  { this->UnmapBuffer(UNPACKED_BUFFER); }
266 
268  { this->UnmapBuffer(PACKED_BUFFER); }
269 
270 //BTX
271  // PACKED_BUFFER for download APP<-PBO
272  // UNPACKED_BUFFER for upload APP->PBO
274  UNPACKED_BUFFER=0,
275  PACKED_BUFFER
276  };
277 
279  void Bind(BufferType buffer);
280 
282 
286  void *MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
287  void *MapBuffer(unsigned int numbytes, BufferType mode);
288  void *MapBuffer(BufferType mode);
290 
293  void UnmapBuffer(BufferType mode);
294 
296 
298  void Allocate(
299  int vtkType,
300  unsigned int numtuples,
301  int comps,
302  BufferType mode);
304 
306 
307  void Allocate(
308  unsigned int nbytes,
309  BufferType mode);
311 
313  void ReleaseMemory();
314 
317  static bool IsSupported(vtkRenderWindow* renWin);
318 
319 //ETX
320 //BTX
321 protected:
324 
327  bool LoadRequiredExtensions(vtkRenderWindow* renWin);
328 
330  void CreateBuffer();
331 
333  void DestroyBuffer();
334 
335  int Usage;
336  unsigned int BufferTarget; // GLenum
337  int Type;
339  unsigned int Size;
341  unsigned int Handle;
342 private:
343  vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented.
344  void operator=(const vtkPixelBufferObject&); // Not implemented.
345  //ETX
346 };
347 
348 #endif
bool Upload1D(int type, void *data, unsigned int numtuples, int comps, vtkIdType increment)
bool Upload2D(int type, void *data, unsigned int dims[2], int comps, vtkIdType increments[2])
abstract base class for most VTK objects
Definition: vtkObject.h:61
bool Download1D(int type, void *data, unsigned int dim, int numcomps, vtkIdType increment)
bool Download2D(int type, void *data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
int vtkIdType
Definition: vtkType.h:247
void * MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
virtual void PrintSelf(ostream &os, vtkIndent indent)
void * MapUnpackedBuffer(unsigned int numbytes)
void * MapPackedBuffer(int type, unsigned int numtuples, int comps)
a simple class to control print indentation
Definition: vtkIndent.h:38
abstracts an OpenGL pixel buffer object.
void * MapPackedBuffer(unsigned int numbytes)
Interface class for querying and using OpenGL extensions.
create a window for renderers to draw into
static vtkObject * New()
vtkWeakPointer< vtkRenderWindow > Context