From f2330059884190d2066c08c5a55f78e7fadbd1aa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 1 Mar 2017 16:43:05 +0000 Subject: [PATCH] Merged the decoration vertices with the same vertex arrays used for text glyphs --- include/osgText/Text | 16 --------- include/osgText/TextBase | 18 ++++++++-- src/osgText/Text.cpp | 5 +-- src/osgText/Text3D.cpp | 4 +-- src/osgText/TextBase.cpp | 72 +++++++++++++++++++--------------------- 5 files changed, 54 insertions(+), 61 deletions(-) diff --git a/include/osgText/Text b/include/osgText/Text index 20b5ee6c0..55bfe32b3 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -23,8 +23,6 @@ namespace osgText { -#define NEW_APPROACH - class OSGTEXT_EXPORT Text : public osgText::TextBase { public: @@ -295,20 +293,6 @@ public: public: - Coords _coords; - ColorCoords _colorCoords; - TexCoords _texcoords; - - unsigned int addCoord(const osg::Vec2& c) { unsigned int s = _coords->size(); _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); return s; } - unsigned int addCoord(const osg::Vec3& c) { unsigned int s = _coords->size(); _coords->push_back(c); return s; } - - void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); } - void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; } - - Coords& getCoords() { return _coords; } - const Coords& getCoords() const { return _coords; } - - void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); } // internal structures, variable and methods used for rendering of characters. struct OSGTEXT_EXPORT GlyphQuads diff --git a/include/osgText/TextBase b/include/osgText/TextBase index 3bb244dd8..fb2f88574 100644 --- a/include/osgText/TextBase +++ b/include/osgText/TextBase @@ -22,7 +22,6 @@ namespace osgText { - class OSGTEXT_EXPORT TextBase : public osg::Drawable { public: @@ -266,6 +265,13 @@ public: virtual osg::BoundingBox computeBoundingBox() const; + typedef osg::ref_ptr Coords; + Coords& getCoords() { return _coords; } + const Coords& getCoords() const { return _coords; } + + void getCoord(unsigned int i, osg::Vec2& c) const { c.set((*_coords)[i].x(), (*_coords)[i].y()); } + void getCoord(unsigned int i, osg::Vec3& c) const { c = (*_coords)[i]; } + protected: virtual ~TextBase(); @@ -279,11 +285,11 @@ protected: virtual void computeGlyphRepresentation() = 0; - typedef osg::ref_ptr Coords; typedef osg::ref_ptr TexCoords; typedef osg::ref_ptr ColorCoords; typedef std::vector< osg::ref_ptr > Primitives; + // members which have public access. osg::Vec4 _color; osg::ref_ptr _font; @@ -315,13 +321,19 @@ protected: mutable osg::Matrix _matrix; - Coords _decorationVertices; Primitives _decorationPrimitives; void setupDecoration(); + Coords _coords; + ColorCoords _colorCoords; + TexCoords _texcoords; + + unsigned int addCoord(const osg::Vec2& c) { unsigned int s = _coords->size(); _coords->push_back(osg::Vec3(c.x(), c.y(), 0.0f)); return s; } + unsigned int addCoord(const osg::Vec3& c) { unsigned int s = _coords->size(); _coords->push_back(c); return s; } + void addTexCoord(const osg::Vec2& tc) { _texcoords->push_back(tc); } }; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 2a326e8d7..e20ac3bb1 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -1094,7 +1094,7 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie if ((_drawMode&(~TEXT))!=0) { - if (_decorationVertices.valid() && !_decorationVertices->empty()) + if (!_decorationPrimitives.empty()) { state.disableNormalPointer(); @@ -1102,7 +1102,8 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false); state.disableAllVertexArrays(); - state.setVertexPointer(_decorationVertices.get()); + + state.setVertexPointer(_coords.get()); #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) switch(_backdropImplementation) diff --git a/src/osgText/Text3D.cpp b/src/osgText/Text3D.cpp index 7c4545395..fb23d1d88 100644 --- a/src/osgText/Text3D.cpp +++ b/src/osgText/Text3D.cpp @@ -461,12 +461,12 @@ void Text3D::drawImplementation(osg::RenderInfo& renderInfo) const if ((_drawMode&(~TEXT))!=0) { - if (_decorationVertices.valid() && !_decorationVertices->empty()) + if (!_decorationPrimitives.empty()) { osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false); osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false); - state.setVertexPointer(_decorationVertices.get()); + state.setVertexPointer(_coords.get()); for(Primitives::const_iterator itr = _decorationPrimitives.begin(); itr != _decorationPrimitives.end(); diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index 20f827996..6dad04dd1 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -617,21 +617,17 @@ void TextBase::setupDecoration() if (_drawMode & BOUNDINGBOX) numVerticesRequired += 8; if (_drawMode & ALIGNMENT) numVerticesRequired += 4; - if (numVerticesRequired==0) - { - _decorationVertices = 0; - return; - } - - if (!_decorationVertices) - { - _decorationVertices = new osg::Vec3Array; - _decorationVertices->resize(numVerticesRequired); - } - - _decorationVertices->clear(); _decorationPrimitives.clear(); + if (numVerticesRequired==0) return; + + Coords& coords = _coords; + if (!coords) + { + coords = new osg::Vec3Array; + coords->resize(numVerticesRequired); + } + if ((_drawMode & FILLEDBOUNDINGBOX)!=0 && _textBB.valid()) { osg::Vec3 c000(_textBB.xMin(),_textBB.yMin(),_textBB.zMin()); @@ -639,12 +635,12 @@ void TextBase::setupDecoration() osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin()); osg::Vec3 c010(_textBB.xMin(),_textBB.yMax(),_textBB.zMin()); - unsigned int base = _decorationVertices->size(); + unsigned int base = coords->size(); - _decorationVertices->push_back(c000); - _decorationVertices->push_back(c100); - _decorationVertices->push_back(c110); - _decorationVertices->push_back(c010); + coords->push_back(c000); + coords->push_back(c100); + coords->push_back(c110); + coords->push_back(c010); osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_TRIANGLES); _decorationPrimitives.push_back(primitives); @@ -666,12 +662,12 @@ void TextBase::setupDecoration() osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin()); osg::Vec3 c010(_textBB.xMin(),_textBB.yMax(),_textBB.zMin()); - unsigned int base = _decorationVertices->size(); + unsigned int base = coords->size(); - _decorationVertices->push_back(c000); - _decorationVertices->push_back(c100); - _decorationVertices->push_back(c110); - _decorationVertices->push_back(c010); + coords->push_back(c000); + coords->push_back(c100); + coords->push_back(c110); + coords->push_back(c010); osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_LINE_LOOP); _decorationPrimitives.push_back(primitives); @@ -693,17 +689,17 @@ void TextBase::setupDecoration() osg::Vec3 c111(_textBB.xMax(),_textBB.yMax(),_textBB.zMax()); osg::Vec3 c011(_textBB.xMin(),_textBB.yMax(),_textBB.zMax()); - unsigned int base = _decorationVertices->size(); + unsigned int base = coords->size(); - _decorationVertices->push_back(c000); // +0 - _decorationVertices->push_back(c100); // +1 - _decorationVertices->push_back(c110); // +2 - _decorationVertices->push_back(c010); // +3 + coords->push_back(c000); // +0 + coords->push_back(c100); // +1 + coords->push_back(c110); // +2 + coords->push_back(c010); // +3 - _decorationVertices->push_back(c001); // +4 - _decorationVertices->push_back(c101); // +5 - _decorationVertices->push_back(c111); // +6 - _decorationVertices->push_back(c011); // +7 + coords->push_back(c001); // +4 + coords->push_back(c101); // +5 + coords->push_back(c111); // +6 + coords->push_back(c011); // +7 osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_LINES); @@ -760,12 +756,12 @@ void TextBase::setupDecoration() osg::Vec3 vt(osg::Vec3(_offset.x(),_offset.y()-cursorsize,_offset.z())); osg::Vec3 vb(osg::Vec3(_offset.x(),_offset.y()+cursorsize,_offset.z())); - unsigned int base = _decorationVertices->size(); + unsigned int base = coords->size(); - _decorationVertices->push_back(hl); - _decorationVertices->push_back(hr); - _decorationVertices->push_back(vt); - _decorationVertices->push_back(vb); + coords->push_back(hl); + coords->push_back(hr); + coords->push_back(vt); + coords->push_back(vb); osg::ref_ptr primitives = new osg::DrawElementsUShort(GL_LINES); _decorationPrimitives.push_back(primitives); @@ -774,7 +770,7 @@ void TextBase::setupDecoration() primitives->push_back(base+0); primitives->push_back(base+1); - primitives->push_back(base+1); primitives->push_back(base+2); + primitives->push_back(base+3); } }