-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpass.js
45 lines (38 loc) · 1.07 KB
/
pass.js
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
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);
return pass;
}
export default createPass;