@kitware/vtk.js 24.5.3 → 24.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Rendering/OpenGL/PolyDataMapper2D.js +4 -2
- package/Rendering/OpenGL/VolumeMapper.js +1 -1
- package/Rendering/WebGPU/BufferManager.js +83 -14
- package/Rendering/WebGPU/CellArrayMapper.js +6 -44
- package/Rendering/WebGPU/Device.js +97 -57
- package/Rendering/WebGPU/Glyph3DMapper.js +2 -0
- package/Rendering/WebGPU/ImageMapper.js +1 -5
- package/Rendering/WebGPU/SphereMapper.js +29 -31
- package/Rendering/WebGPU/StickMapper.js +38 -42
- package/Rendering/WebGPU/StorageBuffer.js +0 -1
- package/Rendering/WebGPU/Texture.js +0 -2
- package/Rendering/WebGPU/TextureManager.js +37 -7
- package/Rendering/WebGPU/UniformBuffer.js +0 -1
- package/Rendering/WebGPU/VolumePass.js +1 -3
- package/Rendering/WebGPU/VolumePassFSQ.js +1 -5
- package/package.json +1 -1
|
@@ -163,7 +163,7 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
|
|
|
163
163
|
// Note that the actor's mtime includes it's properties mtime
|
|
164
164
|
var vmtime = model.VBOBuildTime.getMTime();
|
|
165
165
|
|
|
166
|
-
if (vmtime < publicAPI.getMTime() || vmtime < model.renderable.getMTime() || vmtime < actor.getMTime() || vmtime < model.currentInput.getMTime() || model.renderable.getTransformCoordinate() && vmtime < ren.getMTime()) {
|
|
166
|
+
if (vmtime < publicAPI.getMTime() || vmtime < model._openGLRenderWindow.getMTime() || vmtime < model.renderable.getMTime() || vmtime < actor.getMTime() || vmtime < model.currentInput.getMTime() || model.renderable.getTransformCoordinate() && vmtime < ren.getMTime()) {
|
|
167
167
|
return true;
|
|
168
168
|
}
|
|
169
169
|
|
|
@@ -197,7 +197,9 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
var transformCoordinate = model.renderable.getTransformCoordinate();
|
|
200
|
-
var
|
|
200
|
+
var view = ren.getRenderWindow().getViews()[0];
|
|
201
|
+
var vsize = view.getViewportSize(ren);
|
|
202
|
+
var toString = "".concat(poly.getMTime(), "A").concat(representation, "B").concat(poly.getMTime()) + "C".concat(c ? c.getMTime() : 1) + "D".concat(tcoords ? tcoords.getMTime() : 1) + "E".concat(transformCoordinate ? ren.getMTime() : 1) + "F".concat(vsize);
|
|
201
203
|
|
|
202
204
|
if (model.VBOBuildString !== toString) {
|
|
203
205
|
// Build the VBOs
|
|
@@ -368,7 +368,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
|
|
|
368
368
|
|
|
369
369
|
if (model.zBufferTexture !== null) {
|
|
370
370
|
program.setUniformi('zBufferTexture', model.zBufferTexture.getTextureUnit());
|
|
371
|
-
var size =
|
|
371
|
+
var size = model._useSmallViewport ? [model._smallViewportWidth, model._smallViewportHeight] : model._openGLRenderWindow.getFramebufferSize();
|
|
372
372
|
program.setUniformf('vpWidth', size[0]);
|
|
373
373
|
program.setUniformf('vpHeight', size[1]);
|
|
374
374
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { newInstance as newInstance$1, obj, setGet, newTypedArray, vtkDebugMacro as vtkDebugMacro$1 } from '../../macros.js';
|
|
2
|
+
import { newInstance as newInstance$1, obj, setGet, vtkErrorMacro as vtkErrorMacro$1, newTypedArray, vtkDebugMacro as vtkDebugMacro$1 } from '../../macros.js';
|
|
3
3
|
import { j as cross, l as normalize } from '../../Common/Core/Math/index.js';
|
|
4
|
+
import vtkDataArray from '../../Common/Core/DataArray.js';
|
|
4
5
|
import vtkWebGPUBuffer from './Buffer.js';
|
|
5
6
|
import vtkWebGPUTypes from './Types.js';
|
|
6
7
|
import vtkProperty from '../Core/Property.js';
|
|
@@ -12,7 +13,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
12
13
|
var BufferUsage = Constants.BufferUsage,
|
|
13
14
|
PrimitiveTypes = Constants.PrimitiveTypes;
|
|
14
15
|
var Representation = vtkProperty.Representation;
|
|
15
|
-
var vtkDebugMacro = vtkDebugMacro$1
|
|
16
|
+
var vtkDebugMacro = vtkDebugMacro$1,
|
|
17
|
+
vtkErrorMacro = vtkErrorMacro$1;
|
|
18
|
+
var VtkDataTypes = vtkDataArray.VtkDataTypes; // the webgpu constants all show up as undefined
|
|
16
19
|
|
|
17
20
|
/* eslint-disable no-undef */
|
|
18
21
|
// ----------------------------------------------------------------------------
|
|
@@ -62,6 +65,65 @@ var cellCounters = {
|
|
|
62
65
|
}
|
|
63
66
|
};
|
|
64
67
|
|
|
68
|
+
function _getFormatForDataArray(dataArray) {
|
|
69
|
+
var format;
|
|
70
|
+
|
|
71
|
+
switch (dataArray.getDataType()) {
|
|
72
|
+
case VtkDataTypes.UNSIGNED_CHAR:
|
|
73
|
+
format = 'uint8';
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case VtkDataTypes.FLOAT:
|
|
77
|
+
format = 'float32';
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case VtkDataTypes.UNSIGNED_INT:
|
|
81
|
+
format = 'uint32';
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case VtkDataTypes.INT:
|
|
85
|
+
format = 'sint32';
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case VtkDataTypes.DOUBLE:
|
|
89
|
+
format = 'float32';
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case VtkDataTypes.UNSIGNED_SHORT:
|
|
93
|
+
format = 'uint16';
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case VtkDataTypes.SHORT:
|
|
97
|
+
format = 'sin16';
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
format = 'float32';
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
switch (dataArray.getNumberOfComponents()) {
|
|
106
|
+
case 2:
|
|
107
|
+
format += 'x2';
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case 3:
|
|
111
|
+
// only 32bit types support x3
|
|
112
|
+
if (!format.contains('32')) {
|
|
113
|
+
vtkErrorMacro("unsupported x3 type for ".concat(format));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
format += 'x3';
|
|
117
|
+
break;
|
|
118
|
+
|
|
119
|
+
case 4:
|
|
120
|
+
format += 'x4';
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return format;
|
|
125
|
+
}
|
|
126
|
+
|
|
65
127
|
function getPrimitiveName(primType) {
|
|
66
128
|
switch (primType) {
|
|
67
129
|
case PrimitiveTypes.Points:
|
|
@@ -443,27 +505,34 @@ function vtkWebGPUBufferManager(publicAPI, model) {
|
|
|
443
505
|
} // is the buffer already present?
|
|
444
506
|
|
|
445
507
|
|
|
446
|
-
publicAPI.hasBuffer = function (
|
|
447
|
-
|
|
448
|
-
// if a matching buffer already exists then return true
|
|
449
|
-
var hash = req.time + req.format + req.usage + req.hash;
|
|
450
|
-
return model.device.hasCachedObject(req.owner, hash);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return false;
|
|
508
|
+
publicAPI.hasBuffer = function (hash) {
|
|
509
|
+
return model.device.hasCachedObject(hash);
|
|
454
510
|
};
|
|
455
511
|
|
|
456
512
|
publicAPI.getBuffer = function (req) {
|
|
457
513
|
// if we have a source the get/create/cache the buffer
|
|
458
|
-
if (req.
|
|
459
|
-
|
|
460
|
-
var hash = req.time + req.format + req.usage + req.hash;
|
|
461
|
-
return model.device.getCachedObject(req.owner, hash, _createBuffer, req);
|
|
514
|
+
if (req.hash) {
|
|
515
|
+
return model.device.getCachedObject(req.hash, _createBuffer, req);
|
|
462
516
|
}
|
|
463
517
|
|
|
464
518
|
return _createBuffer(req);
|
|
465
519
|
};
|
|
466
520
|
|
|
521
|
+
publicAPI.getBufferForPointArray = function (dataArray, cells, primitiveType, representation) {
|
|
522
|
+
var format = _getFormatForDataArray(dataArray);
|
|
523
|
+
|
|
524
|
+
var buffRequest = {
|
|
525
|
+
hash: "PA".concat(representation, "P").concat(primitiveType, "D").concat(dataArray.getMTime(), "C").concat(cells.getMTime()).concat(format),
|
|
526
|
+
usage: BufferUsage.PointArray,
|
|
527
|
+
format: format,
|
|
528
|
+
dataArray: dataArray,
|
|
529
|
+
cells: cells,
|
|
530
|
+
primitiveType: primitiveType,
|
|
531
|
+
representation: representation
|
|
532
|
+
};
|
|
533
|
+
return publicAPI.getBuffer(buffRequest);
|
|
534
|
+
};
|
|
535
|
+
|
|
467
536
|
publicAPI.getFullScreenQuadBuffer = function () {
|
|
468
537
|
if (model.fullScreenQuadBuffer) {
|
|
469
538
|
return model.fullScreenQuadBuffer;
|
|
@@ -294,11 +294,9 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
294
294
|
if (points) {
|
|
295
295
|
var shift = model.WebGPUActor.getBufferShift(model.WebGPURenderer);
|
|
296
296
|
var buffRequest = {
|
|
297
|
-
|
|
297
|
+
hash: "".concat(hash).concat(points.getMTime()).concat(cells.getMTime()).concat(shift.join(), "float32x4"),
|
|
298
298
|
usage: BufferUsage.PointArray,
|
|
299
299
|
format: 'float32x4',
|
|
300
|
-
time: Math.max(points.getMTime(), cells.getMTime(), model.WebGPUActor.getKeyMatricesTime().getMTime()),
|
|
301
|
-
hash: hash,
|
|
302
300
|
dataArray: points,
|
|
303
301
|
cells: cells,
|
|
304
302
|
primitiveType: primType,
|
|
@@ -319,7 +317,6 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
319
317
|
var normals = pd.getPointData().getNormals();
|
|
320
318
|
var _buffRequest = {
|
|
321
319
|
format: 'snorm8x4',
|
|
322
|
-
hash: hash,
|
|
323
320
|
cells: cells,
|
|
324
321
|
representation: representation,
|
|
325
322
|
primitiveType: primType,
|
|
@@ -329,18 +326,16 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
329
326
|
};
|
|
330
327
|
|
|
331
328
|
if (normals) {
|
|
332
|
-
_buffRequest.
|
|
329
|
+
_buffRequest.hash = "".concat(hash).concat(normals.getMTime()).concat(cells.getMTime(), "snorm8x4");
|
|
333
330
|
_buffRequest.dataArray = normals;
|
|
334
|
-
_buffRequest.time = Math.max(normals.getMTime(), cells.getMTime());
|
|
335
331
|
_buffRequest.usage = BufferUsage.PointArray;
|
|
336
332
|
|
|
337
333
|
var _buff = device.getBufferManager().getBuffer(_buffRequest);
|
|
338
334
|
|
|
339
335
|
vertexInput.addBuffer(_buff, ['normalMC']);
|
|
340
336
|
} else if (primType === PrimitiveTypes.Triangles) {
|
|
341
|
-
_buffRequest.
|
|
337
|
+
_buffRequest.hash = "".concat(hash).concat(points.getMTime()).concat(cells.getMTime(), "snorm8x4");
|
|
342
338
|
_buffRequest.dataArray = points;
|
|
343
|
-
_buffRequest.time = Math.max(points.getMTime(), cells.getMTime());
|
|
344
339
|
_buffRequest.usage = BufferUsage.NormalsFromPoints;
|
|
345
340
|
|
|
346
341
|
var _buff2 = device.getBufferManager().getBuffer(_buffRequest);
|
|
@@ -368,11 +363,9 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
368
363
|
}
|
|
369
364
|
|
|
370
365
|
var _buffRequest2 = {
|
|
371
|
-
owner: c,
|
|
372
366
|
usage: BufferUsage.PointArray,
|
|
373
367
|
format: 'unorm8x4',
|
|
374
|
-
|
|
375
|
-
hash: hash + haveCellScalars,
|
|
368
|
+
hash: "".concat(hash).concat(haveCellScalars).concat(c.getMTime()).concat(cells.getMTime(), "unorm8x4"),
|
|
376
369
|
dataArray: c,
|
|
377
370
|
cells: cells,
|
|
378
371
|
primitiveType: primType,
|
|
@@ -401,20 +394,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
401
394
|
}
|
|
402
395
|
|
|
403
396
|
if (tcoords && !edges) {
|
|
404
|
-
|
|
405
|
-
var _buffRequest3 = {
|
|
406
|
-
owner: tcoords,
|
|
407
|
-
usage: BufferUsage.PointArray,
|
|
408
|
-
format: 'float32x2',
|
|
409
|
-
time: Math.max(tcoords.getMTime(), cells.getMTime()),
|
|
410
|
-
hash: hash,
|
|
411
|
-
dataArray: tcoords,
|
|
412
|
-
cells: cells,
|
|
413
|
-
primitiveType: primType,
|
|
414
|
-
representation: representation
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
var _buff4 = device.getBufferManager().getBuffer(_buffRequest3);
|
|
397
|
+
var _buff4 = device.getBufferManager().getBufferForPointArray(tcoords, cells, primType, representation);
|
|
418
398
|
|
|
419
399
|
vertexInput.addBuffer(_buff4, ['tcoord']);
|
|
420
400
|
} else {
|
|
@@ -459,25 +439,7 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
459
439
|
|
|
460
440
|
for (var _i = 0; _i < newTextures.length; _i++) {
|
|
461
441
|
var srcTexture = newTextures[_i];
|
|
462
|
-
var
|
|
463
|
-
time: srcTexture.getMTime()
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
if (srcTexture.getInputData()) {
|
|
467
|
-
treq.imageData = srcTexture.getInputData();
|
|
468
|
-
treq.owner = treq.imageData.getPointData().getScalars();
|
|
469
|
-
} else if (srcTexture.getImage()) {
|
|
470
|
-
treq.image = srcTexture.getImage();
|
|
471
|
-
treq.owner = treq.image;
|
|
472
|
-
} else if (srcTexture.getJsImageData()) {
|
|
473
|
-
treq.jsImageData = srcTexture.getJsImageData();
|
|
474
|
-
treq.owner = treq.jsImageData;
|
|
475
|
-
} else if (srcTexture.getCanvas()) {
|
|
476
|
-
treq.canvas = srcTexture.getCanvas();
|
|
477
|
-
treq.owner = treq.canvas;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
var newTex = model.device.getTextureManager().getTexture(treq);
|
|
442
|
+
var newTex = model.device.getTextureManager().getTextureForVTKTexture(srcTexture);
|
|
481
443
|
|
|
482
444
|
if (newTex.getReady()) {
|
|
483
445
|
// is this a new texture
|
|
@@ -1,8 +1,83 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
5
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
6
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
7
|
+
import _get from '@babel/runtime/helpers/get';
|
|
8
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
9
|
+
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
1
10
|
import { newInstance as newInstance$1, obj, setGet, get } from '../../macros.js';
|
|
2
11
|
import vtkWebGPUBufferManager from './BufferManager.js';
|
|
3
12
|
import vtkWebGPUShaderCache from './ShaderCache.js';
|
|
4
13
|
import vtkWebGPUTextureManager from './TextureManager.js';
|
|
5
14
|
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
|
+
/**
|
|
19
|
+
* provide a simple WeakRefMap class to share device objects based on
|
|
20
|
+
* hash values so that buffers/textures etc can be shared betwen mappers.
|
|
21
|
+
* This is roughly based on WeakLRUCache but without the actual caching
|
|
22
|
+
* behavior. This is just a map of key -> WeakRef(value)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/* eslint-disable no-undef */
|
|
26
|
+
|
|
27
|
+
var WeakRefMap = /*#__PURE__*/function (_Map) {
|
|
28
|
+
_inherits(WeakRefMap, _Map);
|
|
29
|
+
|
|
30
|
+
var _super = _createSuper(WeakRefMap);
|
|
31
|
+
|
|
32
|
+
function WeakRefMap() {
|
|
33
|
+
var _thisSuper, _thisSuper2, _this;
|
|
34
|
+
|
|
35
|
+
_classCallCheck(this, WeakRefMap);
|
|
36
|
+
|
|
37
|
+
_this = _super.call(this);
|
|
38
|
+
_this.registry = new FinalizationRegistry(function (key) {
|
|
39
|
+
var entry = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(WeakRefMap.prototype)), "get", _thisSuper).call(_thisSuper, key);
|
|
40
|
+
|
|
41
|
+
if (entry && entry.deref && entry.deref() === undefined) _get((_thisSuper2 = _assertThisInitialized(_this), _getPrototypeOf(WeakRefMap.prototype)), "delete", _thisSuper2).call(_thisSuper2, key);
|
|
42
|
+
});
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_createClass(WeakRefMap, [{
|
|
47
|
+
key: "getValue",
|
|
48
|
+
value: function getValue(key) {
|
|
49
|
+
var entry = _get(_getPrototypeOf(WeakRefMap.prototype), "get", this).call(this, key);
|
|
50
|
+
|
|
51
|
+
if (entry) {
|
|
52
|
+
var value = entry.deref();
|
|
53
|
+
if (value !== undefined) return value;
|
|
54
|
+
|
|
55
|
+
_get(_getPrototypeOf(WeakRefMap.prototype), "delete", this).call(this, key);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "setValue",
|
|
62
|
+
value: function setValue(key, value) {
|
|
63
|
+
var entry;
|
|
64
|
+
|
|
65
|
+
if (value && _typeof(value) === 'object') {
|
|
66
|
+
entry = new WeakRef(value);
|
|
67
|
+
this.registry.register(value, key);
|
|
68
|
+
|
|
69
|
+
_get(_getPrototypeOf(WeakRefMap.prototype), "set", this).call(this, key, entry);
|
|
70
|
+
} // else entry is undefined
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return entry;
|
|
74
|
+
}
|
|
75
|
+
}]);
|
|
76
|
+
|
|
77
|
+
return WeakRefMap;
|
|
78
|
+
}( /*#__PURE__*/_wrapNativeSuper(Map));
|
|
79
|
+
/* eslint-enable no-undef */
|
|
80
|
+
// ----------------------------------------------------------------------------
|
|
6
81
|
// vtkWebGPUDevice methods
|
|
7
82
|
// ----------------------------------------------------------------------------
|
|
8
83
|
|
|
@@ -92,72 +167,34 @@ function vtkWebGPUDevice(publicAPI, model) {
|
|
|
92
167
|
}; // The Device has an object cache that can be used to cache buffers,
|
|
93
168
|
// textures and other objects that can be shared. The basic approach is to
|
|
94
169
|
// call getCachedObject with a request and a create function. The request
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// returns any entry that has a matching owner and hash. If a match isn't
|
|
99
|
-
// found then the create function is called with any extra arguments.
|
|
100
|
-
//
|
|
101
|
-
// For best memory management it is important that the owner be as close
|
|
102
|
-
// to the underlying object as possible. For example for a point data buffer
|
|
103
|
-
// you would want the actual vtkDataArray to be the owner, not the polydata
|
|
104
|
-
// or even worse the actor. As the points data array could be freed wihtout
|
|
105
|
-
// the polydata or actor being freed.
|
|
170
|
+
// is based on a hash. The cache lookup just returns any entry that has a
|
|
171
|
+
// matching hash. If a match isn't found then the create function is
|
|
172
|
+
// called with any extra arguments.
|
|
106
173
|
// is the object already cached?
|
|
107
174
|
|
|
108
175
|
|
|
109
|
-
publicAPI.hasCachedObject = function (
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
} // if a matching request already exists then return true
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (model.objectCache.has(owner)) {
|
|
116
|
-
var objects = model.objectCache.get(owner);
|
|
117
|
-
|
|
118
|
-
for (var i = 0; i < objects.length; i++) {
|
|
119
|
-
if (hash === objects[i].hash) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return false;
|
|
176
|
+
publicAPI.hasCachedObject = function (hash) {
|
|
177
|
+
return model.objectCache.getValue(hash);
|
|
126
178
|
};
|
|
127
179
|
|
|
128
|
-
publicAPI.getCachedObject = function (
|
|
129
|
-
if (!
|
|
130
|
-
vtkErrorMacro('attempt to cache an object without
|
|
180
|
+
publicAPI.getCachedObject = function (hash, creator) {
|
|
181
|
+
if (!hash) {
|
|
182
|
+
vtkErrorMacro('attempt to cache an object without a hash');
|
|
131
183
|
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (model.objectCache.has(owner)) {
|
|
136
|
-
var _objects = model.objectCache.get(owner);
|
|
137
|
-
|
|
138
|
-
for (var i = 0; i < _objects.length; i++) {
|
|
139
|
-
if (hash === _objects[i].hash) {
|
|
140
|
-
return _objects[i].object;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
} // otherwise create the object and cache it
|
|
184
|
+
}
|
|
144
185
|
|
|
186
|
+
var existingValue = model.objectCache.getValue(hash);
|
|
145
187
|
|
|
146
|
-
|
|
147
|
-
|
|
188
|
+
if (existingValue) {
|
|
189
|
+
return existingValue;
|
|
148
190
|
}
|
|
149
191
|
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
if (!model.objectCache.has(owner)) {
|
|
153
|
-
model.objectCache.set(owner, []);
|
|
192
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
193
|
+
args[_key - 2] = arguments[_key];
|
|
154
194
|
}
|
|
155
195
|
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
hash: hash,
|
|
159
|
-
object: createdObject
|
|
160
|
-
});
|
|
196
|
+
var createdObject = creator.apply(void 0, args);
|
|
197
|
+
model.objectCache.setValue(hash, createdObject);
|
|
161
198
|
return createdObject;
|
|
162
199
|
};
|
|
163
200
|
} // ----------------------------------------------------------------------------
|
|
@@ -180,9 +217,12 @@ function extend(publicAPI, model) {
|
|
|
180
217
|
|
|
181
218
|
obj(publicAPI, model);
|
|
182
219
|
setGet(publicAPI, model, ['handle']);
|
|
183
|
-
get(publicAPI, model, ['bufferManager', 'shaderCache', 'textureManager']); // this is a
|
|
220
|
+
get(publicAPI, model, ['bufferManager', 'shaderCache', 'textureManager']); // this is a weak ref cache implementation, we create it without
|
|
221
|
+
// an expirer (so it is strictly based on garbage collection and
|
|
222
|
+
// objects are not held if there are no external references)
|
|
223
|
+
// model.objectCache = new WeakLRUCache({ expirer: false });
|
|
184
224
|
|
|
185
|
-
model.objectCache = new
|
|
225
|
+
model.objectCache = new WeakRefMap();
|
|
186
226
|
model.shaderCache = vtkWebGPUShaderCache.newInstance();
|
|
187
227
|
model.shaderCache.setDevice(publicAPI);
|
|
188
228
|
model.bindGroupLayouts = [];
|
|
@@ -203,4 +243,4 @@ var vtkWebGPUDevice$1 = {
|
|
|
203
243
|
extend: extend
|
|
204
244
|
};
|
|
205
245
|
|
|
206
|
-
export { vtkWebGPUDevice$1 as default, extend, newInstance };
|
|
246
|
+
export { WeakRefMap, vtkWebGPUDevice$1 as default, extend, newInstance };
|
|
@@ -102,6 +102,8 @@ function vtkWebGPUGlyph3DMapper(publicAPI, model) {
|
|
|
102
102
|
|
|
103
103
|
publicAPI.buildPass = function (prepass) {
|
|
104
104
|
if (prepass) {
|
|
105
|
+
model.WebGPUActor = publicAPI.getFirstAncestorOfType('vtkWebGPUActor');
|
|
106
|
+
|
|
105
107
|
if (!model.renderable.getStatic()) {
|
|
106
108
|
model.renderable.update();
|
|
107
109
|
}
|
|
@@ -265,11 +265,7 @@ function vtkWebGPUImageMapper(publicAPI, model) {
|
|
|
265
265
|
|
|
266
266
|
publicAPI.updateBuffers = function () {
|
|
267
267
|
superClassUpdateBuffers();
|
|
268
|
-
var
|
|
269
|
-
imageData: model.currentInput,
|
|
270
|
-
owner: model.currentInput.getPointData().getScalars()
|
|
271
|
-
};
|
|
272
|
-
var newTex = model.device.getTextureManager().getTexture(treq);
|
|
268
|
+
var newTex = model.device.getTextureManager().getTextureForImageData(model.currentInput);
|
|
273
269
|
var tViews = model.textureViews;
|
|
274
270
|
|
|
275
271
|
if (!tViews[0] || tViews[0].getTexture() !== newTex) {
|
|
@@ -74,16 +74,15 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
74
74
|
publicAPI.setNumberOfInstances(1);
|
|
75
75
|
publicAPI.setNumberOfVertices(3 * numPoints);
|
|
76
76
|
var vertexInput = model.vertexInput;
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// xyz v1 v2 v3
|
|
77
|
+
var hash = "spm".concat(points.getMTime(), "float32x3");
|
|
78
|
+
|
|
79
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
80
|
+
var buffRequest = {
|
|
81
|
+
hash: hash,
|
|
82
|
+
usage: BufferUsage.RawVertex,
|
|
83
|
+
format: 'float32x3'
|
|
84
|
+
}; // xyz v1 v2 v3
|
|
85
|
+
|
|
87
86
|
var tmpVBO = new Float32Array(3 * numPoints * 3);
|
|
88
87
|
var pointIdx = 0;
|
|
89
88
|
var vboIdx = 0;
|
|
@@ -117,15 +116,15 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
117
116
|
var defaultRadius = model.renderable.getRadius();
|
|
118
117
|
|
|
119
118
|
if (scales || defaultRadius !== model._lastRadius) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
hash = "spm".concat(scales ? pointData.getArray(model.renderable.getScaleArray()).getMTime() : defaultRadius, "float32x2");
|
|
120
|
+
|
|
121
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
122
|
+
var _buffRequest = {
|
|
123
|
+
hash: hash,
|
|
124
|
+
usage: BufferUsage.RawVertex,
|
|
125
|
+
format: 'float32x2'
|
|
126
|
+
};
|
|
127
127
|
|
|
128
|
-
if (!model.device.getBufferManager().hasBuffer(buffRequest)) {
|
|
129
128
|
var _tmpVBO = new Float32Array(3 * numPoints * 2);
|
|
130
129
|
|
|
131
130
|
var cos30 = Math.cos(radiansFromDegrees(30.0));
|
|
@@ -146,9 +145,9 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
146
145
|
_tmpVBO[_vboIdx++] = 2.0 * radius;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
|
|
148
|
+
_buffRequest.nativeArray = _tmpVBO;
|
|
150
149
|
|
|
151
|
-
var _buff = model.device.getBufferManager().getBuffer(
|
|
150
|
+
var _buff = model.device.getBufferManager().getBuffer(_buffRequest);
|
|
152
151
|
|
|
153
152
|
vertexInput.addBuffer(_buff, ['offsetMC']);
|
|
154
153
|
}
|
|
@@ -163,15 +162,14 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
163
162
|
var c = model.renderable.getColorMapColors();
|
|
164
163
|
|
|
165
164
|
if (c) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (!model.device.getBufferManager().hasBuffer(buffRequest)) {
|
|
165
|
+
hash = "spm".concat(c.getMTime(), "unorm8x4");
|
|
166
|
+
|
|
167
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
168
|
+
var _buffRequest2 = {
|
|
169
|
+
hash: hash,
|
|
170
|
+
usage: BufferUsage.RawVertex,
|
|
171
|
+
format: 'unorm8x4'
|
|
172
|
+
};
|
|
175
173
|
var colorComponents = c.getNumberOfComponents();
|
|
176
174
|
|
|
177
175
|
if (colorComponents !== 4) {
|
|
@@ -194,9 +192,9 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
|
|
195
|
+
_buffRequest2.nativeArray = _tmpVBO2;
|
|
198
196
|
|
|
199
|
-
var _buff2 = model.device.getBufferManager().getBuffer(
|
|
197
|
+
var _buff2 = model.device.getBufferManager().getBuffer(_buffRequest2);
|
|
200
198
|
|
|
201
199
|
vertexInput.addBuffer(_buff2, ['colorVI']);
|
|
202
200
|
}
|
|
@@ -59,7 +59,7 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
59
59
|
vDesc.addBuiltinInput('u32', '@builtin(vertex_index) vertexIndex');
|
|
60
60
|
var fDesc = pipeline.getShaderDescription('fragment');
|
|
61
61
|
fDesc.addBuiltinOutput('f32', '@builtin(frag_depth) fragDepth');
|
|
62
|
-
var stickFrag = "\n // compute the eye position and unit direction\n var vertexVC: vec4<f32>;\n var EyePos: vec3<f32>;\n var EyeDir: vec3<f32>;\n\n if (rendererUBO.cameraParallel != 0u)\n {\n EyePos = vec3<f32>(input.vertexVC.x, input.vertexVC.y, input.vertexVC.z + 3.0*input.radiusVC);\n EyeDir = vec3<f32>(0.0, 0.0, -1.0);\n }\n else\n {\n EyeDir = input.vertexVC.xyz;\n EyePos = vec3<f32>(0.0,0.0,0.0);\n var lengthED: f32 = length(EyeDir);\n EyeDir = normalize(EyeDir);\n // we adjust the EyePos to be closer if it is too far away\n // to prevent floating point precision noise\n if (lengthED > input.radiusVC*3.0)\n {\n EyePos = input.vertexVC.xyz - EyeDir*3.0*input.radiusVC;\n }\n }\n // translate to Sphere center\n EyePos = EyePos - input.centerVC;\n\n // rotate to new basis\n // base1, base2, orientVC\n var base1: vec3<f32>;\n if (abs(input.orientVC.z) < 0.99)\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,0.0,1.0)));\n }\n else\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,1.0,0.0)));\n }\n var base2: vec3<f32> = cross(input.orientVC,base1);\n EyePos = vec3<f32>(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,input.orientVC));\n EyeDir = vec3<f32>(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,input.orientVC));\n\n // scale to radius 1.0\n EyePos = EyePos * (1.0 / input.radiusVC);\n\n // find the intersection\n var a: f32 = EyeDir.x*EyeDir.x + EyeDir.y*EyeDir.y;\n var b: f32 = 2.0*(EyePos.x*EyeDir.x + EyePos.y*EyeDir.y);\n var c: f32 = EyePos.x*EyePos.x + EyePos.y*EyePos.y - 1.0;\n var d: f32 = b*b - 4.0*a*c;\n var normal: vec3<f32> = vec3<f32>(0.0,0.0,1.0);\n if (d < 0.0) { discard; }\n else\n {\n var t: f32 = (-b - sqrt(d))*(0.5 / a);\n var tz: f32 = EyePos.z + t*EyeDir.z;\n var iPoint: vec3<f32> = EyePos + t*EyeDir;\n if (abs(iPoint.z)*input.radiusVC > input.lengthVC*0.5)\n {\n // test for end cap\n var t2: f32 = (-b + sqrt(d))*(0.5 / a);\n var tz2: f32 = EyePos.z + t2*EyeDir.z;\n if (tz2*input.radiusVC > input.lengthVC*0.5 || tz*input.radiusVC < -0.5*input.lengthVC) { discard; }\n else\n {\n normal = input.orientVC;\n var t3: f32 = (input.lengthVC*0.5/input.radiusVC - EyePos.z)/EyeDir.z;\n iPoint = EyePos + t3*EyeDir;\n vertexVC = vec4<f32>(input.radiusVC*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n else\n {\n // The normal is the iPoint.xy rotated back into VC\n normal = iPoint.x*base1 + iPoint.y*base2;\n // rescale rerotate and translate\n vertexVC = vec4<f32>(input.radiusVC*(normal + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n
|
|
62
|
+
var stickFrag = "\n // compute the eye position and unit direction\n var vertexVC: vec4<f32>;\n var EyePos: vec3<f32>;\n var EyeDir: vec3<f32>;\n\n if (rendererUBO.cameraParallel != 0u)\n {\n EyePos = vec3<f32>(input.vertexVC.x, input.vertexVC.y, input.vertexVC.z + 3.0*input.radiusVC);\n EyeDir = vec3<f32>(0.0, 0.0, -1.0);\n }\n else\n {\n EyeDir = input.vertexVC.xyz;\n EyePos = vec3<f32>(0.0,0.0,0.0);\n var lengthED: f32 = length(EyeDir);\n EyeDir = normalize(EyeDir);\n // we adjust the EyePos to be closer if it is too far away\n // to prevent floating point precision noise\n if (lengthED > input.radiusVC*3.0)\n {\n EyePos = input.vertexVC.xyz - EyeDir*3.0*input.radiusVC;\n }\n }\n // translate to Sphere center\n EyePos = EyePos - input.centerVC;\n\n // rotate to new basis\n // base1, base2, orientVC\n var base1: vec3<f32>;\n if (abs(input.orientVC.z) < 0.99)\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,0.0,1.0)));\n }\n else\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,1.0,0.0)));\n }\n var base2: vec3<f32> = cross(input.orientVC,base1);\n EyePos = vec3<f32>(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,input.orientVC));\n EyeDir = vec3<f32>(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,input.orientVC));\n\n // scale to radius 1.0\n EyePos = EyePos * (1.0 / input.radiusVC);\n\n // find the intersection\n var a: f32 = EyeDir.x*EyeDir.x + EyeDir.y*EyeDir.y;\n var b: f32 = 2.0*(EyePos.x*EyeDir.x + EyePos.y*EyeDir.y);\n var c: f32 = EyePos.x*EyePos.x + EyePos.y*EyePos.y - 1.0;\n var d: f32 = b*b - 4.0*a*c;\n var normal: vec3<f32> = vec3<f32>(0.0,0.0,1.0);\n if (d < 0.0) { discard; }\n else\n {\n var t: f32 = (-b - sqrt(d))*(0.5 / a);\n var tz: f32 = EyePos.z + t*EyeDir.z;\n var iPoint: vec3<f32> = EyePos + t*EyeDir;\n if (abs(iPoint.z)*input.radiusVC > input.lengthVC*0.5)\n {\n // test for end cap\n var t2: f32 = (-b + sqrt(d))*(0.5 / a);\n var tz2: f32 = EyePos.z + t2*EyeDir.z;\n if (tz2*input.radiusVC > input.lengthVC*0.5 || tz*input.radiusVC < -0.5*input.lengthVC) { discard; }\n else\n {\n normal = input.orientVC;\n var t3: f32 = (input.lengthVC*0.5/input.radiusVC - EyePos.z)/EyeDir.z;\n iPoint = EyePos + t3*EyeDir;\n vertexVC = vec4<f32>(input.radiusVC*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n else\n {\n // The normal is the iPoint.xy rotated back into VC\n normal = iPoint.x*base1 + iPoint.y*base2;\n // rescale rerotate and translate\n vertexVC = vec4<f32>(input.radiusVC*(normal + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n // compute the pixel's depth\n var pos: vec4<f32> = rendererUBO.VCPCMatrix * vertexVC;\n output.fragDepth = pos.z / pos.w;\n ";
|
|
63
63
|
var code = fDesc.getCode();
|
|
64
64
|
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [stickFrag]).result;
|
|
65
65
|
fDesc.setCode(code);
|
|
@@ -97,16 +97,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
97
97
|
publicAPI.setNumberOfInstances(numPoints);
|
|
98
98
|
publicAPI.setNumberOfVertices(12);
|
|
99
99
|
var vertexInput = model.vertexInput;
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// xyz v1 v2 v3
|
|
100
|
+
var hash = "stm".concat(points.getMTime(), "float32x3");
|
|
101
|
+
|
|
102
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
103
|
+
var buffRequest = {
|
|
104
|
+
hash: hash,
|
|
105
|
+
usage: BufferUsage.RawVertex,
|
|
106
|
+
format: 'float32x3'
|
|
107
|
+
}; // xyz v1 v2 v3
|
|
108
|
+
|
|
110
109
|
var tmpVBO = new Float32Array(numPoints * 3);
|
|
111
110
|
var pointIdx = 0;
|
|
112
111
|
var vboIdx = 0;
|
|
@@ -133,15 +132,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
133
132
|
var defaultRadius = model.renderable.getRadius();
|
|
134
133
|
|
|
135
134
|
if (scales || defaultRadius !== model._lastRadius) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
hash = "stm".concat(scales ? pointData.getArray(model.renderable.getScaleArray()).getMTime() : defaultRadius, "float32");
|
|
136
|
+
|
|
137
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
138
|
+
var _buffRequest = {
|
|
139
|
+
hash: hash,
|
|
140
|
+
usage: BufferUsage.RawVertex,
|
|
141
|
+
format: 'float32'
|
|
142
|
+
};
|
|
143
143
|
|
|
144
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
145
144
|
var _tmpVBO = new Float32Array(numPoints);
|
|
146
145
|
|
|
147
146
|
var _vboIdx = 0;
|
|
@@ -156,9 +155,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
156
155
|
_tmpVBO[_vboIdx++] = radius;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
_buffRequest.nativeArray = _tmpVBO;
|
|
160
159
|
|
|
161
|
-
var _buff = device.getBufferManager().getBuffer(
|
|
160
|
+
var _buff = device.getBufferManager().getBuffer(_buffRequest);
|
|
162
161
|
|
|
163
162
|
vertexInput.addBuffer(_buff, ['radiusMC'], 'instance');
|
|
164
163
|
}
|
|
@@ -174,16 +173,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
174
173
|
vtkErrorMacro(['Error setting orientationArray.\n', 'You have to specify the stick orientation']);
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
hash = "stm".concat(pointData.getArray(model.renderable.getOrientationArray()).getMTime(), "float32x3");
|
|
177
|
+
|
|
178
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
179
|
+
var _buffRequest2 = {
|
|
180
|
+
hash: hash,
|
|
181
|
+
usage: BufferUsage.RawVertex,
|
|
182
|
+
format: 'float32x3'
|
|
183
|
+
}; // xyz v1 v2 v3
|
|
184
184
|
|
|
185
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
186
|
-
// xyz v1 v2 v3
|
|
187
185
|
var _tmpVBO2 = new Float32Array(numPoints * 3);
|
|
188
186
|
|
|
189
187
|
var _pointIdx = 0;
|
|
@@ -202,9 +200,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
202
200
|
_tmpVBO2[_vboIdx2++] = orientationArray[_pointIdx + 2] * length;
|
|
203
201
|
}
|
|
204
202
|
|
|
205
|
-
|
|
203
|
+
_buffRequest2.nativeArray = _tmpVBO2;
|
|
206
204
|
|
|
207
|
-
var _buff2 = device.getBufferManager().getBuffer(
|
|
205
|
+
var _buff2 = device.getBufferManager().getBuffer(_buffRequest2);
|
|
208
206
|
|
|
209
207
|
vertexInput.addBuffer(_buff2, ['orientMC'], 'instance');
|
|
210
208
|
} // deal with colors but only if modified
|
|
@@ -216,15 +214,13 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
216
214
|
var c = model.renderable.getColorMapColors();
|
|
217
215
|
|
|
218
216
|
if (c) {
|
|
219
|
-
|
|
220
|
-
owner: c,
|
|
221
|
-
hash: 'stm',
|
|
222
|
-
time: c.getMTime(),
|
|
223
|
-
usage: BufferUsage.RawVertex,
|
|
224
|
-
format: 'unorm8x4'
|
|
225
|
-
};
|
|
217
|
+
hash = "stm".concat(c.getMTime(), "unorm8x4");
|
|
226
218
|
|
|
227
|
-
if (!device.getBufferManager().hasBuffer(
|
|
219
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
220
|
+
var _buffRequest3 = {
|
|
221
|
+
usage: BufferUsage.RawVertex,
|
|
222
|
+
format: 'unorm8x4'
|
|
223
|
+
};
|
|
228
224
|
var colorComponents = c.getNumberOfComponents();
|
|
229
225
|
|
|
230
226
|
if (colorComponents !== 4) {
|
|
@@ -244,9 +240,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
244
240
|
_tmpVBO3[_vboIdx3++] = colorData[colorIdx + 3];
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
|
|
243
|
+
_buffRequest3.nativeArray = _tmpVBO3;
|
|
248
244
|
|
|
249
|
-
var _buff3 = device.getBufferManager().getBuffer(
|
|
245
|
+
var _buff3 = device.getBufferManager().getBuffer(_buffRequest3);
|
|
250
246
|
|
|
251
247
|
vertexInput.addBuffer(_buff3, ['colorVI'], 'instance');
|
|
252
248
|
}
|
|
@@ -95,7 +95,6 @@ function vtkWebGPUTexture(publicAPI, model) {
|
|
|
95
95
|
|
|
96
96
|
if (req.dataArray) {
|
|
97
97
|
buffRequest.dataArray = req.dataArray;
|
|
98
|
-
buffRequest.time = req.dataArray.getMTime();
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
buffRequest.nativeArray = req.nativeArray; // bytesPerRow must be a multiple of 256 so we might need to rebuild
|
|
@@ -144,7 +143,6 @@ function vtkWebGPUTexture(publicAPI, model) {
|
|
|
144
143
|
|
|
145
144
|
var _buffRequest = {
|
|
146
145
|
nativeArray: imageData.data,
|
|
147
|
-
time: 0,
|
|
148
146
|
|
|
149
147
|
/* eslint-disable no-undef */
|
|
150
148
|
usage: BufferUsage.Texture,
|
|
@@ -119,17 +119,47 @@ function vtkWebGPUTextureManager(publicAPI, model) {
|
|
|
119
119
|
|
|
120
120
|
publicAPI.getTexture = function (req) {
|
|
121
121
|
// if we have a source the get/create/cache the texture
|
|
122
|
-
if (req.
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var hash = req.time + req.format;
|
|
128
|
-
return model.device.getCachedObject(req.owner, hash, _createTexture, req);
|
|
122
|
+
if (req.hash) {
|
|
123
|
+
// if a matching texture already exists then return it
|
|
124
|
+
return model.device.getCachedObject(req.hash, _createTexture, req);
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
return _createTexture(req);
|
|
132
128
|
};
|
|
129
|
+
|
|
130
|
+
publicAPI.getTextureForImageData = function (imgData) {
|
|
131
|
+
var treq = {
|
|
132
|
+
time: imgData.getMTime()
|
|
133
|
+
};
|
|
134
|
+
treq.imageData = imgData; // fill out the req time and format based on imageData/image
|
|
135
|
+
|
|
136
|
+
_fillRequest(treq);
|
|
137
|
+
|
|
138
|
+
treq.hash = treq.time + treq.format;
|
|
139
|
+
return model.device.getTextureManager().getTexture(treq);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
publicAPI.getTextureForVTKTexture = function (srcTexture) {
|
|
143
|
+
var treq = {
|
|
144
|
+
time: srcTexture.getMTime()
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (srcTexture.getInputData()) {
|
|
148
|
+
treq.imageData = srcTexture.getInputData();
|
|
149
|
+
} else if (srcTexture.getImage()) {
|
|
150
|
+
treq.image = srcTexture.getImage();
|
|
151
|
+
} else if (srcTexture.getJsImageData()) {
|
|
152
|
+
treq.jsImageData = srcTexture.getJsImageData();
|
|
153
|
+
} else if (srcTexture.getCanvas()) {
|
|
154
|
+
treq.canvas = srcTexture.getCanvas();
|
|
155
|
+
} // fill out the req time and format based on imageData/image
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
_fillRequest(treq);
|
|
159
|
+
|
|
160
|
+
treq.hash = treq.time + treq.format;
|
|
161
|
+
return model.device.getTextureManager().getTexture(treq);
|
|
162
|
+
};
|
|
133
163
|
} // ----------------------------------------------------------------------------
|
|
134
164
|
// Object factory
|
|
135
165
|
// ----------------------------------------------------------------------------
|
|
@@ -260,11 +260,9 @@ function vtkWebGPUVolumePass(publicAPI, model) {
|
|
|
260
260
|
|
|
261
261
|
var points = pd.getPoints();
|
|
262
262
|
var buffRequest = {
|
|
263
|
-
owner: points,
|
|
264
263
|
usage: BufferUsage.PointArray,
|
|
265
264
|
format: 'float32x4',
|
|
266
|
-
|
|
267
|
-
hash: 'vp',
|
|
265
|
+
hash: "vp".concat(points.getMTime()).concat(cells.getMTime()),
|
|
268
266
|
dataArray: points,
|
|
269
267
|
cells: cells,
|
|
270
268
|
primitiveType: PrimitiveTypes.Triangles,
|
|
@@ -455,11 +455,7 @@ function vtkWebGPUVolumePassFSQ(publicAPI, model) {
|
|
|
455
455
|
|
|
456
456
|
var image = _volMapr4.getInputData();
|
|
457
457
|
|
|
458
|
-
var
|
|
459
|
-
imageData: image,
|
|
460
|
-
owner: image.getPointData().getScalars()
|
|
461
|
-
};
|
|
462
|
-
var newTex = model.device.getTextureManager().getTexture(treq);
|
|
458
|
+
var newTex = model.device.getTextureManager().getTextureForImageData(image);
|
|
463
459
|
|
|
464
460
|
if (!model.textureViews[vidx + 4] || model.textureViews[vidx + 4].getTexture() !== newTex) {
|
|
465
461
|
var tview = newTex.createView("volTexture".concat(vidx));
|