VolumeDataStruct.h 2.62 KB
#ifndef VOLUME_DATA_STRUCT_H
#define VOLUME_DATA_STRUCT_H
#include "rts_glTextureMap.h"
#include "rtsFilename.h"

#define VOLUME_FILE_AUTO	0
#define VOLUME_FILE_RAW		1
#define VOLUME_FILE_IMAGES	2

#define LOAD_LITTLE_ENDIAN	0
#define LOAD_BIG_ENDIAN		1

struct VolumeData
{
	//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
	int FileType;
	vector<rtsFilename> Filenames;

	//volume size
	vector3D<int> Dim;
	int HeaderSize;
	//big or little endian
	int BitType;
	
	//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;
	}

	int GetByteSize(GLuint t)
	{
		switch(t)
		{
		case GL_UNSIGNED_BYTE:
			return 1;
			break;
		case GL_FLOAT:
			return 4;
			break;
		case GL_UNSIGNED_SHORT:
		case GL_SHORT:
			return 2;
			break;
		default:
			break;
		}
		return 0;
	}
};

#endif