Point Cloud Library (PCL)  1.10.0
vtkVertexBufferObject.h
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 =========================================================================*/
15 // .NAME vtkVertexBufferObject - abstracts an OpenGL vertex buffer object.
16 // .SECTION Description
17 // Provides low-level access to GPU memory. Used to pass raw data to GPU.
18 // The data is uploaded into a vertex buffer.
19 // .SECTION See Also
20 // OpenGL Vertex Buffer Object Extension Spec (ARB_vertex_buffer_object):
21 // http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt
22 // .SECTION Caveats
23 // Since most GPUs don't support double format all double data is converted to
24 // float and then uploaded.
25 // DON'T PLAY WITH IT YET.
26 
27 #pragma once
28 
29 #include <vector>
30 
31 #include "vtkObject.h"
32 #include "vtkWeakPointer.h"
33 
34 #include "vtkgl.h" // Needed for gl data types exposed in API
35 #include <pcl/pcl_macros.h>
36 
37 class vtkCellArray;
38 class vtkDataArray;
39 class vtkObject;
40 class vtkPoints;
41 class vtkUnsignedCharArray;
42 class vtkOpenGLExtensionManager;
43 class vtkRenderWindow;
44 
45 class PCL_EXPORTS vtkVertexBufferObject : public vtkObject
46 {
47 public:
48 
49  static vtkVertexBufferObject* New();
50  vtkTypeMacro(vtkVertexBufferObject, vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
53  // Description:
54  // Get/Set the context. Context must be a vtkOpenGLRenderWindow.
55  // This does not increase the reference count of the
56  // context to avoid reference loops.
57  // SetContext() may raise an error is the OpenGL context does not support the
58  // required OpenGL extensions.
59  void SetContext(vtkRenderWindow* context);
60  vtkRenderWindow* GetContext();
61 
62  //BTX
63  // Usage values.
64  enum
65  {
66  StreamDraw=0,
75  NumberOfUsages
76  };
77  //ETX
78 
79  // Description:
80  // Usage is a performance hint.
81  // Valid values are:
82  // - StreamDraw specified once by A, used few times S
83  // - StreamRead specified once by R, queried a few times by A
84  // - StreamCopy specified once by R, used a few times S
85  // - StaticDraw specified once by A, used many times S
86  // - StaticRead specified once by R, queried many times by A
87  // - StaticCopy specified once by R, used many times S
88  // - DynamicDraw respecified repeatedly by A, used many times S
89  // - DynamicRead respecified repeatedly by R, queried many times by A
90  // - DynamicCopy respecified repeatedly by R, used many times S
91  // A: the application
92  // S: as the source for GL drawing and image specification commands.
93  // R: reading data from the GL
94  // Initial value is StaticDraw, as in OpenGL spec.
95  vtkGetMacro(Usage, int);
96  vtkSetMacro(Usage, int);
97 
98  int GetAttributeIndex();
99  void SetUserDefinedAttribute(int index, bool normalized=false, int stride=0);
100  void ResetUserDefinedAttribute();
101 
102  void SetAttributeNormalized(bool normalized);
103 
104  // Description:
105  // Set point data
106  bool Upload(vtkPoints *points);
107 
108  // Description:
109  // Set indice data
110  bool Upload(vtkCellArray *verts);
111 
112  // Description:
113  // Set indice data
114  bool Upload(unsigned int *indices, unsigned int count);
115 
116  // Description:
117  // Set color data
118  bool Upload(vtkUnsignedCharArray *colors);
119 
120  // Description:
121  // Set color data
122  bool Upload(vtkDataArray *array);
123  bool Upload(vtkDataArray *array, int attributeType, int arrayType);
124  bool UploadNormals(vtkDataArray *normals);
125  bool UploadColors(vtkDataArray *colors);
126 
127 
128  // Description:
129  // Get the size of the data loaded into the GPU. Size is in the number of
130  // elements of the uploaded Type.
131  vtkGetMacro(Size, unsigned int);
132 
133  // Description:
134  // Get the size of the data loaded into the GPU. Size is in the number of
135  // elements of the uploaded Type.
136  vtkGetMacro(Count, unsigned int);
137 
138  // Description:
139  // Get the openGL buffer handle.
140  vtkGetMacro(Handle, unsigned int);
141 
142  // Description:
143  // Inactivate the buffer.
144  void UnBind();
145 
146  // Description:
147  // Make the buffer active.
148  void Bind();
149 
150  // Description:
151  // Allocate the memory. size is in number of bytes. type is a VTK type.
152 // void Allocate(unsigned int size, int type);
153 
154 //BTX
155 
156  // Description:
157  // Release the memory allocated without destroying the PBO handle.
158  void ReleaseMemory();
159 
160  // Description:
161  // Returns if the context supports the required extensions.
162  static bool IsSupported(vtkRenderWindow* renWin);
163 
164 //ETX
165 //BTX
166 protected:
169 
170  // Description:
171  // Loads all required OpenGL extensions. Must be called every time a new
172  // context is set.
173  bool LoadRequiredExtensions(vtkOpenGLExtensionManager* mgr);
174 
175  // Description:
176  // Create the pixel buffer object.
177  void CreateBuffer();
178 
179  // Description:
180  // Destroys the pixel buffer object.
181  void DestroyBuffer();
182 
183  // Description:
184  // Uploads data to buffer object
185  bool Upload(GLvoid* data);
186 
187  // Description:
188  // Get the openGL buffer handle.
189  vtkGetMacro(ArrayType, unsigned int);
190 
191  int Usage;
192  unsigned int Size;
193  unsigned int Count;
194  unsigned int Handle;
195  unsigned int ArrayType;
196  unsigned int BufferTarget;
197 
203 
204  vtkWeakPointer<vtkRenderWindow> Context;
205 
206 
207 private:
208  vtkVertexBufferObject(const vtkVertexBufferObject&); // Not implemented.
209  void operator=(const vtkVertexBufferObject&); // Not implemented.
210 
211  // Helper to get data type sizes when passing to opengl
212  int GetDataTypeSize(int type);
213  //ETX
214 };
vtkVertexBufferObject::AttributeIndex
int AttributeIndex
Definition: vtkVertexBufferObject.h:198
pcl_macros.h
Defines all the PCL and non-PCL macros used.
vtkVertexBufferObject::AttributeStride
int AttributeStride
Definition: vtkVertexBufferObject.h:202
vtkVertexBufferObject::StaticDraw
@ StaticDraw
Definition: vtkVertexBufferObject.h:69
vtkVertexBufferObject::AttributeType
int AttributeType
Definition: vtkVertexBufferObject.h:200
vtkVertexBufferObject::Context
vtkWeakPointer< vtkRenderWindow > Context
Definition: vtkVertexBufferObject.h:204
vtkVertexBufferObject::DynamicRead
@ DynamicRead
Definition: vtkVertexBufferObject.h:73
vtkVertexBufferObject::Usage
int Usage
Definition: vtkVertexBufferObject.h:191
vtkVertexBufferObject::Count
unsigned int Count
Definition: vtkVertexBufferObject.h:193
vtkVertexBufferObject::AttributeSize
int AttributeSize
Definition: vtkVertexBufferObject.h:199
vtkVertexBufferObject::Handle
unsigned int Handle
Definition: vtkVertexBufferObject.h:194
vtkVertexBufferObject
Definition: vtkVertexBufferObject.h:45
vtkVertexBufferObject::DynamicCopy
@ DynamicCopy
Definition: vtkVertexBufferObject.h:74
vtkVertexBufferObject::AttributeNormalized
int AttributeNormalized
Definition: vtkVertexBufferObject.h:201
vtkVertexBufferObject::StreamCopy
@ StreamCopy
Definition: vtkVertexBufferObject.h:68
vtkVertexBufferObject::StreamRead
@ StreamRead
Definition: vtkVertexBufferObject.h:67
vtkVertexBufferObject::BufferTarget
unsigned int BufferTarget
Definition: vtkVertexBufferObject.h:196
vtkVertexBufferObject::DynamicDraw
@ DynamicDraw
Definition: vtkVertexBufferObject.h:72
vtkVertexBufferObject::ArrayType
unsigned int ArrayType
Definition: vtkVertexBufferObject.h:195
vtkVertexBufferObject::Size
unsigned int Size
Definition: vtkVertexBufferObject.h:192
vtkVertexBufferObject::StaticCopy
@ StaticCopy
Definition: vtkVertexBufferObject.h:71
vtkVertexBufferObject::StaticRead
@ StaticRead
Definition: vtkVertexBufferObject.h:70
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:253