VTK
vtkglVBOHelper.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 
15 #ifndef vtkGLVBOHelpher_h
16 #define vtkGLVBOHelpher_h
17 
18 #include "vtkRenderingOpenGL2Module.h" // for export macro
19 
20 #include "vtkglBufferObject.h"
21 #include "vtkglVertexArrayObject.h"
22 
23 #include "vtk_glew.h" // used for struct ivars
24 #include <vector> // used for struct ivars
25 #include "vtkTimeStamp.h" // used for struct ivars
26 
27 class vtkCellArray;
28 class vtkPoints;
29 class vtkDataArray;
30 class vtkPolyData;
32 class vtkWindow;
33 
34 namespace vtkgl
35 {
36 
37 // Process the string, and return a version with replacements.
38 std::string VTKRENDERINGOPENGL2_EXPORT replace(std::string source,
39  const std::string &search,
40  const std::string replace, bool all = true);
41 
42 // perform in place string substitutions, indicate if a substitution was done
43 bool VTKRENDERINGOPENGL2_EXPORT substitute(std::string &source,
44  const std::string &search,
45  const std::string replace, bool all = true);
46 
47 // used to create an IBO for triangle primatives
49  BufferObject &indexBuffer,
50  vtkPoints *points, std::vector<unsigned int> &cellPointMap);
51 
52 // used to create an IBO for triangle primatives
54  std::vector<unsigned int> &indexArray,
55  vtkCellArray *cells,
57  std::vector<unsigned int> &cellPointMap,
58  vtkIdType vertexOffset);
59 
60 // create a IBO for wireframe polys/tris
62  BufferObject &indexBuffer);
63 
64 // create a IBO for wireframe polys/tris
66  std::vector<unsigned int> &indexArray,
67  vtkCellArray *cells,
68  vtkIdType vertexOffset);
69 
70 // used to create an IBO for primatives as points
71 size_t CreatePointIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer);
72 
73 // used to create an IBO for primatives as points
75  std::vector<unsigned int> &indexArray,
76  vtkCellArray *cells,
77  vtkIdType vertexOffset);
78 
79 // used to create an IBO for line strips and triangle strips
80 size_t CreateMultiIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer,
81  std::vector<GLintptr> &memoryOffsetArray,
82  std::vector<unsigned int> &elementCountArray,
83  bool wireframeTriStrips);
84 
85 // special index buffer for polys wireframe with edge visibilityflags
86 size_t CreateEdgeFlagIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer,
87  vtkDataArray *edgeflags);
88 
89 // Store the shaders, program, and ibo in a common struct.
90 class VTKRENDERINGOPENGL2_EXPORT CellBO
91 {
92 public:
97 
98  size_t indexCount;
99  // These are client side objects for multi draw where IBOs are not used.
100  std::vector<GLintptr> offsetArray;
101  std::vector<unsigned int> elementsArray;
102 
104 
105  CellBO() {this->Program = NULL; };
106  void ReleaseGraphicsResources(vtkWindow *win);
107 };
108 
109 // Sizes/offsets are all in bytes as OpenGL API expects them.
110 struct VBOLayout
111 {
112  size_t VertexCount; // Number of vertices in the VBO
113  int Stride; // The size of a complete vertex + attributes
114  int VertexOffset; // Offset of the vertex
115  int NormalOffset; // Offset of the normal
116  int TCoordOffset; // Offset of the texture coordinates
117  int TCoordComponents; // Number of texture dimensions
118  int ColorOffset; // Offset of the color
119  int ColorComponents; // Number of color components
120  std::vector<float> PackedVBO; // the data
121 };
122 
123 // Take the points, and pack them into the VBO object supplied. This currently
124 // takes whatever the input type might be and packs them into a VBO using
125 // floats for the vertices and normals, and unsigned char for the colors (if
126 // the array is non-null).
127 VBOLayout CreateVBO(vtkPoints *points, unsigned int numPoints,
128  vtkDataArray *normals,
129  vtkDataArray *tcoords,
130  unsigned char *colors, int colorComponents,
131  BufferObject &vertexBuffer,
132  unsigned int *cellPointMap, unsigned int *pointCellMap,
133  bool cellScalars, bool cellNormals);
134 void AppendVBO(VBOLayout &layout, vtkPoints *points, unsigned int numPoints,
135  vtkDataArray *normals,
136  vtkDataArray *tcoords,
137  unsigned char *colors, int colorComponents,
138  unsigned int *cellPointMap, unsigned int *pointCellMap,
139  bool cellScalars, bool cellNormals);
140 
141 
142 // used to create an IBO for stripped primatives such as lines and strips
144  std::vector<unsigned int> &cellPointMap,
145  std::vector<unsigned int> &pointCellMap);
146 
147 } // End namespace
148 
149 #endif // vtkGLVBOHelpher_h
150 
151 // VTK-HeaderTest-Exclude: vtkglVBOHelper.h
VertexArrayObject vao
void AppendVBO(VBOLayout &layout, vtkPoints *points, unsigned int numPoints, vtkDataArray *normals, vtkDataArray *tcoords, unsigned char *colors, int colorComponents, unsigned int *cellPointMap, unsigned int *pointCellMap, bool cellScalars, bool cellNormals)
OpenGL buffer object.
vtkShaderProgram * Program
vtkTimeStamp ShaderSourceTime
manage Shader Programs within a context
size_t CreatePointIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer)
void AppendTriangleIndexBuffer(std::vector< unsigned int > &indexArray, vtkCellArray *cells, vtkPoints *points, std::vector< unsigned int > &cellPointMap, vtkIdType vertexOffset)
record modification and/or execution time
Definition: vtkTimeStamp.h:34
GLsizei GLsizei GLchar * source
Definition: vtkgl.h:12000
int vtkIdType
Definition: vtkType.h:281
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
size_t CreateEdgeFlagIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer, vtkDataArray *edgeflags)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:33
bool VTKRENDERINGOPENGL2_EXPORT substitute(std::string &source, const std::string &search, const std::string replace, bool all=true)
size_t CreateTriangleLineIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer)
std::vector< float > PackedVBO
Definition: vtkgl.h:11267
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
std::string VTKRENDERINGOPENGL2_EXPORT replace(std::string source, const std::string &search, const std::string replace, bool all=true)
vtkTimeStamp attributeUpdateTime
The VertexArrayObject class uses, or emulates, vertex array objects.
std::vector< unsigned int > elementsArray
object to represent cell connectivity
Definition: vtkCellArray.h:49
GLsizei const GLfloat * points
Definition: vtkgl.h:14786
void CreateCellSupportArrays(vtkPolyData *poly, vtkCellArray *[4], std::vector< unsigned int > &cellPointMap, std::vector< unsigned int > &pointCellMap)
void AppendPointIndexBuffer(std::vector< unsigned int > &indexArray, vtkCellArray *cells, vtkIdType vertexOffset)
void AppendTriangleLineIndexBuffer(std::vector< unsigned int > &indexArray, vtkCellArray *cells, vtkIdType vertexOffset)
std::vector< GLintptr > offsetArray
VBOLayout CreateVBO(vtkPoints *points, unsigned int numPoints, vtkDataArray *normals, vtkDataArray *tcoords, unsigned char *colors, int colorComponents, BufferObject &vertexBuffer, unsigned int *cellPointMap, unsigned int *pointCellMap, bool cellScalars, bool cellNormals)
size_t CreateTriangleIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer, vtkPoints *points, std::vector< unsigned int > &cellPointMap)
size_t CreateMultiIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer, std::vector< GLintptr > &memoryOffsetArray, std::vector< unsigned int > &elementCountArray, bool wireframeTriStrips)
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
represent and manipulate 3D points
Definition: vtkPoints.h:38
BufferObject ibo
The ShaderProgram uses one or more Shader objects.