Skip to content

Commit

Permalink
Shader attribute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Apr 25, 2019
1 parent 2f40726 commit 8ba9051
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 0 additions & 1 deletion modules/core/src/lib/attribute-manager.js
Expand Up @@ -212,7 +212,6 @@ export default class AttributeManager {
}

// Ensure all attribute buffers are updated from props or data.
/* eslint-disable complexity */
update({data, numInstances, transitions, props = {}, buffers = {}, context = {}} = {}) {
// keep track of whether some attributes are updated
let updated = false;
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/lib/base-attribute.js
Expand Up @@ -61,8 +61,12 @@ export default class BaseAttribute {

const size = this.size || opts.size || 0;
if (constant && value.length !== size) {
// NOTE(Tarek): Assuming float constants.
// This is all we currently use, but we'll
// have to update this if we start using int
// attributes (WebGL 2-only)
this.value = new Float32Array(size);
const index = this.offset / 4;
const index = this.offset / 4; // Always 4 bytes/element (float, int or uint)
for (let i = 0; i < this.size; ++i) {
this.value[i] = value[index + i];
}
Expand Down
35 changes: 35 additions & 0 deletions test/modules/core/lib/attribute.spec.js
Expand Up @@ -69,6 +69,41 @@ test('Attribute#getUpdateTriggers', t => {
t.end();
});

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

const attribute = new Attribute(gl, {
id: 'positions',
update,
size: 3,
shaderAttributes: {
positions: {},
instancePositions: {
divisor: 1
}
}
});
t.ok(attribute.shaderAttributes.positions, 'Shader attribute created');
t.equals(
attribute.shaderAttributes.positions.size,
3,
'Shader attribute inherits pointer properties'
);
t.ok(attribute.shaderAttributes.instancePositions, 'Multiple shader attributes created');
t.equals(
attribute.shaderAttributes.instancePositions.size,
3,
'Multiple shader attributes inherit pointer properties'
);
t.equals(
attribute.shaderAttributes.instancePositions.divisor,
1,
'Shader attribute defines pointer properties'
);

t.end();
});

// t.ok(attribute.allocate(attributeName, allocCount), 'Attribute.allocate function available');
// t.ok(attribute._setExternalBuffer(attributeName, buffer, numInstances), 'Attribute._setExternalBuffer function available');
// t.ok(attribute._analyzeBuffer(attributeName, numInstances), 'Attribute._analyzeBuffer function available');
Expand Down

0 comments on commit 8ba9051

Please sign in to comment.