Refactored osgText so that it no longer uses GLBeginEndAdapter

This commit is contained in:
Robert Osfield
2016-09-02 17:01:25 +01:00
parent 987513d309
commit 0f3e61146d
6 changed files with 225 additions and 207 deletions

View File

@@ -474,3 +474,129 @@ void TextBase::positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cu
}
}
void TextBase::setupDecoration()
{
unsigned int numVerticesRequired = 0;
if (_drawMode & FILLEDBOUNDINGBOX) numVerticesRequired += 4;
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();
if ((_drawMode & FILLEDBOUNDINGBOX)!=0 && _textBB.valid())
{
osg::Vec3 c000(_textBB.xMin(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c100(_textBB.xMax(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
osg::Vec3 c010(_textBB.xMin(),_textBB.yMax(),_textBB.zMin());
_decorationVertices->push_back(c000);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c010);
}
if ((_drawMode & BOUNDINGBOX)!=0 && _textBB.valid())
{
if (_textBB.zMin()==_textBB.zMax())
{
osg::Vec3 c000(_textBB.xMin(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c100(_textBB.xMax(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
osg::Vec3 c010(_textBB.xMin(),_textBB.yMax(),_textBB.zMin());
_decorationVertices->push_back(c000);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c010);
_decorationVertices->push_back(c010);
_decorationVertices->push_back(c000);
}
else
{
osg::Vec3 c000(_textBB.xMin(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c100(_textBB.xMax(),_textBB.yMin(),_textBB.zMin());
osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
osg::Vec3 c010(_textBB.xMin(),_textBB.yMax(),_textBB.zMin());
osg::Vec3 c001(_textBB.xMin(),_textBB.yMin(),_textBB.zMax());
osg::Vec3 c101(_textBB.xMax(),_textBB.yMin(),_textBB.zMax());
osg::Vec3 c111(_textBB.xMax(),_textBB.yMax(),_textBB.zMax());
osg::Vec3 c011(_textBB.xMin(),_textBB.yMax(),_textBB.zMax());
// edges from corner 000
_decorationVertices->push_back(c000);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c000);
_decorationVertices->push_back(c001);
_decorationVertices->push_back(c000);
_decorationVertices->push_back(c010);
// edges from corner C101
_decorationVertices->push_back(c101);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c101);
_decorationVertices->push_back(c001);
_decorationVertices->push_back(c101);
_decorationVertices->push_back(c111);
// edges from corner C110
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c010);
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c100);
_decorationVertices->push_back(c110);
_decorationVertices->push_back(c111);
// edges from corner C011
_decorationVertices->push_back(c011);
_decorationVertices->push_back(c010);
_decorationVertices->push_back(c011);
_decorationVertices->push_back(c001);
_decorationVertices->push_back(c011);
_decorationVertices->push_back(c111);
}
}
if (_drawMode & ALIGNMENT)
{
float cursorsize = _characterHeight*0.5f;
osg::Vec3 hl(osg::Vec3(_offset.x()-cursorsize,_offset.y(),_offset.z()));
osg::Vec3 hr(osg::Vec3(_offset.x()+cursorsize,_offset.y(),_offset.z()));
osg::Vec3 vt(osg::Vec3(_offset.x(),_offset.y()-cursorsize,_offset.z()));
osg::Vec3 vb(osg::Vec3(_offset.x(),_offset.y()+cursorsize,_offset.z()));
_decorationVertices->push_back(hl);
_decorationVertices->push_back(hr);
_decorationVertices->push_back(vt);
_decorationVertices->push_back(vb);
}
}