/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2015 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_CONTEXT_H
#define OSGEARTH_TRITON_CONTEXT_H

#include "TritonOptions"
#include <osg/Referenced>
#include <osg/Light>
#include <osgEarth/ThreadingUtils>

namespace osgEarth {
    class SpatialReference;
}

namespace Triton {
    class ResourceLoader;
    class Environment;
    class Ocean;
}

namespace osgEarth { namespace Triton
{
    /**
     * Contains all the Triton SDK handles.
     */
    class TritonContext : public osg::Referenced
    {
    public:
        TritonContext(const TritonOptions& options);

        /** Sets the spatial reference system of the map */
        void setSRS(const osgEarth::SpatialReference* srs);

    public: // accessors

        bool ready() const { return _initAttempted && !_initFailed; }

        /** Spatial reference of the map */
        const osgEarth::SpatialReference* getSRS() const { return _srs.get(); }

        void initialize(osg::RenderInfo& renderInfo);

        void update(double simTime);

        ::Triton::Environment* getEnvironment() { return _environment; }
        ::Triton::Ocean* getOcean() { return _ocean; }

    protected:

        virtual ~TritonContext();


    private:
        TritonOptions    _options;

        bool             _initAttempted;
        bool             _initFailed;
        Threading::Mutex _initMutex;

        osg::ref_ptr<const osgEarth::SpatialReference> _srs;

        ::Triton::ResourceLoader* _resourceLoader;
        ::Triton::Environment*    _environment;
        ::Triton::Ocean*          _ocean;
    };

} } // namespace osgEarth::Triton

#endif // OSGEARTH_TRITON_CONTEXT_H