/* osgCompute - Copyright (C) 2008-2009 SVT Group
*                                                                     
* This library 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 library 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 Lesse General Public License for more details.
*
* The full license is in LICENSE file included with this distribution.
*/

#ifndef PTCLDEMO_PTCL_MAPPER
#define PTCLDEMO_PTCL_MAPPER 1

#include <osg/ref_ptr>
#include <osgCuda/Module>
#include <osgCuda/Export>
#include <osgCuda/Buffer>
#include <osgCuda/Geometry>

namespace PtclDemo
{
    class PtclMapper : public osgCuda::Module 
    {
    public:
        enum SYNCHRONIZE_TYPE
        {
            DO_NOT_SYNC = 0,
            SYNC_GL_WITH_CUDA_DEVICE    = 0x1,
            SYNC_CUDA_WITH_GL_DEVICE    = 0x2,
            SYNC_GL_WITH_CUDA_HOST      = 0x4,
            SYNC_CUDA_WITH_GL_HOST      = 0x8,
        };

    public:
        PtclMapper() : osgCuda::Module() {clearLocal();}

        META_Module( PtclDemo, PtclMapper )

        virtual bool init();
        virtual void clear() { clearLocal(); osgCuda::Module::clear(); }

        virtual void launch( const osgCompute::Context& context ) const;

        inline void setSyncType( unsigned int syncType ) { _syncType = syncType; }
        virtual void acceptResource( osgCompute::Resource& resource );

    protected:
        virtual ~PtclMapper();
        void clearLocal();

        osg::ref_ptr<osgCuda::Vec4fGeometry>              _particlesGL;
        osg::ref_ptr<osgCuda::Vec4fBuffer>                _particlesCUDA;
        unsigned int                                      _syncType;

    private:
        PtclMapper(const PtclMapper&, const osg::CopyOp& ) {} 
        inline PtclMapper &operator=(const PtclMapper &) { return *this; }
    };

};

#endif // PTCLDEMO_PTCL_MAPPER
