Blame view

TextureDataStruct.h 2.18 KB
ee96a02c   David Mayerich   first commit from...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  #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