From 96388cee672e79e578a85daa5a612287e2a7866e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Sep 2003 19:56:00 +0000 Subject: [PATCH] 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. --- src/osgUtil/TriStripVisitor.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp index 233d071bc..cd8e6497a 100644 --- a/src/osgUtil/TriStripVisitor.cpp +++ b/src/osgUtil/TriStripVisitor.cpp @@ -16,6 +16,7 @@ #include #include +#include #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);