diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index afa313d5c..f489af9cd 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -24,12 +24,27 @@ class DrawVertex _vertices(vertices), _indices(indices) { - _verticesType = _vertices->getType(); + _verticesType = _vertices?_vertices->getType():Array::ArrayType; + _indicesType = _indices?_indices->getType():Array::ArrayType; } + inline unsigned int index(unsigned int pos) + { + switch(_indicesType) + { + case(Array::ByteArrayType): return (*static_cast(_indices))[pos]; + case(Array::ShortArrayType): return (*static_cast(_indices))[pos]; + case(Array::IntArrayType): return (*static_cast(_indices))[pos]; + case(Array::UByteArrayType): return (*static_cast(_indices))[pos]; + case(Array::UShortArrayType): return (*static_cast(_indices))[pos]; + case(Array::UIntArrayType): return (*static_cast(_indices))[pos]; + default: return 0; + } + } + inline void operator () (unsigned int pos) { - if (_indices) pos = _indices->index(pos); + if (_indices) pos = index(pos); switch(_verticesType) { @@ -42,6 +57,8 @@ class DrawVertex case(Array::Vec4ArrayType): apply((*(static_cast(_vertices)))[pos]); break; + default: + break; } } @@ -53,6 +70,7 @@ class DrawVertex const Array* _vertices; const IndexArray* _indices; Array::Type _verticesType; + Array::Type _indicesType; }; #else class DrawVertex : public osg::ConstValueVisitor @@ -105,8 +123,8 @@ class DrawColor _colors(colors), _indices(indices) { - _colorsType = _colors->getType(); - _indicesType = _indices->getType(); + _colorsType = _colors?_colors->getType():Array::ArrayType; + _indicesType = _indices?_indices->getType():Array::ArrayType; } inline unsigned int index(unsigned int pos) @@ -138,6 +156,8 @@ class DrawColor case(Array::Vec3ArrayType): apply((*static_cast(_colors))[pos]); break; + default: + break; } }