From 65d029377836046e57bb495553e884fb2c2f0ac0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 8 Jun 2004 13:58:36 +0000 Subject: [PATCH] Added options for controlling mipmapping and aniso-tropic filtering. --- examples/osgdem/osgdem.cpp | 37 ++++++++++++++++++++++++++++++------- include/osgTerrain/DataSet | 19 +++++++++++++++++++ src/osgTerrain/DataSet.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/examples/osgdem/osgdem.cpp b/examples/osgdem/osgdem.cpp index 8cabcc0b8..61c026aa6 100644 --- a/examples/osgdem/osgdem.cpp +++ b/examples/osgdem/osgdem.cpp @@ -186,13 +186,13 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--compressed","Use OpenGL compression on destination imagery"); arguments.getApplicationUsage()->addCommandLineOption("--RGB_16","Use 16bit RGB destination imagery"); arguments.getApplicationUsage()->addCommandLineOption("--RGB_24","Use 24bit RGB destination imagery"); - arguments.getApplicationUsage()->addCommandLineOption("",""); - - if (arguments.argc()<=1) - { - arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); - return 1; - } + arguments.getApplicationUsage()->addCommandLineOption("--max-visible-distance-of-top-level","Set the maximum visiable distance that the top most tile can be viewed at"); + arguments.getApplicationUsage()->addCommandLineOption("--radius-to-max-visible-distance-ratio","Set the maximum visiable distance ratio for all tiles apart from the top most tile. The maximum visuble distance is computed from the ratio * tile radius."); + arguments.getApplicationUsage()->addCommandLineOption("--no-mip-mapping","Disable mip mapping of textures"); + arguments.getApplicationUsage()->addCommandLineOption("--mip-mapping-hardware","Use mip mapped textures, and generate the mipmaps in hardware when available."); + arguments.getApplicationUsage()->addCommandLineOption("--mip-mapping-imagery","Use mip mapped textures, and generate the mipmaps in imagery."); + arguments.getApplicationUsage()->addCommandLineOption("--max-anisotropy","Max anisotropy level to use when texturing, defaults to 1.0."); +// arguments.getApplicationUsage()->addCommandLineOption("",""); // create DataSet. osg::ref_ptr dataset = new osgTerrain::DataSet; @@ -228,6 +228,17 @@ int main( int argc, char **argv ) while (arguments.read("--RGB_16")) { dataset->setTextureType(osgTerrain::DataSet::RGB_16_BIT); } while (arguments.read("--RGB_24")) { dataset->setTextureType(osgTerrain::DataSet::RGB_24_BIT); } + while (arguments.read("--no-mip-mapping")) { dataset->setMipMappingMode(osgTerrain::DataSet::NO_MIP_MAPPING); } + while (arguments.read("--mip-mapping-hardware")) { dataset->setMipMappingMode(osgTerrain::DataSet::MIP_MAPPING_HARDWARE); } + while (arguments.read("--mip-mapping-imagery")) { dataset->setMipMappingMode(osgTerrain::DataSet::MIP_MAPPING_IMAGERY); } + + float maxAnisotropy; + while (arguments.read("--max-anisotropy",maxAnisotropy)) + { + dataset->setMaxAnisotropy(maxAnisotropy); + } + + dataset->setDestinationTileBaseName("output"); dataset->setDestinationTileExtension(".ive"); @@ -247,6 +258,18 @@ int main( int argc, char **argv ) dataset->setSkirtRatio(skirtRatio); } + float maxVisibleDistanceOfTopLevel; + while (arguments.read("--max-visible-distance-of-top-level",maxVisibleDistanceOfTopLevel)) + { + dataset->setMaximumVisibleDistanceOfTopLevel(maxVisibleDistanceOfTopLevel); + } + + float radiusToMaxVisibleDistanceRatio; + while (arguments.read("--radius-to-max-visible-distance-ratio",radiusToMaxVisibleDistanceRatio)) + { + dataset->setRadiusToMaxVisibleDistanceRatio(radiusToMaxVisibleDistanceRatio); + } + // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { diff --git a/include/osgTerrain/DataSet b/include/osgTerrain/DataSet index e1b7991d3..df5b289df 100644 --- a/include/osgTerrain/DataSet +++ b/include/osgTerrain/DataSet @@ -909,9 +909,25 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced void setTextureType(TextureType type) { _textureType = type; } TextureType getTextureType() const { return _textureType; } + void setMaxAnisotropy(float d) { _maxAnisotropy = d; } + float getMaxAnisotropy() const { return _maxAnisotropy; } + + + enum MipMappingMode + { + NO_MIP_MAPPING, /// disable mip mapping - use LINEAR, LINEAR filters. + MIP_MAPPING_HARDWARE, /// use mip mapping, dynamically compute them in hardware if supported + MIP_MAPPING_IMAGERY /// use mip mapping, and store imagery along with associated mip maps. + }; + + void setMipMappingMode(MipMappingMode mipMappingMode) { _mipMappingMode = mipMappingMode; } + MipMappingMode getMipMappingMode() const { return _mipMappingMode; } + + void setUseLocalTileTransform(bool flag) { _useLocalTileTransform = flag; } bool getUseLocalTileTransform() const { return _useLocalTileTransform; } + void setDecorateGeneratedSceneGraphWithCoordinateSystemNode(bool flag) { _decorateWithCoordinateSystemNode = flag; } bool getDecorateGeneratedSceneGraphWithCoordinateSystemNode() const { return _decorateWithCoordinateSystemNode; } @@ -979,6 +995,9 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced DatabaseType _databaseType; GeometryType _geometryType; TextureType _textureType; + float _maxAnisotropy; + MipMappingMode _mipMappingMode; + bool _useLocalTileTransform; bool _decorateWithCoordinateSystemNode; diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index c1557bcbe..2d333a3b0 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -1846,9 +1848,30 @@ osg::StateSet* DataSet::DestinationTile::createStateSet() texture->setImage(image); texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); - texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); - texture->setMaxAnisotropy(8); + switch (_dataSet->getMipMappingMode()) + { + case(DataSet::NO_MIP_MAPPING): + { + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + } + break; + case(DataSet::MIP_MAPPING_HARDWARE): + { + texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + } + break; + case(DataSet::MIP_MAPPING_IMAGERY): + { + osg::notify(osg::NOTICE)<<"Mip mapped imagery not currently supported, falling back to hardware mip mapping."<setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR); + texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); + } + break; + } + + texture->setMaxAnisotropy(_dataSet->getMaxAnisotropy()); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); bool inlineImageFile = _dataSet->getDestinationTileExtension()==".ive"; @@ -2814,6 +2837,9 @@ DataSet::DataSet() _databaseType = PagedLOD_DATABASE; _geometryType = POLYGONAL; _textureType = COMPRESSED_TEXTURE; + _maxAnisotropy = 1.0; + _mipMappingMode = MIP_MAPPING_HARDWARE; + _useLocalTileTransform = true; _decorateWithCoordinateSystemNode = true;