/*
* This source file is part of the osgOcean library
* 
* Copyright (C) 2009 Kim Bale
* Copyright (C) 2009 The University of Hull, UK
* 
* This program 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 3 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.
* http://www.gnu.org/copyleft/lesser.txt.
*/

#pragma once
#include <osgOcean/Export>

#include <osg/Geode>
#include <osg/TextureRectangle>

namespace osgOcean
{
    class OSGOCEAN_EXPORT DistortionSurface : public osg::Geode
    {
    public:
        DistortionSurface( void );

        DistortionSurface( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture );

        DistortionSurface( const DistortionSurface &copy, 
            const osg::CopyOp &copyop = osg::CopyOp::SHALLOW_COPY );

        virtual const char* libraryName() const { return "osgOcean"; }
        virtual const char* className() const { return "DistortionSurface"; }
        virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const DistortionSurface*>(obj) != 0; }
        
        void build( const osg::Vec3f& corner, const osg::Vec2f& dims, osg::TextureRectangle* texture );

        void update(void);

    private:
        float _angle;

    protected:
        ~DistortionSurface( void ){};

        /**
        * Add the default resource paths to osgDB::Registry.
        * Checks if already present.
        * paths: resources/textures and resources/shaders.
        */
        void addResourcePaths(void);

    private:
        void update(const double& dt);
        osg::Program* createShader(void);

    private:
        // ---------------------------------------------
        //            Callback declarations
        // ---------------------------------------------

        class DistortionDataType : public osg::Referenced
        {
        private:
            DistortionSurface& _surface;
            double _oldTime;
            double _newTime;

        public:
            DistortionDataType( DistortionSurface& surface );

            void update( const double& time );
        };

        class DistortionCallback: public osg::NodeCallback
        {
        public:
            virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
        };
    };
}
