/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2018 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/>
 */

#include "Common"
#include "SilverLiningOptions"
#include "SilverLiningCallback"
#include "SilverLiningAPIWrapper"
#include <osgEarthUtil/Sky>
#include <osgEarth/Map>
#include <osgEarth/PhongLightingEffect>
#include <osg/Light>
#include <osg/LightSource>

namespace osgEarth { namespace SilverLining
{
    class SilverLiningContext;
    class SilverLiningNode;

    /**
     * Node that roots the silverlining adapter.
     */
    class SilverLiningContextNode : public osg::Group
    {
    public:
        SilverLiningContextNode(
            SilverLiningNode*          node,
            osg::Camera*               camera,
            osg::Light*                light,
            const SilverLiningOptions& options,
            Callback*                  callback =0L);

    public: 
        void attach(osg::View* view, int lightNum);

        // callbacks from SilverLiningNode.
        void onSetDateTime();
        void onSetMinimumAmbient();
        //get target camera
        osg::Camera* getTargetCamera() const {return _camera;}
        osg::ref_ptr<osg::Geode> getSLGeode() {return _geode;}
        SilverLiningContext* getSLContext() {return _SL.get();}

        osg::StateSet* getCloudsStateSet() const { return _cloudsDrawable.valid() ? _cloudsDrawable->getStateSet() : 0L; }
        osg::StateSet* getSkyStateSet() const { return _skyDrawable.valid() ? _skyDrawable->getStateSet() : 0L; }

    public: // osg::Node

        void traverse(osg::NodeVisitor&);

    protected:
        virtual ~SilverLiningContextNode();

        osg::ref_ptr<SilverLiningContext> _SL;
        osg::ref_ptr<osg::Geode> _geode;
        osg::ref_ptr<osg::Drawable> _skyDrawable;
        osg::ref_ptr<osg::Drawable> _cloudsDrawable;
        SilverLiningNode* _silverLiningNode;
        double _lastAltitude;
        const SilverLiningOptions _options;
        osg::Camera* _camera;
    };

} } // namespace osgEarth::SilverLining