#pragma once

#include "DLLInterface.h"

#include "..\Utilities\Util.h"
#include "..\Utilities\XString.h"
#include "..\Utilities\List.h"

enum SHADERTYPE
{
	SH_NONE = 0,
	SH_ASMVS,
	SH_ASMPS,
	SH_HLVS,
	SH_HLPS,
	SH_FX,
	SH_CMPFX,
	SH_CMP
};

class ShaderManager;

class DXFUNCTIONS_API ShaderProgram : public Ressource, public DXRessource
{
	friend ShaderManager;
	friend ListElement<ShaderProgram>;
	friend LList<ShaderProgram>;

protected:
	SHADERTYPE		m_Type;
	ShaderManager	*m_Manager;
	bool			m_Compiled;
	XString			m_Filename;
	XString			m_ErrorMsgs;
	XString			m_Code;

	__int64			m_ReadedFileSize;
	__time64_t		m_ReadedFileTime;
	XString			m_ReadedFileName;

	ShaderProgram(ShaderManager* const manager, const SHADERTYPE type, const XString& fn);
	virtual ~ShaderProgram(void);
	virtual void ReleaseSH(void){}

	void ReadFile(const XString& fn);
	
public:

	virtual void Save(const XString& fn);
	virtual void Open(const XString& fn);

	void Reload(void);

	SHADERTYPE GetType(void) const {return m_Type;}
	XString GetFilename (void) const {return m_Filename; }
	XString GetErrorMsgs(void) const {return m_ErrorMsgs;}
	XString GetCode     (void) const {return m_Code;     }
	bool   IsCompiled (void) const {return m_Compiled; }
	ShaderManager* GetManager(void) const {return m_Manager;}
	
	void SetCode(const XString& code){ m_Code = code; }

	virtual void Compile(bool debug = false){m_Compiled = false; m_ErrorMsgs = "";}
	virtual XString GetDisassembly(void) {return "";}
};