#pragma once
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QOPenGLVertexArrayObject>
#include <QOpenGlShaderProgram>
#include "..\Header\MshFile.h"

struct Vertex {
	GLfloat position[3];
	GLfloat uv[2];
};

struct textureData {
	bool alpha;
	std::uint32_t width;
	std::uint32_t height;
	std::vector<std::uint8_t>* data;
};

class OpenGlViewer : public QOpenGLWidget, protected QOpenGLFunctions
{
	Q_OBJECT

public:
	OpenGlViewer(QWidget *parent);
	~OpenGlViewer();

private:
// OpenGL ======================================
	QOpenGLBuffer m_vertexBuffer;
	QOpenGLVertexArrayObject m_vertexArray;
	QOpenGLShaderProgram* m_program = nullptr;

// Data ========================================
	std::vector<Model*>* m_vModels = nullptr;
	std::vector<textureData*> m_vTextures;
	BoundingBox m_sceneBoundings;

// Transformation ==============================
	float m_fRotX		= 0;
	float m_fRotY		= 0;
	float m_fRotZ		= 0;
	float m_fTranX		= 0;
	float m_fTranY		= 0;
	float m_fTranZ		= 0;

// Camera ======================================
	float m_fFOV		= 45.0f;
	float m_fMinView	= 0.1f;
	float m_fMaxView	= 100.0f;

private:
	virtual void initializeGL() override final;
	virtual void resizeGL(int w, int h) override final;
	virtual void paintGL() override final;

	void printContextInformation();
	void deleteData();

public:
	void setData(std::vector<Model*>* models, std::vector<textureData*> textures);
};
