Added TerrainNode::setColorFilter(layerNum,Filter) to allow developers to set

what type of texture filter to use, either LINEAER and NEAREST.
This commit is contained in:
Robert Osfield 2007-04-30 09:47:35 +00:00
parent 43e6d7e879
commit efb52dfab9
4 changed files with 64 additions and 1 deletions

View File

@ -84,6 +84,8 @@ int main(int argc, char** argv)
unsigned int layerNum = 0;
std::string filterName;
bool readParameter = false;
float minValue, maxValue;
int pos = 1;
@ -174,6 +176,27 @@ int main(int argc, char** argv)
}
}
else if (arguments.read(pos, "--filter",filterName))
{
readParameter = true;
if (filterName=="NEAREST")
{
osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST);
}
else if (filterName=="LINEAER")
{
osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::LINEAR);
}
else
{
osg::notify(osg::NOTICE)<<"--filter "<<filterName<<" unrecognized filter name, please use LINEAER or NEAREST."<<std::endl;
}
}
else if (arguments.read(pos, "--tf",minValue, maxValue))
{
readParameter = true;

View File

@ -88,6 +88,20 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
/** Get const color transfer function with specified layer number.*/
const osg::TransferFunction* getColorTransferFunction(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].transferFunction.get() : 0; }
enum Filter
{
NEAREST,
LINEAR
};
/** Set a color filter with specified layer number.*/
void setColorFilter(unsigned int i, Filter filter);
/** Set const color filter with specified layer number.*/
Filter getColorFilter(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].filter : LINEAR; }
/** Get the number of colour layers.*/
unsigned int getNumColorLayers() const { return _colorLayers.size(); }
@ -107,7 +121,23 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
struct LayerData
{
osg::ref_ptr<Layer> layer;
LayerData():
filter(LINEAR) {}
LayerData(const LayerData& rhs):
filter(rhs.filter),
layer(rhs.layer),
transferFunction(rhs.transferFunction) {}
LayerData& operator = (const LayerData& rhs)
{
filter = rhs.filter;
layer = rhs.layer;
transferFunction = rhs.transferFunction;
}
Filter filter;
osg::ref_ptr<Layer> layer;
osg::ref_ptr<osg::TransferFunction> transferFunction;
};

View File

@ -49,6 +49,7 @@ void GeometryTechnique::init()
osgTerrain::Layer* elevationLayer = _terrainNode->getElevationLayer();
osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer(0);
osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction(0);
osgTerrain::TerrainNode::Filter filter = _terrainNode->getColorFilter(0);
// if the elevationLayer and colorLayer are the same, and there is colorTF then
// simply assing as a texture coordinate.
@ -286,6 +287,8 @@ void GeometryTechnique::init()
texture2D->setResizeNonPowerOfTwoHint(false);
stateset->setTextureAttributeAndModes(color_index, texture2D, osg::StateAttribute::ON);
texture2D->setFilter(osg::Texture::MAG_FILTER, filter==TerrainNode::LINEAR ? osg::Texture::LINEAR : osg::Texture::NEAREST);
if (tf)
{
// up the precision of hte internal texture format to its maximum.

View File

@ -81,6 +81,13 @@ void TerrainNode::setColorTransferFunction(unsigned int i, osg::TransferFunction
_colorLayers[i].transferFunction = tf;
}
void TerrainNode::setColorFilter(unsigned int i, Filter filter)
{
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].filter = filter;
}
osg::BoundingSphere TerrainNode::computeBound() const
{
osg::BoundingSphere bs;