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:
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 
78  MANUAL_SHIFT_SCALE
79  };
80 
81  // Description:
82  // Get the shift and scale vectors computed by CreateVBO;
83  // or set the values CreateVBO and AppendVBO will use.
84  // Note that the "Set" methods **must** be called before the
85  // first time that CreateVBO or AppendVBO is invoked and
86  // should never be called afterwards.
87  //
88  // The CoordShiftAndScaleMethod describes how the shift
89  // and scale vectors are obtained (or that they should never
90  // be used).
91  // The GetCoordShiftAndScaleEnabled() method returns true if
92  // a shift and scale are currently being applied (or false if not).
93  //
94  // The "Get" methods are used by the mapper to modify the world
95  // and camera transformation matrices to match the scaling applied
96  // to coordinates in the VBO.
97  // CreateVBO only applies a shift and scale when the midpoint
98  // of the point bounding-box is distant from the origin by a
99  // factor of 10,000 or more relative to the size of the box
100  // along any axis.
101  //
102  // For example, if the x coordinates of the points range from
103  // 200,000 to 200,001 then the factor is
104  // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
105  // than 10,000 -- so the coordinates will be shifted and scaled.
106  //
107  // This is important as many OpenGL drivers use reduced precision
108  // to hold point coordinates.
109  //
110  // These methods are used by the mapper to determine the
111  // additional transform (if any) to apply to the rendering transform.
112  vtkGetMacro(CoordShiftAndScaleEnabled,bool);
113  vtkGetMacro(CoordShiftAndScaleMethod,ShiftScaleMethod);
114  virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth);
115  virtual void SetShift(const std::vector<double>& shift);
116  virtual void SetScale(const std::vector<double>& scale);
117  virtual const std::vector<double>& GetShift();
118  virtual const std::vector<double>& GetScale();
119 
120  // Set/Get the DataType to use for the VBO
121  // As a side effect sets the DataTypeSize
122  void SetDataType(int v);
123  vtkGetMacro(DataType, int);
124 
125  // Get the size in bytes of the data type
126  vtkGetMacro(DataTypeSize, unsigned int);
127 
128  // How many tuples in the VBO
129  vtkGetMacro(NumberOfTuples, unsigned int);
130 
131  // How many components in the VBO
132  vtkGetMacro(NumberOfComponents, unsigned int);
133 
134  // Set/Get the VBO stride in bytes
135  vtkSetMacro(Stride, unsigned int);
136  vtkGetMacro(Stride, unsigned int);
137 
138  // Get the underlying VBO array
139  std::vector<float> &GetPackedVBO() {
140  return this->PackedVBO; }
141 
142  // upload the current PackedVBO
143  // only used by mappers that skip the VBOGroup support
144  void UploadVBO();
145 
146  // VBOs may hold onto the cache, never the other way around
147  void SetCache(vtkOpenGLVertexBufferObjectCache *cache);
148 
149 protected:
151  ~vtkOpenGLVertexBufferObject() override;
152 
153  std::vector<float> PackedVBO; // the data
154 
156 
157  unsigned int Stride; // The size of a complete tuple
158  unsigned int NumberOfComponents;
159  unsigned int NumberOfTuples;
160  int DataType;
161  unsigned int DataTypeSize;
162 
165  std::vector<double> Shift;
166  std::vector<double> Scale;
167 
169 
170 private:
172  void operator=(const vtkOpenGLVertexBufferObject&) = delete;
173 };
174 
175 #endif
OpenGL vertex buffer object.
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkOpenGLVertexBufferObjectCache * Cache
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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
static vtkOpenGLBufferObject * New()
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
OpenGL buffer object.