VTK  9.1.0
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
18#include "vtkRenderingOpenGL2Module.h" // for export macro
19#include "vtkWeakPointer.h" // For vtkWeakPointer
20
22
30// useful union for stuffing colors into a float
32 unsigned char c[4];
33 short s[2];
34 float f;
35};
36
37class vtkCamera;
38class vtkProp3D;
39
40class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexBufferObject : public vtkOpenGLBufferObject
41{
42public:
45 void PrintSelf(ostream& os, vtkIndent indent) override;
46
47 // set the VBOs data to the provided data array and upload
48 // this can use a fast path of just passing the
49 // data array pointer to OpenGL if it is suitable
51
52 // append a data array to this VBO, always
53 // copies the data from the data array
55
56 // Get the mtime when this VBO was loaded
57 vtkGetMacro(UploadTime, vtkTimeStamp);
58
80 {
87 FOCAL_POINT_SHIFT_SCALE
88 };
89
90 // Description:
91 // Get the shift and scale vectors computed by CreateVBO;
92 // or set the values CreateVBO and AppendVBO will use.
93 // Note that the "Set" methods **must** be called before the
94 // first time that CreateVBO or AppendVBO is invoked and
95 // should never be called afterwards.
96 //
97 // The CoordShiftAndScaleMethod describes how the shift
98 // and scale vectors are obtained (or that they should never
99 // be used).
100 // The GetCoordShiftAndScaleEnabled() method returns true if
101 // a shift and scale are currently being applied (or false if not).
102 //
103 // The "Get" methods are used by the mapper to modify the world
104 // and camera transformation matrices to match the scaling applied
105 // to coordinates in the VBO.
106 // CreateVBO only applies a shift and scale when the midpoint
107 // of the point bounding-box is distant from the origin by a
108 // factor of 10,000 or more relative to the size of the box
109 // along any axis.
110 //
111 // For example, if the x coordinates of the points range from
112 // 200,000 to 200,001 then the factor is
113 // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
114 // than 10,000 -- so the coordinates will be shifted and scaled.
115 //
116 // This is important as many OpenGL drivers use reduced precision
117 // to hold point coordinates.
118 //
119 // These methods are used by the mapper to determine the
120 // additional transform (if any) to apply to the rendering transform.
124 virtual void SetShift(const std::vector<double>& shift);
125 virtual void SetShift(double x, double y, double z);
126 virtual void SetScale(const std::vector<double>& scale);
127 virtual void SetScale(double x, double y, double z);
128 virtual const std::vector<double>& GetShift();
129 virtual const std::vector<double>& GetScale();
130
131 // update the shift scale if needed
133
134 // Allow all vertex adjustments to be enabled/disabled
135 //
136 // When smaller objects are positioned on the side of a larger scene,
137 // we don't want an individual mapper to try and center all its vertices.
138 //
139 // Complex scenes need to center the whole scene, not an individual mapper,
140 // so allow applications to turn all these shifts off and manage the
141 // float imprecision on their own.
143 static void GlobalCoordShiftAndScaleEnabledOn() { SetGlobalCoordShiftAndScaleEnabled(1); };
144 static void GlobalCoordShiftAndScaleEnabledOff() { SetGlobalCoordShiftAndScaleEnabled(0); };
146
147 // Set/Get the DataType to use for the VBO
148 // As a side effect sets the DataTypeSize
149 void SetDataType(int v);
150 vtkGetMacro(DataType, int);
151
152 // Get the size in bytes of the data type
153 vtkGetMacro(DataTypeSize, unsigned int);
154
155 // How many tuples in the VBO
156 vtkGetMacro(NumberOfTuples, unsigned int);
157
158 // How many components in the VBO
159 vtkGetMacro(NumberOfComponents, unsigned int);
160
161 // Set/Get the VBO stride in bytes
162 vtkSetMacro(Stride, unsigned int);
163 vtkGetMacro(Stride, unsigned int);
164
165 // Get the underlying VBO array
166 std::vector<float>& GetPackedVBO() { return this->PackedVBO; }
167
168 // upload the current PackedVBO
169 // only used by mappers that skip the VBOGroup support
170 void UploadVBO();
171
172 // VBOs may hold onto the cache, never the other way around
174
175 // used by mappers that support camera based shift scale
176 virtual void SetCamera(vtkCamera* cam);
177 virtual void SetProp3D(vtkProp3D* prop3d);
178
179protected:
182
183 std::vector<float> PackedVBO; // the data
184
186
187 unsigned int Stride; // The size of a complete tuple
188 unsigned int NumberOfComponents;
189 unsigned int NumberOfTuples;
191 unsigned int DataTypeSize;
192
195 std::vector<double> Shift;
196 std::vector<double> Scale;
197
199
202
203private:
205 void operator=(const vtkOpenGLVertexBufferObject&) = delete;
206
207 // Initialize static member that controls shifts and scales
208 static vtkTypeBool GlobalCoordShiftAndScaleEnabled;
209};
210
211#endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:155
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
a simple class to control print indentation
Definition: vtkIndent.h:113
OpenGL buffer object.
manage vertex buffer objects shared within a context
void UpdateShiftScale(vtkDataArray *da)
virtual bool GetCoordShiftAndScaleEnabled()
virtual ShiftScaleMethod GetCoordShiftAndScaleMethod()
void SetCache(vtkOpenGLVertexBufferObjectCache *cache)
virtual void SetScale(double x, double y, double z)
static vtkTypeBool GetGlobalCoordShiftAndScaleEnabled()
~vtkOpenGLVertexBufferObject() override
virtual const std::vector< double > & GetShift()
virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth)
void UploadDataArray(vtkDataArray *array)
virtual const std::vector< double > & GetScale()
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.
@ MANUAL_SHIFT_SCALE
Manual shift/scale (for use with AppendVBO)
@ NEAR_PLANE_SHIFT_SCALE
Shift scale based on camera settings.
@ AUTO_SHIFT_SCALE
The default, automatic computation.
virtual void SetScale(const std::vector< double > &scale)
virtual void SetShift(double x, double y, double z)
static void SetGlobalCoordShiftAndScaleEnabled(vtkTypeBool val)
virtual void SetShift(const std::vector< double > &shift)
virtual void SetCamera(vtkCamera *cam)
void AppendDataArray(vtkDataArray *array)
static vtkOpenGLVertexBufferObject * New()
virtual void SetProp3D(vtkProp3D *prop3d)
vtkWeakPointer< vtkProp3D > Prop3D
vtkOpenGLVertexBufferObjectCache * Cache
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWeakPointer< vtkCamera > Camera
represents an 3D object for placement in a rendered scene
Definition: vtkProp3D.h:93
record modification and/or execution time
Definition: vtkTimeStamp.h:52
@ scale
Definition: vtkX3D.h:235
OpenGL vertex buffer object.
int vtkTypeBool
Definition: vtkABI.h:69