forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope-space.js
More file actions
49 lines (41 loc) · 1.25 KB
/
scope-space.js
File metadata and controls
49 lines (41 loc) · 1.25 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
import { ScopeId } from './scope-id.js';
/**
* @class
* @name ScopeSpace
* @classdesc The scope for variables.
* @param {string} name - The scope name.
* @property {string} name The scope name.
*/
class ScopeSpace {
constructor(name) {
// Store the name
this.name = name;
// Create map which maps a uniform name into ScopeId
this.variables = new Map();
}
/**
* @function
* @name ScopeSpace#resolve
* @description Get (or create, if it doesn't already exist) a variable in the scope.
* @param {string} name - The variable name.
* @returns {ScopeId} The variable instance.
*/
resolve(name) {
// add new ScopeId if it does not exist yet
if (!this.variables.has(name)) {
this.variables.set(name, new ScopeId(name));
}
// return the ScopeId instance
return this.variables.get(name);
}
// clears value for any uniform with matching value (used to remove deleted textures)
removeValue(value) {
for (var uniformName in this.variables) {
var uniform = this.variables[uniformName];
if (uniform.value === value) {
uniform.value = null;
}
}
}
}
export { ScopeSpace };