-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrender-graph.js
More file actions
55 lines (53 loc) · 1.31 KB
/
render-graph.js
File metadata and controls
55 lines (53 loc) · 1.31 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
import { NAMESPACE } from "./utils.js";
export default (ctx) => ({
renderPasses: [],
beginFrame() {
this.renderPasses.length = 0;
},
renderPass(options) {
if (options.uses && ctx.debugMode) {
console.debug(NAMESPACE, "render-graph uses", options.uses);
}
this.renderPasses.push(options);
},
endFrame() {
//TODO: this should be render view
for (let i = 0; i < this.renderPasses.length; i++) {
const {
name,
pass,
renderView,
render,
uses = [],
} = this.renderPasses[i];
ctx.submit(
{
name,
pass,
viewport: renderView.viewport,
scissor: renderView.viewport,
},
() => {
try {
for (let j = 0; j < uses.length; j++) {
const texture = uses[j];
//FIXME: mipmap generation should happen only once
if (texture.min === ctx.Filter.LinearMipmapLinear) {
ctx.update(texture, { mipmap: true });
}
}
if (render) render();
} catch (error) {
console.error(
NAMESPACE,
"render-graph",
`Pass "${name}" crashed.`,
error,
pass,
);
}
},
);
}
},
});