-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpass.js
More file actions
67 lines (58 loc) · 1.69 KB
/
pass.js
File metadata and controls
67 lines (58 loc) · 1.69 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
56
57
58
59
60
61
62
63
64
65
66
67
import { checkProps } from "./utils.js";
/**
* @typedef {import("./types.js").PexResource} PassOptions
* @property {import("./types.js").PexTexture2D[] | import("./framebuffer.js").Attachment[]} [color] render target
* @property {import("./types.js").PexTexture2D} [depth] render target
* @property {import("./types.js").Color} [clearColor]
* @property {number} [clearDepth]
*/
const allowedProps = [
"name",
"framebuffer",
"color",
"depth",
"clearColor",
"clearDepth",
];
function createPass(ctx, opts) {
checkProps(allowedProps, opts);
const pass = {
class: "pass",
opts,
clearColor: opts.clearColor,
clearDepth: opts.clearDepth,
_dispose() {
this.opts = null;
this.clearColor = null;
this.clearDepth = null;
if (this.framebuffer) {
ctx.dispose(this.framebuffer);
this.framebuffer = null;
}
},
};
// Inherits framebuffer from parent command or screen, if no target specified
if (opts.color || opts.depth) {
pass.framebuffer = ctx.framebuffer(opts);
const colorsToResolve = opts.color
? opts.color
.map((attachment, index) => {
if (attachment.resolveTarget) {
return { texture: attachment.resolveTarget, sourceIndex: index };
}
})
.filter((a) => a)
: [];
const depthToResolve = opts.depth?.resolveTarget;
if (colorsToResolve.length || depthToResolve) {
const resolveOpts = {
name: `${opts.name ? `${opts.name}_` : ""}resolve`,
color: colorsToResolve,
depth: depthToResolve,
};
pass.resolveFramebuffer = ctx.framebuffer(resolveOpts);
}
}
return pass;
}
export default createPass;