#pragma once

#include "DLLInterface.h"

#include "CompiledEffect.h"

//this class keeps shaders with the same source but different defines in a pool

class DXFUNCTIONS_API EffectCompiler : public ShaderProgram
{
	friend ShaderManager;

	LPD3DXEFFECTPOOL m_Pool;

	CompiledEffect* m_MainEffect;

	LList<CompiledEffect> m_Effects;

protected:

	friend CompiledEffect;

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

	void ReleaseEffect(CompiledEffect* const fx);

	void AddErrorMsgs(const XString& msgs);

	LPD3DXEFFECTPOOL GetPool(void) const { return m_Pool; }

	virtual void DoRestore(void);
	virtual void DoInvalidate(void);

public:
	//recompiles all effects
	void Compile(bool debug = false);
	//XString GetDisassembly(void);

	CompiledEffect* GetMainEffect(void) const { return m_MainEffect; }

	//compiles the shader with certain defines and filter redundant effects
	CompiledEffect* CompileEffect(const bool debug, D3DXMACRO* pDefines);
};