/
ShaderType.ts
50 lines (43 loc) · 1.1 KB
/
ShaderType.ts
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
import {EnumClass, EnumIO, _from, _fromString} from '../misc/EnumIO';
export type ShaderTypeEnum = EnumIO;
class ShaderTypeClass extends EnumClass implements ShaderTypeEnum {
constructor({index, str}: {index: number; str: string}) {
super({index, str});
}
}
const VertexShader: ShaderTypeEnum = new ShaderTypeClass({
index: 1,
str: 'VertexShader',
});
const PixelShader: ShaderTypeEnum = new ShaderTypeClass({
index: 2,
str: 'PixelShader',
});
const VertexAndPixelShader: ShaderTypeEnum = new ShaderTypeClass({
index: 3,
str: 'VertexAndPixelShader',
});
const ComputeShader: ShaderTypeEnum = new ShaderTypeClass({
index: 4,
str: 'ComputeShader',
});
const typeList = [
VertexShader,
PixelShader,
VertexAndPixelShader,
ComputeShader,
];
function from(index: number): ShaderTypeEnum {
return _from({typeList, index}) as ShaderTypeEnum;
}
function fromString(str: string): ShaderTypeEnum {
return _fromString({typeList, str}) as ShaderTypeEnum;
}
export const ShaderType = Object.freeze({
VertexShader,
PixelShader,
VertexAndPixelShader,
ComputeShader,
from,
fromString,
});