2 ******************************************************************************
4 * @file DirtySupport.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "DirtySupport.hpp"
31 #include <osg/NodeVisitor>
35 namespace osgQtQuick
{
38 struct DirtySupport::NodeUpdateCallback
: public osg::NodeCallback
{
40 NodeUpdateCallback(DirtySupport::Hidden
*h
) : h(h
)
43 void operator()(osg::Node
*node
, osg::NodeVisitor
*nv
);
46 DirtySupport::Hidden
*const h
;
49 struct DirtySupport::Hidden
{
51 DirtySupport
*const self
;
53 osg::ref_ptr
<osg::NodeCallback
> nodeUpdateCallback
;
58 Hidden(DirtySupport
*self
) : self(self
), dirtyFlags(0)
61 bool isDirty(int mask
) const
63 return (dirtyFlags
& mask
) != 0;
71 void setDirty(int mask
)
73 // qDebug() << "DirtySupport::setDirty" << mask;
75 osg::Node
*node
= self
->nodeToUpdate();
77 if (!nodeUpdateCallback
.valid()) {
79 nodeUpdateCallback
= new NodeUpdateCallback(this);
81 node
->addUpdateCallback(nodeUpdateCallback
.get());
83 // qWarning() << "DirtySupport::setDirty - node to update is null";
91 osg::Node
*node
= self
->nodeToUpdate();
93 if (node
&& nodeUpdateCallback
.valid()) {
94 node
->removeUpdateCallback(nodeUpdateCallback
.get());
101 // qDebug() << "DirtySupport::update";
103 // qDebug() << "DirtySupport::update - updating...";
110 /* struct DirtySupport::NodeUpdateCallback */
112 void DirtySupport::NodeUpdateCallback::operator()(osg::Node
*node
, osg::NodeVisitor
*nv
)
114 // qDebug() << "DirtySupport::NodeUpdateCallback";
119 /* class DirtySupport */
121 DirtySupport::DirtySupport() : h(new Hidden(this))
124 DirtySupport::~DirtySupport()
129 int DirtySupport::dirty() const
134 bool DirtySupport::isDirty(int mask
) const
136 return h
->isDirty(mask
);
139 void DirtySupport::setDirty(int mask
)
144 void DirtySupport::clearDirty()
148 } // namespace osgQtQuick