2005-10-08 11:55:18 +00:00
|
|
|
// Owner Drawn Gauge helper class
|
|
|
|
//
|
|
|
|
// Written by Harald JOHNSEN, started May 2005.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
|
|
|
|
//
|
2007-06-24 07:57:45 +00:00
|
|
|
// Ported to OSG by Tim Moore - Jun 2007
|
|
|
|
//
|
2012-04-21 13:31:20 +00:00
|
|
|
// Heavily modified to be usable for the 2d Canvas by Thomas Geymayer - April 2012
|
|
|
|
// Supports now multisampling/mipmapping, usage of the stencil buffer and placing
|
|
|
|
// the texture in the scene by certain filter criteria
|
|
|
|
//
|
2005-10-08 11:55:18 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-08 11:55:18 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _OD_GAUGE_HXX
|
|
|
|
#define _OD_GAUGE_HXX
|
|
|
|
|
2012-04-21 13:31:20 +00:00
|
|
|
#include <osg/NodeCallback>
|
|
|
|
#include <osg/Group>
|
2012-04-15 11:03:21 +00:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
class Camera;
|
|
|
|
class Texture2D;
|
|
|
|
}
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2012-04-21 13:31:20 +00:00
|
|
|
class SGPropertyNode;
|
|
|
|
typedef std::vector<osg::ref_ptr<osg::Group> > Placements;
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
/**
|
|
|
|
* Owner Drawn Gauge helper class.
|
|
|
|
*/
|
2012-04-15 11:03:21 +00:00
|
|
|
class FGODGauge
|
|
|
|
{
|
2005-10-08 11:55:18 +00:00
|
|
|
public:
|
|
|
|
FGODGauge();
|
2009-05-06 18:55:20 +00:00
|
|
|
virtual ~FGODGauge();
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2012-04-21 13:31:20 +00:00
|
|
|
/**
|
|
|
|
* Set the size of the render target.
|
|
|
|
*
|
|
|
|
* @param size_x X size
|
|
|
|
* @param size_y Y size. Defaults to size_x if not specified
|
|
|
|
*/
|
|
|
|
void setSize(int size_x, int size_y = -1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the size of the viewport
|
|
|
|
*
|
|
|
|
* @param width
|
|
|
|
* @param height Defaults to width if not specified
|
|
|
|
*/
|
|
|
|
void setViewSize(int width, int height = -1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DEPRECATED
|
|
|
|
*
|
|
|
|
* Get size of squared texture
|
|
|
|
*/
|
|
|
|
int size() const { return _size_x; }
|
2011-06-13 21:34:00 +00:00
|
|
|
|
2012-04-21 13:31:20 +00:00
|
|
|
/**
|
|
|
|
* Set whether to use image coordinates or not.
|
|
|
|
*
|
|
|
|
* Default: origin == center of texture
|
|
|
|
* Image Coords: origin == top left corner
|
|
|
|
*/
|
|
|
|
void useImageCoords(bool use = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/Disable using a stencil buffer
|
|
|
|
*/
|
|
|
|
void useStencil(bool use = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set sampling parameters for mipmapping and coverage sampling
|
|
|
|
* antialiasing.
|
|
|
|
*
|
|
|
|
* @note color_samples is not allowed to be higher than coverage_samples
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void setSampling( bool mipmapping,
|
|
|
|
int coverage_samples = 0,
|
|
|
|
int color_samples = 0 );
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
/**
|
|
|
|
* Say if we can render to a texture.
|
|
|
|
* @return true if rtt is available
|
|
|
|
*/
|
|
|
|
bool serviceable(void);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
/**
|
|
|
|
* Replace an opengl texture name inside the aircraft scene graph.
|
|
|
|
* This is to replace a static texture by a dynamic one
|
|
|
|
* @param name texture filename
|
|
|
|
* @param new_texture dynamic texture to replace the old one
|
2012-04-21 13:31:20 +00:00
|
|
|
* @return A list of groups which override the given texture
|
|
|
|
*/
|
|
|
|
Placements set_texture(const char * name, osg::Texture2D* new_texture);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace an opengl texture name inside the aircraft scene graph.
|
|
|
|
* This is to replace a static texture by a dynamic one. The replacement
|
|
|
|
* is base on certain filtering criteria which have to be stored in string
|
|
|
|
* value childs of the placement node. Recognized nodes are:
|
|
|
|
* - texture Match the name of the texture
|
|
|
|
* - node Match the name of the object
|
|
|
|
* - parent Match any of the object parents names (all the tree upwards)
|
|
|
|
* @param placement the node containing the replacement criteria
|
|
|
|
* @param new_texture dynamic texture to replace the old one
|
|
|
|
* @param an optional cull callback which will be installed on any matching
|
|
|
|
* object
|
|
|
|
* @return A list of groups which override the given texture
|
2005-10-08 11:55:18 +00:00
|
|
|
*/
|
2012-04-21 13:31:20 +00:00
|
|
|
Placements set_texture( const SGPropertyNode* placement,
|
|
|
|
osg::Texture2D* new_texture,
|
|
|
|
osg::NodeCallback* cull_callback = 0 );
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
/**
|
|
|
|
* Get the OSG camera for drawing this gauge.
|
|
|
|
*/
|
2012-07-04 11:15:12 +00:00
|
|
|
osg::Camera* getCamera() const { return camera.get(); }
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2012-07-04 11:15:12 +00:00
|
|
|
osg::Texture2D* getTexture() const { return texture.get(); }
|
2012-04-21 13:31:20 +00:00
|
|
|
//void setTexture(osg::Texture2D* t) { texture = t; }
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
// Real initialization function. Bad name.
|
2012-04-21 13:31:20 +00:00
|
|
|
void allocRT(osg::NodeCallback* camera_cull_callback = 0);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
private:
|
2012-04-21 13:31:20 +00:00
|
|
|
int _size_x,
|
|
|
|
_size_y,
|
|
|
|
_view_width,
|
|
|
|
_view_height;
|
|
|
|
bool _use_image_coords,
|
|
|
|
_use_stencil,
|
|
|
|
_use_mipmapping;
|
|
|
|
|
|
|
|
// Multisampling parameters
|
|
|
|
int _coverage_samples,
|
|
|
|
_color_samples;
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
bool rtAvailable;
|
2007-06-24 07:57:45 +00:00
|
|
|
osg::ref_ptr<osg::Camera> camera;
|
|
|
|
osg::ref_ptr<osg::Texture2D> texture;
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2012-04-21 13:31:20 +00:00
|
|
|
void updateCoordinateFrame();
|
|
|
|
void updateStencil();
|
|
|
|
void updateSampling();
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _OD_GAUGE_HXX
|