VTK  9.3.1
vtkPixelBufferObject.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
21 #ifndef vtkPixelBufferObject_h
22 #define vtkPixelBufferObject_h
23 
24 #include "vtkObject.h"
25 #include "vtkRenderingOpenGL2Module.h" // For export macro
26 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
27 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkRenderWindow;
30 class vtkOpenGLExtensionManager;
31 
32 class VTKRENDERINGOPENGL2_EXPORT vtkPixelBufferObject : public vtkObject
33 {
34 public:
35  // Usage values.
36  enum
37  {
38  StreamDraw = 0,
47  NumberOfUsages
48  };
49 
50  static vtkPixelBufferObject* New();
52  void PrintSelf(ostream& os, vtkIndent indent) override;
53 
55 
62  void SetContext(vtkRenderWindow* context);
63  vtkRenderWindow* GetContext();
65 
67 
84  vtkGetMacro(Usage, int);
85  vtkSetMacro(Usage, int);
87 
89 
98  bool Upload1D(int type, void* data, unsigned int numtuples, int comps, vtkIdType increment)
99  {
100  unsigned int newdims[3];
101  newdims[0] = numtuples;
102  newdims[1] = 1;
103  newdims[2] = 1;
104  vtkIdType newinc[3];
105  newinc[0] = increment;
106  newinc[1] = 0;
107  newinc[2] = 0;
108  return this->Upload3D(type, data, newdims, comps, newinc, 0, nullptr);
109  }
111 
113 
121  bool Upload2D(int type, void* data, unsigned int dims[2], int comps, vtkIdType increments[2])
122  {
123  unsigned int newdims[3];
124  newdims[0] = dims[0];
125  newdims[1] = dims[1];
126  newdims[2] = 1;
127  vtkIdType newinc[3];
128  newinc[0] = increments[0];
129  newinc[1] = increments[1];
130  newinc[2] = 0;
131  return this->Upload3D(type, data, newdims, comps, newinc, 0, nullptr);
132  }
134 
143  bool Upload3D(int type, void* data, unsigned int dims[3], int comps, vtkIdType increments[3],
144  int components, int* componentList);
145 
147 
152  vtkGetMacro(Type, int);
153  vtkSetMacro(Type, int);
155 
157 
160  vtkGetMacro(Components, int);
161  vtkSetMacro(Components, int);
163 
165 
169  vtkGetMacro(Size, unsigned int);
170  vtkSetMacro(Size, unsigned int);
171  void SetSize(unsigned int nTups, int nComps);
173 
175 
178  vtkGetMacro(Handle, unsigned int);
180 
182 
186  bool Download1D(int type, void* data, unsigned int dim, int numcomps, vtkIdType increment)
187  {
188  unsigned int newdims[3];
189  newdims[0] = dim;
190  newdims[1] = 1;
191  newdims[2] = 1;
192  vtkIdType newincrements[3];
193  newincrements[0] = increment;
194  newincrements[1] = 0;
195  newincrements[2] = 0;
196  return this->Download3D(type, data, newdims, numcomps, newincrements);
197  }
199 
201 
205  bool Download2D(int type, void* data, unsigned int dims[2], int numcomps, vtkIdType increments[2])
206  {
207  unsigned int newdims[3];
208  newdims[0] = dims[0];
209  newdims[1] = dims[1];
210  newdims[2] = 1;
211  vtkIdType newincrements[3];
212  newincrements[0] = increments[0];
213  newincrements[1] = increments[1];
214  newincrements[2] = 0;
215  return this->Download3D(type, data, newdims, numcomps, newincrements);
216  }
218 
224  bool Download3D(
225  int type, void* data, unsigned int dims[3], int numcomps, vtkIdType increments[3]);
226 
230  void BindToPackedBuffer() { this->Bind(PACKED_BUFFER); }
231 
232  void BindToUnPackedBuffer() { this->Bind(UNPACKED_BUFFER); }
233 
237  void UnBind();
238 
243  void* MapPackedBuffer() { return this->MapBuffer(PACKED_BUFFER); }
244 
245  void* MapPackedBuffer(int type, unsigned int numtuples, int comps)
246  {
247  return this->MapBuffer(type, numtuples, comps, PACKED_BUFFER);
248  }
249 
250  void* MapPackedBuffer(unsigned int numbytes) { return this->MapBuffer(numbytes, PACKED_BUFFER); }
251 
252  void* MapUnpackedBuffer() { return this->MapBuffer(UNPACKED_BUFFER); }
253 
254  void* MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
255  {
256  return this->MapBuffer(type, numtuples, comps, UNPACKED_BUFFER);
257  }
258 
259  void* MapUnpackedBuffer(unsigned int numbytes)
260  {
261  return this->MapBuffer(numbytes, UNPACKED_BUFFER);
262  }
263 
268  void UnmapUnpackedBuffer() { this->UnmapBuffer(UNPACKED_BUFFER); }
269 
270  void UnmapPackedBuffer() { this->UnmapBuffer(PACKED_BUFFER); }
271 
272  // PACKED_BUFFER for download APP<-PBO
273  // UNPACKED_BUFFER for upload APP->PBO
275  {
276  UNPACKED_BUFFER = 0,
277  PACKED_BUFFER
278  };
279 
283  void Bind(BufferType buffer);
284 
286 
292  void* MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode);
293  void* MapBuffer(unsigned int numbytes, BufferType mode);
294  void* MapBuffer(BufferType mode);
296 
301  void UnmapBuffer(BufferType mode);
302 
306  void Allocate(int vtkType, unsigned int numtuples, int comps, BufferType mode);
307 
311  void Allocate(unsigned int nbytes, BufferType mode);
312 
316  void ReleaseMemory();
317 
322  static bool IsSupported(vtkRenderWindow* renWin);
323 
324 protected:
326  ~vtkPixelBufferObject() override;
327 
332  bool LoadRequiredExtensions(vtkRenderWindow* renWin);
333 
337  void CreateBuffer();
338 
342  void DestroyBuffer();
343 
344  int Usage;
345  unsigned int BufferTarget; // GLenum
346  int Type;
348  unsigned int Size;
350  unsigned int Handle;
351 
352 private:
354  void operator=(const vtkPixelBufferObject&) = delete;
355 };
356 
357 VTK_ABI_NAMESPACE_END
358 #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.
vtkWeakPointer< vtkRenderWindow > Context
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:315
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:28
abstracts an OpenGL pixel buffer object.
void * MapPackedBuffer(unsigned int numbytes)
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.