diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 798a23d7b..5cedc7cb0 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -733,6 +733,7 @@ void Text::computePositions(unsigned int contextID) const } GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID]; + if (!transformedCoords) transformedCoords = new osg::Vec3Array; unsigned int numCoords = coords2->size(); if (numCoords != transformedCoords->size()) @@ -818,6 +819,8 @@ void Text::computeBackdropPositions(unsigned int contextID) const } GlyphQuads::Coords3& transformedCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; + if (!transformedCoords) transformedCoords = new osg::Vec3Array(); + unsigned int numCoords = coords2->size(); if (numCoords!=transformedCoords->size()) { @@ -1302,7 +1305,7 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie if ( !_textureGlyphQuadMap.empty() ) { const GlyphQuads& glyphquad = (_textureGlyphQuadMap.begin())->second; - if ( glyphquad._transformedCoords[contextID]->empty() ) + if (!glyphquad._transformedCoords[contextID].valid() || glyphquad._transformedCoords[contextID]->empty() ) { computePositions(contextID); } @@ -1477,8 +1480,12 @@ void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const ++titr) { const GlyphQuads& glyphquad = titr->second; - af.apply(osg::Drawable::VERTICES, glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); - af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front())); + if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid()) + { + af.apply(osg::Drawable::VERTICES, glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); + af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front())); + } + } } @@ -1489,9 +1496,11 @@ void Text::accept(osg::PrimitiveFunctor& pf) const ++titr) { const GlyphQuads& glyphquad = titr->second; - - pf.setVertexArray(glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); - pf.drawArrays(GL_QUADS, 0, glyphquad._transformedCoords[0]->size()); + if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid()) + { + pf.setVertexArray(glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front())); + pf.drawArrays(GL_QUADS, 0, glyphquad._transformedCoords[0]->size()); + } } @@ -1604,7 +1613,7 @@ void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, co unsigned int contextID = state.getContextID(); const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID]; - if (!transformedCoords->empty()) + if (transformedCoords.valid() && !transformedCoords->empty()) { state.setVertexPointer(transformedCoords.get()); state.setTexCoordPointer(0, glyphquad._texcoords.get()); @@ -1701,7 +1710,7 @@ void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultipl for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer(transformedBackdropCoords.get()); glyphquad._quadIndices->draw(state, _useVertexBufferObjects); @@ -1757,7 +1766,7 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front())); glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), @@ -1816,7 +1825,7 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front())); state.drawQuads(0,transformedBackdropCoords->size()); @@ -1872,7 +1881,7 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front())); double offset = double(max_backdrop_index-backdrop_index)*0.0001; @@ -1970,7 +1979,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front())); state.drawQuads(0,transformedBackdropCoords->size()); @@ -1979,7 +1988,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult // Draw the foreground text const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID]; - if (!transformedCoords->empty()) + if (transformedCoords.valid() && !transformedCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedCoords->front())); state.setTexCoordPointer( 0, 2, GL_FLOAT, 0, &(glyphquad._texcoords->front())); @@ -2038,7 +2047,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult for( ; backdrop_index < max_backdrop_index; backdrop_index++) { const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID]; - if (!transformedBackdropCoords->empty()) + if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front())); state.drawQuads(0,transformedBackdropCoords->size()); @@ -2116,15 +2125,21 @@ void Text::GlyphQuads::initGPUBufferObjects() _colorCoords->setVertexBufferObject(vbo); for (size_t i = 0; i < _transformedCoords.size(); i++) { - _transformedCoords[i]->setBinding(osg::Array::BIND_PER_VERTEX); - _transformedCoords[i]->setVertexBufferObject(vbo); + if (_transformedCoords[i].valid()) + { + _transformedCoords[i]->setBinding(osg::Array::BIND_PER_VERTEX); + _transformedCoords[i]->setVertexBufferObject(vbo); + } } for (int j = 0; j < 8; j++) { for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) { - _transformedBackdropCoords[j][i]->setBinding(osg::Array::BIND_PER_VERTEX); - _transformedBackdropCoords[j][i]->setVertexBufferObject(vbo); + if (_transformedBackdropCoords[j][i].valid()) + { + _transformedBackdropCoords[j][i]->setBinding(osg::Array::BIND_PER_VERTEX); + _transformedBackdropCoords[j][i]->setVertexBufferObject(vbo); + } } } @@ -2140,7 +2155,10 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) { for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) { - _transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize); + if (_transformedBackdropCoords[j][i].valid()) + { + _transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize); + } } } @@ -2155,7 +2173,10 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const { for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++) { - _transformedBackdropCoords[j][i]->releaseGLObjects(state); + if (_transformedBackdropCoords[j][i].valid()) + { + _transformedBackdropCoords[j][i]->releaseGLObjects(state); + } } }