/*
 *	osgART/GenericVideoObject
 *	osgART: AR ToolKit for OpenSceneGraph
 *
 *	Copyright (c) 2005-2007 ARToolworks, Inc. All rights reserved.
 *	
 *	Rev		Date		Who		Changes
 *  1.0   	2006-12-08  ---     Version 1.0 release.
 *
 */
/*
 * This file is part of osgART - AR Toolkit for OpenSceneGraph
 *
 * Copyright (c) 2005-2007 ARToolworks, Inc. All rights reserved.
 *
 * (See the AUTHORS file in the root of this distribution.)
 *
 *
 * OSGART is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * OSGART 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OSGART; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */


#ifndef OSGART_GENERICVIDEOOBJECT
#define OSGART_GENERICVIDEOOBJECT 1

//standard include
#include <iostream>
#include <string>

//graphics include
#include <osg/Node>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/Geometry>
#include <osg/Projection>

//personnal include
#include "osgART/Export"
#include "osgART/VideoTexture"
#include "osgART/GenericVideoShader"
#include "osgART/GenericVideo"

namespace osgART {

	/**
	 * A generic interface for video sources. It implements the very
	 * basic video functionality been used in osgART. 
	 */

	class OSGART_EXPORT GenericVideoObject : public osg::Group
	{
	public:
	
	
		/**
		 * Calculate power of two for OpenGL textures
		 * \param x dimension to be calculated
		 * \return power of two which is above or equal to the value given
		 */	
		static unsigned int mathNextPowerOf2(unsigned int x);
		        
	    
	    /** 
	     * Modes how the video is being rendered.
	     */
		enum TextureMode {
			USE_TEXTURE_AUTO = 0,	/**< Automatically determine best texture mode */
			USE_TEXTURE_2D,			/**< Video is being pasted into a 2D texture */
			USE_TEXTURE_RECTANGLE,	/**< Video is being attached to a 2D rectangle */
			USE_TEXTURE_VIDEO		/**< different way to construct a video */
		};

		/**
		 * Mode used to correct camera distortion.
		 */
		enum DistortionCorrectionMode {
			NO_CORRECTION,			/**< No correction is applied to the Texture */
			CAMERA_PARAM_CORRECTION	/**< The texture is being corrected from camera parameters */
		};
		
		
		/** 
		* \brief default constructor.
		* @param videoId the number of the video used for the background
		*/    
		GenericVideoObject(GenericVideo* video);

	


		/** 
		 * All initialisation needs to be done within here.
		 * 
		 */
		virtual void init() = 0;
	    
	    
		inline void setTexture(osg::Texture* vt) {
			m_vTexture=vt;
		}

		inline osg::ref_ptr<osg::Texture> getTexture() {
			return m_vTexture;
		}
	    
		inline void setShader(GenericVideoShader* vs) { 
			m_vShader=vs;
		}
	    
		inline osg::ref_ptr<GenericVideoShader> getShader() {
			return m_vShader;
		}    
	    
		inline void setTextureMode(TextureMode tm) {
			m_textureMode=tm;
		}

		inline TextureMode getTextureMode() const {
			return m_textureMode;
		}

		inline void setDistortionCorrectionMode(DistortionCorrectionMode dcm) {
			m_distortionMode=dcm;
		}

		inline DistortionCorrectionMode getDistorsionCorrectionMode() const {
			return m_distortionMode;
		}
	    
	    
	protected:
	
	
		/**
		 * \brief destructor.
		 */
		virtual ~GenericVideoObject();
	
	
		osg::ref_ptr<GenericVideoShader>	m_vShader;
		osg::ref_ptr<osg::Texture>			m_vTexture;

	
		osg::ref_ptr<GenericVideo>			m_video;
		
		
		
		DistortionCorrectionMode m_distortionMode;
		TextureMode m_textureMode;
		
		osg::ref_ptr<osg::Image> m_videoimage;

	};
};

#endif // !defined GenericVideoObject_h
