diff --git a/include/osgText/Text b/include/osgText/Text index 7c5259ff2..879e3f8f6 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -23,7 +23,7 @@ namespace osgText { -// #define NEW_APPROACH +#define NEW_APPROACH class OSGTEXT_EXPORT Text : public osgText::TextBase { @@ -310,8 +310,9 @@ public: ColorCoords _colorCoords; TexCoords _texcoords; - +#ifndef NEW_APPROACH Coords _transformedBackdropCoords[8]; +#endif Primitives _primitives; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index dea61e43b..f00db7e94 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -626,8 +626,13 @@ void Text::computeBackdropPositions() ++titr) { GlyphQuads& glyphquad = titr->second; + unsigned int numCoords = glyphquad._glyphs.size()*4; + GlyphQuads::Coords& coords = glyphquad._coords; +#ifdef NEW_APPROACH + GlyphQuads::TexCoords& texcoords = glyphquad._texcoords; +#endif unsigned int backdrop_index; unsigned int max_backdrop_index; if(_backdropType == OUTLINE) @@ -653,16 +658,12 @@ void Text::computeBackdropPositions() } for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + GlyphQuads::Coords& transformedCoords = glyphquad._coords; +#else GlyphQuads::Coords& transformedCoords = glyphquad._transformedBackdropCoords[backdrop_index]; - if (!transformedCoords) transformedCoords = new osg::Vec3Array(); - - unsigned int numCoords = coords->size(); - if (numCoords!=transformedCoords->size()) - { - transformedCoords->resize(numCoords); - } - +#endif for(i=0;idirty(); } } @@ -1452,18 +1456,25 @@ void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultipl max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer(0, glyphquad._texcoords.get()); state.disableColorPointer(); state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a()); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { - const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; - if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) +#ifdef NEW_APPROACH + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else + const GlyphQuads::Coords& transformedCoords = glyphquad._transformedBackdropCoords[backdrop_index]; + if (transformedCoords.valid() && !transformedCoords->empty()) { - state.setVertexPointer(transformedBackdropCoords.get()); + state.setVertexPointer(transformedCoords.get()); glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } } @@ -1507,20 +1518,27 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer( 0, glyphquad._texcoords.get()); state.disableColorPointer(); state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a()); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), osg::PolygonOffset::getUnitsMultiplier() * (max_backdrop_index-backdrop_index) ); + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), osg::PolygonOffset::getUnitsMultiplier() * (max_backdrop_index-backdrop_index) ); - state.setVertexPointer( transformedBackdropCoords.get()); glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } // Reset the polygon offset so the foreground text is on top @@ -1565,18 +1583,25 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer( 0, glyphquad._texcoords.get()); state.disableColorPointer(); state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a()); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } drawForegroundText(state, glyphquad, colorMultiplier); @@ -1620,12 +1645,20 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer( 0, glyphquad._texcoords.get()); state.disableColorPointer(); state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a()); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + double offset = double(max_backdrop_index-backdrop_index)*0.0001; + glDepthRange( offset, 1.0+offset); + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { @@ -1633,8 +1666,9 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl glDepthRange( offset, 1.0+offset); state.setVertexPointer( transformedBackdropCoords.get()); - state.drawQuads(0,transformedBackdropCoords->size()); + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } glDepthRange(0.0, 1.0); @@ -1718,27 +1752,30 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer( 0, glyphquad._texcoords.get()); state.disableColorPointer(); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); - state.drawQuads(0,transformedBackdropCoords->size()); + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } // Draw the foreground text - const GlyphQuads::Coords& transformedCoords = glyphquad._coords; - if (transformedCoords.valid() && !transformedCoords->empty()) - { - state.setVertexPointer( transformedCoords.get()); - state.setTexCoordPointer( 0, glyphquad._texcoords.get()); - state.drawQuads(0, transformedCoords->size()); - } + state.setVertexPointer( glyphquad._coords.get()); + state.setTexCoordPointer( 0, glyphquad._texcoords.get()); + glyphquad._primitives[0]->draw(state, _useVertexBufferObjects); } @@ -1785,18 +1822,25 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult max_backdrop_index = _backdropType+1; } +#ifdef NEW_APPROACH + state.setVertexPointer(glyphquad._coords.get()); +#endif state.setTexCoordPointer( 0, glyphquad._texcoords.get()); state.disableColorPointer(); state.Color(_backdropColor.r(),_backdropColor.g(),_backdropColor.b(),_backdropColor.a()); for( ; backdrop_index < max_backdrop_index; backdrop_index++) { +#ifdef NEW_APPROACH + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); +#else const GlyphQuads::Coords& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index]; if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty()) { state.setVertexPointer( transformedBackdropCoords.get()); - state.drawQuads(0,transformedBackdropCoords->size()); + glyphquad._primitives[backdrop_index+1]->draw(state, _useVertexBufferObjects); } +#endif } drawForegroundText(state, glyphquad, colorMultiplier); @@ -1824,18 +1868,23 @@ void Text::GlyphQuads::initGlyphQuads() _texcoords = new osg::Vec2Array(); _colorCoords = new osg::Vec4Array(); +#ifndef NEW_APPROACH for (int j = 0; j < 8; j++) { _transformedBackdropCoords[j] = new osg::Vec3Array(); _primitives.push_back(new DrawElementsUShort(PrimitiveSet::TRIANGLES)); } - +#endif } void Text::GlyphQuads::setupPrimitives(BackdropType backdropType) { + OSG_NOTICE<<"Text::GlyphQuads::setupPrimitives() _glyphs.size()="<<_glyphs.size()<<", "<<_coords->size()<get(); indices->clear(); - for (unsigned short i = 0; i < (unsigned short)_coords->size(); i += 4) + +#ifndef NEW_APPROACH + baseIndex = 0; +#endif + unsigned int endIndex = baseIndex + numCoords; + for (unsigned short i = baseIndex; i < endIndex; i += 4) { indices->push_back(i); indices->push_back(i + 1); @@ -1861,6 +1916,7 @@ void Text::GlyphQuads::setupPrimitives(BackdropType backdropType) indices->push_back(i + 2); indices->push_back(i + 3); } + baseIndex = endIndex; } } @@ -1874,6 +1930,7 @@ void Text::GlyphQuads::initGPUBufferObjects() _colorCoords->setBinding(osg::Array::BIND_PER_VERTEX); _colorCoords->setVertexBufferObject(vbo); +#ifndef NEW_APPROACH for (int j = 0; j < 8; j++) { if (_transformedBackdropCoords[j].valid()) @@ -1882,7 +1939,7 @@ void Text::GlyphQuads::initGPUBufferObjects() _transformedBackdropCoords[j]->setVertexBufferObject(vbo); } } - +#endif osg::ref_ptr ebo = new osg::ElementBufferObject(); for(Primitives::iterator itr = _primitives.begin(); itr != _primitives.end(); @@ -1900,6 +1957,7 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) _texcoords->resizeGLObjectBuffers(maxSize); _colorCoords->resizeGLObjectBuffers(maxSize); +#ifndef NEW_APPROACH for (int j = 0; j < 8; j++) { if (_transformedBackdropCoords[j].valid()) @@ -1907,7 +1965,7 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize) _transformedBackdropCoords[j]->resizeGLObjectBuffers(maxSize); } } - +#endif for(Primitives::iterator itr = _primitives.begin(); itr != _primitives.end(); ++itr) @@ -1924,6 +1982,7 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const _texcoords->releaseGLObjects(state); _colorCoords->releaseGLObjects(state); +#ifndef NEW_APPROACH for (int j = 0; j < 8; j++) { if (_transformedBackdropCoords[j].valid()) @@ -1931,6 +1990,7 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const _transformedBackdropCoords[j]->releaseGLObjects(state); } } +#endif for(Primitives::const_iterator itr = _primitives.begin(); itr != _primitives.end();