Webgl / add utils for pushing geojson geometries in webgl buffers

For now only point geometries are handled.
This commit is contained in:
Olivier Guyot
2019-05-14 12:37:21 +02:00
parent 5e36468245
commit 3a429d3f6c
2 changed files with 154 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
import VectorLayer from '../../../../../src/ol/layer/Vector.js';
import VectorSource from '../../../../../src/ol/source/Vector.js';
import WebGLLayerRenderer, {getBlankTexture} from '../../../../../src/ol/renderer/webgl/Layer';
import WebGLLayerRenderer, {getBlankTexture, pushFeatureInBuffer} from '../../../../../src/ol/renderer/webgl/Layer';
import WebGLArrayBuffer from '../../../../../src/ol/webgl/Buffer';
import Layer from '../../../../../src/ol/layer/Layer';
describe('ol.renderer.webgl.Layer', function() {
@@ -21,15 +21,94 @@ describe('ol.renderer.webgl.Layer', function() {
});
it('creates a new instance', function () {
const layer = new VectorLayer({
source: new VectorSource()
});
const layer = new Layer({});
const renderer = new WebGLLayerRenderer(layer);
expect(renderer).to.be.a(WebGLLayerRenderer);
});
});
describe('pushFeatureInBuffer', function() {
let vertexBuffer, indexBuffer;
beforeEach(function () {
vertexBuffer = new WebGLArrayBuffer();
indexBuffer = new WebGLArrayBuffer();
});
it('does nothing if the feature has no geometry', function() {
const feature = {
type: "Feature",
id: "AFG",
properties: {
color:[0.5, 1, 0.2, 0.7],
size: 3
},
geometry: null
};
pushFeatureInBuffer(vertexBuffer, indexBuffer, feature);
expect(vertexBuffer.getArray().length).to.eql(0);
expect(indexBuffer.getArray().length).to.eql(0);
});
it('adds two triangles with the correct attributes for a point geometry', function() {
const feature = {
type: "Feature",
id: "AFG",
properties: {
color:[0.5, 1, 0.2, 0.7],
size: 3
},
geometry: {
type: "Point",
coordinates: [ -75, 47 ]
}
};
const attributePerVertex = 12;
pushFeatureInBuffer(vertexBuffer, indexBuffer, feature);
expect(vertexBuffer.getArray().length).to.eql(attributePerVertex * 4);
expect(indexBuffer.getArray().length).to.eql(6);
});
it('correctly sets indices & coordinates for several features', function() {
const feature = {
type: "Feature",
id: "AFG",
properties: {
color:[0.5, 1, 0.2, 0.7],
size: 3
},
geometry: {
type: "Point",
coordinates: [ -75, 47 ]
}
};
const attributePerVertex = 12;
pushFeatureInBuffer(vertexBuffer, indexBuffer, feature);
pushFeatureInBuffer(vertexBuffer, indexBuffer, feature);
expect(vertexBuffer.getArray()[0]).to.eql(-75);
expect(vertexBuffer.getArray()[1]).to.eql(47);
expect(vertexBuffer.getArray()[0 + attributePerVertex]).to.eql(-75);
expect(vertexBuffer.getArray()[1 + attributePerVertex]).to.eql(47);
// first point
expect(indexBuffer.getArray()[0]).to.eql(0);
expect(indexBuffer.getArray()[1]).to.eql(1);
expect(indexBuffer.getArray()[2]).to.eql(3);
expect(indexBuffer.getArray()[3]).to.eql(1);
expect(indexBuffer.getArray()[4]).to.eql(2);
expect(indexBuffer.getArray()[5]).to.eql(3);
// second point
expect(indexBuffer.getArray()[6]).to.eql(4);
expect(indexBuffer.getArray()[7]).to.eql(5);
expect(indexBuffer.getArray()[8]).to.eql(7);
expect(indexBuffer.getArray()[9]).to.eql(5);
expect(indexBuffer.getArray()[10]).to.eql(6);
expect(indexBuffer.getArray()[11]).to.eql(7);
});
});
describe('getBlankTexture', function() {
it('creates a 1x1 white texture', function() {
const texture = getBlankTexture();