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 "vtkRenderingOpenGL2Module.h" // For export macro
37 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
38 
39 class vtkRenderWindow;
41 
43 {
44 public:
45 
46  // Usage values.
47  enum
48  {
49  StreamDraw=0,
50  StreamRead,
51  StreamCopy,
52  StaticDraw,
53  StaticRead,
54  StaticCopy,
55  DynamicDraw,
56  DynamicRead,
57  DynamicCopy,
58  NumberOfUsages
59  };
60 
61  static vtkPixelBufferObject* New();
63  void PrintSelf(ostream& os, vtkIndent indent);
64 
66 
70  void SetContext(vtkRenderWindow* context);
71  vtkRenderWindow* GetContext();
73 
75 
86  vtkGetMacro(Usage,int);
87  vtkSetMacro(Usage,int);
89 
91 
98  bool Upload1D(int type, void* data,
99  unsigned int numtuples, int comps, vtkIdType increment)
100  {
101  unsigned int newdims[3];
102  newdims[0] = numtuples;
103  newdims[1] = 1;
104  newdims[2] = 1;
105  vtkIdType newinc[3];
106  newinc[0] = increment;
107  newinc[1] = 0;
108  newinc[2] = 0;
109  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
110  }
112 
114 
119  bool Upload2D(int type, void* data,
120  unsigned int dims[2],
121  int comps,
122  vtkIdType increments[2])
123  {
124  unsigned int newdims[3];
125  newdims[0] = dims[0];
126  newdims[1] = dims[1];
127  newdims[2] = 1;
128  vtkIdType newinc[3];
129  newinc[0] = increments[0];
130  newinc[1] = increments[1];
131  newinc[2] = 0;
132  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
133  }
135 
137 
142  bool Upload3D(int type, void* data,
143  unsigned int dims[3], int comps,
144  vtkIdType increments[3],
145  int components,
146  int *componentList);
148 
150 
153  vtkGetMacro(Type, int);
154  vtkSetMacro(Type, int);
156 
158 
159  vtkGetMacro(Components, int);
160  vtkSetMacro(Components, int);
162 
164 
166  vtkGetMacro(Size, unsigned int);
167  vtkSetMacro(Size, unsigned int);
168  void SetSize(unsigned int nTups, int nComps);
170 
172 
173  vtkGetMacro(Handle, unsigned int);
175 
177 
180  int type, void* data,
181  unsigned int dim,
182  int numcomps, vtkIdType increment)
183  {
184  unsigned int newdims[3];
185  newdims[0] = dim;
186  newdims[1] = 1;
187  newdims[2] = 1;
188  vtkIdType newincrements[3];
189  newincrements[0] = increment;
190  newincrements[1] = 0;
191  newincrements[2] = 0;
192  return this->Download3D(type, data, newdims, numcomps, newincrements);
193  }
195 
197 
200  int type, void* data,
201  unsigned int dims[2],
202  int numcomps, vtkIdType increments[2])
203  {
204  unsigned int newdims[3];
205  newdims[0] = dims[0];
206  newdims[1] = dims[1];
207  newdims[2] = 1;
208  vtkIdType newincrements[3];
209  newincrements[0] = increments[0];
210  newincrements[1] = increments[1];
211  newincrements[2] = 0;
212  return this->Download3D(type, data, newdims, numcomps, newincrements);
213  }
215 
217 
219  bool Download3D(int type, void* data,
220  unsigned int dims[3],
221  int numcomps, vtkIdType increments[3]);
223 
225 
227  { this->Bind(PACKED_BUFFER); }
229 
231  { this->Bind(UNPACKED_BUFFER); }
232 
234  void UnBind();
235 
237 
240  { return this->MapBuffer(PACKED_BUFFER); }
242 
243  void *MapPackedBuffer(int type, unsigned int numtuples, int comps)
244  { return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER); }
245 
246  void *MapPackedBuffer(unsigned int numbytes)
247  { return this->MapBuffer(numbytes, PACKED_BUFFER); }
248 
250  { return this->MapBuffer(UNPACKED_BUFFER); }
251 
252  void *MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
253  { return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER); }
254 
255  void *MapUnpackedBuffer(unsigned int numbytes)
256  { return this->MapBuffer(numbytes, UNPACKED_BUFFER); }
257 
259 
262  { this->UnmapBuffer(UNPACKED_BUFFER); }
264 
266  { this->UnmapBuffer(PACKED_BUFFER); }
267 
268  // PACKED_BUFFER for download APP<-PBO
269  // UNPACKED_BUFFER for upload APP->PBO
271  UNPACKED_BUFFER=0,
272  PACKED_BUFFER
273  };
274 
276  void Bind(BufferType buffer);
277 
279 
283  void *MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
284  void *MapBuffer(unsigned int numbytes, BufferType mode);
285  void *MapBuffer(BufferType mode);
287 
290  void UnmapBuffer(BufferType mode);
291 
293 
295  void Allocate(
296  int vtkType,
297  unsigned int numtuples,
298  int comps,
299  BufferType mode);
301 
303 
304  void Allocate(
305  unsigned int nbytes,
306  BufferType mode);
308 
310  void ReleaseMemory();
311 
314  static bool IsSupported(vtkRenderWindow* renWin);
315 
316 protected:
319 
322  bool LoadRequiredExtensions(vtkRenderWindow* renWin);
323 
325  void CreateBuffer();
326 
328  void DestroyBuffer();
329 
330  int Usage;
331  unsigned int BufferTarget; // GLenum
332  int Type;
333  int Components;
334  unsigned int Size;
336  unsigned int Handle;
337 private:
338  vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented.
339  void operator=(const vtkPixelBufferObject&); // Not implemented.
340 };
341 
342 #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)
#define VTKRENDERINGOPENGL2_EXPORT
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()