Skip to content

Commit

Permalink
Merge e58fff1 into e031eab
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Nov 7, 2019
2 parents e031eab + e58fff1 commit d76e9eb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
7 changes: 6 additions & 1 deletion modules/core/src/lib/attribute.js
Expand Up @@ -260,7 +260,12 @@ export default class Attribute extends BaseAttribute {
// Upload the full existing attribute value to the GPU, so that updateBuffer
// can choose to only update a partial range.
// TODO - copy old buffer to new buffer on the GPU
this.buffer.subData(oldValue);
this.buffer.subData({
data:
oldValue instanceof Float64Array
? toDoublePrecisionArray(oldValue, {size: this.size})
: oldValue
});
}
}

Expand Down
70 changes: 69 additions & 1 deletion test/modules/core/lib/attribute.spec.js
Expand Up @@ -21,7 +21,7 @@
/* eslint-disable dot-notation, max-statements, no-unused-vars */
import Attribute from '@deck.gl/core/lib/attribute';
import GL from '@luma.gl/constants';
import {Buffer} from '@luma.gl/core';
import {Buffer, isWebGL2} from '@luma.gl/core';
import test from 'tape-catch';
import {gl} from '@deck.gl/test-utils';
import {makeSpy} from '@probe.gl/test-utils';
Expand Down Expand Up @@ -131,6 +131,74 @@ test('Attribute#allocate', t => {
t.end();
});

test('Attribute#allocate - partial', t => {
if (!isWebGL2(gl)) {
// buffer.getData() is WebGL2 only
t.comment('This test requires WebGL2');
t.end();
return;
}

let positions = new Attribute(gl, {
id: 'positions',
update: attr => {
attr.value[0] = 180;
attr.value[1] = 90;
},
size: 2
});

positions.allocate(1);
let value = positions.value;
value[0] = 180;
value[1] = 90;
// make sure buffer is created
positions.updateBuffer({});
t.deepEqual(positions.buffer.getData().slice(0, 2), [180, 90], 'value uploaded to buffer');

positions.setNeedsUpdate('test', {startRow: 1, endRow: 2});
positions.allocate(value.length / 2 + 1); // array might be overallocated
t.notEqual(positions.value, value, 'a new value array is allocated');
t.deepEqual(positions.value.slice(0, 2), [180, 90], 'old value is copied to new array');
t.deepEqual(positions.buffer.getData().slice(0, 2), [180, 90], 'old value is copied to buffer');

positions.delete();

// double precision
positions = new Attribute(gl, {
id: 'positions64',
type: GL.DOUBLE,
update: attr => {
attr.value[0] = 179.9;
attr.value[1] = 89.9;
},
size: 2
});

positions.allocate(1);
value = positions.value;
// make sure buffer is created
positions.updateBuffer({});
t.deepEqual(
positions.buffer.getData().slice(0, 4),
[179.89999389648438, 89.9000015258789, 0.00000610351571594947, -0.0000015258789289873675],
'value uploaded to buffer'
);

positions.setNeedsUpdate('test', {startRow: 1, endRow: 2});
positions.allocate(value.length / 2 + 1); // array might be overallocated
t.notEqual(positions.value, value, 'a new value array is allocated');
t.deepEqual(positions.value.slice(0, 2), [179.9, 89.9], 'old value is copied to new array');
t.deepEqual(
positions.buffer.getData().slice(0, 4),
[179.89999389648438, 89.9000015258789, 0.00000610351571594947, -0.0000015258789289873675],
'old value is copied to buffer'
);

positions.delete();
t.end();
});

test('Attribute#shaderAttributes', t => {
const update = () => {};

Expand Down

0 comments on commit d76e9eb

Please sign in to comment.