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 library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Library General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Library General Public License for more details.
23 // You should have received a copy of the GNU Library General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #ifndef _SG_OD_GAUGE_HXX
28 #define _SG_OD_GAUGE_HXX
30 #include "canvas_fwd.hxx"
32 #include <osg/NodeCallback>
47 * Owner Drawn Gauge (aka render-to-texture) helper class
56 void setSystemAdapter(const SystemAdapterPtr& system_adapter);
59 * Set the size of the render target.
61 * @param size_x X size
62 * @param size_y Y size. Defaults to size_x if not specified
64 void setSize(int size_x, int size_y = -1);
67 * Set the size of the viewport
70 * @param height Defaults to width if not specified
72 void setViewSize(int width, int height = -1);
74 osg::Vec2s getViewSize() const;
79 * Get size of squared texture
81 int size() const { return _size_x; }
84 * Set whether to use image coordinates or not.
86 * Default: origin == center of texture
87 * Image Coords: origin == top left corner
89 void useImageCoords(bool use = true);
92 * Enable/Disable using a stencil buffer
94 void useStencil(bool use = true);
97 * Enable/Disable additive alpha blending (Can improve results with
98 * transparent background)
100 void useAdditiveBlend(bool use = true);
103 * Set sampling parameters for mipmapping and coverage sampling
106 * @note color_samples is not allowed to be higher than coverage_samples
109 void setSampling( bool mipmapping,
110 int coverage_samples = 0,
111 int color_samples = 0 );
114 * Enable/Disable updating the texture (If disabled the contents of the
115 * texture remains with the outcome of the last rendering pass)
117 void setRender(bool render);
120 * Say if we can render to a texture.
121 * @return true if rtt is available
123 bool serviceable() const;
126 * Get the OSG camera for drawing this gauge.
128 osg::Camera* getCamera() const { return camera.get(); }
130 osg::Texture2D* getTexture() const { return texture.get(); }
132 // Real initialization function. Bad name.
133 void allocRT(osg::NodeCallback* camera_cull_callback = 0);
139 SystemAdapterPtr _system_adapter;
149 USE_IMAGE_COORDS = AVAILABLE << 1,
150 USE_STENCIL = USE_IMAGE_COORDS << 1,
151 USE_MIPMAPPING = USE_STENCIL << 1,
152 USE_ADDITIVE_BLEND = USE_MIPMAPPING << 1
157 // Multisampling parameters
158 int _coverage_samples,
161 osg::ref_ptr<osg::Camera> camera;
162 osg::ref_ptr<osg::Texture2D> texture;
164 bool updateFlag(Flags flag, bool enable);
166 void updateCoordinateFrame();
167 void updateStencil();
168 void updateSampling();
169 void updateBlendMode();
173 } // namespace canvas
174 } // namespace simgear
176 #endif // _SG_OD_GAUGE_HXX