//
// C++ wrapper for framebuffer object
//
// Author: Alex V. Boreskoff <alexboreskoff@mtu-net.ru>, <steps3d@narod.ru>
//

#ifndef	__FRAME_BUFFER__
#define	__FRAME_BUFFER__

#ifdef	_WIN32
	#include	<windows.h>
#endif

#include	<GL/gl.h>

class	FrameBuffer
{
	int			flags;
	int			width;
	int			height;
	unsigned	frameBuffer;
	unsigned	depthBuffer;
	unsigned	stencilBuffer;
	
public:
	FrameBuffer  ( int theWidth, int theHeight, int theFlags = 0 );
	~FrameBuffer ();
	
	int	getWidth () const
	{
		return width;
	}
	
	int	getHeight () const
	{
		return height;
	}
	
	bool	hasStencil () const
	{
		return stencilBuffer != 0;
	}
	
	bool	hasDepth () const
	{
		return depthBuffer != 0;
	}
	
	bool	isOk   () const;
	bool	create ();
	bool	bind   ();
	bool	unbind ();
	
	bool	attachColorTexture ( GLenum target, unsigned texId, int no = 0 );
	bool	attachDepthTexture ( GLenum target, unsigned texId );
	
	bool	detachColorTexture ( GLenum target )
	{
		return attachColorTexture ( target, 0 );
	}
	
	bool	detachDepthTexture ( GLenum target )
	{
		return attachDepthTexture ( target, 0 );
	}
	
										// create texture for attaching 
	unsigned	createColorTexture ( GLenum format = GL_RGB, GLenum internalFormat = GL_RGB8 );
	
	enum								// flags for depth and stencil buffers
	{
		depth16 = 1,					// 16-bit depth buffer
		depth24 = 2,					// 24-bit depth buffer
		depth32 = 4,					// 32-bit depth buffer
		
		stencil1  = 16,					// 1-bit stencil buffer
		stencil4  = 32,					// 4-bit stencil buffer
		stencil8  = 64,					// 8-bit stencil buffer
		stencil16 = 128					// 16-bit stencil buffer
	};
	
	static	bool	isSupported         ();
	static	int		maxColorAttachemnts ();
	static	int		maxSize             ();
};

#endif
