Fixed bug related to clean up of text fonts.

This commit is contained in:
Robert Osfield
2006-10-03 11:14:34 +00:00
parent 392232ec06
commit 7c6b528588
10 changed files with 59 additions and 18 deletions

View File

@@ -979,6 +979,15 @@ void Viewer::cleanup_frame()
++itr)
{
(*itr)->releaseGLObjects();
ViewerEventHandler* veh = dynamic_cast<ViewerEventHandler*>(itr->get());
if (veh)
{
// switch off stats so it doesn't try to redraw them.
veh->setFrameStatsMode(ViewerEventHandler::NO_STATS);
veh->setDisplayHelp(false);
veh->setWriteImageOnNextFrame(false);
}
}
OsgCameraGroup::cleanup_frame();

View File

@@ -104,11 +104,41 @@ public:
virtual void operator()( const Producer::Camera & camera);
typedef std::vector< osg::ref_ptr<osgText::Text> > TextList;
void releaseTextList(const TextList& list) const
{
for(TextList::const_iterator itr = list.begin();
itr != list.end();
++itr)
{
(*itr)->releaseGLObjects();
}
}
void releaseGLObjects() const
{
{ for(TextList::const_iterator itr = _descriptionList.begin(); itr != _descriptionList.end(); ++itr) (*itr)->releaseGLObjects(); }
{ for(TextList::const_iterator itr = _optionList.begin(); itr != _optionList.end(); ++itr) (*itr)->releaseGLObjects(); }
{ for(TextList::const_iterator itr = _explanationList.begin(); itr != _explanationList.end(); ++itr) (*itr)->releaseGLObjects(); }
releaseTextList(_descriptionList);
releaseTextList(_optionList);
releaseTextList(_explanationList);
releaseTextList(_statsLabelList);
releaseTextList(_infoLabelList);
releaseTextList(_sceneStatsLabelList);
releaseTextList(_cullTimeText);
releaseTextList(_drawTimeText);
releaseTextList(_gpuTimeText);
if (_frameRateLabelText.valid()) _frameRateLabelText->releaseGLObjects();
if (_frameRateCounterText.valid()) _frameRateCounterText->releaseGLObjects();
if (_updateTimeText.valid()) _updateTimeText->releaseGLObjects();
if (_positionText.valid()) _positionText->releaseGLObjects();
if (_orientationText.valid()) _orientationText->releaseGLObjects();
if (_speedText.valid()) _speedText->releaseGLObjects();
if (_numVerticesText.valid()) _numVerticesText->releaseGLObjects();
if (_numPrimitivesText.valid()) _numPrimitivesText->releaseGLObjects();
if (_numDrawablesText.valid()) _numDrawablesText->releaseGLObjects();
}
protected:
@@ -125,7 +155,6 @@ protected:
void displayHelp();
void createHelpText();
typedef std::vector< osg::ref_ptr<osgText::Text> > TextList;
bool _helpInitialized;
TextList _descriptionList;
TextList _optionList;

View File

