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
40class vtkRenderWindow;
42
43class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
44{
45public:
46
47 // Usage values.
48 enum
49 {
50 StreamDraw=0,
59 NumberOfUsages
60 };
61
64 void PrintSelf(ostream& os, vtkIndent indent);
65
67
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);
322
328
333 int vtkType,
334 unsigned int numtuples,
335 int comps,
337
342 unsigned int nbytes,
344
349
354 static bool IsSupported(vtkRenderWindow* renWin);
355
356protected:
359
365
370
375
376 int Usage;
377 unsigned int BufferTarget; // GLenum
378 int Type;
380 unsigned int Size;
382 unsigned int Handle;
383private:
384 vtkPixelBufferObject(const vtkPixelBufferObject&) VTK_DELETE_FUNCTION;
385 void operator=(const vtkPixelBufferObject&) VTK_DELETE_FUNCTION;
386
387};
388
389#endif
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
Interface class for querying and using OpenGL extensions.
abstracts an OpenGL pixel buffer object.
void SetSize(unsigned int nTups, int nComps)
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
static bool IsSupported(vtkRenderWindow *renWin)
Returns if the context supports the required extensions.
void * MapBuffer(int type, unsigned int numtuples, int comps, BufferType mode)
Map the buffer to our addresspace.
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()
Inactivate 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.
bool LoadRequiredExtensions(vtkRenderWindow *renWin)
Loads all required OpenGL extensions.
void * MapBuffer(unsigned int numbytes, BufferType mode)
void * MapBuffer(BufferType mode)
void * MapUnpackedBuffer(int type, unsigned int numtuples, int comps)
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 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 * MapPackedBuffer(int type, unsigned int numtuples, int comps)
void BindToPackedBuffer()
Convenience methods for binding.
void SetContext(vtkRenderWindow *context)
Get/Set the context.
void Allocate(int vtkType, unsigned int numtuples, int comps, BufferType mode)
Allocate PACKED/UNPACKED memory to hold numTuples*numComponents of vtkType.
vtkWeakPointer< vtkRenderWindow > Context
void CreateBuffer()
Create the pixel buffer object.
void * MapPackedBuffer(unsigned int numbytes)
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.
static vtkPixelBufferObject * New()
void * MapPackedBuffer()
Convenience api for mapping buffers to app address space.
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.
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:247
@ type
Definition: vtkX3D.h:516
@ data
Definition: vtkX3D.h:315
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287