forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifferent-texture-cloning.js
More file actions
78 lines (67 loc) · 2.49 KB
/
different-texture-cloning.js
File metadata and controls
78 lines (67 loc) · 2.49 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
const { assert, test, module: describe, only, skip } = require('qunit');
const { GPU } = require('../../src');
describe('internal: different texture cloning');
function testArrayThenArray1D4(mode) {
const gpu = new GPU({ mode });
function createTextureOf(value, type) {
return (gpu.createKernel(function(value) {
return value[this.thread.x];
}, {
output: [1],
pipeline: true,
argumentTypes: { value: type }
}))(value);
}
const arrayTexture = createTextureOf([1], 'Array');
const arrayTextureClone = arrayTexture.clone();
const array4Texture = createTextureOf([[1,2,3,4]], 'Array1D(4)');
const array4TextureClone = array4Texture.clone();
assert.notEqual(arrayTextureClone, array4TextureClone);
assert.deepEqual(arrayTextureClone.toArray(), new Float32Array([1]));
assert.deepEqual(array4TextureClone.toArray(), [new Float32Array([1,2,3,4])]);
gpu.destroy();
}
test('Array then Array1D(4) auto', () => {
testArrayThenArray1D4();
});
(GPU.isWebGLSupported ? test : skip)('Array then Array1D(4) webgl', () => {
testArrayThenArray1D4('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('Array then Array1D(4) webgl2', () => {
testArrayThenArray1D4('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('Array then Array1D(4) headlessgl', () => {
testArrayThenArray1D4('headlessgl');
});
function testArray1D4ThenArray(mode) {
const gpu = new GPU({ mode });
function createTextureOf(value, type) {
return (gpu.createKernel(function(value) {
return value[this.thread.x];
}, {
output: [1],
pipeline: true,
argumentTypes: { value: type }
}))(value);
}
const array4Texture = createTextureOf([[1,2,3,4]], 'Array1D(4)');
const array4TextureClone = array4Texture.clone();
const arrayTexture = createTextureOf([1], 'Array');
const arrayTextureClone = arrayTexture.clone();
assert.notEqual(array4TextureClone, arrayTextureClone);
assert.deepEqual(array4TextureClone.toArray(), [new Float32Array([1,2,3,4])]);
assert.deepEqual(arrayTextureClone.toArray(), new Float32Array([1]));
gpu.destroy();
}
test('Array1D(4) then Array auto', () => {
testArray1D4ThenArray();
});
(GPU.isWebGLSupported ? test : skip)('Array1D(4) then Array webgl', () => {
testArray1D4ThenArray('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('Array1D(4) then Array webgl2', () => {
testArray1D4ThenArray('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('Array1D(4) then Array headlessgl', () => {
testArray1D4ThenArray('headlessgl');
});