VTK  9.0.2
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 "vtkRenderingOpenGL2Module.h" // For export macro
38 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
39 
40 class vtkRenderWindow;
41 class vtkOpenGLExtensionManager;
42 
43 class VTKRENDERINGOPENGL2_EXPORT vtkPixelBufferObject : public vtkObject
44 {
45 public:
46  // Usage values.
47  enum
48  {
49  StreamDraw = 0,
58  NumberOfUsages
59  };
60 
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64 
66 
73  void SetContext(vtkRenderWindow* context);
76 
78 
95  vtkGetMacro(Usage, int);
96  vtkSetMacro(Usage, int);
98 
100 
109  bool Upload1D(int type, void* data, unsigned int numtuples, int comps, vtkIdType increment)
110  {
111  unsigned int newdims[3];
112  newdims[0] = numtuples;
113  newdims[1] = 1;
114  newdims[2] = 1;
115  vtkIdType newinc[3];
116  newinc[0] = increment;
117  newinc[1] = 0;
118  newinc[2] = 0;
119  return this->Upload3D(type, data, newdims, comps, newinc, 0, nullptr);
120  }
122 
124 
132  bool Upload2D(int type, void* data, unsigned int dims[2], int comps, vtkIdType increments[2])
133  {
134  unsigned int newdims[3];
135  newdims[0] = dims[0];
136  newdims[1] = dims[1];
137  newdims[2] = 1;
138  vtkIdType newinc[3];
139  newinc[0] = increments[0];
140  newinc[1] = increments[1];
141  newinc[2] = 0;
142  return this->Upload3D(type, data, newdims, comps, newinc, 0, nullptr);
143  }
145 
154  bool Upload3D(int type, void* data, unsigned int dims[3], int comps, vtkIdType increments[3],
155  int components, int* componentList);
156 
158 
163  vtkGetMacro(Type, int);
164  vtkSetMacro(Type, int);
166 
168 
171  vtkGetMacro(Components, int);
172  vtkSetMacro(Components, int);
174 
176 
180  vtkGetMacro(Size, unsigned int);
181  vtkSetMacro(Size, unsigned int);
182  void SetSize(unsigned int nTups, int nComps);
184 
186 
189  vtkGetMacro(Handle, unsigned int);
191 
193 
197  bool Download1D(int type, void* data, unsigned int dim, int numcomps, vtkIdType increment)
198  {
199  unsigned int newdims[3];
200  newdims[0] = dim;
201  newdims[1] = 1;
202  newdims[2] = 1;
203  vtkIdType newincrements[3];
204  newincrements[0] = increment;
205  newincrements[1] = 0;
206  newincrements[2] = 0;
207  return this->Download3D(type, data, newdims, numcomps, newincrements);
208  }
210 
212 
216  bool Download2D(int type, void* data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
217  {
218  unsigned int newdims[3];
219  newdims[0] = dims[0];
220  newdims[1] = dims[1];
221  newdims[2] = 1;
222  vtkIdType newincrements[3];
223  newincrements[0] = increments[0];
224  newincrements[1] = increments[1];
225  newincrements[2] = 0;
226  return this->Download3D(type, data, newdims, numcomps, newincrements);
227  }
229 
236  int type, void* data, unsigned int dims[3], int numcomps, vtkIdType increments[3]);
237 
241  void BindToPackedBuffer() { this->Bind(PACKED_BUFFER); }
242 
243  void BindToUnPackedBuffer() { this->Bind(UNPACKED_BUFFER); }
244 
248  void UnBind();
249 
254  void* MapPackedBuffer() { return this->MapBuffer(PACKED_BUFFER); }
255 
256  void* MapPackedBuffer(int type, unsigned int numtuples, int comps)
257  {
258  return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER);
259  }
260 
261  void* MapPackedBuffer(unsigned int numbytes) { return this->MapBuffer(numbytes, PACKED_BUFFER); }
262 
263  void* MapUnpackedBuffer() { return this->MapBuffer(UNPACKED_BUFFER); }
264 
265  void* MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
266  {
267  return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER);
268  }
269 
270  void* MapUnpackedBuffer(unsigned int numbytes)
271  {
272  return this->MapBuffer(numbytes, UNPACKED_BUFFER);
273  }
274 
279  void UnmapUnpackedBuffer() { this->UnmapBuffer(UNPACKED_BUFFER); }
280 
281  void UnmapPackedBuffer() { this->UnmapBuffer(PACKED_BUFFER); }
282 
283  // PACKED_BUFFER for download APP<-PBO
284  // UNPACKED_BUFFER for upload APP->PBO
286  {
287  UNPACKED_BUFFER = 0,
288  PACKED_BUFFER
289  };
290 
294  void Bind(BufferType buffer);
295 
297 
303  void* MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
304  void* MapBuffer(unsigned int numbytes, BufferType mode);
307 
313 
317  void Allocate(int vtkType, unsigned int numtuples, int comps, BufferType mode);
318 
322  void Allocate(unsigned int nbytes, BufferType mode);
323 
328 
333  static bool IsSupported(vtkRenderWindow* renWin);
334 
335 protected:
338 
344 
348  void CreateBuffer();
349 
354 
355  int Usage;
356  unsigned int BufferTarget; // GLenum
357  int Type;
359  unsigned int Size;
361  unsigned int Handle;
362 
363 private:
365  void operator=(const vtkPixelBufferObject&) = delete;
366 };
367 
368 #endif
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
abstracts an OpenGL pixel buffer object.
void SetSize(unsigned int nTups, int nComps)
static bool IsSupported(vtkRenderWindow *renWin)
Returns if the context supports the required extensions.
void DestroyBuffer()
Destroys the pixel buffer object.
vtkRenderWindow * GetContext()
void UnmapUnpackedBuffer()
Convenience api for unmapping buffers from app address space.
void Allocate(unsigned int nbytes, BufferType mode)
Allocate PACKED/UNPACKED memory to hold nBytes of data.
void UnBind()
Deactivate the buffer.
void Bind(BufferType buffer)
Make the buffer active.
bool Download2D(int type, void *data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
Download data from pixel buffer to the 2D array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool LoadRequiredExtensions(vtkRenderWindow *renWin)
Loads all required OpenGL extensions.
bool Download3D(int type, void *data, unsigned int dims[3], int numcomps, vtkIdType increments[3])
Download data from pixel buffer to the 3D array.
void * MapUnpackedBuffer(unsigned int numbytes)
void * MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode)
Map the buffer to our addresspace.
void ReleaseMemory()
Release the memory allocated without destroying the PBO handle.
bool Upload1D(int type, void *data, unsigned int numtuples, int comps, vtkIdType increment)
Upload data to PBO mapped.
void BindToPackedBuffer()
Convenience methods for binding.
void * MapPackedBuffer()
Convenience api for mapping buffers to app address space.
void SetContext(vtkRenderWindow *context)
Get/Set the context.
void * MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
void Allocate(int vtkType, unsigned int numtuples, int comps, BufferType mode)
Allocate PACKED/UNPACKED memory to hold numTuples*numComponents of vtkType.
void * MapBuffer(BufferType mode)
void * MapPackedBuffer(int type, unsigned int numtuples, int comps)
~vtkPixelBufferObject() override
void CreateBuffer()
Create the pixel buffer object.
void UnmapBuffer(BufferType mode)
Un-map the buffer from our address space, OpenGL can then use/reclaim the buffer contents.
bool Download1D(int type, void *data, unsigned int dim, int numcomps, vtkIdType increment)
Download data from pixel buffer to the 1D array.
void * MapPackedBuffer(unsigned int numbytes)
void * MapBuffer(unsigned int numbytes, BufferType mode)
bool Upload3D(int type, void *data, unsigned int dims[3], int comps, vtkIdType increments[3], int components, int *componentList)
Update data to PBO mapped sourcing it from a 3D array.
static vtkPixelBufferObject * New()
vtkWeakPointer< vtkRenderWindow > Context
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.
create a window for renderers to draw into
@ mode
Definition: vtkX3D.h:253
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
int vtkIdType
Definition: vtkType.h:338