/* osgEarth
 * Copyright 2008-2014 Pelican Mapping
 * MIT License
 */
#ifndef OSGEARTH_SPLAT_MODEL_SPLATTER
#define OSGEARTH_SPLAT_MODEL_SPLATTER 1

#include "SplatExport"
#include "SplatOptions"
#include <osgEarth/TileKey>
#include <osgEarth/TerrainEngineNode>

namespace osgEarth { namespace Splat
{
    using namespace osgEarth;

    /**
     * Extension for loading the splatting effect on demand.
     */
    class ModelSplatter : public TerrainEngine::NodeCallback
    {
    public:
        ModelSplatter();

        /**
         * Sets the model to splat
         */
        void setModel(osg::Node* node);

        void setNumInstances(unsigned num);

        void setMinLOD(unsigned lod);


    public: // TileNodeCallback

        // Attaches the model splatter to a new tile node
        void operator()(const TileKey& key, osg::Node* tileNode);

    protected:
        virtual ~ModelSplatter();

    private:
        osg::ref_ptr<osg::Node> _model;
        Threading::Mutex        _modelMutex;
        unsigned                _count;
        unsigned                _minLOD;
        bool                    _dirty;

        void establish();
        osg::Node* makeChild(int delta);
    };

} } // namespace osgEarth::Splat

#endif // OSGEARTH_SPLAT_MODEL_SPLATTER
