Skip to content

Commit

Permalink
Fix Default Values in AttributeManager add method (visgl#6130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold authored Aug 25, 2021
1 parent 437fc79 commit fca8f27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/core/src/lib/attribute/attribute-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,18 @@ export default class AttributeManager {
/* eslint-enable max-statements */

_createAttribute(name, attribute, extraProps) {
// For expected default values see:
// https://github.com/visgl/luma.gl/blob/1affe21352e289eeaccee2a876865138858a765c/modules/webgl/src/classes/accessor.js#L5-L13
// and https://deck.gl/docs/api-reference/core/attribute-manager#add
const props = {
...attribute,
id: name,
isIndexed: attribute.isIndexed || attribute.elements || false,
// Luma fields
constant: attribute.constant || false,
isIndexed: attribute.isIndexed || attribute.elements,
size: (attribute.elements && 1) || attribute.size,
size: (attribute.elements && 1) || attribute.size || 1,
value: attribute.value || null,
divisor: attribute.instanced || extraProps.instanced ? 1 : attribute.divisor
divisor: attribute.instanced || extraProps.instanced ? 1 : attribute.divisor || 0
};

return new Attribute(this.gl, props);
Expand Down
10 changes: 10 additions & 0 deletions test/modules/core/lib/attribute/attribute-manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ test('AttributeManager.add', t => {
{positions: ['positions'], getPosition: ['positions']},
'AttributeManager.add - build update triggers mapping'
);
t.equals(
attributeManager.getAttributes()['positions'].settings.divisor,
0,
'AttributeManager.add creates attribute with default divisor of 0'
);
t.equals(
attributeManager.getAttributes()['positions'].settings.isIndexed,
false,
'AttributeManager.add creates attribute with default isIndexed of false'
);
t.end();
});

Expand Down

0 comments on commit fca8f27

Please sign in to comment.