Canvas: Fix detection if something has changed
- Reset dirty flag for redrawing canvas properly after rendering has complted. - Update path properly if path elements have been removed.
This commit is contained in:
parent
293d6b3565
commit
efe978e679
4 changed files with 38 additions and 6 deletions
|
@ -35,6 +35,26 @@
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for resetting the render_dirty flag after rendering a frame.
|
||||||
|
*/
|
||||||
|
class Canvas::DrawCallback:
|
||||||
|
public osg::Camera::DrawCallback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DrawCallback(Canvas* canvas):
|
||||||
|
_canvas(canvas)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void operator()(osg::RenderInfo& renderInfo) const
|
||||||
|
{
|
||||||
|
_canvas->_render_dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Canvas *_canvas;
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
Canvas::CameraCullCallback::CameraCullCallback():
|
Canvas::CameraCullCallback::CameraCullCallback():
|
||||||
_render( true ),
|
_render( true ),
|
||||||
|
@ -142,6 +162,7 @@ void Canvas::update(double delta_time_sec)
|
||||||
_texture.allocRT(_camera_callback);
|
_texture.allocRT(_camera_callback);
|
||||||
_texture.getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 1.0f));
|
_texture.getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 1.0f));
|
||||||
_texture.getCamera()->addChild(_root_group->getMatrixTransform());
|
_texture.getCamera()->addChild(_root_group->getMatrixTransform());
|
||||||
|
_texture.getCamera()->setFinalDrawCallback(new DrawCallback(this));
|
||||||
|
|
||||||
if( _texture.serviceable() )
|
if( _texture.serviceable() )
|
||||||
{
|
{
|
||||||
|
@ -154,12 +175,8 @@ void Canvas::update(double delta_time_sec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_root_group->update(delta_time_sec);
|
|
||||||
|
|
||||||
_texture.setRender(_render_dirty);
|
_texture.setRender(_render_dirty);
|
||||||
|
_root_group->update(delta_time_sec);
|
||||||
// Always render if sampling or color has changed
|
|
||||||
_render_dirty = _sampling_dirty || _color_dirty;
|
|
||||||
|
|
||||||
if( _sampling_dirty )
|
if( _sampling_dirty )
|
||||||
{
|
{
|
||||||
|
@ -169,6 +186,7 @@ void Canvas::update(double delta_time_sec)
|
||||||
_node->getIntValue("color-samples")
|
_node->getIntValue("color-samples")
|
||||||
);
|
);
|
||||||
_sampling_dirty = false;
|
_sampling_dirty = false;
|
||||||
|
_render_dirty = true;
|
||||||
}
|
}
|
||||||
if( _color_dirty )
|
if( _color_dirty )
|
||||||
{
|
{
|
||||||
|
@ -180,6 +198,7 @@ void Canvas::update(double delta_time_sec)
|
||||||
_color_background[3]->getFloatValue() )
|
_color_background[3]->getFloatValue() )
|
||||||
);
|
);
|
||||||
_color_dirty = false;
|
_color_dirty = false;
|
||||||
|
_render_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while( !_dirty_placements.empty() )
|
while( !_dirty_placements.empty() )
|
||||||
|
@ -311,6 +330,8 @@ void Canvas::childAdded( SGPropertyNode * parent,
|
||||||
void Canvas::childRemoved( SGPropertyNode * parent,
|
void Canvas::childRemoved( SGPropertyNode * parent,
|
||||||
SGPropertyNode * child )
|
SGPropertyNode * child )
|
||||||
{
|
{
|
||||||
|
_render_dirty = true;
|
||||||
|
|
||||||
if( parent != _node )
|
if( parent != _node )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -327,7 +348,6 @@ void Canvas::valueChanged(SGPropertyNode* node)
|
||||||
if( boost::starts_with(node->getNameString(), "status")
|
if( boost::starts_with(node->getNameString(), "status")
|
||||||
|| node->getParent()->getNameString() == "bounding-box" )
|
|| node->getParent()->getNameString() == "bounding-box" )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_render_dirty = true;
|
_render_dirty = true;
|
||||||
|
|
||||||
bool handled = true;
|
bool handled = true;
|
||||||
|
|
|
@ -86,6 +86,11 @@ class Canvas:
|
||||||
};
|
};
|
||||||
typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
|
typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for resetting the render_dirty flag after rendering a frame.
|
||||||
|
*/
|
||||||
|
class DrawCallback;
|
||||||
|
|
||||||
Canvas(SGPropertyNode* node);
|
Canvas(SGPropertyNode* node);
|
||||||
virtual ~Canvas();
|
virtual ~Canvas();
|
||||||
|
|
||||||
|
|
|
@ -392,6 +392,12 @@ namespace canvas
|
||||||
Element::update(dt);
|
Element::update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void Path::childRemoved(SGPropertyNode* child)
|
||||||
|
{
|
||||||
|
childChanged(child);
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void Path::childChanged(SGPropertyNode* child)
|
void Path::childChanged(SGPropertyNode* child)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace canvas
|
||||||
|
|
||||||
osg::ref_ptr<PathDrawable> _path;
|
osg::ref_ptr<PathDrawable> _path;
|
||||||
|
|
||||||
|
virtual void childRemoved(SGPropertyNode * child);
|
||||||
virtual void childChanged(SGPropertyNode * child);
|
virtual void childChanged(SGPropertyNode * child);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue