From 71eeb62c1bd1bd3d58f73fd4079de59f38a08033 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Wed, 31 Oct 2012 01:40:43 +0100 Subject: [PATCH] Simplify canvas OpenVG initialization and fix sometimes rendering too lazy --- src/Canvas/canvas.cxx | 12 +------ src/Canvas/canvas_fwd.hpp | 2 -- src/Canvas/elements/path.cxx | 66 ++---------------------------------- src/Main/main.cxx | 5 +++ 4 files changed, 9 insertions(+), 76 deletions(-) diff --git a/src/Canvas/canvas.cxx b/src/Canvas/canvas.cxx index 943f21809..92aab2a8c 100644 --- a/src/Canvas/canvas.cxx +++ b/src/Canvas/canvas.cxx @@ -22,7 +22,6 @@ #include #include #include
-#include
#include #include @@ -49,16 +48,7 @@ class Canvas::DrawCallback: virtual void operator()(osg::RenderInfo& renderInfo) const { - const long frame = renderInfo.getView()->getFrameStamp() - ->getFrameNumber(); - - static SGPropertyNode_ptr node_frame = - globals->get_props()->getNode(canvas::VG_INIT_SIGNAL, true); - - // If OpenVG has been initialized we need to redraw the frame, because - // initializing has happened instead of rendering. - // Otherwise we just reset the _render_dirty flag. - _canvas->_render_dirty = (frame == node_frame->getLongValue()); + _canvas->_render_dirty = false; } protected: diff --git a/src/Canvas/canvas_fwd.hpp b/src/Canvas/canvas_fwd.hpp index 356ea1c57..927e8f9bb 100644 --- a/src/Canvas/canvas_fwd.hpp +++ b/src/Canvas/canvas_fwd.hpp @@ -32,8 +32,6 @@ typedef boost::weak_ptr CanvasWeakPtr; namespace canvas { - const std::string VG_INIT_SIGNAL = "/sim/signals/vg-initialized-frame"; - class Group; class Image; class MouseEvent; diff --git a/src/Canvas/elements/path.cxx b/src/Canvas/elements/path.cxx index c9875a8b1..0d43bb005 100644 --- a/src/Canvas/elements/path.cxx +++ b/src/Canvas/elements/path.cxx @@ -52,24 +52,10 @@ namespace canvas setDataVariance(Object::DYNAMIC); setUpdateCallback(new PathUpdateCallback()); - setCullCallback(new NoCullCallback()); } virtual ~PathDrawable() { - if( !_vg_initialized ) - { - if( _path != VG_INVALID_HANDLE ) - SG_LOG - ( - SG_GL, - SG_WARN, - "Can't destroy path without OpenVG context: " - << _path_element->_node->getPath() - ); - return; - } - if( _path != VG_INVALID_HANDLE ) vgDestroyPath(_path); if( _paint != VG_INVALID_HANDLE ) @@ -93,7 +79,7 @@ namespace canvas _cmds = cmds; _coords = coords; - _attributes_dirty |= PATH; + _attributes_dirty |= (PATH | BOUNDING_BOX); } /** @@ -182,7 +168,7 @@ namespace canvas */ virtual void drawImplementation(osg::RenderInfo& renderInfo) const { - if( (_attributes_dirty & PATH) && _vg_initialized ) + if( _attributes_dirty & PATH ) return; osg::State* state = renderInfo.getState(); @@ -196,21 +182,6 @@ namespace canvas // eg. doesn't include GL_MULTISAMPLE_BIT glPushClientAttrib(~0u); - // Initialize OpenVG itself - if( !_vg_initialized ) - { - GLint vp[4]; - glGetIntegerv(GL_VIEWPORT, vp); - - vgCreateContextSH(vp[2], vp[3]); - _vg_initialized = true; - - fgSetInt( canvas::VG_INIT_SIGNAL, - renderInfo.getView()->getFrameStamp()->getFrameNumber() ); - - return; - } - // Initialize/Update the paint if( _attributes_dirty & STROKE_COLOR ) { @@ -268,7 +239,7 @@ namespace canvas */ virtual osg::BoundingBox computeBound() const { - if( _path == VG_INVALID_HANDLE ) + if( _path == VG_INVALID_HANDLE || (_attributes_dirty & PATH) ) return osg::BoundingBox(); VGfloat min[2], size[2]; @@ -291,8 +262,6 @@ namespace canvas private: - static bool _vg_initialized; - enum Attributes { PATH = 0x0001, @@ -352,45 +321,16 @@ namespace canvas dirtyBound(); } - /** - * Updating the path before drawing is needed to enable correct bounding - * box calculations and make culling work. - */ struct PathUpdateCallback: public osg::Drawable::UpdateCallback { virtual void update(osg::NodeVisitor*, osg::Drawable* drawable) { - if( !_vg_initialized ) - return; static_cast(drawable)->update(); } }; - - /** - * Callback used to prevent culling as long as OpenVG is not initialized. - * This is needed because OpenVG needs an active OpenGL context for - * initialization which is only available in #drawImplementation. - * As soon as OpenVG is correctly initialized the callback automatically - * removes itself from the node, so that the normal culling can get - * active. - */ - struct NoCullCallback: - public osg::Drawable::CullCallback - { - virtual bool cull( osg::NodeVisitor*, - osg::Drawable* drawable, - osg::State* ) const - { - if( _vg_initialized ) - drawable->setCullCallback(0); - return false; - } - }; }; - bool Path::PathDrawable::_vg_initialized = false; - //---------------------------------------------------------------------------- Path::Path(SGPropertyNode_ptr node, const Style& parent_style): Element(node, parent_style), diff --git a/src/Main/main.cxx b/src/Main/main.cxx index c7d2a0db2..5455b3106 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -34,6 +34,7 @@ #include // Class references +#include #include #include #include @@ -52,6 +53,7 @@ #include #include #include +#include #include #include "fg_commands.hxx" @@ -249,6 +251,9 @@ static void fgIdleFunction ( void ) { globals->get_renderer()->resize( fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize") ); + WindowSystemAdapter::getWSA()->windows[0]->gc->add( + new simgear::canvas::VGInitOperation() + ); int session = fgGetInt("/sim/session",0); session++; -- 2.39.5