VTK  9.0.1
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 
21 
29 // useful union for stuffing colors into a float
31  unsigned char c[4];
32  short s[2];
33  float f;
34 };
35 
36 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexBufferObject : public vtkOpenGLBufferObject
37 {
38 public:
41  void PrintSelf(ostream& os, vtkIndent indent) override;
42 
43  // set the VBOs data to the provided data array and upload
44  // this can use a fast path of just passing the
45  // data array pointer to OpenGL if it is suitable
46  void UploadDataArray(vtkDataArray* array);
47 
48  // append a data array to this VBO, always
49  // copies the data from the data array
50  void AppendDataArray(vtkDataArray* array);
51 
52  // Get the mtime when this VBO was loaded
53  vtkGetMacro(UploadTime, vtkTimeStamp);
54 
73  {
77  MANUAL_SHIFT_SCALE
78  };
79 
80  // Description:
81  // Get the shift and scale vectors computed by CreateVBO;
82  // or set the values CreateVBO and AppendVBO will use.
83  // Note that the "Set" methods **must** be called before the
84  // first time that CreateVBO or AppendVBO is invoked and
85  // should never be called afterwards.
86  //
87  // The CoordShiftAndScaleMethod describes how the shift
88  // and scale vectors are obtained (or that they should never
89  // be used).
90  // The GetCoordShiftAndScaleEnabled() method returns true if
91  // a shift and scale are currently being applied (or false if not).
92  //
93  // The "Get" methods are used by the mapper to modify the world
94  // and camera transformation matrices to match the scaling applied
95  // to coordinates in the VBO.
96  // CreateVBO only applies a shift and scale when the midpoint
97  // of the point bounding-box is distant from the origin by a
98  // factor of 10,000 or more relative to the size of the box
99  // along any axis.
100  //
101  // For example, if the x coordinates of the points range from
102  // 200,000 to 200,001 then the factor is
103  // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
104  // than 10,000 -- so the coordinates will be shifted and scaled.
105  //
106  // This is important as many OpenGL drivers use reduced precision
107  // to hold point coordinates.
108  //
109  // These methods are used by the mapper to determine the
110  // additional transform (if any) to apply to the rendering transform.
111  vtkGetMacro(CoordShiftAndScaleEnabled, bool);
112  vtkGetMacro(CoordShiftAndScaleMethod, ShiftScaleMethod);
113  virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth);
114  virtual void SetShift(const std::vector<double>& shift);
115  virtual void SetScale(const std::vector<double>& scale);
116  virtual const std::vector<double>& GetShift();
117  virtual const std::vector<double>& GetScale();
118 
119  // Set/Get the DataType to use for the VBO
120  // As a side effect sets the DataTypeSize
121  void SetDataType(int v);
122  vtkGetMacro(DataType, int);
123 
124  // Get the size in bytes of the data type
125  vtkGetMacro(DataTypeSize, unsigned int);
126 
127  // How many tuples in the VBO
128  vtkGetMacro(NumberOfTuples, unsigned int);
129 
130  // How many components in the VBO
131  vtkGetMacro(NumberOfComponents, unsigned int);
132 
133  // Set/Get the VBO stride in bytes
134  vtkSetMacro(Stride, unsigned int);
135  vtkGetMacro(Stride, unsigned int);
136 
137  // Get the underlying VBO array
138  std::vector<float>& GetPackedVBO() { return this->PackedVBO; }
139 
140  // upload the current PackedVBO
141  // only used by mappers that skip the VBOGroup support
142  void UploadVBO();
143 
144  // VBOs may hold onto the cache, never the other way around
145  void SetCache(vtkOpenGLVertexBufferObjectCache* cache);
146 
147 protected:
149  ~vtkOpenGLVertexBufferObject() override;
150 
151  std::vector<float> PackedVBO; // the data
152 
154 
155  unsigned int Stride; // The size of a complete tuple
156  unsigned int NumberOfComponents;
157  unsigned int NumberOfTuples;
158  int DataType;
159  unsigned int DataTypeSize;
160 
163  std::vector<double> Shift;
164  std::vector<double> Scale;
165 
167 
168 private:
170  void operator=(const vtkOpenGLVertexBufferObject&) = delete;
171 };
172 
173 #endif
vtkOpenGLVertexBufferObject::Scale
std::vector< double > Scale
Definition: vtkOpenGLVertexBufferObject.h:164
vtkOpenGLVertexBufferObject::Shift
std::vector< double > Shift
Definition: vtkOpenGLVertexBufferObject.h:163
vtkFourByteUnion::c
unsigned char c[4]
Definition: vtkOpenGLVertexBufferObject.h:31
vtkOpenGLVertexBufferObject::PackedVBO
std::vector< float > PackedVBO
Definition: vtkOpenGLVertexBufferObject.h:151
vtkOpenGLBufferObject::New
static vtkOpenGLBufferObject * New()
vtkOpenGLBufferObject
OpenGL buffer object.
Definition: vtkOpenGLBufferObject.h:33
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkOpenGLVertexBufferObject::GetPackedVBO
std::vector< float > & GetPackedVBO()
Definition: vtkOpenGLVertexBufferObject.h:138
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkOpenGLVertexBufferObject::UploadTime
vtkTimeStamp UploadTime
Definition: vtkOpenGLVertexBufferObject.h:153
vtkFourByteUnion::s
short s[2]
Definition: vtkOpenGLVertexBufferObject.h:32
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkOpenGLVertexBufferObject::CoordShiftAndScaleEnabled
bool CoordShiftAndScaleEnabled
Definition: vtkOpenGLVertexBufferObject.h:162
vtkOpenGLVertexBufferObject::CoordShiftAndScaleMethod
ShiftScaleMethod CoordShiftAndScaleMethod
Definition: vtkOpenGLVertexBufferObject.h:161
vtkOpenGLVertexBufferObject::NumberOfComponents
unsigned int NumberOfComponents
Definition: vtkOpenGLVertexBufferObject.h:156
vtkOpenGLVertexBufferObject::DataTypeSize
unsigned int DataTypeSize
Definition: vtkOpenGLVertexBufferObject.h:159
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkFourByteUnion
OpenGL vertex buffer object.
Definition: vtkOpenGLVertexBufferObject.h:30
vtkOpenGLVertexBufferObject::Stride
unsigned int Stride
Definition: vtkOpenGLVertexBufferObject.h:155
vtkOpenGLVertexBufferObject
Definition: vtkOpenGLVertexBufferObject.h:36
vtkOpenGLVertexBufferObject::ALWAYS_AUTO_SHIFT_SCALE
@ ALWAYS_AUTO_SHIFT_SCALE
Always shift scale using auto computed values.
Definition: vtkOpenGLVertexBufferObject.h:76
vtkOpenGLVertexBufferObject::NumberOfTuples
unsigned int NumberOfTuples
Definition: vtkOpenGLVertexBufferObject.h:157
vtkOpenGLVertexBufferObject::ShiftScaleMethod
ShiftScaleMethod
Methods for VBO coordinate shift+scale-computation.
Definition: vtkOpenGLVertexBufferObject.h:72
vtkOpenGLBufferObject.h
vtkOpenGLVertexBufferObject::AUTO_SHIFT_SCALE
@ AUTO_SHIFT_SCALE
The default, automatic computation.
Definition: vtkOpenGLVertexBufferObject.h:75
vtkOpenGLVertexBufferObjectCache
manage vertex buffer objects shared within a context
Definition: vtkOpenGLVertexBufferObjectCache.h:38
vtkOpenGLVertexBufferObject::DISABLE_SHIFT_SCALE
@ DISABLE_SHIFT_SCALE
Do not shift/scale point coordinates. Ever!
Definition: vtkOpenGLVertexBufferObject.h:74
vtkFourByteUnion::f
float f
Definition: vtkOpenGLVertexBufferObject.h:33
vtkOpenGLVertexBufferObject::DataType
int DataType
Definition: vtkOpenGLVertexBufferObject.h:158
vtkOpenGLVertexBufferObject::Cache
vtkOpenGLVertexBufferObjectCache * Cache
Definition: vtkOpenGLVertexBufferObject.h:166
vtkOpenGLBufferObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.