-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathTextureHeader.cpp
More file actions
129 lines (125 loc) · 2.75 KB
/
TextureHeader.cpp
File metadata and controls
129 lines (125 loc) · 2.75 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "TextureHeader.hpp"
#include <cassert>
void ProcessHeader(uint8_t* data, CodecType& type, int32_t& width, int32_t& height, size_t& dataOffset){
auto data32 = (uint32_t*)data;
if( *data32 == 0x03525650 )
{
// PVR
switch( *(data32+2) )
{
case 6:
type = Etc1;
break;
case 7:
type = Bc1;
break;
case 11:
type = Bc3;
break;
case 12:
type = Bc4;
break;
case 13:
type = Bc5;
break;
case 15:
type = Bc7;
break;
case 22:
type = Etc2_RGB;
break;
case 23:
type = Etc2_RGBA;
break;
case 25:
type = Etc2_R11;
break;
case 26:
type = Etc2_RG11;
break;
default:
assert( false );
break;
}
height = *(data32+6);
width = *(data32+7);
dataOffset = 52 + *(data32+12);
}
else if( *data32 == 0x58544BAB )
{
// KTX
switch( *(data32+7) )
{
case 0x9274:
type = Etc2_RGB;
break;
case 0x9278:
type = Etc2_RGBA;
break;
case 0x9270:
type = Etc2_R11;
break;
case 0x9272:
type = Etc2_RG11;
break;
default:
assert( false );
break;
}
width = *(data32+9);
height = *(data32+10);
dataOffset = sizeof( uint32_t ) * 17 + *(data32+15);
}
else if( *data32 == 0x20534444 )
{
// DDS
switch( *(data32+21) )
{
case 0x31545844:
type = Bc1;
dataOffset = 128;
break;
case 0x35545844:
type = Bc3;
dataOffset = 128;
break;
case 0x30315844:
dataOffset = 148;
// DXGI_FORMAT_BCn
switch( *(data32+32) )
{
case 71:
case 72:
type = Bc1;
break;
case 77:
case 78:
type = Bc3;
break;
case 80:
type = Bc4;
break;
case 83:
type = Bc5;
break;
case 98:
case 99:
type = Bc7;
break;
default:
assert( false );
break;
};
break;
default:
assert( false );
break;
};
width = *(data32+4);
height = *(data32+3);
}
else
{
assert( false );
}
}