Merged the decoration vertices with the same vertex arrays used for text glyphs
This commit is contained in:
parent
f4966a96d4
commit
f233005988
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
namespace osgText {
|
namespace osgText {
|
||||||
|
|
||||||
#define NEW_APPROACH
|
|
||||||
|
|
||||||
class OSGTEXT_EXPORT Text : public osgText::TextBase
|
class OSGTEXT_EXPORT Text : public osgText::TextBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -295,20 +293,6 @@ public:
|
|||||||
|
|
||||||
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.
|
// internal structures, variable and methods used for rendering of characters.
|
||||||
struct OSGTEXT_EXPORT GlyphQuads
|
struct OSGTEXT_EXPORT GlyphQuads
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
namespace osgText {
|
namespace osgText {
|
||||||
|
|
||||||
|
|
||||||
class OSGTEXT_EXPORT TextBase : public osg::Drawable
|
class OSGTEXT_EXPORT TextBase : public osg::Drawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -266,6 +265,13 @@ public:
|
|||||||
|
|
||||||
virtual osg::BoundingBox computeBoundingBox() const;
|
virtual osg::BoundingBox computeBoundingBox() const;
|
||||||
|
|
||||||
|
typedef osg::ref_ptr<osg::Vec3Array> 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:
|
protected:
|
||||||
|
|
||||||
virtual ~TextBase();
|
virtual ~TextBase();
|
||||||
@ -279,11 +285,11 @@ protected:
|
|||||||
|
|
||||||
virtual void computeGlyphRepresentation() = 0;
|
virtual void computeGlyphRepresentation() = 0;
|
||||||
|
|
||||||
typedef osg::ref_ptr<osg::Vec3Array> Coords;
|
|
||||||
typedef osg::ref_ptr<osg::Vec2Array> TexCoords;
|
typedef osg::ref_ptr<osg::Vec2Array> TexCoords;
|
||||||
typedef osg::ref_ptr<osg::Vec4Array> ColorCoords;
|
typedef osg::ref_ptr<osg::Vec4Array> ColorCoords;
|
||||||
typedef std::vector< osg::ref_ptr<osg::DrawElementsUShort> > Primitives;
|
typedef std::vector< osg::ref_ptr<osg::DrawElementsUShort> > Primitives;
|
||||||
|
|
||||||
|
|
||||||
// members which have public access.
|
// members which have public access.
|
||||||
osg::Vec4 _color;
|
osg::Vec4 _color;
|
||||||
osg::ref_ptr<Font> _font;
|
osg::ref_ptr<Font> _font;
|
||||||
@ -315,13 +321,19 @@ protected:
|
|||||||
|
|
||||||
mutable osg::Matrix _matrix;
|
mutable osg::Matrix _matrix;
|
||||||
|
|
||||||
Coords _decorationVertices;
|
|
||||||
Primitives _decorationPrimitives;
|
Primitives _decorationPrimitives;
|
||||||
|
|
||||||
void setupDecoration();
|
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); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1094,7 +1094,7 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
|||||||
if ((_drawMode&(~TEXT))!=0)
|
if ((_drawMode&(~TEXT))!=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_decorationVertices.valid() && !_decorationVertices->empty())
|
if (!_decorationPrimitives.empty())
|
||||||
{
|
{
|
||||||
state.disableNormalPointer();
|
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);
|
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false);
|
||||||
|
|
||||||
state.disableAllVertexArrays();
|
state.disableAllVertexArrays();
|
||||||
state.setVertexPointer(_decorationVertices.get());
|
|
||||||
|
state.setVertexPointer(_coords.get());
|
||||||
|
|
||||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||||
switch(_backdropImplementation)
|
switch(_backdropImplementation)
|
||||||
|
@ -461,12 +461,12 @@ void Text3D::drawImplementation(osg::RenderInfo& renderInfo) const
|
|||||||
if ((_drawMode&(~TEXT))!=0)
|
if ((_drawMode&(~TEXT))!=0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_decorationVertices.valid() && !_decorationVertices->empty())
|
if (!_decorationPrimitives.empty())
|
||||||
{
|
{
|
||||||
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
||||||
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, 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();
|
for(Primitives::const_iterator itr = _decorationPrimitives.begin();
|
||||||
itr != _decorationPrimitives.end();
|
itr != _decorationPrimitives.end();
|
||||||
|
@ -617,21 +617,17 @@ void TextBase::setupDecoration()
|
|||||||
if (_drawMode & BOUNDINGBOX) numVerticesRequired += 8;
|
if (_drawMode & BOUNDINGBOX) numVerticesRequired += 8;
|
||||||
if (_drawMode & ALIGNMENT) numVerticesRequired += 4;
|
if (_drawMode & ALIGNMENT) numVerticesRequired += 4;
|
||||||
|
|
||||||
if (numVerticesRequired==0)
|
|
||||||
{
|
|
||||||
_decorationVertices = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_decorationVertices)
|
|
||||||
{
|
|
||||||
_decorationVertices = new osg::Vec3Array;
|
|
||||||
_decorationVertices->resize(numVerticesRequired);
|
|
||||||
}
|
|
||||||
|
|
||||||
_decorationVertices->clear();
|
|
||||||
_decorationPrimitives.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())
|
if ((_drawMode & FILLEDBOUNDINGBOX)!=0 && _textBB.valid())
|
||||||
{
|
{
|
||||||
osg::Vec3 c000(_textBB.xMin(),_textBB.yMin(),_textBB.zMin());
|
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 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
|
||||||
osg::Vec3 c010(_textBB.xMin(),_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);
|
coords->push_back(c000);
|
||||||
_decorationVertices->push_back(c100);
|
coords->push_back(c100);
|
||||||
_decorationVertices->push_back(c110);
|
coords->push_back(c110);
|
||||||
_decorationVertices->push_back(c010);
|
coords->push_back(c010);
|
||||||
|
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_TRIANGLES);
|
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_TRIANGLES);
|
||||||
_decorationPrimitives.push_back(primitives);
|
_decorationPrimitives.push_back(primitives);
|
||||||
@ -666,12 +662,12 @@ void TextBase::setupDecoration()
|
|||||||
osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
|
osg::Vec3 c110(_textBB.xMax(),_textBB.yMax(),_textBB.zMin());
|
||||||
osg::Vec3 c010(_textBB.xMin(),_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);
|
coords->push_back(c000);
|
||||||
_decorationVertices->push_back(c100);
|
coords->push_back(c100);
|
||||||
_decorationVertices->push_back(c110);
|
coords->push_back(c110);
|
||||||
_decorationVertices->push_back(c010);
|
coords->push_back(c010);
|
||||||
|
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_LINE_LOOP);
|
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_LINE_LOOP);
|
||||||
_decorationPrimitives.push_back(primitives);
|
_decorationPrimitives.push_back(primitives);
|
||||||
@ -693,17 +689,17 @@ void TextBase::setupDecoration()
|
|||||||
osg::Vec3 c111(_textBB.xMax(),_textBB.yMax(),_textBB.zMax());
|
osg::Vec3 c111(_textBB.xMax(),_textBB.yMax(),_textBB.zMax());
|
||||||
osg::Vec3 c011(_textBB.xMin(),_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
|
coords->push_back(c000); // +0
|
||||||
_decorationVertices->push_back(c100); // +1
|
coords->push_back(c100); // +1
|
||||||
_decorationVertices->push_back(c110); // +2
|
coords->push_back(c110); // +2
|
||||||
_decorationVertices->push_back(c010); // +3
|
coords->push_back(c010); // +3
|
||||||
|
|
||||||
_decorationVertices->push_back(c001); // +4
|
coords->push_back(c001); // +4
|
||||||
_decorationVertices->push_back(c101); // +5
|
coords->push_back(c101); // +5
|
||||||
_decorationVertices->push_back(c111); // +6
|
coords->push_back(c111); // +6
|
||||||
_decorationVertices->push_back(c011); // +7
|
coords->push_back(c011); // +7
|
||||||
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_LINES);
|
osg::ref_ptr<osg::DrawElementsUShort> 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 vt(osg::Vec3(_offset.x(),_offset.y()-cursorsize,_offset.z()));
|
||||||
osg::Vec3 vb(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);
|
coords->push_back(hl);
|
||||||
_decorationVertices->push_back(hr);
|
coords->push_back(hr);
|
||||||
_decorationVertices->push_back(vt);
|
coords->push_back(vt);
|
||||||
_decorationVertices->push_back(vb);
|
coords->push_back(vb);
|
||||||
|
|
||||||
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_LINES);
|
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(GL_LINES);
|
||||||
_decorationPrimitives.push_back(primitives);
|
_decorationPrimitives.push_back(primitives);
|
||||||
@ -774,7 +770,7 @@ void TextBase::setupDecoration()
|
|||||||
primitives->push_back(base+0);
|
primitives->push_back(base+0);
|
||||||
primitives->push_back(base+1);
|
primitives->push_back(base+1);
|
||||||
|
|
||||||
primitives->push_back(base+1);
|
|
||||||
primitives->push_back(base+2);
|
primitives->push_back(base+2);
|
||||||
|
primitives->push_back(base+3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user