TextureDataStruct.h 2.18 KB
#ifndef TEXTURE_DATA_STRUCT_H
#define TEXTURE_DATA_STRUCT_H
#include "rts_glTextureMap.h"
#include "rtsFilename.h"

struct TextureData
{
	//character name of the texture for the shader
	string Name;

	//RTS variable for the texture map (takes care of texture management)
	rts_glTextureMap Texture;

	//file information
	rtsFilename Filename;

	//image size
	int sX, sY;

	int components;

	//format of the incoming data
	int ExternalComponents;
	GLuint ExternalDatatype;

	//format of the data on the GPU
	int InternalComponents;
	GLuint InternalDatatype;
	int Normalized;

	GLuint getInternalFormat()
	{
		switch(InternalComponents)
		{
		case 1:
			if(InternalDatatype == GL_FLOAT)
				return GL_LUMINANCE32F_ARB;
			if(InternalDatatype == GL_UNSIGNED_BYTE && !Normalized)
				return GL_R8;
			if(InternalDatatype == GL_UNSIGNED_BYTE && Normalized)
				return GL_R8_SNORM;
			if(InternalDatatype == GL_SHORT && !Normalized)
				return GL_R16;
			if(InternalDatatype == GL_SHORT && Normalized)
				return GL_R16_SNORM;
			break;
		case 2:
			break;
		case 3:
			if(InternalDatatype == GL_FLOAT)
				return GL_RGB32F;
			if(InternalDatatype == GL_UNSIGNED_BYTE && !Normalized)
				return GL_RGB8;
			if(InternalDatatype == GL_UNSIGNED_BYTE && Normalized)
				return GL_RGB8_SNORM;
			if(InternalDatatype == GL_SHORT && !Normalized)
				return GL_RGB16;
			if(InternalDatatype == GL_SHORT && Normalized)
				return GL_RGB16_SNORM;
			break;
		case 4:
			if(InternalDatatype == GL_FLOAT)
				return GL_RGBA32F;
			if(InternalDatatype == GL_UNSIGNED_BYTE && !Normalized)
				return GL_RGBA8;
			if(InternalDatatype == GL_UNSIGNED_BYTE && Normalized)
				return GL_RGBA8_SNORM;
			if(InternalDatatype == GL_SHORT && !Normalized)
				return GL_RGBA16;
			if(InternalDatatype == GL_SHORT && Normalized)
				return GL_RGBA16_SNORM;
			break;
		default:
			break;
		}
		cout<<"Error getting internal format."<<endl;
		return GL_LUMINANCE;
	}

	GLuint getExternalFormat()
	{
		switch(ExternalComponents)
		{
		case 1:
			return GL_LUMINANCE;
			break;
		case 2:
			return GL_LUMINANCE_ALPHA;
			break;
		case 3:
			return GL_RGB;
			break;
		case 4:
			return GL_RGBA;
			break;
		default:
			break;
		}
		return GL_LUMINANCE;
	}
};

#endif