Refactored osgText so that it no longer uses GLBeginEndAdapter
This commit is contained in:
parent
987513d309
commit
0f3e61146d
@ -422,6 +422,7 @@ protected:
|
||||
osg::Vec4 _colorGradientBottomRight;
|
||||
osg::Vec4 _colorGradientTopRight;
|
||||
|
||||
|
||||
// Helper function for color interpolation
|
||||
float bilinearInterpolate(float x1, float x2, float y1, float y2, float x, float y, float q11, float q12, float q21, float q22) const;
|
||||
};
|
||||
|
@ -149,10 +149,6 @@ class OSGTEXT_EXPORT Text3D : public osgText::TextBase
|
||||
|
||||
osg::ref_ptr<osg::StateSet> _wallStateSet;
|
||||
osg::ref_ptr<osg::StateSet> _backStateSet;
|
||||
|
||||
void setupDecoration();
|
||||
|
||||
osg::ref_ptr<osg::Vec3Array> _decorationVertices;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -327,6 +327,11 @@ protected:
|
||||
mutable osg::Vec3 _offset;
|
||||
mutable osg::Vec3 _normal;
|
||||
mutable osg::BoundingBox _textBB;
|
||||
|
||||
void setupDecoration();
|
||||
|
||||
osg::ref_ptr<osg::Vec3Array> _decorationVertices;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -538,6 +538,9 @@ void Text::computeGlyphRepresentation()
|
||||
computeBackdropBoundingBox();
|
||||
computeBoundingBoxMargin();
|
||||
computeColorGradients();
|
||||
|
||||
// set up the vertices for any boundinbox or alignment decoration
|
||||
setupDecoration();
|
||||
}
|
||||
|
||||
// Returns false if there are no glyphs and the width/height values are invalid.
|
||||
@ -1311,24 +1314,39 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
||||
}
|
||||
}
|
||||
|
||||
osg::GLBeginEndAdapter& gl = (state.getGLBeginEndAdapter());
|
||||
|
||||
state.Normal(_normal.x(), _normal.y(), _normal.z());
|
||||
|
||||
if (_drawMode & FILLEDBOUNDINGBOX)
|
||||
if ((_drawMode&(~TEXT))!=0)
|
||||
{
|
||||
if (_textBB.valid())
|
||||
|
||||
// ** save the previous modelview matrix
|
||||
osg::Matrix previous(state.getModelViewMatrix());
|
||||
|
||||
// ** get the modelview for this context
|
||||
osg::Matrix modelview(_autoTransformCache[contextID]._matrix);
|
||||
|
||||
// ** mult previous by the modelview for this context
|
||||
modelview.postMult(previous);
|
||||
|
||||
// ** apply this new modelview matrix
|
||||
state.applyModelViewMatrix(modelview);
|
||||
|
||||
state.disableNormalPointer();
|
||||
|
||||
state.Color(colorMultiplier.r()*_textBBColor.r(),colorMultiplier.g()*_textBBColor.g(),colorMultiplier.b()*_textBBColor.b(),colorMultiplier.a()*_textBBColor.a());
|
||||
|
||||
if (_decorationVertices.valid() && !_decorationVertices->empty())
|
||||
{
|
||||
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
||||
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false);
|
||||
|
||||
state.setVertexPointer(_decorationVertices.get());
|
||||
|
||||
unsigned int start_index = 0;
|
||||
if ((_drawMode & FILLEDBOUNDINGBOX)!=0 && _textBB.valid())
|
||||
{
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);
|
||||
|
||||
const osg::Matrix& matrix = _autoTransformCache[contextID]._matrix;
|
||||
|
||||
osg::Vec3 c00(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c10(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c11(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c01(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix);
|
||||
|
||||
switch(_backdropImplementation)
|
||||
{
|
||||
case NO_DEPTH_BUFFER:
|
||||
@ -1349,13 +1367,8 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
||||
glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(), 10.0f * osg::PolygonOffset::getUnitsMultiplier() );
|
||||
}
|
||||
|
||||
gl.Color4f(colorMultiplier.r()*_textBBColor.r(),colorMultiplier.g()*_textBBColor.g(),colorMultiplier.b()*_textBBColor.b(),colorMultiplier.a()*_textBBColor.a());
|
||||
gl.Begin(GL_QUADS);
|
||||
gl.Vertex3fv(c00.ptr());
|
||||
gl.Vertex3fv(c10.ptr());
|
||||
gl.Vertex3fv(c11.ptr());
|
||||
gl.Vertex3fv(c01.ptr());
|
||||
gl.End();
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
start_index += 4;
|
||||
|
||||
switch(_backdropImplementation)
|
||||
{
|
||||
@ -1372,10 +1385,18 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPopAttrib();
|
||||
}
|
||||
#else
|
||||
OSG_NOTICE<<"Warning: Text::drawImplementation() fillMode FILLEDBOUNDINGBOX not supported"<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (start_index<_decorationVertices->size())
|
||||
{
|
||||
state.Color(colorMultiplier.r(),colorMultiplier.g(),colorMultiplier.b(),colorMultiplier.a());
|
||||
glDrawArrays(GL_LINES, start_index, _decorationVertices->size());
|
||||
}
|
||||
}
|
||||
|
||||
// restore the previous modelview matrix
|
||||
state.applyModelViewMatrix(previous);
|
||||
}
|
||||
|
||||
#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
|
||||
@ -1423,54 +1444,6 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
||||
state.unbindElementBufferObject();
|
||||
}
|
||||
|
||||
if (_drawMode & BOUNDINGBOX)
|
||||
{
|
||||
|
||||
if (_textBB.valid())
|
||||
{
|
||||
state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);
|
||||
|
||||
const osg::Matrix& matrix = _autoTransformCache[contextID]._matrix;
|
||||
|
||||
osg::Vec3 c00(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c10(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c11(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix);
|
||||
osg::Vec3 c01(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix);
|
||||
|
||||
|
||||
gl.Color4f(colorMultiplier.r()*_textBBColor.r(),colorMultiplier.g()*_textBBColor.g(),colorMultiplier.b()*_textBBColor.b(),colorMultiplier.a()*_textBBColor.a());
|
||||
gl.Begin(GL_LINE_LOOP);
|
||||
gl.Vertex3fv(c00.ptr());
|
||||
gl.Vertex3fv(c10.ptr());
|
||||
gl.Vertex3fv(c11.ptr());
|
||||
gl.Vertex3fv(c01.ptr());
|
||||
gl.End();
|
||||
}
|
||||
}
|
||||
|
||||
if (_drawMode & ALIGNMENT)
|
||||
{
|
||||
gl.Color4fv(colorMultiplier.ptr());
|
||||
|
||||
float cursorsize = _characterHeight*0.5f;
|
||||
|
||||
const osg::Matrix& matrix = _autoTransformCache[contextID]._matrix;
|
||||
|
||||
osg::Vec3 hl(osg::Vec3(_offset.x()-cursorsize,_offset.y(),_offset.z())*matrix);
|
||||
osg::Vec3 hr(osg::Vec3(_offset.x()+cursorsize,_offset.y(),_offset.z())*matrix);
|
||||
osg::Vec3 vt(osg::Vec3(_offset.x(),_offset.y()-cursorsize,_offset.z())*matrix);
|
||||
osg::Vec3 vb(osg::Vec3(_offset.x(),_offset.y()+cursorsize,_offset.z())*matrix);
|
||||
|
||||
state.applyTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OFF);
|
||||
|
||||
gl.Begin(GL_LINES);
|
||||
gl.Vertex3fv(hl.ptr());
|
||||
gl.Vertex3fv(hr.ptr());
|
||||
gl.Vertex3fv(vt.ptr());
|
||||
gl.Vertex3fv(vb.ptr());
|
||||
gl.End();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const
|
||||
|
@ -498,27 +498,35 @@ void Text3D::drawImplementation(osg::RenderInfo& renderInfo) const
|
||||
|
||||
state.disableAllVertexArrays();
|
||||
|
||||
state.Color(_color.r(),_color.g(),_color.b(),_color.a());
|
||||
if ((_drawMode&(~TEXT))!=0)
|
||||
{
|
||||
|
||||
if (_decorationVertices.valid() && !_decorationVertices->empty())
|
||||
{
|
||||
state.disableNormalPointer();
|
||||
|
||||
osg::State::ApplyModeProxy applyMode(state, GL_LIGHTING, false);
|
||||
|
||||
// bool lighting_value = state.getLastAppliedModeValue(GL_LIGHTING);
|
||||
// if (lighting_value) state.applyMode(GL_LIGHTING, false);
|
||||
osg::State::ApplyTextureModeProxy applyTextureMode(state, 0, GL_TEXTURE_2D, false);
|
||||
|
||||
state.setVertexPointer(_decorationVertices.get());
|
||||
|
||||
glDrawArrays(GL_LINES, 0, _decorationVertices->size());
|
||||
unsigned int start_index = 0;
|
||||
if ((_drawMode & FILLEDBOUNDINGBOX)!=0 && _textBB.valid())
|
||||
{
|
||||
state.Color(_textBBColor.r(),_textBBColor.g(),_textBBColor.b(),_textBBColor.a());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
start_index += 4;
|
||||
}
|
||||
|
||||
///if (lighting_value) state.applyMode(GL_LIGHTING, true);
|
||||
if (start_index<_decorationVertices->size())
|
||||
{
|
||||
state.Color(_color.r(),_color.g(),_color.b(),_color.a());
|
||||
glDrawArrays(GL_LINES, start_index, _decorationVertices->size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_drawMode & TEXT)
|
||||
{
|
||||
|
||||
state.Color(_color.r(),_color.g(),_color.b(),_color.a());
|
||||
|
||||
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)
|
||||
renderInfo.getState()->applyMode(GL_NORMALIZE, true);
|
||||
@ -727,96 +735,5 @@ void Text3D::releaseGLObjects(osg::State* state) const
|
||||
if (_font.valid()) _font->releaseGLObjects(state);
|
||||
}
|
||||
|
||||
|
||||
void Text3D::setupDecoration()
|
||||
{
|
||||
unsigned int numVerticesRequired = 0;
|
||||
if (_drawMode & BOUNDINGBOX) numVerticesRequired += 24;
|
||||
if (_drawMode & ALIGNMENT) numVerticesRequired += 4;
|
||||
|
||||
if (numVerticesRequired==0)
|
||||
{
|
||||
_decorationVertices = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_decorationVertices)
|
||||
{
|
||||
_decorationVertices = new osg::Vec3Array;
|
||||
_decorationVertices->resize(numVerticesRequired);
|
||||
}
|
||||
|
||||
_decorationVertices->clear();
|
||||
|
||||
if ((_drawMode & BOUNDINGBOX)!=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());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user