/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2016 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.
 *
 * This program 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
 * GNU Lesser General Public License for more details.
 *
 * 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_TILE_PATCH_CALLBACK_H
#define OSGEARTH_TILE_PATCH_CALLBACK_H 1

#include <osgEarth/TileKey>
#include <vector>

// forward declarations
namespace osg {
    class Node;
    class StateSet;
}
namespace osgUtil {
    class CullVisitor;
}

namespace osgEarth
{
    /**
     * A "Tile Patch" is a patch of surface geometry that corresponds to a terrain tile.
     * For an engine that supports patches, this callback will let you install custom
     * rendering state for a tile patch.
     */
    class OSGEARTH_EXPORT TilePatchCallback : public osg::Referenced
    {
    public:
        /**
         * Cull the patch for a given tile. You must push the passed-in stateset, traverse
         * the patch, and then pop the stateset yourself. You can of course push any additional
         * state or cull any additional drawables that you want to.
         *
         * @param[in ] nv Cull visitor that is traversing the scene graph
         * @param[in ] key Tile key of the tile currenting being culled
         * @param[in ] stateSet StateSet corresponding to the current TileKey; the implementation
         *             is responsible for pushing/popping this
         * @param[in ] patch Optional node to traverse if you want to render a tessellation patch.
         */
        virtual void cull(
            osgUtil::CullVisitor* nv, 
            const TileKey&        key, 
            osg::StateSet*        stateSet, 
            osg::Node*            patch) =0;

        /**
         * Release any resources associated with the provided tile key. The engine will call
         * this automatically then a tile is removed from the scene.
         *
         * @param[in ] key TileKey for which to release resources.
         */
        virtual void release(
            const TileKey& key) { }

    protected:
        virtual ~TilePatchCallback() { }
    };

    typedef std::vector< osg::ref_ptr<TilePatchCallback> > TilePatchCallbacks;


} // namespace osgEarth

#endif // OSGEARTH_TILE_PATCH_CALLBACK_H
