VTK  9.4.20241123
vtkOpenGLVertexBufferObject.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkOpenGLVertexBufferObject_h
4#define vtkOpenGLVertexBufferObject_h
5
7#include "vtkPolyDataMapper.h" // for ShiftScaleMethodType
8#include "vtkRenderingOpenGL2Module.h" // for export macro
9#include "vtkWeakPointer.h" // For vtkWeakPointer
10
11VTK_ABI_NAMESPACE_BEGIN
13
21// useful union for stuffing colors into a float
23{
24 unsigned char c[4];
25 short s[2];
26 float f;
27};
28
29class vtkCamera;
30class vtkProp3D;
31
32class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexBufferObject : public vtkOpenGLBufferObject
33{
34public:
37 void PrintSelf(ostream& os, vtkIndent indent) override;
38
39 // set the VBOs data to the provided data array and upload
40 // this can use a fast path of just passing the
41 // data array pointer to OpenGL if it is suitable
43
44 // append a data array to this VBO, always
45 // copies the data from the data array
47
48 // Get the mtime when this VBO was loaded
49 vtkGetMacro(UploadTime, vtkTimeStamp);
50
52
54
57 static constexpr int DISABLE_SHIFT_SCALE = ShiftScaleMethod::DISABLE_SHIFT_SCALE;
58 static constexpr int AUTO_SHIFT_SCALE = ShiftScaleMethod::AUTO_SHIFT_SCALE;
59 static constexpr int ALWAYS_AUTO_SHIFT_SCALE = ShiftScaleMethod::ALWAYS_AUTO_SHIFT_SCALE;
60 static constexpr int MANUAL_SHIFT_SCALE = ShiftScaleMethod::MANUAL_SHIFT_SCALE;
61 static constexpr int AUTO_SHIFT = ShiftScaleMethod::AUTO_SHIFT;
62 static constexpr int NEAR_PLANE_SHIFT_SCALE = ShiftScaleMethod::NEAR_PLANE_SHIFT_SCALE;
63 static constexpr int FOCAL_POINT_SHIFT_SCALE = ShiftScaleMethod::FOCAL_POINT_SHIFT_SCALE;
65
66 // Description:
67 // Get the shift and scale vectors computed by CreateVBO;
68 // or set the values CreateVBO and AppendVBO will use.
69 // Note that the "Set" methods **must** be called before the
70 // first time that CreateVBO or AppendVBO is invoked and
71 // should never be called afterwards.
72 //
73 // The CoordShiftAndScaleMethod describes how the shift
74 // and scale vectors are obtained (or that they should never
75 // be used).
76 // The GetCoordShiftAndScaleEnabled() method returns true if
77 // a shift and scale are currently being applied (or false if not).
78 //
79 // The "Get" methods are used by the mapper to modify the world
80 // and camera transformation matrices to match the scaling applied
81 // to coordinates in the VBO.
82 // CreateVBO only applies a shift and scale when the midpoint
83 // of the point bounding-box is distant from the origin by a
84 // factor of 10,000 or more relative to the size of the box
85 // along any axis.
86 //
87 // For example, if the x coordinates of the points range from
88 // 200,000 to 200,001 then the factor is
89 // 200,000.5 / (200,001 - 200,000) = 2x10^5, which is larger
90 // than 10,000 -- so the coordinates will be shifted and scaled.
91 //
92 // This is important as many OpenGL drivers use reduced precision
93 // to hold point coordinates.
94 //
95 // These methods are used by the mapper to determine the
96 // additional transform (if any) to apply to the rendering transform.
99 virtual void SetCoordShiftAndScaleMethod(int meth);
100 virtual void SetShift(const std::vector<double>& shift);
101 virtual void SetShift(double x, double y, double z);
102 virtual void SetScale(const std::vector<double>& scale);
103 virtual void SetScale(double x, double y, double z);
104 virtual const std::vector<double>& GetShift();
105 virtual const std::vector<double>& GetScale();
106
107 // update the shift scale if needed
109
110 // Allow all vertex adjustments to be enabled/disabled
111 //
112 // When smaller objects are positioned on the side of a larger scene,
113 // we don't want an individual mapper to try and center all its vertices.
114 //
115 // Complex scenes need to center the whole scene, not an individual mapper,
116 // so allow applications to turn all these shifts off and manage the
117 // float imprecision on their own.
119 static void GlobalCoordShiftAndScaleEnabledOn() { SetGlobalCoordShiftAndScaleEnabled(1); }
120 static void GlobalCoordShiftAndScaleEnabledOff() { SetGlobalCoordShiftAndScaleEnabled(0); }
122
123 // Set/Get the DataType to use for the VBO
124 // As a side effect sets the DataTypeSize
125 void SetDataType(int v);
126 vtkGetMacro(DataType, int);
127
128 // Get the size in bytes of the data type
129 vtkGetMacro(DataTypeSize, unsigned int);
130
131 // How many tuples in the VBO
132 vtkGetMacro(NumberOfTuples, unsigned int);
133
134 // How many components in the VBO
135 vtkGetMacro(NumberOfComponents, unsigned int);
136
137 // Set/Get the VBO stride in bytes
138 vtkSetMacro(Stride, unsigned int);
139 vtkGetMacro(Stride, unsigned int);
140
141 // Get the underlying VBO array
142 std::vector<float>& GetPackedVBO() { return this->PackedVBO; }
143
144 // upload the current PackedVBO
145 // only used by mappers that skip the VBOGroup support
146 void UploadVBO();
147
148 // VBOs may hold onto the cache, never the other way around
150
151 // used by mappers that support camera based shift scale
152 virtual void SetCamera(vtkCamera* cam);
153 virtual void SetProp3D(vtkProp3D* prop3d);
154
155protected:
158
159 std::vector<float> PackedVBO; // the data
160
162
163 unsigned int Stride; // The size of a complete tuple
164 unsigned int NumberOfComponents;
165 unsigned int NumberOfTuples;
167 unsigned int DataTypeSize;
168
171 std::vector<double> Shift;
172 std::vector<double> Scale;
173
175
178
179private:
181 void operator=(const vtkOpenGLVertexBufferObject&) = delete;
182
183 // Initialize static member that controls shifts and scales
184 static vtkTypeBool GlobalCoordShiftAndScaleEnabled;
185};
186
187VTK_ABI_NAMESPACE_END
188#endif
a virtual camera for 3D rendering
Definition vtkCamera.h:151
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:108
OpenGL buffer object.
manage vertex buffer objects shared within a context
void UpdateShiftScale(vtkDataArray *da)
virtual bool GetCoordShiftAndScaleEnabled()
void SetCache(vtkOpenGLVertexBufferObjectCache *cache)
virtual void SetScale(double x, double y, double z)
virtual void SetCoordShiftAndScaleMethod(int meth)
static vtkTypeBool GetGlobalCoordShiftAndScaleEnabled()
~vtkOpenGLVertexBufferObject() override
virtual const std::vector< double > & GetShift()
void UploadDataArray(vtkDataArray *array)
virtual const std::vector< double > & GetScale()
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 int GetCoordShiftAndScaleMethod()
virtual void SetCamera(vtkCamera *cam)
void AppendDataArray(vtkDataArray *array)
static vtkOpenGLVertexBufferObject * New()
virtual void SetProp3D(vtkProp3D *prop3d)
vtkOpenGLVertexBufferObjectCache * Cache
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
ShiftScaleMethodType
Methods for VBO coordinate shift+scale-computation.
represents an 3D object for placement in a rendered scene
Definition vtkProp3D.h:89
record modification and/or execution time
a weak reference to a vtkObject.
OpenGL vertex buffer object.
int vtkTypeBool
Definition vtkABI.h:64