/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2014 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_DRIVERS_MP_MASK_GENERATOR
#define OSGEARTH_DRIVERS_MP_MASK_GENERATOR 1

#include "Common"
#include <osgEarth/TileKey>
#include <osg/Geometry>

namespace osgEarth { namespace Drivers { namespace MPTerrainEngine
{
    using namespace osgEarth;

    /**
     * Record that stores the data for a single masking region.
     */
    struct MaskRecord
    {
        osg::ref_ptr<osg::Vec3dArray> _boundary;
        osg::Vec3d                    _ndcMin, _ndcMax;
        osg::Geometry*                _geom;
        osg::ref_ptr<osg::Vec3Array>  _internal;

        MaskRecord(osg::Vec3dArray* boundary, osg::Vec3d& ndcMin, osg::Vec3d& ndcMax, osg::Geometry* geom) 
            : _boundary(boundary), _ndcMin(ndcMin), _ndcMax(ndcMax), _geom(geom), _internal(new osg::Vec3Array()) { }
    };

    typedef std::vector<MaskRecord> MaskRecordVector;


    /**
     * Creates geometry for the part of a tile containing mask data.
     */
    class MaskGenerator
    {
    public:
        MaskGenerator(const TileKey& key);

        /** whether a texcoord indicates that the corresponding vert is masked. */
        bool isMasked(const osg::Vec3f& texCoord) const
        {
            return texCoord.z() == 0.0f;
        }

        /** whether the masking geometry contains a unit location. */
        bool contains(float nx, float ny) const
        {
            // Placeholder for now.
            return false;
        }

        bool containedByQuadAtColRow(int col, int row, int tileSize) const
        {
            // Placeholder for now.
            return false;
        }

    protected:
        const TileKey    _key;
        MaskRecordVector _maskRecords;
    };

} } } // namespace osgEarth::Drivers::MPTerrainEngine

#endif // OSGEARTH_DRIVERS_MP_MASK_GENERATOR
