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

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

namespace TexDemo
{
    class TexStreamer : public osgCuda::Module 
    {
    public:
        TexStreamer() : osgCuda::Module() {clearLocal();}
        
        META_Module( TexDemo, TexStreamer )

        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 );
        virtual bool usesParam( const std::string& handle ) const;
        virtual void removeParam( const std::string& handle );
        virtual osgCompute::Param* getParam( const std::string& handle );
        virtual const osgCompute::Param* getParam( const std::string& handle ) const;

    protected:
        virtual ~TexStreamer() { clearLocal(); }
        void clearLocal();

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

        mutable osg::Vec2s                                _numBlocks;
        mutable osg::Vec2s                                _numThreads;
        osg::ref_ptr<osgCuda::Vec4ubArray>                _srcArray;
        osg::ref_ptr<osgCuda::Vec4ubBuffer>               _trgBuffer;

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

};

#endif // TEXSTREAMER_H
