]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/od_gauge.hxx
Make traffic take-off roll look a little better.
[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 <Canvas/canvas_fwd.hpp>
33 #include <Canvas/placement.hxx>
34
35 #include <osg/NodeCallback>
36 #include <osg/Group>
37
38 namespace osg {
39   class Camera;
40   class Texture2D;
41 }
42
43 class SGPropertyNode;
44
45 /**
46  * Owner Drawn Gauge helper class.
47  */
48 class FGODGauge
49 {
50   public:
51     FGODGauge();
52     virtual ~FGODGauge();
53
54     /**
55      * Set the size of the render target.
56      *
57      * @param size_x    X size
58      * @param size_y    Y size. Defaults to size_x if not specified
59      */
60     void setSize(int size_x, int size_y = -1);
61
62     /**
63      * Set the size of the viewport
64      *
65      * @param width
66      * @param height    Defaults to width if not specified
67      */
68     void setViewSize(int width, int height = -1);
69
70     /**
71      * DEPRECATED
72      *
73      * Get size of squared texture
74      */
75     int size() const { return _size_x; }
76     
77     /**
78      * Set whether to use image coordinates or not.
79      *
80      * Default: origin == center of texture
81      * Image Coords: origin == top left corner
82      */
83     void useImageCoords(bool use = true);
84
85     /**
86      * Enable/Disable using a stencil buffer
87      */
88     void useStencil(bool use = true);
89
90     /**
91      * Set sampling parameters for mipmapping and coverage sampling
92      * antialiasing.
93      *
94      * @note color_samples is not allowed to be higher than coverage_samples
95      *
96      */
97     void setSampling( bool mipmapping,
98                       int coverage_samples = 0,
99                       int color_samples = 0 );
100
101     /**
102      * Enable/Disable updating the texture (If disabled the contents of the
103      * texture remains with the outcome of the last rendering pass)
104      */
105     void setRender(bool render);
106
107     /**
108      * Say if we can render to a texture.
109      * @return true if rtt is available
110      */
111     bool serviceable(void);
112
113     /**
114      * Replace an opengl texture name inside the aircraft scene graph.
115      * This is to replace a static texture by a dynamic one
116      * @param name texture filename
117      * @param new_texture dynamic texture to replace the old one
118      * @return A list of groups which override the given texture
119      */
120     static
121     canvas::Placements set_texture( const char * name,
122                                     osg::Texture2D* new_texture );
123
124     /**
125      * Replace an opengl texture name inside the aircraft scene graph.
126      * This is to replace a static texture by a dynamic one. The replacement
127      * is base on certain filtering criteria which have to be stored in string
128      * value childs of the placement node. Recognized nodes are:
129      *   - texture  Match the name of the texture
130      *   - node     Match the name of the object
131      *   - parent   Match any of the object parents names (all the tree upwards)
132      * @param placement the node containing the replacement criteria
133      * @param new_texture dynamic texture to replace the old one
134      * @param an optional cull callback which will be installed on any matching
135      *        object
136      * @return A list of groups which override the given texture
137      */
138     static
139     canvas::Placements set_texture( const SGPropertyNode* placement,
140                                     osg::Texture2D* new_texture,
141                                     osg::NodeCallback* cull_callback = 0 );
142
143     /**
144      * Get the OSG camera for drawing this gauge.
145      */
146     osg::Camera* getCamera() const { return camera.get(); }
147
148     osg::Texture2D* getTexture() const { return texture.get(); }
149     //void setTexture(osg::Texture2D* t) { texture = t; }
150
151     // Real initialization function. Bad name.
152     void allocRT(osg::NodeCallback* camera_cull_callback = 0);
153
154   private:
155     int _size_x,
156         _size_y,
157         _view_width,
158         _view_height;
159     bool _use_image_coords,
160          _use_stencil,
161          _use_mipmapping;
162
163     // Multisampling parameters
164     int  _coverage_samples,
165          _color_samples;
166
167     bool rtAvailable;
168     osg::ref_ptr<osg::Camera> camera;
169     osg::ref_ptr<osg::Texture2D> texture;
170
171     void updateCoordinateFrame();
172     void updateStencil();
173     void updateSampling();
174
175 };
176
177 #endif // _OD_GAUGE_HXX