|
|
Line 244: |
Line 244: |
| }}</ref> | | }}</ref> |
| * check if '''CullThreadPerCameraDrawThreadPerContext''' works, see [[Howto:Activate multi core and multi GPU support]] | | * check if '''CullThreadPerCameraDrawThreadPerContext''' works, see [[Howto:Activate multi core and multi GPU support]] |
|
| |
| == C++ ==
| |
| The following is the boilerplate code neede to add a new element to the Canvas system inheriting from the Canvas::Image class, i.e. an element having its own allocated Image/texture buffer, which is what we can use to render a camera into it:
| |
|
| |
| <syntaxhighlight lang="diff">
| |
|
| |
| diff --git a/simgear/canvas/elements/CMakeLists.txt b/simgear/canvas/elements/CMakeLists.txt
| |
| index 2b537c0..4eb1e95 100644
| |
| --- a/simgear/canvas/elements/CMakeLists.txt
| |
| +++ b/simgear/canvas/elements/CMakeLists.txt
| |
| @@ -7,6 +7,7 @@ set(HEADERS
| |
| CanvasMap.hxx
| |
| CanvasPath.hxx
| |
| CanvasText.hxx
| |
| + CanvasView.hxx
| |
| )
| |
|
| |
| set(DETAIL_HEADERS
| |
| @@ -20,6 +21,7 @@ set(SOURCES
| |
| CanvasMap.cxx
| |
| CanvasPath.cxx
| |
| CanvasText.cxx
| |
| + CanvasView.cxx
| |
| )
| |
|
| |
| simgear_scene_component(canvas-elements canvas/elements "${SOURCES}" "${HEADERS}")
| |
| @@ -28,4 +30,4 @@ simgear_component(canvas-elements/detail canvas/elements/detail "" "${DETAIL_HEA
| |
| add_boost_test(canvas_element
| |
| SOURCES canvas_element_test.cpp
| |
| LIBRARIES ${TEST_LIBS}
| |
| -)
| |
| \ No newline at end of file
| |
| +)
| |
| diff --git a/simgear/canvas/elements/CanvasGroup.cxx b/simgear/canvas/elements/CanvasGroup.cxx
| |
| index c753c2e..5d2585e 100644
| |
| --- a/simgear/canvas/elements/CanvasGroup.cxx
| |
| +++ b/simgear/canvas/elements/CanvasGroup.cxx
| |
| @@ -23,6 +23,8 @@
| |
| #include "CanvasMap.hxx"
| |
| #include "CanvasPath.hxx"
| |
| #include "CanvasText.hxx"
| |
| +#include "CanvasView.hxx"
| |
| +
| |
| #include <simgear/canvas/CanvasEventVisitor.hxx>
| |
| #include <simgear/canvas/events/MouseEvent.hxx>
| |
|
| |
| @@ -66,6 +68,7 @@ namespace canvas
| |
| add<Map >(_child_factories);
| |
| add<Path >(_child_factories);
| |
| add<Text >(_child_factories);
| |
| + add<View >(_child_factories);
| |
| }
| |
|
| |
| //----------------------------------------------------------------------------
| |
| diff --git a/simgear/canvas/elements/CanvasView.cxx b/simgear/canvas/elements/CanvasView.cxx
| |
| new file mode 100644
| |
| index 0000000..edae7ab
| |
| --- /dev/null
| |
| +++ b/simgear/canvas/elements/CanvasView.cxx
| |
| @@ -0,0 +1,88 @@
| |
| +// This library is free software; you can redistribute it and/or
| |
| +// modify it under the terms of the GNU Library General Public
| |
| +// License as published by the Free Software Foundation; either
| |
| +// version 2 of the License, or (at your option) any later version.
| |
| +//
| |
| +// This library is distributed in the hope that it will be useful,
| |
| +// but WITHOUT ANY WARRANTY; without even the implied warranty of
| |
| +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
| |
| +// Library General Public License for more details.
| |
| +//
| |
| +// You should have received a copy of the GNU Library General Public
| |
| +// License along with this library; if not, write to the Free Software
| |
| +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
| |
| +
| |
| +#include <simgear_config.h>
| |
| +#include "CanvasView.hxx"
| |
| +
| |
| +#include <cmath>
| |
| +
| |
| +#include <boost/algorithm/string/predicate.hpp>
| |
| +
| |
| +namespace simgear
| |
| +{
| |
| +namespace canvas
| |
| +{
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + const std::string View::TYPE_NAME = "view-camera";
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::staticInit()
| |
| + {
| |
| + Image::staticInit();
| |
| +
| |
| + if( isInit<View>() )
| |
| + return;
| |
| +
| |
| + // Do some initialization if needed...
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + View::View( const CanvasWeakPtr& canvas,
| |
| + const SGPropertyNode_ptr& node,
| |
| + const Style& parent_style,
| |
| + ElementWeakPtr parent ):
| |
| + Image(canvas, node, parent_style, parent)
| |
| + {
| |
| + staticInit();
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + View::~View()
| |
| + {
| |
| +
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::update(double dt)
| |
| + {
| |
| + Image::update(dt);
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::childAdded(SGPropertyNode* parent, SGPropertyNode* child)
| |
| + {
| |
| + return Image::childAdded(parent, child);
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::childRemoved(SGPropertyNode* parent, SGPropertyNode* child)
| |
| + {
| |
| + return Image::childRemoved(parent, child);
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::valueChanged(SGPropertyNode* child)
| |
| + {
| |
| + return Image::valueChanged(child);
| |
| + }
| |
| +
| |
| + //----------------------------------------------------------------------------
| |
| + void View::childChanged(SGPropertyNode* child)
| |
| + {
| |
| + return Image::childChanged(child);
| |
| +
| |
| + }
| |
| +} // namespace canvas
| |
| +} // namespace simgear
| |
| diff --git a/simgear/canvas/elements/CanvasView.hxx b/simgear/canvas/elements/CanvasView.hxx
| |
| new file mode 100644
| |
| index 0000000..7b2ec4e
| |
| --- /dev/null
| |
| +++ b/simgear/canvas/elements/CanvasView.hxx
| |
| @@ -0,0 +1,59 @@
| |
| +// Based on https://forum.flightgear.org/viewtopic.php?f=71&t=23929
| |
| +//
| |
| +// This library is free software; you can redistribute it and/or
| |
| +// modify it under the terms of the GNU Library General Public
| |
| +// License as published by the Free Software Foundation; either
| |
| +// version 2 of the License, or (at your option) any later version.
| |
| +//
| |
| +// This library is distributed in the hope that it will be useful,
| |
| +// but WITHOUT ANY WARRANTY; without even the implied warranty of
| |
| +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
| |
| +// Library General Public License for more details.
| |
| +//
| |
| +// You should have received a copy of the GNU Library General Public
| |
| +// License along with this library; if not, write to the Free Software
| |
| +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
| |
| +
| |
| +#ifndef CANVAS_VIEW_HXX_
| |
| +#define CANVAS_VIEW_HXX_
| |
| +
| |
| +#include "CanvasImage.hxx"
| |
| +
| |
| +#include <boost/shared_ptr.hpp>
| |
| +#include <boost/unordered_map.hpp>
| |
| +#include <boost/unordered_set.hpp>
| |
| +
| |
| +namespace simgear
| |
| +{
| |
| +namespace canvas
| |
| +{
| |
| + class View:
| |
| + public Image
| |
| + {
| |
| + public:
| |
| + static const std::string TYPE_NAME;
| |
| + static void staticInit();
| |
| +
| |
| + View( const CanvasWeakPtr& canvas,
| |
| + const SGPropertyNode_ptr& node,
| |
| + const Style& parent_style,
| |
| + ElementWeakPtr parent = 0 );
| |
| + virtual ~View();
| |
| +
| |
| + virtual void update(double dt);
| |
| +
| |
| + virtual void childAdded( SGPropertyNode * parent,
| |
| + SGPropertyNode * child );
| |
| + virtual void childRemoved( SGPropertyNode * parent,
| |
| + SGPropertyNode * child );
| |
| + virtual void valueChanged(SGPropertyNode * child);
| |
| +
| |
| + //protected:
| |
| +
| |
| + virtual void childChanged(SGPropertyNode * child);
| |
| + };
| |
| +
| |
| +} // namespace canvas
| |
| +} // namespace simgear
| |
| +
| |
| +#endif /* CANVAS_VIEW_HXX_ */
| |
|
| |
|
| |
| </syntaxhighlight>
| |
|
| |
|
| == Base Package == | | == Base Package == |