VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Rendering/OpenGL2/vtkglVBOHelper.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004 
00005   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00006   All rights reserved.
00007   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 
00015 #ifndef vtkGLVBOHelpher_h
00016 #define vtkGLVBOHelpher_h
00017 
00018 #include "vtkRenderingOpenGL2Module.h" // for export macro
00019 
00020 #include "vtkglBufferObject.h"
00021 #include "vtkglVertexArrayObject.h"
00022 
00023 #include "vtk_glew.h" // used for struct ivars
00024 #include <vector> // used for struct ivars
00025 #include "vtkTimeStamp.h" // used for struct ivars
00026 
00027 class vtkCellArray;
00028 class vtkPoints;
00029 class vtkDataArray;
00030 class vtkPolyData;
00031 class vtkOpenGLShaderCache;
00032 class vtkWindow;
00033 
00034 namespace vtkgl
00035 {
00036 
00037 // Process the string, and return a version with replacements.
00038 std::string VTKRENDERINGOPENGL2_EXPORT replace(std::string source,
00039   const std::string &search,
00040   const std::string replace, bool all = true);
00041 
00042 // perform in place string substitutions, indicate if a substitution was done
00043 bool VTKRENDERINGOPENGL2_EXPORT substitute(std::string &source,
00044   const std::string &search,
00045   const std::string replace, bool all = true);
00046 
00047 // used to create an IBO for triangle primatives
00048 size_t CreateTriangleIndexBuffer(vtkCellArray *cells,
00049   BufferObject &indexBuffer,
00050   vtkPoints *points, std::vector<unsigned int> &cellPointMap);
00051 
00052 // used to create an IBO for triangle primatives
00053 void AppendTriangleIndexBuffer(
00054   std::vector<unsigned int> &indexArray,
00055   vtkCellArray *cells,
00056   vtkPoints *points,
00057   std::vector<unsigned int> &cellPointMap,
00058   vtkIdType vertexOffset);
00059 
00060 // create a IBO for wireframe polys/tris
00061 size_t CreateTriangleLineIndexBuffer(vtkCellArray *cells,
00062   BufferObject &indexBuffer);
00063 
00064 // create a IBO for wireframe polys/tris
00065 void AppendTriangleLineIndexBuffer(
00066   std::vector<unsigned int> &indexArray,
00067   vtkCellArray *cells,
00068   vtkIdType vertexOffset);
00069 
00070 // used to create an IBO for primatives as points
00071 size_t CreatePointIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer);
00072 
00073 // used to create an IBO for primatives as points
00074 void AppendPointIndexBuffer(
00075   std::vector<unsigned int> &indexArray,
00076   vtkCellArray *cells,
00077   vtkIdType vertexOffset);
00078 
00079 // used to create an IBO for line strips and triangle strips
00080 size_t CreateMultiIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer,
00081                               std::vector<GLintptr> &memoryOffsetArray,
00082                               std::vector<unsigned int> &elementCountArray,
00083                               bool wireframeTriStrips);
00084 
00085 // special index buffer for polys wireframe with edge visibilityflags
00086 size_t CreateEdgeFlagIndexBuffer(vtkCellArray *cells, BufferObject &indexBuffer,
00087                                  vtkDataArray *edgeflags);
00088 
00089 // Store the shaders, program, and ibo in a common struct.
00090 class VTKRENDERINGOPENGL2_EXPORT CellBO
00091 {
00092 public:
00093   vtkShaderProgram *Program;
00094   BufferObject ibo;
00095   VertexArrayObject vao;
00096   vtkTimeStamp ShaderSourceTime;
00097 
00098   size_t indexCount;
00099   // These are client side objects for multi draw where IBOs are not used.
00100   std::vector<GLintptr> offsetArray;
00101   std::vector<unsigned int> elementsArray;
00102 
00103   vtkTimeStamp attributeUpdateTime;
00104 
00105   CellBO() {this->Program = NULL; };
00106   void ReleaseGraphicsResources(vtkWindow *win);
00107 };
00108 
00109 // Sizes/offsets are all in bytes as OpenGL API expects them.
00110 struct VBOLayout
00111 {
00112   size_t VertexCount; // Number of vertices in the VBO
00113   int Stride;       // The size of a complete vertex + attributes
00114   int VertexOffset; // Offset of the vertex
00115   int NormalOffset; // Offset of the normal
00116   int TCoordOffset; // Offset of the texture coordinates
00117   int TCoordComponents; // Number of texture dimensions
00118   int ColorOffset;  // Offset of the color
00119   int ColorComponents; // Number of color components
00120   std::vector<float> PackedVBO; // the data
00121 };
00122 
00123 // Take the points, and pack them into the VBO object supplied. This currently
00124 // takes whatever the input type might be and packs them into a VBO using
00125 // floats for the vertices and normals, and unsigned char for the colors (if
00126 // the array is non-null).
00127 VBOLayout CreateVBO(vtkPoints *points, unsigned int numPoints,
00128     vtkDataArray *normals,
00129     vtkDataArray *tcoords,
00130     unsigned char *colors, int colorComponents,
00131     BufferObject &vertexBuffer,
00132     unsigned int *cellPointMap, unsigned int *pointCellMap,
00133     bool cellScalars, bool cellNormals);
00134 void AppendVBO(VBOLayout &layout, vtkPoints *points, unsigned int numPoints,
00135     vtkDataArray *normals,
00136     vtkDataArray *tcoords,
00137     unsigned char *colors, int colorComponents,
00138     unsigned int *cellPointMap, unsigned int *pointCellMap,
00139     bool cellScalars, bool cellNormals);
00140 
00141 
00142 // used to create an IBO for stripped primatives such as lines and strips
00143 void CreateCellSupportArrays(vtkPolyData *poly, vtkCellArray *[4],
00144                              std::vector<unsigned int> &cellPointMap,
00145                              std::vector<unsigned int> &pointCellMap);
00146 
00147 } // End namespace
00148 
00149 #endif // vtkGLVBOHelpher_h
00150 
00151 // VTK-HeaderTest-Exclude: vtkglVBOHelper.h