Added checks for the validity of chached coordinate arrays.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/branches/OpenSceneGraph-3.4@15061 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
0153c3e7e2
commit
732364d49b
@ -733,6 +733,7 @@ void Text::computePositions(unsigned int contextID) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
||||||
|
if (!transformedCoords) transformedCoords = new osg::Vec3Array;
|
||||||
|
|
||||||
unsigned int numCoords = coords2->size();
|
unsigned int numCoords = coords2->size();
|
||||||
if (numCoords != transformedCoords->size())
|
if (numCoords != transformedCoords->size())
|
||||||
@ -818,6 +819,8 @@ void Text::computeBackdropPositions(unsigned int contextID) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
|
if (!transformedCoords) transformedCoords = new osg::Vec3Array();
|
||||||
|
|
||||||
unsigned int numCoords = coords2->size();
|
unsigned int numCoords = coords2->size();
|
||||||
if (numCoords!=transformedCoords->size())
|
if (numCoords!=transformedCoords->size())
|
||||||
{
|
{
|
||||||
@ -1302,7 +1305,7 @@ void Text::drawImplementation(osg::State& state, const osg::Vec4& colorMultiplie
|
|||||||
if ( !_textureGlyphQuadMap.empty() )
|
if ( !_textureGlyphQuadMap.empty() )
|
||||||
{
|
{
|
||||||
const GlyphQuads& glyphquad = (_textureGlyphQuadMap.begin())->second;
|
const GlyphQuads& glyphquad = (_textureGlyphQuadMap.begin())->second;
|
||||||
if ( glyphquad._transformedCoords[contextID]->empty() )
|
if (!glyphquad._transformedCoords[contextID].valid() || glyphquad._transformedCoords[contextID]->empty() )
|
||||||
{
|
{
|
||||||
computePositions(contextID);
|
computePositions(contextID);
|
||||||
}
|
}
|
||||||
@ -1477,9 +1480,13 @@ void Text::accept(osg::Drawable::ConstAttributeFunctor& af) const
|
|||||||
++titr)
|
++titr)
|
||||||
{
|
{
|
||||||
const GlyphQuads& glyphquad = titr->second;
|
const GlyphQuads& glyphquad = titr->second;
|
||||||
|
if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid())
|
||||||
|
{
|
||||||
af.apply(osg::Drawable::VERTICES, glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front()));
|
af.apply(osg::Drawable::VERTICES, glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front()));
|
||||||
af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front()));
|
af.apply(osg::Drawable::TEXTURE_COORDS_0, glyphquad._texcoords->size(), &(glyphquad._texcoords->front()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::accept(osg::PrimitiveFunctor& pf) const
|
void Text::accept(osg::PrimitiveFunctor& pf) const
|
||||||
@ -1489,9 +1496,11 @@ void Text::accept(osg::PrimitiveFunctor& pf) const
|
|||||||
++titr)
|
++titr)
|
||||||
{
|
{
|
||||||
const GlyphQuads& glyphquad = titr->second;
|
const GlyphQuads& glyphquad = titr->second;
|
||||||
|
if (!glyphquad._transformedCoords.empty() && glyphquad._transformedCoords[0].valid())
|
||||||
|
{
|
||||||
pf.setVertexArray(glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front()));
|
pf.setVertexArray(glyphquad._transformedCoords[0]->size(), &(glyphquad._transformedCoords[0]->front()));
|
||||||
pf.drawArrays(GL_QUADS, 0, glyphquad._transformedCoords[0]->size());
|
pf.drawArrays(GL_QUADS, 0, glyphquad._transformedCoords[0]->size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1604,7 +1613,7 @@ void Text::drawForegroundText(osg::State& state, const GlyphQuads& glyphquad, co
|
|||||||
unsigned int contextID = state.getContextID();
|
unsigned int contextID = state.getContextID();
|
||||||
|
|
||||||
const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
||||||
if (!transformedCoords->empty())
|
if (transformedCoords.valid() && !transformedCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer(transformedCoords.get());
|
state.setVertexPointer(transformedCoords.get());
|
||||||
state.setTexCoordPointer(0, glyphquad._texcoords.get());
|
state.setTexCoordPointer(0, glyphquad._texcoords.get());
|
||||||
@ -1701,7 +1710,7 @@ void Text::drawTextWithBackdrop(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer(transformedBackdropCoords.get());
|
state.setVertexPointer(transformedBackdropCoords.get());
|
||||||
glyphquad._quadIndices->draw(state, _useVertexBufferObjects);
|
glyphquad._quadIndices->draw(state, _useVertexBufferObjects);
|
||||||
@ -1757,7 +1766,7 @@ void Text::renderWithPolygonOffset(osg::State& state, const osg::Vec4& colorMult
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
||||||
glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(),
|
glPolygonOffset(0.1f * osg::PolygonOffset::getFactorMultiplier(),
|
||||||
@ -1816,7 +1825,7 @@ void Text::renderWithNoDepthBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
||||||
state.drawQuads(0,transformedBackdropCoords->size());
|
state.drawQuads(0,transformedBackdropCoords->size());
|
||||||
@ -1872,7 +1881,7 @@ void Text::renderWithDepthRange(osg::State& state, const osg::Vec4& colorMultipl
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
||||||
double offset = double(max_backdrop_index-backdrop_index)*0.0001;
|
double offset = double(max_backdrop_index-backdrop_index)*0.0001;
|
||||||
@ -1970,7 +1979,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
||||||
state.drawQuads(0,transformedBackdropCoords->size());
|
state.drawQuads(0,transformedBackdropCoords->size());
|
||||||
@ -1979,7 +1988,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
|
|
||||||
// Draw the foreground text
|
// Draw the foreground text
|
||||||
const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
const GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
||||||
if (!transformedCoords->empty())
|
if (transformedCoords.valid() && !transformedCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedCoords->front()));
|
||||||
state.setTexCoordPointer( 0, 2, GL_FLOAT, 0, &(glyphquad._texcoords->front()));
|
state.setTexCoordPointer( 0, 2, GL_FLOAT, 0, &(glyphquad._texcoords->front()));
|
||||||
@ -2038,7 +2047,7 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
for( ; backdrop_index < max_backdrop_index; backdrop_index++)
|
||||||
{
|
{
|
||||||
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
const GlyphQuads::Coords3& transformedBackdropCoords = glyphquad._transformedBackdropCoords[backdrop_index][contextID];
|
||||||
if (!transformedBackdropCoords->empty())
|
if (transformedBackdropCoords.valid() && !transformedBackdropCoords->empty())
|
||||||
{
|
{
|
||||||
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
state.setVertexPointer( 3, GL_FLOAT, 0, &(transformedBackdropCoords->front()));
|
||||||
state.drawQuads(0,transformedBackdropCoords->size());
|
state.drawQuads(0,transformedBackdropCoords->size());
|
||||||
@ -2115,18 +2124,24 @@ void Text::GlyphQuads::initGPUBufferObjects()
|
|||||||
_colorCoords->setBinding(osg::Array::BIND_PER_VERTEX);
|
_colorCoords->setBinding(osg::Array::BIND_PER_VERTEX);
|
||||||
_colorCoords->setVertexBufferObject(vbo);
|
_colorCoords->setVertexBufferObject(vbo);
|
||||||
for (size_t i = 0; i < _transformedCoords.size(); i++)
|
for (size_t i = 0; i < _transformedCoords.size(); i++)
|
||||||
|
{
|
||||||
|
if (_transformedCoords[i].valid())
|
||||||
{
|
{
|
||||||
_transformedCoords[i]->setBinding(osg::Array::BIND_PER_VERTEX);
|
_transformedCoords[i]->setBinding(osg::Array::BIND_PER_VERTEX);
|
||||||
_transformedCoords[i]->setVertexBufferObject(vbo);
|
_transformedCoords[i]->setVertexBufferObject(vbo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
||||||
|
{
|
||||||
|
if (_transformedBackdropCoords[j][i].valid())
|
||||||
{
|
{
|
||||||
_transformedBackdropCoords[j][i]->setBinding(osg::Array::BIND_PER_VERTEX);
|
_transformedBackdropCoords[j][i]->setBinding(osg::Array::BIND_PER_VERTEX);
|
||||||
_transformedBackdropCoords[j][i]->setVertexBufferObject(vbo);
|
_transformedBackdropCoords[j][i]->setVertexBufferObject(vbo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_quadIndices->setElementBufferObject(new osg::ElementBufferObject());
|
_quadIndices->setElementBufferObject(new osg::ElementBufferObject());
|
||||||
}
|
}
|
||||||
@ -2139,10 +2154,13 @@ void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize)
|
|||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
||||||
|
{
|
||||||
|
if (_transformedBackdropCoords[j][i].valid())
|
||||||
{
|
{
|
||||||
_transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize);
|
_transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_quadIndices->resizeGLObjectBuffers(maxSize);
|
_quadIndices->resizeGLObjectBuffers(maxSize);
|
||||||
|
|
||||||
@ -2154,10 +2172,13 @@ void Text::GlyphQuads::releaseGLObjects(osg::State* state) const
|
|||||||
for (int j = 0; j < 8; j++)
|
for (int j = 0; j < 8; j++)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
||||||
|
{
|
||||||
|
if (_transformedBackdropCoords[j][i].valid())
|
||||||
{
|
{
|
||||||
_transformedBackdropCoords[j][i]->releaseGLObjects(state);
|
_transformedBackdropCoords[j][i]->releaseGLObjects(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_quadIndices->releaseGLObjects(state);
|
_quadIndices->releaseGLObjects(state);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user