diff --git a/include/osg/GLBeginEndAdapter b/include/osg/GLBeginEndAdapter index 813193c9d..29c80592e 100644 --- a/include/osg/GLBeginEndAdapter +++ b/include/osg/GLBeginEndAdapter @@ -157,6 +157,9 @@ class OSG_EXPORT GLBeginEndAdapter osg::ref_ptr _colors; VertexArrayList _texCoordsList; VertexArrayList _vertexAttribsList; + + typedef std::vector UShortArray; + UShortArray _indexArray; }; } diff --git a/src/osg/GLBeginEndAdapter.cpp b/src/osg/GLBeginEndAdapter.cpp index f2be4fcc8..2a8975ee0 100644 --- a/src/osg/GLBeginEndAdapter.cpp +++ b/src/osg/GLBeginEndAdapter.cpp @@ -280,5 +280,35 @@ void GLBeginEndAdapter::End() _state->applyDisablingOfVertexAttributes(); - glDrawArrays(_primitiveMode, 0, _vertices->size()); + if (_primitiveMode==GL_QUADS) + { + unsigned int numQuads = _vertices->size()/4; + unsigned int numIndices = numQuads * 6; + if (numIndices > _indexArray.size()) + { + // we need to expand the _indexArray to be big enough to cope with all the quads required. + unsigned int numExistingQuads = _indexArray.size()/6; + _indexArray.reserve(numIndices); + for(unsigned int i=numExistingQuads; isize()); + } + else if (_primitiveMode==GL_POLYGON) glDrawArrays(GL_TRIANGLE_FAN, 0, _vertices->size()); + else glDrawArrays(_primitiveMode, 0, _vertices->size()); }