#ifndef TEXTURESUPPORT_H
#define TEXTURESUPPORT_H

#include "./../../lib/GLee/GLee.h"	
#include <string>
#include <vector>

using namespace std;

typedef GLuint ID;
typedef string NAME;


///Auxiliary structure, contains OpenGL texture info
template <typename DATA>
struct InternalTextureData
{
	//vyznam parametru viz http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml 
	unsigned int sizeX;
	unsigned int sizeY;

	GLenum format;			//   GL_COLOR_INDEX, GL_RED, GL_GREEN,  GL_BLUE,  GL_ALPHA, GL_RGB, GL_BGR, GL_RGBA,  GL_BGRA,  GL_LUMINANCE,   GL_LUMINANCE_ALPHA
	GLenum type;			// GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT, ...

	
	vector<DATA>	pixelData;

	InternalTextureData();
};

template <typename DATA>
InternalTextureData<DATA>::InternalTextureData(void)
{
	sizeX=0;
	sizeY=0;
	type=GL_UNSIGNED_BYTE;
	format=GL_RGB;
}



///Auxiliary structure, contains OpenGL texture param values
struct TextureParam
{
	GLenum  glParam;
	GLint	glValue;

	TextureParam(GLenum glParam, GLint glValue);
};


//kompletni informace o texture (obsahuje presne informace jak texturu vytvorit...casto tyto informace nejsou nacteny z obrazku ale uzivatelem rucne dospecifikovany)

///Detailed OpenGL texture data, contains complex informations to be able to create OpenGl texture.
template <typename DATA>
struct Texture
{
	InternalTextureData<DATA> internalData;

	GLint internalFormat;	// reprezentace na GPU
	vector<TextureParam> textureParams;

	Texture();
};

//TODO FORMAT by to chtelo nastavit podle DATA ...specializaci sablony toho lze docilit!!!
template <typename DATA>
Texture<DATA>::Texture(void)
{
	internalFormat=GL_RGB;
	internalData.format=GL_RGB;

	textureParams.clear();
	textureParams.push_back( TextureParam(GL_TEXTURE_WRAP_S, GL_REPEAT) );
	textureParams.push_back( TextureParam(GL_TEXTURE_WRAP_T, GL_REPEAT) );
	textureParams.push_back( TextureParam(GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR) );
	textureParams.push_back( TextureParam(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) );
}

template <typename DATA>
void prepareWhiteTexture( Texture<DATA> &texData)	/**< prepare 1x1 pixel RGB texture, which is white */
{
	texData.internalFormat=GL_RGB;
	texData.internalData.format=GL_RGB;
	texData.internalData.sizeX=1;
	texData.internalData.sizeY=1;
	texData.internalData.pixelData.clear();
	texData.internalData.pixelData.push_back(1.0);	//R=1.0
	texData.internalData.pixelData.push_back(1.0);	//G=1.0
	texData.internalData.pixelData.push_back(1.0);	//B=1.0

	texData.internalData.type=GL_UNSIGNED_BYTE;

	texData.textureParams.clear();
	texData.textureParams.push_back( TextureParam(GL_TEXTURE_WRAP_S, GL_REPEAT) );
	texData.textureParams.push_back( TextureParam(GL_TEXTURE_WRAP_T, GL_REPEAT) );
	texData.textureParams.push_back( TextureParam(GL_TEXTURE_MAG_FILTER, GL_NEAREST) );
	texData.textureParams.push_back( TextureParam(GL_TEXTURE_MIN_FILTER, GL_NEAREST) );
}

#endif