#ifndef FBO_H
#define FBO_H

#include "./../../lib/GLee/GLee.h"
#include "./context/Context.h"
#include "./exception/Exception.h"
#include <cassert>
// more info on http://www.gamedev.net/reference/articles/article2331.asp

class FBO;	//forward declaration


///Frame Buffer Object context.
class FBOContext: public Context
{
private:
	FBO *fbo;

public:
	virtual void makeCurrent(void);
	virtual void doneCurrent(void);

	virtual void swapBuffers(void);
	FBOContext( FBO* fbo);
};

///Frame Buffer Object exception
class FBOexception : public BasicException
{
public:
	FBOexception( void );
};


//TODO FIXME WARNING: actually it works only with depthTextures	
///Frame Buffer Object
class FBO
{
private:
	unsigned int fboID;		/**< frame buffer id*/
	unsigned int renderID;	/**<  render buffer id*/
	unsigned int texID;		/**<  texture id */

	int frameSizeX, frameSizeY;

	FBO( const FBO& ); /**< Canot be copied */

	void setSize( int width, int height );

public:
	FBO( int width, int height ) { setSize(width, height); }

	/**<  texID = texture Id where the FBO should render into */
	FBO( int width, int height, int texID);
	~FBO(void);

	
	void setTexture( unsigned int texID );


	void clear(void);	/**< Cleaf depth texture and frame texture */
	void bind(void);	/**< Bind FBO */
	void unbind(void);	/**< Unbind FBO */

	unsigned int getTextureId(void) const;	/**< Return texture Id which is render into  */
	int getFrameSizeX(void) const;	/**< Return the Framebuffer and Texture width */ 
	int getFrameSizeY(void) const;	/**< Return the Framebuffer and Texture height */ 
};




#endif