]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/od_gauge.hxx
Basic 2D canvas implementation.
[flightgear.git] / src / Instrumentation / od_gauge.hxx
1 // Owner Drawn Gauge helper class
2 //
3 // Written by Harald JOHNSEN, started May 2005.
4 //
5 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
6 //
7 // Ported to OSG by Tim Moore - Jun 2007
8 //
9 // Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April 2012
10 // Supports now multisampling/mipmapping, usage of the stencil buffer and placing
11 // the texture in the scene by certain filter criteria
12 //
13 // This program is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU General Public License as
15 // published by the Free Software Foundation; either version 2 of the
16 // License, or (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 // General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26 //
27 //
28
29 #ifndef _OD_GAUGE_HXX
30 #define _OD_GAUGE_HXX
31
32 #include <osg/NodeCallback>
33 #include <osg/Group>
34
35 namespace osg {
36   class Camera;
37   class Texture2D;
38 }
39
40 class SGPropertyNode;
41 typedef std::vector<osg::ref_ptr<osg::Group> > Placements;
42
43 /**
44  * Owner Drawn Gauge helper class.
45  */
46 class FGODGauge
47 {
48 public:
49     FGODGauge();
50     virtual ~FGODGauge();
51
52     /**
53      * Set the size of the render target.
54      *
55      * @param size_x    X size
56      * @param size_y    Y size. Defaults to size_x if not specified
57      */
58     void setSize(int size_x, int size_y = -1);
59
60     /**
61      * Set the size of the viewport
62      *
63      * @param width
64      * @param height    Defaults to width if not specified
65      */
66     void setViewSize(int width, int height = -1);
67
68     /**
69      * DEPRECATED
70      *
71      * Get size of squared texture
72      */
73     int size() const { return _size_x; }
74     
75     /**
76      * Set whether to use image coordinates or not.
77      *
78      * Default: origin == center of texture
79      * Image Coords: origin == top left corner
80      */
81     void useImageCoords(bool use = true);
82
83     /**
84      * Enable/Disable using a stencil buffer
85      */
86     void useStencil(bool use = true);
87
88     /**
89      * Set sampling parameters for mipmapping and coverage sampling
90      * antialiasing.
91      *
92      * @note color_samples is not allowed to be higher than coverage_samples
93      *
94      */
95     void setSampling( bool mipmapping,
96                       int coverage_samples = 0,
97                       int color_samples = 0 );
98
99     /**
100      * Say if we can render to a texture.
101      * @return true if rtt is available
102      */
103     bool serviceable(void);
104
105     /**
106      * Replace an opengl texture name inside the aircraft scene graph.
107      * This is to replace a static texture by a dynamic one
108      * @param name texture filename
109      * @param new_texture dynamic texture to replace the old one
110      * @return A list of groups which override the given texture
111      */
112     Placements set_texture(const char * name, osg::Texture2D* new_texture);
113
114     /**
115      * Replace an opengl texture name inside the aircraft scene graph.
116      * This is to replace a static texture by a dynamic one. The replacement
117      * is base on certain filtering criteria which have to be stored in string
118      * value childs of the placement node. Recognized nodes are:
119      *   - texture  Match the name of the texture
120      *   - node     Match the name of the object
121      *   - parent   Match any of the object parents names (all the tree upwards)
122      * @param placement the node containing the replacement criteria
123      * @param new_texture dynamic texture to replace the old one
124      * @param an optional cull callback which will be installed on any matching
125      *        object
126      * @return A list of groups which override the given texture
127      */
128     Placements set_texture( const SGPropertyNode* placement,
129                             osg::Texture2D* new_texture,
130                             osg::NodeCallback* cull_callback = 0 );
131
132     /**
133      * Get the OSG camera for drawing this gauge.
134      */
135     osg::Camera* getCamera() { return camera.get(); }
136
137     osg::Texture2D* getTexture() { return texture.get(); }
138     //void setTexture(osg::Texture2D* t) { texture = t; }
139
140     // Real initialization function. Bad name.
141     void allocRT(osg::NodeCallback* camera_cull_callback = 0);
142
143 private:
144     int _size_x,
145         _size_y,
146         _view_width,
147         _view_height;
148     bool _use_image_coords,
149          _use_stencil,
150          _use_mipmapping;
151
152     // Multisampling parameters
153     int  _coverage_samples,
154          _color_samples;
155
156     bool rtAvailable;
157     osg::ref_ptr<osg::Camera> camera;
158     osg::ref_ptr<osg::Texture2D> texture;
159
160     void updateCoordinateFrame();
161     void updateStencil();
162     void updateSampling();
163
164 };
165
166 #endif // _OD_GAUGE_HXX