/* 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 <osgCompute/Module>
#include <osgCompute/Buffer>

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

        virtual bool init();

        virtual void clear() { clearLocal(); osgCompute::Module::clear(); }

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

        virtual void acceptResource( osgCompute::Resource& resource );
        virtual bool usesResource( const std::string& handle ) const;
        virtual void removeResource( const std::string& handle );
        virtual osgCompute::Resource* getResource( const std::string& handle );
        virtual const osgCompute::Resource* getResource( const std::string& handle ) const;

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

        mutable osg::Vec2s                                _numBlocks;
        mutable osg::Vec2s                                _numThreads;
        osgCompute::Buffer*                               _srcArray;
        osgCompute::Buffer*                               _trgTmpBuffer;
        osgCompute::Buffer*                               _trgBuffer;

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

};

#endif // TEXSTREAMER_H
