VTK  9.0.2
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
47 
48  // append a data array to this VBO, always
49  // copies the data from the data 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);
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
146 
147 protected:
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
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
a simple class to control print indentation
Definition: vtkIndent.h:34
OpenGL buffer object.
manage vertex buffer objects shared within a context
void SetCache(vtkOpenGLVertexBufferObjectCache *cache)
~vtkOpenGLVertexBufferObject() override
virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth)
void UploadDataArray(vtkDataArray *array)
ShiftScaleMethod
Methods for VBO coordinate shift+scale-computation.
@ DISABLE_SHIFT_SCALE
Do not shift/scale point coordinates. Ever!
@ ALWAYS_AUTO_SHIFT_SCALE
Always shift scale using auto computed values.
@ AUTO_SHIFT_SCALE
The default, automatic computation.
virtual const std::vector< double > & GetScale()
virtual void SetScale(const std::vector< double > &scale)
virtual const std::vector< double > & GetShift()
virtual void SetShift(const std::vector< double > &shift)
static vtkOpenGLVertexBufferObject * New()
void AppendDataArray(vtkDataArray *array)
vtkOpenGLVertexBufferObjectCache * Cache
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
record modification and/or execution time
Definition: vtkTimeStamp.h:33
@ scale
Definition: vtkX3D.h:235
OpenGL vertex buffer object.