/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library 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 * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include #include #include using namespace osgTerrain; GeometryTechnique::GeometryTechnique() { } GeometryTechnique::GeometryTechnique(const GeometryTechnique& gt,const osg::CopyOp& copyop): TerrainTechnique(gt,copyop) { } GeometryTechnique::~GeometryTechnique() { } void GeometryTechnique::init() { osg::notify(osg::NOTICE)<<"Doing init()"<getElevationLayer(); osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer(); osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction(); // if the elevationLayer and colorLayer are the same, and there is colorTF then // simply assing as a texture coordinate. if ((elevationLayer==colorLayer) && colorTF) colorLayer = 0; osg::notify(osg::NOTICE)<<"elevationLayer = "<computeLocalBounds(*elevationLocator, bottomLeftNDC, topRightNDC); } else { bottomLeftNDC.x() = osg::minimum(bottomLeftNDC.x(), 0.0); bottomLeftNDC.y() = osg::minimum(bottomLeftNDC.y(), 0.0); topRightNDC.x() = osg::maximum(topRightNDC.x(), 1.0); topRightNDC.y() = osg::maximum(topRightNDC.y(), 1.0); } } if (colorLayer) { if (colorLocator!= masterLocator) { masterLocator->computeLocalBounds(*colorLocator, bottomLeftNDC, topRightNDC); } else { bottomLeftNDC.x() = osg::minimum(bottomLeftNDC.x(), 0.0); bottomLeftNDC.y() = osg::minimum(bottomLeftNDC.y(), 0.0); topRightNDC.x() = osg::maximum(topRightNDC.x(), 1.0); topRightNDC.y() = osg::maximum(topRightNDC.y(), 1.0); } } osg::notify(osg::NOTICE)<<"bottomLeftNDC = "<getImage(); osg::StateSet* stateset = _geode->getOrCreateStateSet(); osg::Texture1D* texture1D = new osg::Texture1D; texture1D->setImage(image); texture1D->setResizeNonPowerOfTwoHint(false); texture1D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST); texture1D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); stateset->setTextureAttributeAndModes(tf_index, texture1D, osg::StateAttribute::ON); if (colorLayer) { osg::notify(osg::NOTICE)<<"Using fragment program"<setAttribute(program); // get shaders from source std::string vertexShaderFile = osgDB::findDataFile("lookup.vert"); if (!vertexShaderFile.empty()) { program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexShaderFile)); } else { osg::notify(osg::NOTICE)<<"Not found lookup.vert"<addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentShaderFile)); } else { osg::notify(osg::NOTICE)<<"Not found lookup.frag"<addUniform(sourceSampler); osg::Uniform* lookupTexture = new osg::Uniform("lookupTexture",tf_index); stateset->addUniform(lookupTexture); osg::Uniform* minValue = new osg::Uniform("minValue", tf->getMinimum()); stateset->addUniform(minValue); osg::Uniform* inverseRange = new osg::Uniform("inverseRange", 1.0f/(tf->getMaximum()-tf->getMinimum())); stateset->addUniform(inverseRange); } else { osg::notify(osg::NOTICE)<<"Using standard OpenGL fixed function pipeline"<setUseDisplayList(false); _dirty = false; } void GeometryTechnique::update(osgUtil::UpdateVisitor* nv) { } void GeometryTechnique::cull(osgUtil::CullVisitor* nv) { if (_geode.valid()) { _geode->accept(*nv); } } void GeometryTechnique::cleanSceneGraph() { } void GeometryTechnique::dirty() { TerrainTechnique::dirty(); }