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 * Enable/Disable updating the texture (If disabled the contents of the
103 * texture remains with the outcome of the last rendering pass)
105 void setRender(bool render);
108 * Say if we can render to a texture.
109 * @return true if rtt is available
111 bool serviceable(void);
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
121 canvas::Placements set_texture( const char * name,
122 osg::Texture2D* new_texture );
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
136 * @return A list of groups which override the given texture
139 canvas::Placements set_texture( const SGPropertyNode* placement,
140 osg::Texture2D* new_texture,
141 osg::NodeCallback* cull_callback = 0 );
144 * Get the OSG camera for drawing this gauge.
146 osg::Camera* getCamera() const { return camera.get(); }
148 osg::Texture2D* getTexture() const { return texture.get(); }
149 //void setTexture(osg::Texture2D* t) { texture = t; }
151 // Real initialization function. Bad name.
152 void allocRT(osg::NodeCallback* camera_cull_callback = 0);
159 bool _use_image_coords,
163 // Multisampling parameters
164 int _coverage_samples,
168 osg::ref_ptr<osg::Camera> camera;
169 osg::ref_ptr<osg::Texture2D> texture;
171 void updateCoordinateFrame();
172 void updateStencil();
173 void updateSampling();
177 #endif // _OD_GAUGE_HXX