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 =========================================================================*/
33 #ifndef vtkPixelBufferObject_h
34 #define vtkPixelBufferObject_h
35 
36 #include "vtkObject.h"
37 #include "vtkRenderingOpenGLModule.h" // For export macro
38 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
39 
40 class vtkRenderWindow;
42 
43 class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
44 {
45 public:
46 
47  // Usage values.
48  enum
49  {
50  StreamDraw=0,
59  NumberOfUsages
60  };
61 
62  static vtkPixelBufferObject* New();
64  void PrintSelf(ostream& os, vtkIndent indent);
65 
67 
74  void SetContext(vtkRenderWindow* context);
75  vtkRenderWindow* GetContext();
77 
79 
96  vtkGetMacro(Usage,int);
97  vtkSetMacro(Usage,int);
99 
101 
110  bool Upload1D(int type, void* data,
111  unsigned int numtuples, int comps, vtkIdType increment)
112  {
113  unsigned int newdims[3];
114  newdims[0] = numtuples;
115  newdims[1] = 1;
116  newdims[2] = 1;
117  vtkIdType newinc[3];
118  newinc[0] = increment;
119  newinc[1] = 0;
120  newinc[2] = 0;
121  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
122  }
124 
126 
134  bool Upload2D(int type, void* data,
135  unsigned int dims[2],
136  int comps,
137  vtkIdType increments[2])
138  {
139  unsigned int newdims[3];
140  newdims[0] = dims[0];
141  newdims[1] = dims[1];
142  newdims[2] = 1;
143  vtkIdType newinc[3];
144  newinc[0] = increments[0];
145  newinc[1] = increments[1];
146  newinc[2] = 0;
147  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
148  }
150 
159  bool Upload3D(int type, void* data,
160  unsigned int dims[3], int comps,
161  vtkIdType increments[3],
162  int components,
163  int *componentList);
164 
166 
171  vtkGetMacro(Type, int);
172  vtkSetMacro(Type, int);
174 
176 
179  vtkGetMacro(Components, int);
180  vtkSetMacro(Components, int);
182 
184 
188  vtkGetMacro(Size, unsigned int);
189  vtkSetMacro(Size, unsigned int);
190  void SetSize(unsigned int nTups, int nComps);
192 
194 
197  vtkGetMacro(Handle, unsigned int);
199 
201 
206  int type, void* data,
207  unsigned int dim,
208  int numcomps, vtkIdType increment)
209  {
210  unsigned int newdims[3];
211  newdims[0] = dim;
212  newdims[1] = 1;
213  newdims[2] = 1;
214  vtkIdType newincrements[3];
215  newincrements[0] = increment;
216  newincrements[1] = 0;
217  newincrements[2] = 0;
218  return this->Download3D(type, data, newdims, numcomps, newincrements);
219  }
221 
223 
228  int type, void* data,
229  unsigned int dims[2],
230  int numcomps, vtkIdType increments[2])
231  {
232  unsigned int newdims[3];
233  newdims[0] = dims[0];
234  newdims[1] = dims[1];
235  newdims[2] = 1;
236  vtkIdType newincrements[3];
237  newincrements[0] = increments[0];
238  newincrements[1] = increments[1];
239  newincrements[2] = 0;
240  return this->Download3D(type, data, newdims, numcomps, newincrements);
241  }
243 
249  bool Download3D(int type, void* data,
250  unsigned int dims[3],
251  int numcomps, vtkIdType increments[3]);
252 
257  { this->Bind(PACKED_BUFFER); }
258 
260  { this->Bind(UNPACKED_BUFFER); }
261 
265  void UnBind();
266 
272  { return this->MapBuffer(PACKED_BUFFER); }
273 
274  void *MapPackedBuffer(int type, unsigned int numtuples, int comps)
275  { return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER); }
276 
277  void *MapPackedBuffer(unsigned int numbytes)
278  { return this->MapBuffer(numbytes, PACKED_BUFFER); }
279 
281  { return this->MapBuffer(UNPACKED_BUFFER); }
282 
283  void *MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
284  { return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER); }
285 
286  void *MapUnpackedBuffer(unsigned int numbytes)
287  { return this->MapBuffer(numbytes, UNPACKED_BUFFER); }
288 
294  { this->UnmapBuffer(UNPACKED_BUFFER); }
295 
297  { this->UnmapBuffer(PACKED_BUFFER); }
298 
299  // PACKED_BUFFER for download APP<-PBO
300  // UNPACKED_BUFFER for upload APP->PBO
302  UNPACKED_BUFFER=0,
303  PACKED_BUFFER
304  };
305 
309  void Bind(BufferType buffer);
310 
312 
318  void *MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
319  void *MapBuffer(unsigned int numbytes, BufferType mode);
320  void *MapBuffer(BufferType mode);
322 
327  void UnmapBuffer(BufferType mode);
328 
332  void Allocate(
333  int vtkType,
334  unsigned int numtuples,
335  int comps,
336  BufferType mode);
337 
341  void Allocate(
342  unsigned int nbytes,
343  BufferType mode);
344 
348  void ReleaseMemory();
349 
354  static bool IsSupported(vtkRenderWindow* renWin);
355 
356 protected:
359 
364  bool LoadRequiredExtensions(vtkRenderWindow* renWin);
365 
369  void CreateBuffer();
370 
374  void DestroyBuffer();
375 
376  int Usage;
377  unsigned int BufferTarget; // GLenum
378  int Type;
380  unsigned int Size;
382  unsigned int Handle;
383 private:
384  vtkPixelBufferObject(const vtkPixelBufferObject&) VTK_DELETE_FUNCTION;
385  void operator=(const vtkPixelBufferObject&) VTK_DELETE_FUNCTION;
386 
387 };
388 
389 #endif
bool Upload1D(int type, void *data, unsigned int numtuples, int comps, vtkIdType increment)
Upload data to PBO mapped.
bool Upload2D(int type, void *data, unsigned int dims[2], int comps, vtkIdType increments[2])
Update data to PBO mapped sourcing it from a 2D array.
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool Download1D(int type, void *data, unsigned int dim, int numcomps, vtkIdType increment)
Download data from pixel buffer to the 1D array.
void BindToPackedBuffer()
Convenience methods for binding.
bool Download2D(int type, void *data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
Download data from pixel buffer to the 2D array.
int vtkIdType
Definition: vtkType.h:287
void * MapPackedBuffer()
Convenience api for mapping buffers to app address space.
void * MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
void * MapUnpackedBuffer(unsigned int numbytes)
void * MapPackedBuffer(int type, unsigned int numtuples, int comps)
a simple class to control print indentation
Definition: vtkIndent.h:39
abstracts an OpenGL pixel buffer object.
void * MapPackedBuffer(unsigned int numbytes)
Interface class for querying and using OpenGL extensions.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
create a window for renderers to draw into
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void UnmapUnpackedBuffer()
Convenience api for unmapping buffers from app address space.
vtkWeakPointer< vtkRenderWindow > Context