From 48aa852f42dc578e610b8ebccf8ea70199f27c48 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Mar 2017 09:43:19 +0000 Subject: [PATCH] Replaced GL_QUADS and GL_QUAD_STRIP usage with indexed GL_TRIANGLES --- src/osg/Shape.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/osg/Shape.cpp b/src/osg/Shape.cpp index 89dd852b0..67d4d71f8 100644 --- a/src/osg/Shape.cpp +++ b/src/osg/Shape.cpp @@ -243,7 +243,53 @@ void BuildShapeGeometryVisitor::End() { if (_start_index>=_vertices->size()) return; - _geometry->addPrimitiveSet(new DrawArrays(_mode, _start_index, _vertices->size()-_start_index)); + + if (_mode==GL_QUADS) + { + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLES); + _geometry->addPrimitiveSet(primitives.get()); + + for(unsigned int i=_start_index; i<_vertices->size(); i+=4) + { + unsigned int p0 = i; + unsigned int p1 = i+1; + unsigned int p2 = i+2; + unsigned int p3 = i+3; + + primitives->push_back(p0); + primitives->push_back(p3); + primitives->push_back(p1); + + primitives->push_back(p1); + primitives->push_back(p3); + primitives->push_back(p2); + } + } + else if (_mode==GL_QUAD_STRIP) + { + osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLES); + _geometry->addPrimitiveSet(primitives.get()); + + for(unsigned int i=_start_index; i<_vertices->size()-2; i+=2) + { + unsigned int p0 = i; + unsigned int p1 = i+1; + unsigned int p2 = i+2; + unsigned int p3 = i+3; + + primitives->push_back(p0); + primitives->push_back(p2); + primitives->push_back(p1); + + primitives->push_back(p1); + primitives->push_back(p2); + primitives->push_back(p3); + } + } + else + { + _geometry->addPrimitiveSet(new DrawArrays(_mode, _start_index, _vertices->size()-_start_index)); + } for(unsigned int i=_start_index; i<_vertices->size(); ++i) {