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

#include <osgCompute/Computation>
#include <osgCompute/Visitor>
#include <osgCuda/Export>

//! \namespace osgCuda CUDA functionality 
/** \namespace osgCuda 
	Defines the namespace for all CUDA classes that
	implement the osgCompute interfaces for the CUDA API.
*/ 
namespace osgCuda
{
	//! Class for CUDA modules and resources.
	/** The osgCuda::Computation class implements the CUDA device handling. The 
	resource handling is unchanged from osgCompute::Computation. Please see 
	osgCompute::Computation for the resource handling.
    */
    class LIBRARY_EXPORT Computation : public osgCompute::Computation
    {
    public:
		/** Constructor. 
		*/
        Computation();

        META_Computation( osgCuda, Computation, osgCompute, ComputationBin );

		/** Sets the CUDA device. Use the OpenGL device ID here if synchronization
		between GL and CUDA memory space should be fast. All resources can only use a single
		device. The current implementation of osgCuda does not support handling of
		multiple devices. The default device is the first to be found.
		@param[in] device The ID of the CUDA device.
		*/
        static void setupDevice( int device );
        
		/** Releases all resources attached to the computation including modules
		*/
		virtual void clear();

    protected:
		/** Destructor will release all resources first.
		*/
        virtual ~Computation() { clearLocal(); }

		/** Checks the CUDA device. If it is not ready yet then it will be setup by
		calling setupDevice().
		*/
        virtual void checkDevice();

    private:
        // copy constructor and operator should not be called
        Computation( const Computation&, const osg::CopyOp& ) {}
		Computation &operator=(const Computation &) { return *this; }

		void clearLocal();
    };
}

#endif //OSGCUDA_COMPUTATION
