1 // The canvas for rendering with the 2d api
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "placement.hxx"
23 #include "property_based_element.hxx"
25 #include <Canvas/canvas_fwd.hpp>
26 #include <Instrumentation/od_gauge.hxx>
28 #include <simgear/props/propertyObject.hxx>
29 #include <osg/NodeCallback>
35 public PropertyBasedElement
42 MISSING_SIZE_X = 0x0001,
43 MISSING_SIZE_Y = 0x0002,
44 CREATE_FAILED = 0x0004
48 * Callback used to disable/enable rendering to the texture if it is not
51 class CameraCullCallback:
52 public osg::NodeCallback
58 * Enable rendering for the next frame
60 void enableRendering();
64 unsigned int _render_frame;
66 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
68 typedef osg::ref_ptr<CameraCullCallback> CameraCullCallbackPtr;
71 * This callback is installed on every placement of the canvas in the
72 * scene to only render the canvas if at least one placement is visible
75 public osg::NodeCallback
78 CullCallback(CameraCullCallback* camera_cull);
81 CameraCullCallback *_camera_cull;
83 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
85 typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
87 Canvas(SGPropertyNode* node);
90 void update(double delta_time_sec);
98 void setSizeX(int sx);
99 void setSizeY(int sy);
101 void setViewWidth(int w);
102 void setViewHeight(int h);
104 bool handleMouseEvent(const canvas::MouseEvent& event);
106 virtual void childAdded( SGPropertyNode * parent,
107 SGPropertyNode * child );
108 virtual void childRemoved( SGPropertyNode * parent,
109 SGPropertyNode * child );
110 virtual void valueChanged (SGPropertyNode * node);
112 osg::Texture2D* getTexture() const;
113 GLuint getTexId() const;
115 CameraCullCallbackPtr getCameraCullCallback() const;
116 CullCallbackPtr getCullCallback() const;
118 static void addPlacementFactory( const std::string& type,
119 canvas::PlacementFactory factory );
123 Canvas(const Canvas&); // = delete;
124 Canvas& operator=(const Canvas&); // = delete;
131 simgear::PropertyObject<int> _status;
132 simgear::PropertyObject<std::string> _status_msg;
134 simgear::PropertyObject<int> _mouse_x, _mouse_y,
135 _mouse_dx, _mouse_dy,
142 bool _sampling_dirty,
146 std::auto_ptr<canvas::Group> _root_group;
148 std::vector<SGPropertyNode_ptr> _color_background;
150 CameraCullCallbackPtr _camera_callback;
151 CullCallbackPtr _cull_callback;
152 bool _render_always; //<! Used to disable automatic lazy rendering (culling)
154 std::vector<SGPropertyNode*> _dirty_placements;
155 std::vector<canvas::Placements> _placements;
157 typedef std::map<std::string, canvas::PlacementFactory> PlacementFactoryMap;
158 static PlacementFactoryMap _placement_factories;
160 void setStatusFlags(unsigned int flags, bool set = true);
163 #endif /* CANVAS_HXX_ */