]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/od_gauge.hxx
Merge branch 'timoore/optimization' into next
[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      * Say if we can render to a texture.
103      * @return true if rtt is available
104      */
105     bool serviceable(void);
106
107     /**
108      * Replace an opengl texture name inside the aircraft scene graph.
109      * This is to replace a static texture by a dynamic one
110      * @param name texture filename
111      * @param new_texture dynamic texture to replace the old one
112      * @return A list of groups which override the given texture
113      */
114     static
115     canvas::Placements set_texture( const char * name,
116                                     osg::Texture2D* new_texture );
117
118     /**
119      * Replace an opengl texture name inside the aircraft scene graph.
120      * This is to replace a static texture by a dynamic one. The replacement
121      * is base on certain filtering criteria which have to be stored in string
122      * value childs of the placement node. Recognized nodes are:
123      *   - texture  Match the name of the texture
124      *   - node     Match the name of the object
125      *   - parent   Match any of the object parents names (all the tree upwards)
126      * @param placement the node containing the replacement criteria
127      * @param new_texture dynamic texture to replace the old one
128      * @param an optional cull callback which will be installed on any matching
129      *        object
130      * @return A list of groups which override the given texture
131      */
132     static
133     canvas::Placements set_texture( const SGPropertyNode* placement,
134                                     osg::Texture2D* new_texture,
135                                     osg::NodeCallback* cull_callback = 0 );
136
137     /**
138      * Get the OSG camera for drawing this gauge.
139      */
140     osg::Camera* getCamera() const { return camera.get(); }
141
142     osg::Texture2D* getTexture() const { return texture.get(); }
143     //void setTexture(osg::Texture2D* t) { texture = t; }
144
145     // Real initialization function. Bad name.
146     void allocRT(osg::NodeCallback* camera_cull_callback = 0);
147
148 private:
149     int _size_x,
150         _size_y,
151         _view_width,
152         _view_height;
153     bool _use_image_coords,
154          _use_stencil,
155          _use_mipmapping;
156
157     // Multisampling parameters
158     int  _coverage_samples,
159          _color_samples;
160
161     bool rtAvailable;
162     osg::ref_ptr<osg::Camera> camera;
163     osg::ref_ptr<osg::Texture2D> texture;
164
165     void updateCoordinateFrame();
166     void updateStencil();
167     void updateSampling();
168
169 };
170
171 #endif // _OD_GAUGE_HXX