#ifndef DEBUGRENDER_H
#define DEBUGRENDER_H

#include <vector>
#include <utils/maths.h>

class VertexBuffer;
class IndexBuffer;
class Shader;

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

	void Initialize();
	void Shutdown();

	void DrawAxis(const Vec3& vec);
	void DrawLine(const Vec3& from, const Vec3& to, const Vec3& color);
	void DrawBoundingBox(const BoundingBox& box, const glm::vec3& color);
	void DrawEllipse(const glm::mat4& trans, const Vec3& color);

	void RenderFrame();

private:
	void BeginDraw();
	void EndDraw();

	void DrawLinesInternal();
	void DrawCmds();

private:
	// Primitives
	struct Line
	{
		Vec3 from;
		Vec3 color0;

		Vec3 to;
		Vec3 color1;
	};

	struct EllipseDrawCmd
	{
		glm::mat4 trans;
		Vec3 color;
	};

	std::vector<Line> m_lines;
	std::vector<EllipseDrawCmd> m_ellipseDrawCmd;

private:
	VertexBuffer* m_verticesBuffer;
	VertexBuffer* m_ellipseVertexBuffer;
	IndexBuffer* m_ellipseIndexBuffer;
	Shader* m_shader;

	unsigned int m_vao;
	unsigned int m_savedVao;
};

extern DebugRender* g_debugRender;

extern bool g_drawDebug;

#endif // !DEBUGRENDER_H
