/* -*-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_TRITON_NODE
#define OSGEARTH_TRITON_NODE 1

#include "Common"
#include "TritonOptions"
#include "TritonAPIWrapper"
#include "TritonCallback"
#include <osgEarthUtil/Ocean>
#include <osgEarth/MapNode>
#include <osgEarth/ImageLayer>
#include <osgEarth/ResourceReleaser>
#include <osg/Drawable>

namespace osgEarth { namespace Triton
{
    class TritonContext;

    /**
     * Node that roots the Triton adapter.
     */
    class OSGEARTHTRITON_EXPORT TritonNode : public osgEarth::Util::OceanNode
    {
    public:
        /** Consruct a TritonNode */
        TritonNode(const TritonOptions& options,
                   Callback* userCallback =0L);

        /** @deprecated - place TritonNode under MapNode, or call setMapNode
         *  Construct a TritonNode */
        TritonNode(osgEarth::MapNode* mapNode, const TritonOptions& options, Callback* callback =0L);

        /** MapNode to use; will be discovered automatically if not set here */
        void setMapNode(osgEarth::MapNode* mapNode);

        /** Layer to use to mask the rendering of the ocean surface */
        void setMaskLayer(const osgEarth::ImageLayer* layer);

    protected: // OceanNode

        void onSetSeaLevel();

        void onSetAlpha();

    public: // osg::Node

        osg::BoundingSphere computeBound() const;

        void traverse(osg::NodeVisitor&);

    protected:
        virtual ~TritonNode();

        osg::ref_ptr<TritonContext> _TRITON;
        TritonOptions               _options;
        osg::Drawable*              _drawable;
        osg::ref_ptr<osg::Uniform>  _alphaUniform;
        osg::observer_ptr<ResourceReleaser> _releaser;
        osg::observer_ptr<const ImageLayer> _maskLayer;
        osg::observer_ptr<MapNode> _mapNode;
        osg::ref_ptr<Callback> _callback;
        bool _needsMapNode;

        void create();
    };

} } // namespace osgEarth::Triton

#endif // OSGEARTH_TRITON_NODE
