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

#include <osg/Geometry>
#include <osgCompute/Interoperability>

namespace osgCuda
{
	class GeometryBuffer;
    /**
    */
    class LIBRARY_EXPORT Geometry : public osg::Geometry, public osgCompute::InteropObject
    {
    public:
        Geometry();

        META_Object( osgCuda, Geometry )
					
		virtual osgCompute::InteropBuffer* getBuffer();
		virtual const osgCompute::InteropBuffer* getBuffer() const;
		virtual osgCompute::InteropBuffer* getOrCreateBuffer();

		virtual void addHandle( const std::string& handle );
		virtual void removeHandle( const std::string& handle );
		virtual bool isAddressedByHandle( const std::string& handle ) const;

        virtual bool init();

        virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
        virtual void releaseGLObjects(osg::State* state=0) const;

		virtual bool isClear();
        virtual void clear();

    protected:
		friend class GeometryBuffer;
        virtual ~Geometry();
        void clearLocal();

		mutable GeometryBuffer* 	_proxy;
		bool						_clear;
		osgCompute::HandleSet		_handles;

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

#endif //OSGCUDA_GEOMETRYBUFFER_H
