From efb52dfab9d52f5921d97ea9db41452cf7aa176d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 30 Apr 2007 09:47:35 +0000 Subject: [PATCH] Added TerrainNode::setColorFilter(layerNum,Filter) to allow developers to set what type of texture filter to use, either LINEAER and NEAREST. --- examples/osgterrain/osgterrain.cpp | 23 ++++++++++++++++++++ include/osgTerrain/TerrainNode | 32 +++++++++++++++++++++++++++- src/osgTerrain/GeometryTechnique.cpp | 3 +++ src/osgTerrain/TerrainNode.cpp | 7 ++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 4647c6d3b..b8e0d0363 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -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 "<setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST); + } + else if (filterName=="LINEAER") + { + osg::notify(osg::NOTICE)<<"--filter "<setColorFilter(layerNum, osgTerrain::TerrainNode::LINEAR); + } + else + { + osg::notify(osg::NOTICE)<<"--filter "< 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; osg::ref_ptr transferFunction; }; diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index f8182a918..ff4b9621c 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -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. diff --git a/src/osgTerrain/TerrainNode.cpp b/src/osgTerrain/TerrainNode.cpp index 6fb8c2690..cd22b5634 100644 --- a/src/osgTerrain/TerrainNode.cpp +++ b/src/osgTerrain/TerrainNode.cpp @@ -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;