Added option for combining the GlyphQuad::backdropcoords into the GlyphQuad::coords.

This commit is contained in:
Robert Osfield
2017-02-27 11:53:42 +00:00
parent 0ec204f6e4
commit 80c96cd54f
2 changed files with 90 additions and 29 deletions

View File

@@ -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;i<numCoords;++i)
{
float horizontal_shift_direction;
@@ -723,7 +724,10 @@ void Text::computeBackdropPositions()
vertical_shift_direction = -1.0f;
}
}
(*transformedCoords)[i] = osg::Vec3(horizontal_shift_direction * _backdropHorizontalOffset * avg_width + (*coords)[i].x(), vertical_shift_direction * _backdropVerticalOffset * avg_height + (*coords)[i].y(), 0.0f);
#ifdef NEW_APPROACH
(*texcoords).push_back((*texcoords)[i]);
#endif
(*transformedCoords).push_back(osg::Vec3(horizontal_shift_direction * _backdropHorizontalOffset * avg_width + (*coords)[i].x(), vertical_shift_direction * _backdropVerticalOffset * avg_height + (*coords)[i].y(), 0.0f));
transformedCoords->dirty();
}
}
@@ -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()<<std::endl;
_primitives.clear();
unsigned int numCoords = _glyphs.size()*4;
unsigned int numPrimtives = 1;
if (backdropType==Text::OUTLINE) numPrimtives += 8;
if (backdropType!=Text::NONE) numPrimtives += 1;
@@ -1845,13 +1894,19 @@ void Text::GlyphQuads::setupPrimitives(BackdropType backdropType)
_primitives.push_back(new DrawElementsUShort(PrimitiveSet::TRIANGLES));
}
unsigned int baseIndex = 0;
for(Primitives::iterator itr = _primitives.begin();
itr != _primitives.end();
++itr)
{
DrawElementsUShort* indices = itr->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<osg::ElementBufferObject> 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();