/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
------------------------------------------------------------------------------*/


#ifndef	__GPUVBO__
#define __GPUVBO__


		#include "memory/memory.h"
		#include "alloc/ialloc.h"


namespace GS {
	namespace GPU {
		class Renderer;

/*!
	@short	GPU data buffer object.
*/
struct	VBO
{
		NPLACEMENT_NEW(Renderer)

enum	Usage
{
	Static		=	0,
	Dynamic
};
enum	Type
{
	Index		=	0,
	Vertex
};

		Renderer		&renderer;

		/// Get VBO size.
virtual	size_t			GetSize() const = 0;

		/// Map VBO to main memory.
virtual	void			*Map() = 0;
		/// Unmap VBO.
virtual	void			Unmap() = 0;

		/// Update VBO content.
virtual	bool			Update(const void *, size_t start = 0, size_t size = 0) = 0;

		/// Create VBO.
virtual	bool			Create(size_t size, Type = Vertex, Usage = Static) = 0;
		/// Create VBO, map and set data.
virtual	bool			Create(const void *data, size_t size, Type type = Vertex, Usage usage = Static)
		{
			if	(!Create(size, type, usage))
				return false;

			void *p = Map();
			if	(!p)
				return false;

			Memory::Copy(p, data, size);
			Unmap();
			return true;
		}

		/// Free VBO.
virtual	void			Free() = 0;

		VBO(Renderer &r) : renderer(r) {}
virtual	~VBO() {}
};

	} // GPU
} // GS


#endif	// __GPUVBO__