@@ -256,12 +256,14 @@ Font::Glyph* Font::getGlyph(unsigned int charcode)
void Font::releaseGLObjects(osg::State* state) const
{
for(GlyphTextureList::const_iterator itr=_glyphTextureList.begin();
itr!=_glyphTextureList.end();
++itr)
{
(*itr)->releaseGLObjects(state);
}
for(GlyphTextureList::const_iterator itr=_glyphTextureList.begin();
itr!=_glyphTextureList.end();
++itr)
{
(*itr)->releaseGLObjects(state);
}
const_cast<Font*>(this)->_glyphTextureList.clear();
const_cast<Font*>(this)->_sizeGlyphMap.clear();
}
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
@@ -280,12 +282,8 @@ bool Font::hasVertical() const
void Font::addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph)
{
//cout << "charcode "<<(char)charcode<<" "<<&_glyphTextureList<<endl;
_sizeGlyphMap[SizePair(width,height)][charcode]=glyph;
int posX=0,posY=0;
GlyphTexture* glyphTexture = 0;

View File

@@ -1639,13 +1639,10 @@ void Text::accept(osg::PrimitiveFunctor& pf) const
}
/** If State is non-zero, this function releases OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
void Text::releaseGLObjects(osg::State* state) const
{
Drawable::releaseGLObjects(state);
if (_font.valid()) _font->releaseGLObjects(state);
getActiveFont()->releaseGLObjects(state);
}

View File

@@ -40,6 +40,7 @@ BEGIN_ENUM_REFLECTOR(osg::CullSettings::VariablesMask)
I_EnumLabel(osg::CullSettings::CULL_MASK);
I_EnumLabel(osg::CullSettings::CULL_MASK_LEFT);
I_EnumLabel(osg::CullSettings::CULL_MASK_RIGHT);
I_EnumLabel(osg::CullSettings::CLEAR_COLOR);
I_EnumLabel(osg::CullSettings::NO_VARIABLES);
I_EnumLabel(osg::CullSettings::ALL_VARIABLES);
END_REFLECTOR

View File

@@ -217,6 +217,7 @@ BEGIN_OBJECT_REFLECTOR(osg::Drawable::DrawCallback)
I_Method0(const char *, className);
I_Method2(void, drawImplementation, IN, osg::State &, x, IN, const osg::Drawable *, x);
I_Method2(void, drawImplementation, IN, osg::RenderInfo &, renderInfo, IN, const osg::Drawable *, drawable);
I_MethodWithDefaults1(void, releaseGLObjects, IN, osg::State *, x, 0);
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osg::Drawable::EventCallback)

View File

@@ -15,6 +15,7 @@
#include <osg/NodeCallback>
#include <osg/NodeVisitor>
#include <osg/Object>
#include <osg/State>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
@@ -39,6 +40,7 @@ BEGIN_OBJECT_REFLECTOR(osg::NodeCallback)
I_Method0(const osg::NodeCallback *, getNestedCallback);
I_Method1(void, addNestedCallback, IN, osg::NodeCallback *, nc);
I_Method1(void, removeNestedCallback, IN, osg::NodeCallback *, nc);
I_MethodWithDefaults1(void, releaseGLObjects, IN, osg::State *, x, 0);
I_Property(osg::NodeCallback *, NestedCallback);
I_PublicMemberProperty(osg::ref_ptr< osg::NodeCallback >, _nestedCallback);
END_REFLECTOR

View File

@@ -55,6 +55,7 @@ BEGIN_OBJECT_REFLECTOR(osgGA::SimpleViewer)
I_Method0(void, frameUpdateTraversal);
I_Method0(void, frameCullTraversal);
I_Method0(void, frameDrawTraversal);
I_Method0(void, releaseAllGLObjects);
I_Method0(void, cleanup);
I_Method0(void, requestRedraw);
I_MethodWithDefaults1(void, requestContinuousUpdate, IN, bool, x, true);

View File

@@ -125,6 +125,7 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::Viewer)
I_Method0(osg::Quat, getOrientation);
I_Method1(void, getUsage, IN, osg::ApplicationUsage &, usage);
I_Method0(void, updatedSceneData);
I_Method0(void, cleanup_frame);
I_StaticMethod0(const char *, getDefaultImageFileName);
I_Property(osg::AnimationPath *, AnimationPath);
I_ReadOnlyProperty(osg::NodePath, CoordinateSystemNodePath);

View File

@@ -11,6 +11,7 @@
#include <osgIntrospection/Attributes>
#include <osg/ApplicationUsage>
#include <osg/State>
#include <osgGA/GUIActionAdapter>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandlerVisitor>
@@ -49,6 +50,7 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::ViewerEventHandler)
I_Method1(void, setWriteImageOnNextFrame, IN, bool, writeImageOnNextFrame);
I_Method1(void, setWriteImageFileName, IN, const std::string &, filename);
I_Method0(const std::string &, getWriteImageFileName);
I_MethodWithDefaults1(void, releaseGLObjects, IN, osg::State *, x, 0);
I_Property(bool, DisplayHelp);
I_Property(osgProducer::ViewerEventHandler::FrameStatsMode, FrameStatsMode);
I_ReadOnlyProperty(osgProducer::OsgCameraGroup *, OsgCameraGroup);