/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2012 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_SPLAT_LANDCOVER_TERRAIN_EFFECT_H
#define OSGEARTH_SPLAT_LANDCOVER_TERRAIN_EFFECT_H

#include "Export"
#include "Coverage"
#include "Zone"
#include "LandCoverTilePatchCallback"

#include <osgEarth/TerrainEffect>
#include <osg/Uniform>
#include <osgDB/Options>

using namespace osgEarth;

namespace osgEarth { namespace Splat
{
    /**
     * Effect that renders land cover data (trees, grass, rocks, etc.)
     */
    class OSGEARTHSPLAT_EXPORT LandCoverTerrainEffect : public TerrainEffect
    {
    public:
        /** constructor */
        LandCoverTerrainEffect();

        /**
         * Sets the OSG DB options to use when performing I/O
         */
        void setDBOptions(const osgDB::Options* dbo);

        /**
         * Sets the coverage/surface zones.
         */
        void setZones(const Zones& zones) { _zones = zones; }
        const Zones& getZones() const { return _zones; }

        /**
         * Sets the coverage source. This is optional, if you do not install
         * a coverage source the land cover will render everywhere unconstrained.
         */
        void setCoverage(Coverage* coverage) { _coverage = coverage; }
        Coverage* getCoverage() const { return _coverage.get(); }

    public: // TerrainEffect interface

        void onInstall(TerrainEngineNode* engine);

        void onUninstall(TerrainEngineNode* engine);


    protected:
        virtual ~LandCoverTerrainEffect() { }

        osg::ref_ptr<const osgDB::Options> _dbo;

        osg::ref_ptr<Coverage> _coverage;
        Zones _zones;
        int _noiseTexUnit;
        int _landCoverTexUnit;

        osg::ref_ptr<LandCoverTilePatchCallback> _tilePatchCallback;
    };

} } // namespace osgEarth::Splat

#endif // OSGEARTH_SPLAT_LANDCOVER_TERRAIN_EFFECT_H
