#ifndef _CTEXTUREMANAGER_H_
#define _CTEXTUREMANAGER_H_

#include <LIST>
#include <VECTOR>
#include "../app/EngineH.h"
#include "../LogFile/LogFile.h"

const int TM_NONE			= 0x000000;
const int TM_MAX_NEAREST	= 0x000001;
const int TM_MIN_NEAREST	= 0x000010;
const int TM_MAX_LINEAR		= 0x000100;
const int TM_MIN_LINEAR		= 0x001000;
const int TM_MIP_NEAREST	= 0x010000;
const int TM_MIP_LINEAR		= 0x101100;
const int TM_LINEAR			= 0x001100;
const int TM_NEAREST		= 0x000011;
//0x101100
const int TM_BMP			= 0;
const int TM_BMP_RLE		= 1;
const int TM_JPEG_QSUPER	= 2;
const int TM_JPEG_QGOOD		= 3;
const int TM_JPEG_QNORMAL	= 4;
const int TM_JPEG_QAVERAGE	= 5;
const int TM_JPEG_QBAD		= 6;

struct TTexture
{
	bool				enable;	// plati nebo je smayana??, 0-neplati, 1-plati
	std::string			name;
	unsigned int		texture_id;
	std::string			pripona;
	int					flags;
	bool				nacteno;
	TRGBi				rgb_alpha;		// barva alpha kanalu pro nacitani
	unsigned char		roz;			// rozmezi		
	bool				alphaTest;
};

class C_TEXTURE_MANAGER_0
{
private :
	std::vector<TTexture>	_lTextures;
	int						_raptMemory;
	int						_citac;
	TRGBi					_rgb_alpha;
	unsigned char			_roz;
	unsigned int			_CreateGlTexture(int width,int height,int bpp,unsigned char *data,int flags=0x000000);	
	std::string				_GetPripona(std::string name);
	C_LOG_FILE				_logFile;
	float					_completTime;

public :
	C_TEXTURE_MANAGER_0();
	~C_TEXTURE_MANAGER_0();
	
public :
	inline int AddTexture(std::string name, int flags=TM_NONE, bool alpha=0)
	{
		if(name.size() == 0) return -1;
		TTexture temp;
		temp.enable = 1;
		temp.name = name;
		temp.texture_id = 0;
		temp.flags = flags;
		temp.nacteno = false;
		temp.rgb_alpha = _rgb_alpha;
		temp.roz = _roz;
		temp.alphaTest = alpha;
		for(register int i = 0;i < _lTextures.size();i++)
		{
			if( !_lTextures[i].enable ) continue;
			if(temp.name == _lTextures[i].name)
			{
				return i;
			}
		}
		_lTextures.push_back(temp);
		//return _lTextures.size();
		return _citac++;
	}
	unsigned int GetIdTexture(int citac) const
	{
		if(citac >= _lTextures.size() || citac < 0) return 0;
		return _lTextures[citac].texture_id;
	}

	bool ReloadTextures(bool all=0);
	void DeleteTexture( int id );
	void DeleteAll();
	int GetRaptMemory() const{return _raptMemory;}
	void SetColorAlpha(TRGBi rgb_alpha) {_rgb_alpha = rgb_alpha;}
	void SetColorAlpha(int r=0,int g=255,int b=0)
	{
		_rgb_alpha.r = r;
		_rgb_alpha.g = g;
		_rgb_alpha.b = b;
	}
	void SetAlphaRozmezi(UCHAR u) {_roz = u;}
	UCHAR GetAlphaRozmezi() const {return _roz;}
	TRGBi GetColorAlpha() const{return _rgb_alpha;}
	bool SaveScreenShotTga(std::string file_name,int width,int height);
	bool SaveImage(std::string file_name,int width,int height,unsigned int flags = TM_BMP);
};

#endif //_CTEXTUREMANAGER_H_