-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathprogram-cache.js
More file actions
28 lines (25 loc) · 875 Bytes
/
program-cache.js
File metadata and controls
28 lines (25 loc) · 875 Bytes
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
//TODO: MARCIN: why this is not in ResourceCache? The usecase is slightly different and would require requesting and releasing immediately, or never blocking. Could it be solved with different Usage type?
class ProgramCache {
values = [];
get(flags, vert, frag) {
for (let i = 0; i < this.values.length; i++) {
const value = this.values[i];
if (value.frag === frag && value.vert === vert) {
if (value.flags.length === flags.length) {
let sameFlags = true;
for (let j = 0; j < flags.length; j++) {
if (value.flags[j] !== flags[j]) {
sameFlags = false;
break;
}
}
if (sameFlags) return value.program;
}
}
}
}
set(flags, vert, frag, program) {
this.values.push({ flags, vert, frag, program });
}
}
export default ProgramCache;