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 
20 
29 // useful union for stuffing colors into a float
31 {
32  unsigned char c[4];
33  float f;
34 };
35 
36 class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLVertexBufferObject :
38 {
39 public:
42  void PrintSelf(ostream& os, vtkIndent indent);
43 
44  // Take the points, and pack them into this VBO. This currently
45  // takes whatever the input type might be and packs them into a VBO using
46  // floats for the vertices and normals, and unsigned char for the colors (if
47  // the array is non-null).
48  void CreateVBO(vtkPoints *points, unsigned int numPoints,
49  vtkDataArray *normals,
50  vtkDataArray *tcoords,
51  unsigned char *colors, int colorComponents);
52 
53  void AppendVBO(vtkPoints *points, unsigned int numPoints,
54  vtkDataArray *normals,
55  vtkDataArray *tcoords,
56  unsigned char *colors, int colorComponents);
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  vtkGetVector3Macro(CoordShift,double);
115  vtkGetVector3Macro(CoordScale,double);
117  virtual void SetCoordShift(double x, double y, double z);
118  virtual void SetCoordShift(const double s[3]);
119  virtual void SetCoordScale(double sx, double sy, double sz);
120  virtual void SetCoordScale(const double s[3]);
121 
122  // Sizes/offsets are all in bytes as OpenGL API expects them.
123  size_t VertexCount; // Number of vertices in the VBO
124  int Stride; // The size of a complete vertex + attributes
125  int VertexOffset; // Offset of the vertex
126  int NormalOffset; // Offset of the normal
127  int TCoordOffset; // Offset of the texture coordinates
128  int TCoordComponents; // Number of texture dimensions
129  int ColorOffset; // Offset of the color
130  int ColorComponents; // Number of color components
131  std::vector<float> PackedVBO; // the data
132 
133 protected:
136 
137  double CoordShift[3];
138  double CoordScale[3];
141 
142 private:
143  vtkOpenGLVertexBufferObject(const vtkOpenGLVertexBufferObject&) VTK_DELETE_FUNCTION;
144  void operator=(const vtkOpenGLVertexBufferObject&) VTK_DELETE_FUNCTION;
145 };
146 
147 #endif
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
a simple class to control print indentation
Definition: vtkIndent.h:40
OpenGL buffer object.
void AppendVBO(vtkPoints *points, unsigned int numPoints, vtkDataArray *normals, vtkDataArray *tcoords, unsigned char *colors, int colorComponents)
virtual void SetCoordScale(const double s[3])
virtual void SetCoordShiftAndScaleMethod(ShiftScaleMethod meth)
ShiftScaleMethod
Methods for VBO coordinate shift+scale-computation.
@ DISABLE_SHIFT_SCALE
Do not shift/scale point coordinates. Ever!
@ AUTO_SHIFT_SCALE
The default, automatic computation.
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual void SetCoordScale(double sx, double sy, double sz)
virtual void SetCoordShift(double x, double y, double z)
void CreateVBO(vtkPoints *points, unsigned int numPoints, vtkDataArray *normals, vtkDataArray *tcoords, unsigned char *colors, int colorComponents)
virtual void SetCoordShift(const double s[3])
static vtkOpenGLVertexBufferObject * New()
represent and manipulate 3D points
Definition: vtkPoints.h:40
@ points
Definition: vtkX3D.h:446
OpenGL vertex buffer object.
unsigned char c[4]