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) VTK_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 
60  bool DoesArrayConformToVBO(vtkDataArray * array);
61 
66  void InitVBO(vtkDataArray * array, int destType);
67 
68  void UploadVBO();
69  vtkGetMacro(UploadTime,vtkTimeStamp);
70 
91  MANUAL_SHIFT_SCALE
92  };
93 
94  // Description:
95  // Get the shift and scale vectors computed by CreateVBO;
96  // or set the values CreateVBO and AppendVBO will use.
97  // Note that the "Set" methods **must** be called before the
98  // first time that CreateVBO or AppendVBO is invoked and
99  // should never be called afterwards.
100  //
101  // The CoordShiftAndScaleMethod describes how the shift
102  // and scale vectors are obtained (or that they should never
103  // be used).
104  // The GetCoordShiftAndScaleEnabled() method returns true if
105  // a shift and scale are currently being applied (or false if not).
106  //
107  // The "Get" methods are used by the mapper to modify the world
108  // and camera transformation matrices to match the scaling applied
109  // to coordinates in the VBO.
110  // CreateVBO only applies a shift and scale when the midpoint
111  // of the point bounding-box is distant from the origin by a
112  // factor of 10,000 or more relative to the size of the box
113  // along any axis.
114  //
115  // For example, if the x coordinates of the points range from
116  // 200,000 to 200,001 then the factor is
117  // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
118  // than 10,000 -- so the coordinates will be shifted and scaled.
119  //
120  // This is important as many OpenGL drivers use reduced precision
121  // to hold point coordinates.
122  //
123  // These methods are used by the mapper to determine the
124  // additional transform (if any) to apply to the rendering transform.
125  vtkGetMacro(CoordShiftAndScaleEnabled,bool);
126  vtkGetMacro(CoordShiftAndScaleMethod,ShiftScaleMethod);
127  virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth);
128  virtual void SetShift(const std::vector<double>& shift);
129  virtual void SetScale(const std::vector<double>& scale);
130  virtual const std::vector<double>& GetShift();
131  virtual const std::vector<double>& GetScale();
132 
133  std::vector<float> PackedVBO; // the data
135  unsigned int Stride; // The size of a complete tuple
136  unsigned int NumberOfComponents;
137  unsigned int NumberOfTuples;
138  int DataType;
139  unsigned int DataTypeSize;
140 
141  // VBOs may hold onto the cache, never the other way around
142  void SetCache(vtkOpenGLVertexBufferObjectCache *cache);
143 
144 protected:
146  ~vtkOpenGLVertexBufferObject() VTK_OVERRIDE;
147 
148  ShiftScaleMethod CoordShiftAndScaleMethod;
149  bool CoordShiftAndScaleEnabled;
150  std::vector<double> Shift;
151  std::vector<double> Scale;
152 
154 
155 private:
156  vtkOpenGLVertexBufferObject(const vtkOpenGLVertexBufferObject&) VTK_DELETE_FUNCTION;
157  void operator=(const vtkOpenGLVertexBufferObject&) VTK_DELETE_FUNCTION;
158 };
159 
160 #endif
OpenGL vertex buffer object.
record modification and/or execution time
Definition: vtkTimeStamp.h:32
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:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
OpenGL buffer object.