Skip to content

Commit

Permalink
fix tesselator when using external luma.gl buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Jan 8, 2020
1 parent ae7ff99 commit ad810b9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
3 changes: 1 addition & 2 deletions modules/layers/src/solid-polygon-layer/polygon-tesselator.js
Expand Up @@ -66,9 +66,8 @@ export default class PolygonTesselator extends Tesselator {
}

getGeometryFromBuffer(buffer) {
const getGeometry = super.getGeometryFromBuffer(buffer);
if (this.normalize || !this.buffers.indices) {
return getGeometry;
return super.getGeometryFromBuffer(buffer);
}
// we don't need to read the positions if no normalization/tesselation
return () => null;
Expand Down
59 changes: 59 additions & 0 deletions test/modules/layers/polygon-tesselation.spec.js
Expand Up @@ -23,6 +23,9 @@ import test from 'tape-catch';
import * as Polygon from '@deck.gl/layers/solid-polygon-layer/polygon';
import PolygonTesselator from '@deck.gl/layers/solid-polygon-layer/polygon-tesselator';

import {Buffer} from '@luma.gl/core';
import {gl} from '@deck.gl/test-utils';

const SAMPLE_DATA = [
{polygon: [], name: 'empty array'},
{polygon: [[1, 1]], name: 'too few points', height: 1, color: [255, 0, 0]},
Expand Down Expand Up @@ -340,3 +343,59 @@ test('PolygonTesselator#geometryBuffer', t => {

t.end();
});

test('PolygonTesselator#geometryBuffer#buffer', t => {
const buffer = new Buffer(gl, {
data: new Float32Array([1, 1, 2, 2, 3, 3, 0, 0, 2, 0, 2, 2, 0, 2, 0, 0])
});
const sampleData = {
length: 2,
startIndices: [0, 3],
attributes: {
getPolygon: {buffer, size: 2}
}
};
t.throws(
() =>
new PolygonTesselator({
data: sampleData,
buffers: sampleData.attributes,
geometryBuffer: sampleData.attributes.getPolygon,
positionFormat: 'XY'
}),
'throws on invalid options'
);

t.throws(
() =>
new PolygonTesselator({
data: sampleData,
buffers: sampleData.attributes,
geometryBuffer: sampleData.attributes.getPolygon,
normalize: false,
positionFormat: 'XY'
}),
'throws on invalid options'
);

sampleData.attributes.indices = new Uint16Array([0, 1, 2, 3, 4, 5]);

const tesselator = new PolygonTesselator({
data: sampleData,
buffers: sampleData.attributes,
geometryBuffer: sampleData.attributes.getPolygon,
normalize: false,
positionFormat: 'XY'
});

t.is(tesselator.instanceCount, 8, 'Updated instanceCount from geometryBuffer');
t.notOk(tesselator.get('positions'), 'skipped packing positions');
t.notOk(tesselator.get('indices'), 'skipped packing indices');
t.deepEquals(
tesselator.get('vertexValid').slice(0, 8),
[1, 1, 0, 1, 1, 1, 1, 0],
'vertexValid are populated'
);

t.end();
});

0 comments on commit ad810b9

Please sign in to comment.