/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 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
*/
#ifndef OSGEARTH_TRITON_CONTEXT_H
#define OSGEARTH_TRITON_CONTEXT_H
#include
#include // Triton
#include "TritonLayer.h"
#include "TritonAPIWrapper.h"
#include "TritonCallback.h"
#include
#include
#include
namespace osgEarth {
class SpatialReference;
}
namespace osgEarth { namespace Triton
{
/**
* Contains all the Triton SDK handles.
*/
class TritonContext : public osg::Object
{
public:
META_Object(osgEarth, TritonContext);
TritonContext(const TritonLayer::Options&);
/** Sets the spatial reference system of the map */
void setSRS(const osgEarth::SpatialReference* srs);
/** Sets the user callback */
void setCallback(Callback* callback);
Callback* getCallback() const { return _callback.get(); }
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);
bool intersect(const osg::Vec3d& start, const osg::Vec3d& dir, float& out_height, osg::Vec3f& out_normal) const;
::Triton::Environment* getEnvironment() { return _environment; }
Environment& getEnvironmentWrapper() const { return *_environmentWrapper; }
::Triton::Ocean* getOcean() { return _ocean; }
Ocean& getOceanWrapper() const { return *_oceanWrapper; }
bool passHeightMapToTriton() const;
int getHeightMapSize() const;
const std::string& getMaskLayerName() const;
public: // osg::Object
void resizeGLObjectBuffers(unsigned maxSize);
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objects
* for all graphics contexts. */
void releaseGLObjects(osg::State* state) const;
protected:
virtual ~TritonContext();
// hidden ctors (for META_Object)
TritonContext() { }
TritonContext(const TritonContext&, const osg::CopyOp&) { }
private:
TritonLayer::Options _options;
bool _initAttempted;
bool _initFailed;
std::mutex _initMutex;
osg::ref_ptr _srs;
mutable ::Triton::ResourceLoader* _resourceLoader;
mutable ::Triton::Environment* _environment;
mutable ::Triton::Ocean* _ocean;
Environment* _environmentWrapper;
Ocean* _oceanWrapper;
osg::ref_ptr _callback;
};
} } // namespace osgEarth::Triton
#endif // OSGEARTH_TRITON_CONTEXT_H