#pragma once


#include "sprite.h"
#include "colour.h"

namespace Halley {
	class RendererLayer {
	public:
		RendererLayer();
		void render(Renderer& r);

		bool rendered;
		SpriteList sprites;
		std::map<int, SpriteList> particles;
	};


	class RendererSprite {
	public:
		RendererSprite() {}
		RendererSprite(float _x, float _y, float _ox, float _oy, float _angle, float _scale, bool _flip, Colour _col)
			: x(_x), y(_y), angle(_angle), scale(_scale), ox(_ox), oy(_oy), flip(_flip), col(_col)
		{}
		float x, y;
		float ox, oy;
		float angle;
		float scale;
		bool flip;
		Colour col;
	};


	class Renderer {
	public:
		Renderer();
		~Renderer();

		void startRendering();
		void endRendering();

		void renderLayer(int n);
		void renderLayers(int min, int max);
		void renderAllLayers();

		void addSprite(spSprite sprite);
		void removeSprite(spSprite sprite);

		void drawImage(Vector2f pos, Vector2f offset, int texId, double angle, double scale, int type, bool flip=false, Colour col=Colour(1, 1, 1, 1));
		void drawParticles(SpriteList& list);

	private:
		SpriteList& getList(spSprite sprite);
		void drawImageGroup(RendererSprite* s, int nSprites, int texId, int type);

		std::map<int, RendererLayer> layers;
		std::vector<GLfloat> tmpData;
		bool rendering;

		static unsigned int vbo;
	};
}
