/*
	ZOpenGLDataBuffer.hpp
	Author: James Russell <jcrussell@762studios.com>
	Created: 3/20/2011

	Purpose: 
	
	OpenGL implementation of the ZDataBuffer interfaces.

	License:

	TODO
*/

#pragma once

#ifndef _ZOPENGLDATABUFFER_HPP
#define _ZOPENGLDATABUFFER_HPP

#include <ZUtil/ZUtil.hpp>

#include <ZRenderer/ZDataBufferBase.hpp>

//Forward Declarations
class ZOpenGLRenderer;

/*
OpenGL Data Buffer.
*/
class ZOpenGLDataBuffer : public ZDataBufferBase
{
protected:
	//Renderer associated with this buffer
	ZOpenGLRenderer *Renderer;

	//The current offset to use
	size_t NextOffset;

	//Offset Alignment Requirement
	static int OffsetAlignment;

	//Gets the buffer data from the graphics device as part of a thread request
	static void GetDeviceData_( ZThread *_renderThread, void *_dataBuffer );

	//Subclass Override
	virtual void GetDeviceData(void* _buffer);

	//Subclass Override
	virtual size_t GetNextBlockOffset(size_t _size);

	//Subclass Override
	virtual void ResetBlockOffset();

public:
	//OpenGL Handle to the Buffer
	GLuint GLHandle;

	//Gets a GLenum based off of type
	GLenum GetGLType()
	{
		switch (Type)
		{
		case ZDBT_UNIFORM:	return GL_UNIFORM_BUFFER;
		case ZDBT_VERTEX:	return GL_ARRAY_BUFFER;
		case ZDBT_INDEX:	return GL_ELEMENT_ARRAY_BUFFER;
		default:			return GL_INVALID_ENUM;
		}
	}

	//Gets a GLenum based off of usage
	GLenum GetGLUsage()
	{
		switch(Usage)
		{
		case ZDBU_STATIC:		return GL_STATIC_DRAW;
		case ZDBU_DYNAMIC:		return GL_DYNAMIC_DRAW;
		case ZDBU_STREAMING:	return GL_STREAM_DRAW;	
		default:				return GL_INVALID_ENUM;	
		}
	}

	/*
	Constructor.

	@param _renderer - the current renderer
	@param _type - the type of buffer this is
	@param _usage - the usage type of this buffer
	@param _size - the size (in bytes) of the data buffer
	*/
	ZOpenGLDataBuffer(ZOpenGLRenderer *_renderer, ZDataBufferType _type, ZDataBufferUsage _usage, size_t _size);

	/*
	Destructor.
	*/
	virtual ~ZOpenGLDataBuffer();
};

#endif
