Commit 88b79a05 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

more robust estimation of split-count in MeshCompiler refs #2195

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18789 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 25eca745
......@@ -546,6 +546,7 @@ void MeshCompiler::splitVertices()
// estimate number of splits
int estimatedSplitCount = 0;
int numDifferentInputCounts = 0;
for (int i = 0; i < numAttributes_; ++i)
{
......@@ -555,12 +556,53 @@ void MeshCompiler::splitVertices()
{
const int diff = input_[i].count - numPositions;
estimatedSplitCount = diff * ( (estimatedSplitCount > 0) ? estimatedSplitCount : 1);
if (diff > 0)
{
estimatedSplitCount = std::max(diff, estimatedSplitCount);
++numDifferentInputCounts;
}
}
}
}
estimatedSplitCount = int(float(estimatedSplitCount) * 1.2f);
if (numDifferentInputCounts > 1)
{
// estimation probably too small, increase by 20 %
estimatedSplitCount = int(float(estimatedSplitCount) * 1.2f);
}
assert(estimatedSplitCount >= 0);
// worst case: each vertex can be used by only one face
// clamp estimation-count accordingly
int maxSplitCount = 0;
if (numIndices_ > 0)
{
if (numIndices_ > numPositions)
maxSplitCount = numIndices_ - numPositions;
}
else
{
// numIndices_ is unknown
int sumFaceSize = 0;
if (constantFaceSize_)
sumFaceSize = numFaces_ * maxFaceSize_;
else
{
for (int i = 0; i < numFaces_; ++i)
sumFaceSize += getFaceSize(i);
}
if (sumFaceSize > numPositions)
maxSplitCount = sumFaceSize - numPositions;
}
estimatedSplitCount = std::min(estimatedSplitCount, maxSplitCount);
// std::cout << "estimated split count: " << estimatedSplitCount << std::endl;
delete splitter_;
splitter_ = new VertexSplitter(decl_.getNumElements(),
......@@ -593,6 +635,10 @@ void MeshCompiler::splitVertices()
}
// std::cout << "actual split count: " << (numDrawVerts_ - numPositions) << std::endl;
// Fix splitting list if there are isolated vertices in between.
// Isolated vertices currently occupy spots in in the interleaved vertex buffer.
// -> Remove them from the vbo.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment