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 =========================================================================*/
29 #ifndef __vtkPixelBufferObject_h
30 #define __vtkPixelBufferObject_h
31 
32 #include "vtkRenderingOpenGLModule.h" // For export macro
33 #include "vtkObject.h"
34 #include "vtkWeakPointer.h" // needed for vtkWeakPointer.
35 
36 class vtkRenderWindow;
38 
39 class VTKRENDERINGOPENGL_EXPORT vtkPixelBufferObject : public vtkObject
40 {
41 public:
42 
43  //BTX
44  // Usage values.
45  enum
46  {
47  StreamDraw=0,
56  NumberOfUsages
57  };
58  //ETX
59 
60  static vtkPixelBufferObject* New();
62  void PrintSelf(ostream& os, vtkIndent indent);
63 
65 
69  void SetContext(vtkRenderWindow* context);
70  vtkRenderWindow* GetContext();
72 
74 
85  vtkGetMacro(Usage,int);
86  vtkSetMacro(Usage,int);
88 
90 
96  bool Upload1D(int type, void* data,
97  unsigned int numtuples, int comps, vtkIdType increment)
98  {
99  unsigned int newdims[3];
100  newdims[0] = numtuples;
101  newdims[1] = 1;
102  newdims[2] = 1;
103  vtkIdType newinc[3];
104  newinc[0] = increment;
105  newinc[1] = 0;
106  newinc[2] = 0;
107  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
108  }
110 
112 
117  bool Upload2D(int type, void* data,
118  unsigned int dims[2],
119  int comps,
120  vtkIdType increments[2])
121  {
122  unsigned int newdims[3];
123  newdims[0] = dims[0];
124  newdims[1] = dims[1];
125  newdims[2] = 1;
126  vtkIdType newinc[3];
127  newinc[0] = increments[0];
128  newinc[1] = increments[1];
129  newinc[2] = 0;
130  return this->Upload3D(type, data, newdims, comps, newinc,0,0);
131  }
133 
135 
140  bool Upload3D(int type, void* data,
141  unsigned int dims[3], int comps,
142  vtkIdType increments[3],
143  int components,
144  int *componentList);
146 
148 
151  vtkGetMacro(Type, int);
153 
155 
157  vtkGetMacro(Size, unsigned int);
159 
161 
162  vtkGetMacro(Handle, unsigned int);
164 
166 
168  bool Download1D(
169  int type, void* data,
170  unsigned int dim,
171  int numcomps, vtkIdType increment)
172  {
173  unsigned int newdims[3];
174  newdims[0] = dim;
175  newdims[1] = 1;
176  newdims[2] = 1;
177  vtkIdType newincrements[3];
178  newincrements[0] = increment;
179  newincrements[1] = 0;
180  newincrements[2] = 0;
181  return this->Download3D(type, data, newdims, numcomps, newincrements);
182  }
184 
186 
188  bool Download2D(
189  int type, void* data,
190  unsigned int dims[2],
191  int numcomps, vtkIdType increments[2])
192  {
193  unsigned int newdims[3];
194  newdims[0] = dims[0];
195  newdims[1] = dims[1];
196  newdims[2] = 1;
197  vtkIdType newincrements[3];
198  newincrements[0] = increments[0];
199  newincrements[1] = increments[1];
200  newincrements[2] = 0;
201  return this->Download3D(type, data, newdims, numcomps, newincrements);
202  }
204 
206 
208  bool Download3D(int type, void* data,
209  unsigned int dims[3],
210  int numcomps, vtkIdType increments[3]);
212 
214 
215  void BindToPackedBuffer()
216  { this->Bind(PACKED_BUFFER); }
218 
219  void BindToUnPackedBuffer()
220  { this->Bind(UNPACKED_BUFFER); }
221 
223  void UnBind();
224 
225 //BTX
226  // We can't use just PACKED because this is a cygwin macro defined as
227  // __attribute__((packed))
230  UNPACKED_BUFFER
231  };
232 
234  void Bind(BufferType buffer);
235 
237 
238  void Allocate(unsigned int size,
239  int type);
241 
243  void ReleaseMemory();
244 
246  static bool IsSupported(vtkRenderWindow* renWin);
247 
248 //ETX
249 //BTX
250 protected:
253 
256  bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
257 
259  void CreateBuffer();
260 
262  void DestroyBuffer();
263 
264  int Usage;
265  unsigned int BufferTarget; // GLenum
266  int Type;
267  unsigned int Size;
269  unsigned int Handle;
270 private:
271  vtkPixelBufferObject(const vtkPixelBufferObject&); // Not implemented.
272  void operator=(const vtkPixelBufferObject&); // Not implemented.
273  //ETX
274 };
275 
276 #endif
277 
278