From c4fdc930538b709f1838061e6c60ff58498c3685 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 13 Jul 2015 16:09:45 +0000 Subject: [PATCH] Added Text::GlyphQuads::release/resizeGLObjects() and handling of inconsistent contextID sizes to avoid crashes when viewers and scene graphs aren't initialized correctly to the right number of contexts. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14947 16af8721-9629-0410-8352-f15c8da7e697 --- include/osgText/Text | 18 ++++++++++-- src/osgText/Text.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/include/osgText/Text b/include/osgText/Text index df0414552..4300788a5 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -317,11 +317,13 @@ public: void updateQuadIndices(); GlyphQuads(); + GlyphQuads(const GlyphQuads& gq); + void initGlyphQuads(); void initGPUBufferObjects(); - Glyphs getGlyphs() { return _glyphs; } - const Glyphs getGlyphs() const { return _glyphs; } + Glyphs& getGlyphs() { return _glyphs; } + const Glyphs& getGlyphs() const { return _glyphs; } Coords2& getCoords() { return _coords; } const Coords2& getCoords() const { return _coords; } @@ -334,6 +336,18 @@ public: LineNumbers& getLineNumbers() { return _lineNumbers; } const LineNumbers& getLineNumbers() const { return _lineNumbers; } + + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + + /** If State is non-zero, this function releases OpenGL objects for + * the specified graphics context. Otherwise, releases OpenGL objexts + * for all graphics contexts. */ + virtual void releaseGLObjects(osg::State* state=0) const; + + private: + + GlyphQuads& operator = (const GlyphQuads&) { return *this; } }; typedef std::map,GlyphQuads> TextureGlyphQuadMap; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index c6a123b5f..84e71b378 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -723,7 +723,15 @@ void Text::computePositions(unsigned int contextID) const ++titr) { GlyphQuads& glyphquad = titr->second; + //OSG_NOTICE<<"Text::computePositions("<size(); i += 4) { _quadIndices->push_back(i); @@ -2087,3 +2124,34 @@ void Text::GlyphQuads::initGPUBufferObjects() _quadIndices->setElementBufferObject(new osg::ElementBufferObject()); } + + +void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) +{ + _transformedCoords.resize(maxSize); + + for (int j = 0; j < 8; j++) + { + for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) + { + _transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize); + } + } + + _quadIndices->resizeGLObjectBuffers(maxSize); + + initGPUBufferObjects(); +} + +void Text::GlyphQuads::releaseGLObjects(osg::State* state) const +{ + for (int j = 0; j < 8; j++) + { + for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) + { + _transformedBackdropCoords[j][i]->releaseGLObjects(state); + } + } + + _quadIndices->releaseGLObjects(state); +}