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