#include <Canvas/MouseEvent.hxx>
#include <Canvas/property_helper.hxx>
#include <Main/fg_props.hxx>
-#include <Main/globals.hxx>
#include <Viewer/CameraGroup.hxx>
#include <Viewer/renderer.hxx>
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:
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 )
_cmds = cmds;
_coords = coords;
- _attributes_dirty |= PATH;
+ _attributes_dirty |= (PATH | BOUNDING_BOX);
}
/**
*/
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
{
- if( (_attributes_dirty & PATH) && _vg_initialized )
+ if( _attributes_dirty & PATH )
return;
osg::State* state = renderInfo.getState();
// 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 )
{
*/
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];
private:
- static bool _vg_initialized;
-
enum Attributes
{
PATH = 0x0001,
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<PathDrawable*>(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),
#include <osgDB/Registry>
// Class references
+#include <simgear/canvas/VGInitOperation.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/props/AtomicChangeListener.hxx>
#include <GUI/gui.h>
#include <Viewer/splash.hxx>
#include <Viewer/renderer.hxx>
+#include <Viewer/WindowSystemAdapter.hxx>
#include <Navaids/NavDataCache.hxx>
#include "fg_commands.hxx"
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++;