Skip to content
Snippets Groups Projects
Commit 7ba5402a authored by Alexy Pellegrini's avatar Alexy Pellegrini
Browse files

vtkOpenGLIndexBufferObject optimize IBO creation for common cases

Common cases:
- Cell array only contains triangles
- Cell array only contains triangles, and connectivity type is uint32
parent bb131fb2
No related branches found
No related tags found
No related merge requests found
# Improve IBO construction performances in vtkOpenGLIndexBufferObject
For the common cases of triangles-only polydata, the IBO construction time as been reduced by about 25%.
It is even more faster if the polydata cell arrays use 32bits connectivity IDs. This can be forced using the `VTK_USE_64BIT_IDS=OFF` when building, or using `vtkCellArray::SetDefaultStorageIs64Bit(false);` or `polydata->GetPolys()->ConvertTo32BitStorage()`.
......@@ -137,6 +137,13 @@ void vtkOpenGLIndexBufferObject::AppendTriangleIndexBuffer(std::vector<unsigned
vtkCellArray* cells, vtkPoints* points, vtkIdType vOffset, std::vector<unsigned char>* edgeArray,
vtkDataArray* edgeFlags)
{
const bool hasOnlyTriangles =
cells->GetNumberOfConnectivityIds() == cells->GetNumberOfCells() * 3;
if (hasOnlyTriangles)
{
indexArray.reserve(cells->GetNumberOfConnectivityIds());
}
if (cells->GetNumberOfConnectivityIds() > cells->GetNumberOfCells() * 3)
{
size_t targetSize =
......@@ -187,11 +194,26 @@ size_t vtkOpenGLIndexBufferObject::CreateTriangleIndexBuffer(vtkCellArray* cells
this->IndexCount = 0;
return 0;
}
std::vector<unsigned int> indexArray;
AppendTriangleIndexBuffer(indexArray, cells, points, 0, edgeValues, edgeFlags);
this->Upload(indexArray, vtkOpenGLIndexBufferObject::ElementArrayBuffer);
this->IndexCount = indexArray.size();
return indexArray.size();
const bool hasOnlyTriangles =
cells->GetNumberOfConnectivityIds() == cells->GetNumberOfCells() * 3;
if (!cells->IsStorage64Bit() && hasOnlyTriangles)
{
// If connectivity ids are 32-bits and we only have triangles, upload them as-is.
vtkCellArray::ArrayType32* array = cells->GetConnectivityArray32();
this->Upload(array->GetPointer(0), array->GetNumberOfValues(),
vtkOpenGLIndexBufferObject::ElementArrayBuffer);
this->IndexCount = array->GetNumberOfValues();
}
else
{
std::vector<unsigned int> indexArray;
AppendTriangleIndexBuffer(indexArray, cells, points, 0, edgeValues, edgeFlags);
this->Upload(indexArray, vtkOpenGLIndexBufferObject::ElementArrayBuffer);
this->IndexCount = indexArray.size();
}
return this->IndexCount;
}
// used to create an IBO for point primitives
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment