/
DataFormatGL.cpp
89 lines (76 loc) · 1.81 KB
/
DataFormatGL.cpp
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
#include "thin3d/DataFormatGL.h"
#include "base/logging.h"
#include "Common/Log.h"
namespace Draw {
// TODO: Also output storage format (GL_RGBA8 etc) for modern GL usage.
bool Thin3DFormatToFormatAndType(DataFormat fmt, GLuint &internalFormat, GLuint &format, GLuint &type, int &alignment) {
alignment = 4;
switch (fmt) {
case DataFormat::R8G8B8A8_UNORM:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
break;
case DataFormat::D32F:
internalFormat = GL_DEPTH_COMPONENT;
format = GL_DEPTH_COMPONENT;
type = GL_FLOAT;
break;
#ifndef USING_GLES2
case DataFormat::S8:
internalFormat = GL_STENCIL_INDEX;
format = GL_STENCIL_INDEX;
type = GL_UNSIGNED_BYTE;
alignment = 1;
break;
#endif
case DataFormat::R8G8B8_UNORM:
internalFormat = GL_RGB;
format = GL_RGB;
type = GL_UNSIGNED_BYTE;
alignment = 1;
break;
case DataFormat::B4G4R4A4_UNORM_PACK16:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_4_4_4_4;
alignment = 2;
break;
case DataFormat::B5G6R5_UNORM_PACK16:
internalFormat = GL_RGB;
format = GL_RGB;
type = GL_UNSIGNED_SHORT_5_6_5;
alignment = 2;
break;
case DataFormat::B5G5R5A1_UNORM_PACK16:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_5_5_5_1;
alignment = 2;
break;
#ifndef USING_GLES2
case DataFormat::A4R4G4B4_UNORM_PACK16:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
alignment = 2;
break;
case DataFormat::R5G6B5_UNORM_PACK16:
internalFormat = GL_RGB;
format = GL_RGB;
type = GL_UNSIGNED_SHORT_5_6_5_REV;
alignment = 2;
break;
case DataFormat::A1R5G5B5_UNORM_PACK16:
internalFormat = GL_RGBA;
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
alignment = 2;
break;
#endif
default:
return false;
}
return true;
}
}