UNPKG

1.26 kBJavaScriptView Raw
1import { Runner } from '@pixi/runner';
2import { Program } from './Program.mjs';
3import { UniformGroup } from './UniformGroup.mjs';
4
5class Shader {
6 constructor(program, uniforms) {
7 this.uniformBindCount = 0;
8 this.program = program;
9 if (uniforms) {
10 if (uniforms instanceof UniformGroup) {
11 this.uniformGroup = uniforms;
12 } else {
13 this.uniformGroup = new UniformGroup(uniforms);
14 }
15 } else {
16 this.uniformGroup = new UniformGroup({});
17 }
18 this.disposeRunner = new Runner("disposeShader");
19 }
20 checkUniformExists(name, group) {
21 if (group.uniforms[name]) {
22 return true;
23 }
24 for (const i in group.uniforms) {
25 const uniform = group.uniforms[i];
26 if (uniform.group) {
27 if (this.checkUniformExists(name, uniform)) {
28 return true;
29 }
30 }
31 }
32 return false;
33 }
34 destroy() {
35 this.uniformGroup = null;
36 this.disposeRunner.emit(this);
37 this.disposeRunner.destroy();
38 }
39 get uniforms() {
40 return this.uniformGroup.uniforms;
41 }
42 static from(vertexSrc, fragmentSrc, uniforms) {
43 const program = Program.from(vertexSrc, fragmentSrc);
44 return new Shader(program, uniforms);
45 }
46}
47
48export { Shader };
49//# sourceMappingURL=Shader.mjs.map