/* 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_EMITTER
#define PTCLDEMO_PTCL_EMITTER 1

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

namespace PtclDemo
{
    class PtclEmitter : public osgCuda::Module 
    {
    public:
        PtclEmitter() : osgCuda::Module(), _context(NULL) {clearLocal();}

        META_Module( PtclDemo, PtclEmitter )

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

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

        virtual void acceptParam( const std::string& handle, osgCompute::Param& param );

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

        virtual bool init( const osgCompute::Context& context ) const;
        virtual void clear( const osgCompute::Context& context ) const;

        mutable const osgCuda::Context*                   _context;
        mutable float*                                    _seeds;
        unsigned int                                      _seedCount;

        unsigned int                                      _numBlocks;
        unsigned int                                      _numThreads;

        osg::ref_ptr<osgCuda::Vec3fConstant>              _seedBoxMin;
        osg::ref_ptr<osgCuda::Vec3fConstant>              _seedBoxMax;
        osg::ref_ptr<osgCuda::Vec4fBuffer>                _particles;

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

};

#endif // PTCLDEMO_PTCL_EMITTER
