#ifndef MODELMANAGER_H
#define MODELMANAGER_H

#include <vector>

#include <utils/maths.h>

class VertexBuffer;
class IndexBuffer;
class Texture2D;

struct StaticMeshVertex
{
	glm::vec3 position;
	glm::vec3 normal;
	glm::vec2 texcoord;
};

struct ModelData_t
{
	VertexBuffer* vb;
	IndexBuffer* ib;
	uint32_t vbcount;
	uint32_t ibcount;
};

void ReleaseModelData(ModelData_t& data);

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

	void LoadObj( const char* filename );
	void LoadMtl( const char* filename );

	void LoadIQM( const char* filename );

	void Draw( const glm::mat4& model, bool isTransparent = false );

	BoundingBox GetBoundingBox() { return m_boundingBox; } 

private:
	ModelData_t m_data;
	BoundingBox m_boundingBox;
	Texture2D* m_AlbedoTexture;
};

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

	// Buffer creation
	VertexBuffer* CreateVertexBuffer( void* data, int size );
	IndexBuffer* CreateIndexBuffer( void* data, int size );

	Model* LoadModel(const char* filename);

private:
	struct ModelEntry
	{
		char filename[260];
		Model* model;
	};

	std::vector< ModelEntry > m_models;

};

extern ModelManager* g_modelManager;

#endif // !MODELMANAGER_H
