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 <Canvas/canvas_fwd.hpp>
33 #include <Canvas/placement.hxx>
35 #include <osg/NodeCallback>
46 * Owner Drawn Gauge helper class.
55 * Set the size of the render target.
57 * @param size_x X size
58 * @param size_y Y size. Defaults to size_x if not specified
60 void setSize(int size_x, int size_y = -1);
63 * Set the size of the viewport
66 * @param height Defaults to width if not specified
68 void setViewSize(int width, int height = -1);
73 * Get size of squared texture
75 int size() const { return _size_x; }
78 * Set whether to use image coordinates or not.
80 * Default: origin == center of texture
81 * Image Coords: origin == top left corner
83 void useImageCoords(bool use = true);
86 * Enable/Disable using a stencil buffer
88 void useStencil(bool use = true);
91 * Set sampling parameters for mipmapping and coverage sampling
94 * @note color_samples is not allowed to be higher than coverage_samples
97 void setSampling( bool mipmapping,
98 int coverage_samples = 0,
99 int color_samples = 0 );
102 * Say if we can render to a texture.
103 * @return true if rtt is available
105 bool serviceable(void);
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
115 canvas::Placements set_texture( const char * name,
116 osg::Texture2D* new_texture );
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
130 * @return A list of groups which override the given texture
133 canvas::Placements set_texture( const SGPropertyNode* placement,
134 osg::Texture2D* new_texture,
135 osg::NodeCallback* cull_callback = 0 );
138 * Get the OSG camera for drawing this gauge.
140 osg::Camera* getCamera() const { return camera.get(); }
142 osg::Texture2D* getTexture() const { return texture.get(); }
143 //void setTexture(osg::Texture2D* t) { texture = t; }
145 // Real initialization function. Bad name.
146 void allocRT(osg::NodeCallback* camera_cull_callback = 0);
153 bool _use_image_coords,
157 // Multisampling parameters
158 int _coverage_samples,
162 osg::ref_ptr<osg::Camera> camera;
163 osg::ref_ptr<osg::Texture2D> texture;
165 void updateCoordinateFrame();
166 void updateStencil();
167 void updateSampling();
171 #endif // _OD_GAUGE_HXX