Added Text::GlyphQuads::release/resizeGLObjects() and handling of inconsistent contextID sizes to avoid crashes when viewers and scene graphs aren't initialized correctly to the right number of contexts.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14947 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
e94c3334f9
commit
c4fdc93053
@ -317,11 +317,13 @@ public:
|
|||||||
void updateQuadIndices();
|
void updateQuadIndices();
|
||||||
|
|
||||||
GlyphQuads();
|
GlyphQuads();
|
||||||
|
GlyphQuads(const GlyphQuads& gq);
|
||||||
|
|
||||||
|
void initGlyphQuads();
|
||||||
void initGPUBufferObjects();
|
void initGPUBufferObjects();
|
||||||
|
|
||||||
Glyphs getGlyphs() { return _glyphs; }
|
Glyphs& getGlyphs() { return _glyphs; }
|
||||||
const Glyphs getGlyphs() const { return _glyphs; }
|
const Glyphs& getGlyphs() const { return _glyphs; }
|
||||||
|
|
||||||
Coords2& getCoords() { return _coords; }
|
Coords2& getCoords() { return _coords; }
|
||||||
const Coords2& getCoords() const { return _coords; }
|
const Coords2& getCoords() const { return _coords; }
|
||||||
@ -334,6 +336,18 @@ public:
|
|||||||
|
|
||||||
LineNumbers& getLineNumbers() { return _lineNumbers; }
|
LineNumbers& getLineNumbers() { return _lineNumbers; }
|
||||||
const LineNumbers& getLineNumbers() const { return _lineNumbers; }
|
const LineNumbers& getLineNumbers() const { return _lineNumbers; }
|
||||||
|
|
||||||
|
/** Resize any per context GLObject buffers to specified size. */
|
||||||
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||||
|
|
||||||
|
/** If State is non-zero, this function releases OpenGL objects for
|
||||||
|
* the specified graphics context. Otherwise, releases OpenGL objexts
|
||||||
|
* for all graphics contexts. */
|
||||||
|
virtual void releaseGLObjects(osg::State* state=0) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
GlyphQuads& operator = (const GlyphQuads&) { return *this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<osg::ref_ptr<GlyphTexture>,GlyphQuads> TextureGlyphQuadMap;
|
typedef std::map<osg::ref_ptr<GlyphTexture>,GlyphQuads> TextureGlyphQuadMap;
|
||||||
|
@ -723,7 +723,15 @@ void Text::computePositions(unsigned int contextID) const
|
|||||||
++titr)
|
++titr)
|
||||||
{
|
{
|
||||||
GlyphQuads& glyphquad = titr->second;
|
GlyphQuads& glyphquad = titr->second;
|
||||||
|
//OSG_NOTICE<<"Text::computePositions("<<contextID<<") glyphquad= "<<&glyphquad<<std::endl;
|
||||||
GlyphQuads::Coords2& coords2 = glyphquad._coords;
|
GlyphQuads::Coords2& coords2 = glyphquad._coords;
|
||||||
|
|
||||||
|
if (contextID>=glyphquad._transformedCoords.size())
|
||||||
|
{
|
||||||
|
// contextID exceeds one setup for glyphquad._transformedCoords, ignore this request.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
GlyphQuads::Coords3& transformedCoords = glyphquad._transformedCoords[contextID];
|
||||||
|
|
||||||
unsigned int numCoords = coords2->size();
|
unsigned int numCoords = coords2->size();
|
||||||
@ -1496,13 +1504,28 @@ void Text::resizeGLObjectBuffers(unsigned int maxSize)
|
|||||||
TextBase::resizeGLObjectBuffers(maxSize);
|
TextBase::resizeGLObjectBuffers(maxSize);
|
||||||
|
|
||||||
getActiveFont()->resizeGLObjectBuffers(maxSize);
|
getActiveFont()->resizeGLObjectBuffers(maxSize);
|
||||||
|
|
||||||
|
for(TextureGlyphQuadMap::iterator itr = _textureGlyphQuadMap.begin();
|
||||||
|
itr != _textureGlyphQuadMap.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
itr->second.resizeGLObjectBuffers(maxSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Text::releaseGLObjects(osg::State* state) const
|
void Text::releaseGLObjects(osg::State* state) const
|
||||||
{
|
{
|
||||||
TextBase::releaseGLObjects(state);
|
TextBase::releaseGLObjects(state);
|
||||||
|
|
||||||
getActiveFont()->releaseGLObjects(state);
|
getActiveFont()->releaseGLObjects(state);
|
||||||
|
|
||||||
|
for(TextureGlyphQuadMap::iterator itr = _textureGlyphQuadMap.begin();
|
||||||
|
itr != _textureGlyphQuadMap.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
itr->second.releaseGLObjects(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2026,10 +2049,21 @@ void Text::renderWithStencilBuffer(osg::State& state, const osg::Vec4& colorMult
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text::GlyphQuads::GlyphQuads()
|
Text::GlyphQuads::GlyphQuads()
|
||||||
|
{
|
||||||
|
initGlyphQuads();
|
||||||
|
}
|
||||||
|
|
||||||
|
Text::GlyphQuads::GlyphQuads(const GlyphQuads&)
|
||||||
|
{
|
||||||
|
initGlyphQuads();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Text::GlyphQuads::initGlyphQuads()
|
||||||
{
|
{
|
||||||
_coords = new osg::Vec2Array();
|
_coords = new osg::Vec2Array();
|
||||||
_texcoords = new osg::Vec2Array();
|
_texcoords = new osg::Vec2Array();
|
||||||
_colorCoords = new osg::Vec4Array();
|
_colorCoords = new osg::Vec4Array();
|
||||||
|
|
||||||
for (size_t i = 0; i < _transformedCoords.size(); i++)
|
for (size_t i = 0; i < _transformedCoords.size(); i++)
|
||||||
{
|
{
|
||||||
_transformedCoords[i] = new osg::Vec3Array();
|
_transformedCoords[i] = new osg::Vec3Array();
|
||||||
@ -2049,7 +2083,10 @@ void Text::GlyphQuads::updateQuadIndices()
|
|||||||
{
|
{
|
||||||
_quadIndices->clear();
|
_quadIndices->clear();
|
||||||
if (_coords->size() % 4 != 0)
|
if (_coords->size() % 4 != 0)
|
||||||
|
{
|
||||||
OSG_WARN << "size of _coords is not divisible by 4.";
|
OSG_WARN << "size of _coords is not divisible by 4.";
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < (unsigned int)_coords->size(); i += 4)
|
for (unsigned int i = 0; i < (unsigned int)_coords->size(); i += 4)
|
||||||
{
|
{
|
||||||
_quadIndices->push_back(i);
|
_quadIndices->push_back(i);
|
||||||
@ -2087,3 +2124,34 @@ void Text::GlyphQuads::initGPUBufferObjects()
|
|||||||
|
|
||||||
_quadIndices->setElementBufferObject(new osg::ElementBufferObject());
|
_quadIndices->setElementBufferObject(new osg::ElementBufferObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Text::GlyphQuads::resizeGLObjectBuffers(unsigned int maxSize)
|
||||||
|
{
|
||||||
|
_transformedCoords.resize(maxSize);
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
||||||
|
{
|
||||||
|
_transformedBackdropCoords[j][i]->resizeGLObjectBuffers(maxSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_quadIndices->resizeGLObjectBuffers(maxSize);
|
||||||
|
|
||||||
|
initGPUBufferObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Text::GlyphQuads::releaseGLObjects(osg::State* state) const
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < _transformedBackdropCoords[j].size(); i++)
|
||||||
|
{
|
||||||
|
_transformedBackdropCoords[j][i]->releaseGLObjects(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_quadIndices->releaseGLObjects(state);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user