1 // Owner Drawn Gauge helper class
3 // Written by Harald JOHNSEN, started May 2005.
5 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
7 // Ported to OSG by Tim Moore - Jun 2007
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
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.
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.
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.
32 #include <osg/NodeCallback>
41 typedef std::vector<osg::ref_ptr<osg::Group> > Placements;
44 * Owner Drawn Gauge helper class.
53 * Set the size of the render target.
55 * @param size_x X size
56 * @param size_y Y size. Defaults to size_x if not specified
58 void setSize(int size_x, int size_y = -1);
61 * Set the size of the viewport
64 * @param height Defaults to width if not specified
66 void setViewSize(int width, int height = -1);
71 * Get size of squared texture
73 int size() const { return _size_x; }
76 * Set whether to use image coordinates or not.
78 * Default: origin == center of texture
79 * Image Coords: origin == top left corner
81 void useImageCoords(bool use = true);
84 * Enable/Disable using a stencil buffer
86 void useStencil(bool use = true);
89 * Set sampling parameters for mipmapping and coverage sampling
92 * @note color_samples is not allowed to be higher than coverage_samples
95 void setSampling( bool mipmapping,
96 int coverage_samples = 0,
97 int color_samples = 0 );
100 * Say if we can render to a texture.
101 * @return true if rtt is available
103 bool serviceable(void);
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
112 Placements set_texture(const char * name, osg::Texture2D* new_texture);
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
126 * @return A list of groups which override the given texture
128 Placements set_texture( const SGPropertyNode* placement,
129 osg::Texture2D* new_texture,
130 osg::NodeCallback* cull_callback = 0 );
133 * Get the OSG camera for drawing this gauge.
135 osg::Camera* getCamera() { return camera.get(); }
137 osg::Texture2D* getTexture() { return texture.get(); }
138 //void setTexture(osg::Texture2D* t) { texture = t; }
140 // Real initialization function. Bad name.
141 void allocRT(osg::NodeCallback* camera_cull_callback = 0);
148 bool _use_image_coords,
152 // Multisampling parameters
153 int _coverage_samples,
157 osg::ref_ptr<osg::Camera> camera;
158 osg::ref_ptr<osg::Texture2D> texture;
160 void updateCoordinateFrame();
161 void updateStencil();
162 void updateSampling();
166 #endif // _OD_GAUGE_HXX