-
-
Notifications
You must be signed in to change notification settings - Fork 419
Expand file tree
/
Copy pathindex.js
More file actions
131 lines (107 loc) · 4.01 KB
/
Copy pathindex.js
File metadata and controls
131 lines (107 loc) · 4.01 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import macro from 'vtk.js/Sources/macros';
const { vtkErrorMacro } = macro;
// ----------------------------------------------------------------------------
// vtkOpenGLTextureUnitManager methods
// ----------------------------------------------------------------------------
function vtkOpenGLTextureUnitManager(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkOpenGLTextureUnitManager');
// ----------------------------------------------------------------------------
// Description:
// Delete the allocation table and check if it is not called before
// all the texture units have been released.
publicAPI.deleteTable = () => {
for (let i = 0; i < model.numberOfTextureUnits; ++i) {
if (model.textureUnits[i] === true) {
vtkErrorMacro('some texture units were not properly released');
}
}
model.textureUnits = [];
model.numberOfTextureUnits = 0;
};
// ----------------------------------------------------------------------------
publicAPI.setContext = (ctx) => {
if (model.context !== ctx) {
if (model.context !== 0) {
publicAPI.deleteTable();
}
model.context = ctx;
if (model.context) {
model.numberOfTextureUnits = ctx.getParameter(
ctx.MAX_TEXTURE_IMAGE_UNITS
);
for (let i = 0; i < model.numberOfTextureUnits; ++i) {
model.textureUnits[i] = false;
}
}
publicAPI.modified();
}
};
// ----------------------------------------------------------------------------
// Description:
// Reserve a texture unit. It returns its number.
// It returns -1 if the allocation failed (because there are no more
// texture units left).
// \post valid_result: result==-1 || result>=0 && result<this->GetNumberOfTextureUnits())
// \post allocated: result==-1 || this->IsAllocated(result)
publicAPI.allocate = () => {
for (let i = 0; i < model.numberOfTextureUnits; i++) {
if (!publicAPI.isAllocated(i)) {
model.textureUnits[i] = true;
return i;
}
}
return -1;
};
publicAPI.allocateUnit = (unit) => {
if (publicAPI.isAllocated(unit)) {
return -1;
}
model.textureUnits[unit] = true;
return unit;
};
// ----------------------------------------------------------------------------
// Description:
// Tell if texture unit `textureUnitId' is already allocated.
// \pre valid_id_range : textureUnitId>=0 && textureUnitId<this->GetNumberOfTextureUnits()
publicAPI.isAllocated = (textureUnitId) => model.textureUnits[textureUnitId];
// ----------------------------------------------------------------------------
// Description:
// Release a texture unit.
// \pre valid_id: textureUnitId>=0 && textureUnitId<this->GetNumberOfTextureUnits()
// \pre allocated_id: this->IsAllocated(textureUnitId)
publicAPI.free = (val) => {
model.textureUnits[val] = false;
};
publicAPI.freeAll = () => {
for (let i = 0; i < model.numberOfTextureUnits; ++i) {
model.textureUnits[i] = false;
}
};
}
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
context: null,
numberOfTextureUnits: 0,
textureUnits: 0,
};
// ----------------------------------------------------------------------------
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
model.textureUnits = [];
// Build VTK API
macro.get(publicAPI, model, ['numberOfTextureUnits']);
macro.setGet(publicAPI, model, ['context']);
// Object methods
vtkOpenGLTextureUnitManager(publicAPI, model);
}
// ----------------------------------------------------------------------------
export const newInstance = macro.newInstance(
extend,
'vtkOpenGLTextureUnitManager'
);
// ----------------------------------------------------------------------------
export default { newInstance, extend };