From 8b433f8364a02bb07f57e96c6de9abbc2d42adce Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 May 2017 10:41:12 +0100 Subject: [PATCH] Replaced osg::DrawElementeUInt usage for a more flexible DrawElements base class approach with the default set to DrawElementUShort to ensure compatibility with GLES2 implementes that don't support uint for glDrawElements. --- include/osgText/Text | 2 +- src/osgText/Text.cpp | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/osgText/Text b/include/osgText/Text index 67d861461..3c7b5a58a 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -313,7 +313,7 @@ public: osg::buffered_object _transformedBackdropCoords[8]; ColorCoords _colorCoords; - osg::ref_ptr _quadIndices; + osg::ref_ptr _quadIndices; void updateQuadIndices(); GlyphQuads(); diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 5cedc7cb0..77bf8786b 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -2091,26 +2091,33 @@ void Text::GlyphQuads::initGlyphQuads() } } - _quadIndices = new DrawElementsUInt(PrimitiveSet::TRIANGLES); + _quadIndices = new DrawElementsUShort(PrimitiveSet::TRIANGLES); } void Text::GlyphQuads::updateQuadIndices() { - _quadIndices->clear(); - if (_coords->size() % 4 != 0) + unsigned int numCoords = _coords->size(); + unsigned int numQuads = numCoords/4; + unsigned int numVertices = numQuads*6; + + if (numCoords % 4 != 0) { OSG_WARN << "size of _coords is not divisible by 4."; } - for (unsigned int i = 0; i < (unsigned int)_coords->size(); i += 4) - { - _quadIndices->push_back(i); - _quadIndices->push_back(i + 1); - _quadIndices->push_back(i + 3); - _quadIndices->push_back(i + 1); - _quadIndices->push_back(i + 2); - _quadIndices->push_back(i + 3); + _quadIndices->resizeElements(numVertices); + + unsigned int vi=0; + for (unsigned int i = 0; i < numCoords; i += 4) + { + _quadIndices->setElement(vi++, i); + _quadIndices->setElement(vi++, i + 1); + _quadIndices->setElement(vi++, i + 3); + + _quadIndices->setElement(vi++, i + 1); + _quadIndices->setElement(vi++, i + 2); + _quadIndices->setElement(vi++, i + 3); } }