VTK  9.0.1
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 
61  static vtkPixelBufferObject* New();
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64 
66 
73  void SetContext(vtkRenderWindow* context);
74  vtkRenderWindow* GetContext();
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 
235  bool Download3D(
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);
305  void* MapBuffer(BufferType mode);
307 
312  void UnmapBuffer(BufferType mode);
313 
317  void Allocate(int vtkType, unsigned int numtuples, int comps, BufferType mode);
318 
322  void Allocate(unsigned int nbytes, BufferType mode);
323 
327  void ReleaseMemory();
328 
333  static bool IsSupported(vtkRenderWindow* renWin);
334 
335 protected:
337  ~vtkPixelBufferObject() override;
338 
343  bool LoadRequiredExtensions(vtkRenderWindow* renWin);
344 
348  void CreateBuffer();
349 
353  void DestroyBuffer();
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
vtkPixelBufferObject::Download1D
bool Download1D(int type, void *data, unsigned int dim, int numcomps, vtkIdType increment)
Download data from pixel buffer to the 1D array.
Definition: vtkPixelBufferObject.h:197
vtkPixelBufferObject::BindToPackedBuffer
void BindToPackedBuffer()
Convenience methods for binding.
Definition: vtkPixelBufferObject.h:241
vtkX3D::type
@ type
Definition: vtkX3D.h:522
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkX3D::data
@ data
Definition: vtkX3D.h:321
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkPixelBufferObject::Upload2D
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.
Definition: vtkPixelBufferObject.h:132
vtkPixelBufferObject::StaticCopy
@ StaticCopy
Definition: vtkPixelBufferObject.h:54
vtkPixelBufferObject::StaticRead
@ StaticRead
Definition: vtkPixelBufferObject.h:53
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkPixelBufferObject::MapPackedBuffer
void * MapPackedBuffer()
Convenience api for mapping buffers to app address space.
Definition: vtkPixelBufferObject.h:254
vtkPixelBufferObject::MapUnpackedBuffer
void * MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
Definition: vtkPixelBufferObject.h:265
vtkPixelBufferObject::Download2D
bool Download2D(int type, void *data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
Download data from pixel buffer to the 2D array.
Definition: vtkPixelBufferObject.h:216
detail::Type
Type
Definition: TestQtCommon.h:21
vtkPixelBufferObject::UnmapPackedBuffer
void UnmapPackedBuffer()
Definition: vtkPixelBufferObject.h:281
vtkPixelBufferObject::StreamCopy
@ StreamCopy
Definition: vtkPixelBufferObject.h:51
vtkPixelBufferObject::DynamicRead
@ DynamicRead
Definition: vtkPixelBufferObject.h:56
vtkPixelBufferObject::Components
int Components
Definition: vtkPixelBufferObject.h:358
vtkPixelBufferObject::BufferType
BufferType
Definition: vtkPixelBufferObject.h:285
vtkPixelBufferObject::DynamicCopy
@ DynamicCopy
Definition: vtkPixelBufferObject.h:57
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkPixelBufferObject::StaticDraw
@ StaticDraw
Definition: vtkPixelBufferObject.h:52
vtkPixelBufferObject::Handle
unsigned int Handle
Definition: vtkPixelBufferObject.h:361
vtkPixelBufferObject::MapPackedBuffer
void * MapPackedBuffer(int type, unsigned int numtuples, int comps)
Definition: vtkPixelBufferObject.h:256
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWeakPointer.h
vtkPixelBufferObject::MapUnpackedBuffer
void * MapUnpackedBuffer(unsigned int numbytes)
Definition: vtkPixelBufferObject.h:270
vtkPixelBufferObject::MapPackedBuffer
void * MapPackedBuffer(unsigned int numbytes)
Definition: vtkPixelBufferObject.h:261
vtkPixelBufferObject::StreamRead
@ StreamRead
Definition: vtkPixelBufferObject.h:50
vtkObject.h
vtkPixelBufferObject::MapUnpackedBuffer
void * MapUnpackedBuffer()
Definition: vtkPixelBufferObject.h:263
vtkPixelBufferObject::DynamicDraw
@ DynamicDraw
Definition: vtkPixelBufferObject.h:55
vtkPixelBufferObject::Size
unsigned int Size
Definition: vtkPixelBufferObject.h:359
vtkPixelBufferObject::BindToUnPackedBuffer
void BindToUnPackedBuffer()
Definition: vtkPixelBufferObject.h:243
vtkPixelBufferObject::Type
int Type
Definition: vtkPixelBufferObject.h:357
vtkPixelBufferObject::BufferTarget
unsigned int BufferTarget
Definition: vtkPixelBufferObject.h:356
vtkX3D::mode
@ mode
Definition: vtkX3D.h:253
vtkPixelBufferObject::UnmapUnpackedBuffer
void UnmapUnpackedBuffer()
Convenience api for unmapping buffers from app address space.
Definition: vtkPixelBufferObject.h:279
vtkRenderWindow
create a window for renderers to draw into
Definition: vtkRenderWindow.h:93
vtkPixelBufferObject::Upload1D
bool Upload1D(int type, void *data, unsigned int numtuples, int comps, vtkIdType increment)
Upload data to PBO mapped.
Definition: vtkPixelBufferObject.h:109
vtkPixelBufferObject::Usage
int Usage
Definition: vtkPixelBufferObject.h:355
vtkPixelBufferObject::Context
vtkWeakPointer< vtkRenderWindow > Context
Definition: vtkPixelBufferObject.h:360
vtkPixelBufferObject
abstracts an OpenGL pixel buffer object.
Definition: vtkPixelBufferObject.h:43
vtkWeakPointer< vtkRenderWindow >