
#ifndef SPECTRE_BATCH_RENDERER2D_H
#define SPECTRE_BATCH_RENDERER2D_H

#include "Renderer2D.h"
#include <Spectre/Scene/Camera2D.h>

#include <Spectre/Graphics/RenderState.h>
#include <Spectre/Graphics/Vertex2D.h>
#include <Spectre/Math/Matrix4.h>
#include <vector>

class ShaderProgram;

class Texture;

class BatchRenderer2D : public Renderer2D
{
public :

	BatchRenderer2D();
	~BatchRenderer2D();

	void setBatchSize(unsigned short value);

	void begin();

	void end();

	void submit(const Renderable2D& renderable);

	// Drawing
	virtual void draw(const Renderable2D* renderable);

	void render();

protected :

	struct Batch
	{
		RenderType	type;
		const Texture*	texture;
		unsigned int	count;
		unsigned int	offset;
	};

	typedef std::vector<Batch> BatchQueue;

	void prepareQueue();

	unsigned int addRenderable(Vertex2D* buffer, const Renderable2D* renderable);

	void uploadBatch(const Batch& batch);

	void drawBatch(Batch& batch);

protected :

	std::vector<const Renderable2D*> m_queue;

	unsigned int m_VAO;
	unsigned int m_IBO;
	unsigned int m_VBO;

	RenderState m_state;
	
	unsigned short m_size;

	ShaderProgram m_textShader;
	ShaderProgram m_spriteShader;
};

#endif /* SPECTRE_BATCH_RENDERER2D_H */