From d0b021568ef384f80d93ef94e5cd7db8ce67a1a0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 10 Nov 2009 11:36:07 +0000 Subject: [PATCH] Added support for mapping GL_QUADS, GL_QUAD_STRIP and GL_POLYGONS to GL_TRIANGLE equivalents. --- include/osg/GLBeginEndAdapter | 3 +++ src/osg/GLBeginEndAdapter.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) 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()); }