VTK  9.0.20200807
vtkOpenGLVertexBufferObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4 
5  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkOpenGLVertexBufferObject_h
15 #define vtkOpenGLVertexBufferObject_h
16 
17 #include "vtkOpenGLBufferObject.h"
18 #include "vtkRenderingOpenGL2Module.h" // for export macro
19 #include "vtkWeakPointer.h" // For vtkWeakPointer
20 
22 
30 // useful union for stuffing colors into a float
32  unsigned char c[4];
33  short s[2];
34  float f;
35 };
36 
37 class vtkCamera;
38 class vtkProp3D;
39 
40 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexBufferObject : public vtkOpenGLBufferObject
41 {
42 public:
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
47  // set the VBOs data to the provided data array and upload
48  // this can use a fast path of just passing the
49  // data array pointer to OpenGL if it is suitable
50  void UploadDataArray(vtkDataArray* array);
51 
52  // append a data array to this VBO, always
53  // copies the data from the data array
54  void AppendDataArray(vtkDataArray* array);
55 
56  // Get the mtime when this VBO was loaded
57  vtkGetMacro(UploadTime, vtkTimeStamp);
58 
80  {
87  FOCAL_POINT_SHIFT_SCALE
88  };
89 
90  // Description:
91  // Get the shift and scale vectors computed by CreateVBO;
92  // or set the values CreateVBO and AppendVBO will use.
93  // Note that the "Set" methods **must** be called before the
94  // first time that CreateVBO or AppendVBO is invoked and
95  // should never be called afterwards.
96  //
97  // The CoordShiftAndScaleMethod describes how the shift
98  // and scale vectors are obtained (or that they should never
99  // be used).
100  // The GetCoordShiftAndScaleEnabled() method returns true if
101  // a shift and scale are currently being applied (or false if not).
102  //
103  // The "Get" methods are used by the mapper to modify the world
104  // and camera transformation matrices to match the scaling applied
105  // to coordinates in the VBO.
106  // CreateVBO only applies a shift and scale when the midpoint
107  // of the point bounding-box is distant from the origin by a
108  // factor of 10,000 or more relative to the size of the box
109  // along any axis.
110  //
111  // For example, if the x coordinates of the points range from
112  // 200,000 to 200,001 then the factor is
113  // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
114  // than 10,000 -- so the coordinates will be shifted and scaled.
115  //
116  // This is important as many OpenGL drivers use reduced precision
117  // to hold point coordinates.
118  //
119  // These methods are used by the mapper to determine the
120  // additional transform (if any) to apply to the rendering transform.
121  vtkGetMacro(CoordShiftAndScaleEnabled, bool);
122  vtkGetMacro(CoordShiftAndScaleMethod, ShiftScaleMethod);
123  virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth);
124  virtual void SetShift(const std::vector<double>& shift);
125  virtual void SetShift(double x, double y, double z);
126  virtual void SetScale(const std::vector<double>& scale);
127  virtual void SetScale(double x, double y, double z);
128  virtual const std::vector<double>& GetShift();
129  virtual const std::vector<double>& GetScale();
130 
131  // update the shift scale if needed
132  void UpdateShiftScale(vtkDataArray* da);
133 
134  // Set/Get the DataType to use for the VBO
135  // As a side effect sets the DataTypeSize
136  void SetDataType(int v);
137  vtkGetMacro(DataType, int);
138 
139  // Get the size in bytes of the data type
140  vtkGetMacro(DataTypeSize, unsigned int);
141 
142  // How many tuples in the VBO
143  vtkGetMacro(NumberOfTuples, unsigned int);
144 
145  // How many components in the VBO
146  vtkGetMacro(NumberOfComponents, unsigned int);
147 
148  // Set/Get the VBO stride in bytes
149  vtkSetMacro(Stride, unsigned int);
150  vtkGetMacro(Stride, unsigned int);
151 
152  // Get the underlying VBO array
153  std::vector<float>& GetPackedVBO() { return this->PackedVBO; }
154 
155  // upload the current PackedVBO
156  // only used by mappers that skip the VBOGroup support
157  void UploadVBO();
158 
159  // VBOs may hold onto the cache, never the other way around
160  void SetCache(vtkOpenGLVertexBufferObjectCache* cache);
161 
162  // used by mappers that support camera based shift scale
163  virtual void SetCamera(vtkCamera* cam);
164  virtual void SetProp3D(vtkProp3D* prop3d);
165 
166 protected:
168  ~vtkOpenGLVertexBufferObject() override;
169 
170  std::vector<float> PackedVBO; // the data
171 
173 
174  unsigned int Stride; // The size of a complete tuple
175  unsigned int NumberOfComponents;
176  unsigned int NumberOfTuples;
177  int DataType;
178  unsigned int DataTypeSize;
179 
182  std::vector<double> Shift;
183  std::vector<double> Scale;
184 
186 
189 
190 private:
192  void operator=(const vtkOpenGLVertexBufferObject&) = delete;
193 };
194 
195 #endif
vtkOpenGLVertexBufferObject::Scale
std::vector< double > Scale
Definition: vtkOpenGLVertexBufferObject.h:183
vtkOpenGLVertexBufferObject::Shift
std::vector< double > Shift
Definition: vtkOpenGLVertexBufferObject.h:182
vtkFourByteUnion::c
unsigned char c[4]
Definition: vtkOpenGLVertexBufferObject.h:32
vtkOpenGLVertexBufferObject::PackedVBO
std::vector< float > PackedVBO
Definition: vtkOpenGLVertexBufferObject.h:170
vtkOpenGLBufferObject::New
static vtkOpenGLBufferObject * New()
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkX3D::scale
Definition: vtkX3D.h:235
vtkOpenGLVertexBufferObject::GetPackedVBO
std::vector< float > & GetPackedVBO()
Definition: vtkOpenGLVertexBufferObject.h:153
vtkProp3D
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:43
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkOpenGLVertexBufferObject::UploadTime
vtkTimeStamp UploadTime
Definition: vtkOpenGLVertexBufferObject.h:172
vtkFourByteUnion::s
short s[2]
Definition: vtkOpenGLVertexBufferObject.h:33
vtkOpenGLVertexBufferObject::Prop3D
vtkWeakPointer< vtkProp3D > Prop3D
Definition: vtkOpenGLVertexBufferObject.h:188
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkOpenGLVertexBufferObject::CoordShiftAndScaleEnabled
bool CoordShiftAndScaleEnabled
Definition: vtkOpenGLVertexBufferObject.h:181
vtkOpenGLVertexBufferObject::CoordShiftAndScaleMethod
ShiftScaleMethod CoordShiftAndScaleMethod
Definition: vtkOpenGLVertexBufferObject.h:180
vtkOpenGLVertexBufferObject::NumberOfComponents
unsigned int NumberOfComponents
Definition: vtkOpenGLVertexBufferObject.h:175
vtkOpenGLVertexBufferObject::DataTypeSize
unsigned int DataTypeSize
Definition: vtkOpenGLVertexBufferObject.h:178
vtkOpenGLVertexBufferObject::AUTO_SHIFT
Only Apply the shift.
Definition: vtkOpenGLVertexBufferObject.h:85
vtkOpenGLVertexBufferObject::Camera
vtkWeakPointer< vtkCamera > Camera
Definition: vtkOpenGLVertexBufferObject.h:187
vtkOpenGLVertexBufferObject::MANUAL_SHIFT_SCALE
Manual shift/scale (for use with AppendVBO)
Definition: vtkOpenGLVertexBufferObject.h:84
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkFourByteUnion
OpenGL vertex buffer object.
Definition: vtkOpenGLVertexBufferObject.h:31
vtkCamera
a virtual camera for 3D rendering
Definition: vtkCamera.h:45
vtkOpenGLVertexBufferObject::Stride
unsigned int Stride
Definition: vtkOpenGLVertexBufferObject.h:174
vtkOpenGLVertexBufferObject::NEAR_PLANE_SHIFT_SCALE
Shift scale based on camera settings.
Definition: vtkOpenGLVertexBufferObject.h:86
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:40
vtkWeakPointer.h
vtkOpenGLVertexBufferObject::ALWAYS_AUTO_SHIFT_SCALE
Always shift scale using auto computed values.
Definition: vtkOpenGLVertexBufferObject.h:83
vtkOpenGLVertexBufferObject::NumberOfTuples
unsigned int NumberOfTuples
Definition: vtkOpenGLVertexBufferObject.h:176
vtkOpenGLVertexBufferObject::ShiftScaleMethod
ShiftScaleMethod
Methods for VBO coordinate shift+scale-computation.
Definition: vtkOpenGLVertexBufferObject.h:79
vtkOpenGLBufferObject.h
vtkOpenGLVertexBufferObject::AUTO_SHIFT_SCALE
The default, automatic computation.
Definition: vtkOpenGLVertexBufferObject.h:82
vtkOpenGLVertexBufferObjectCache
manage vertex buffer objects shared within a context
Definition: vtkOpenGLVertexBufferObjectCache.h:38
vtkOpenGLVertexBufferObject::DISABLE_SHIFT_SCALE
Do not shift/scale point coordinates. Ever!
Definition: vtkOpenGLVertexBufferObject.h:81
vtkFourByteUnion::f
float f
Definition: vtkOpenGLVertexBufferObject.h:34
vtkOpenGLVertexBufferObject::DataType
int DataType
Definition: vtkOpenGLVertexBufferObject.h:177
vtkWeakPointer< vtkCamera >
vtkOpenGLVertexBufferObject::Cache
vtkOpenGLVertexBufferObjectCache * Cache
Definition: vtkOpenGLVertexBufferObject.h:185
vtkOpenGLBufferObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.