Added a check for the maximum index values of primitives, and then use this
to select whether to use UByte,UShort or UInt versions of osg::DrawElements.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <osgUtil/TriStripVisitor>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "TriStrip_tri_stripper.h"
|
||||
|
||||
@@ -141,11 +142,29 @@ void TriStripVisitor::stripify(Geometry& geom)
|
||||
pitr!=outPrimitives.end();
|
||||
++pitr)
|
||||
{
|
||||
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(pitr->m_Type);
|
||||
elements->reserve(pitr->m_Indices.size());
|
||||
std::copy(pitr->m_Indices.begin(),pitr->m_Indices.end(),std::back_inserter(*elements));
|
||||
//elements->insert(elements->end(),);
|
||||
new_primitives.push_back(elements);
|
||||
|
||||
unsigned int maxValue = *(std::max_element(pitr->m_Indices.begin(),pitr->m_Indices.end()));
|
||||
if (maxValue<256)
|
||||
{
|
||||
osg::DrawElementsUByte* elements = new osg::DrawElementsUByte(pitr->m_Type);
|
||||
elements->reserve(pitr->m_Indices.size());
|
||||
std::copy(pitr->m_Indices.begin(),pitr->m_Indices.end(),std::back_inserter(*elements));
|
||||
new_primitives.push_back(elements);
|
||||
}
|
||||
else if (maxValue<65536)
|
||||
{
|
||||
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(pitr->m_Type);
|
||||
elements->reserve(pitr->m_Indices.size());
|
||||
std::copy(pitr->m_Indices.begin(),pitr->m_Indices.end(),std::back_inserter(*elements));
|
||||
new_primitives.push_back(elements);
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(pitr->m_Type);
|
||||
elements->reserve(pitr->m_Indices.size());
|
||||
std::copy(pitr->m_Indices.begin(),pitr->m_Indices.end(),std::back_inserter(*elements));
|
||||
new_primitives.push_back(elements);
|
||||
}
|
||||
}
|
||||
|
||||
geom.setPrimitiveSetList(new_primitives);
|
||||
|
||||
Reference in New Issue
Block a user