-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
shader.ts
153 lines (133 loc) · 2.65 KB
/
shader.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* @category gfx
*/
import { GFXObject, GFXObjectType, GFXShaderType, GFXType } from './define';
import { GFXDevice } from './device';
/**
* @zh
* GFX着色器宏。
*/
export interface IGFXShaderMacro {
macro: string;
value: string;
}
/**
* @zh
* GFX着色器阶段。
*/
export interface IGFXShaderStage {
type: GFXShaderType;
source: string;
macros?: IGFXShaderMacro[];
}
/**
* @zh
* GFX Uniform。
*/
export class GFXUniform {
public name: string = '';
public type: GFXType = GFXType.UNKNOWN;
public count: number = 1;
}
/**
* @zh
* GFX Uniform块。
*/
export class GFXUniformBlock {
public binding: number = -1;
public name: string = '';
// instance : string;
public members: GFXUniform[] = [];
}
/**
* @zh
* GFX Uniform采样器。
*/
export class GFXUniformSampler {
public binding: number = -1;
public name: string = '';
public type: GFXType = GFXType.UNKNOWN;
public count: number = 1;
}
/**
* @zh
* GFX着色器描述信息。
*/
export interface IGFXShaderInfo {
name: string;
stages: IGFXShaderStage[];
// bindings: GFXBinding[];
blocks?: GFXUniformBlock[];
samplers?: GFXUniformSampler[];
}
/**
* @zh
* GFX着色器。
*/
export abstract class GFXShader extends GFXObject {
/**
* @zh
* 着色器id。
*/
public get id (): number {
return this._id;
}
/**
* @zh
* 着色器名称。
*/
public get name (): string {
return this._name;
}
/**
* @zh
* GFX设备。
*/
protected _device: GFXDevice;
/**
* @zh
* 着色器id。
*/
protected _id: number;
/**
* @zh
* 着色器名称。
*/
protected _name: string = '';
/**
* @zh
* 着色器阶段数组。
*/
protected _stages: IGFXShaderStage[] = [];
// protected _bindings: GFXBinding[] = [];
/**
* @zh
* 着色器Uniform块数组。
*/
protected _blocks: GFXUniformBlock[] = []; // blocks are used for being compatible with single uniforms
/**
* @zh
* 着色器Uniform采样器数组。
*/
protected _samplers: GFXUniformSampler[] = [];
/**
* 构造函数。
* @param device GFX设备。
*/
constructor (device: GFXDevice) {
super(GFXObjectType.SHADER);
this._device = device;
this._id = device.genShaderId();
}
/**
* @zh
* 初始化函数。
* @param info GFX着色器描述信息。
*/
public abstract initialize (info: IGFXShaderInfo): boolean;
/**
* @zh
* 销毁函数。
*/
public abstract destroy ();
}