Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
import WebGLArrayBuffer, {getArrayClassForType} from '../../../../src/ol/webgl/Buffer.js';
|
||||
import WebGLArrayBuffer, {
|
||||
getArrayClassForType,
|
||||
} from '../../../../src/ol/webgl/Buffer.js';
|
||||
import {
|
||||
ARRAY_BUFFER,
|
||||
ELEMENT_ARRAY_BUFFER,
|
||||
STATIC_DRAW,
|
||||
STREAM_DRAW
|
||||
STREAM_DRAW,
|
||||
} from '../../../../src/ol/webgl.js';
|
||||
|
||||
|
||||
describe('ol.webgl.Buffer', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('sets the default usage when not specified', function() {
|
||||
describe('ol.webgl.Buffer', function () {
|
||||
describe('constructor', function () {
|
||||
it('sets the default usage when not specified', function () {
|
||||
const b = new WebGLArrayBuffer(ARRAY_BUFFER);
|
||||
expect(b.getUsage()).to.be(STATIC_DRAW);
|
||||
});
|
||||
|
||||
it('sets the given usage when specified', function() {
|
||||
it('sets the given usage when specified', function () {
|
||||
const b = new WebGLArrayBuffer(ARRAY_BUFFER, STREAM_DRAW);
|
||||
expect(b.getUsage()).to.be(STREAM_DRAW);
|
||||
});
|
||||
|
||||
it('raises an error if an incorrect type is used', function(done) {
|
||||
it('raises an error if an incorrect type is used', function (done) {
|
||||
try {
|
||||
new WebGLArrayBuffer(1234);
|
||||
} catch (e) {
|
||||
@@ -31,28 +30,27 @@ describe('ol.webgl.Buffer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getArrayClassForType', function() {
|
||||
it('returns the correct typed array constructor', function() {
|
||||
describe('#getArrayClassForType', function () {
|
||||
it('returns the correct typed array constructor', function () {
|
||||
expect(getArrayClassForType(ARRAY_BUFFER)).to.be(Float32Array);
|
||||
expect(getArrayClassForType(ELEMENT_ARRAY_BUFFER)).to.be(Uint32Array);
|
||||
});
|
||||
});
|
||||
|
||||
describe('populate methods', function() {
|
||||
|
||||
describe('populate methods', function () {
|
||||
let b;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
b = new WebGLArrayBuffer(ARRAY_BUFFER);
|
||||
});
|
||||
|
||||
it('initializes the array using a size', function() {
|
||||
it('initializes the array using a size', function () {
|
||||
b.ofSize(12);
|
||||
expect(b.getArray().length).to.be(12);
|
||||
expect(b.getArray()[0]).to.be(0);
|
||||
expect(b.getArray()[11]).to.be(0);
|
||||
});
|
||||
|
||||
it('initializes the array using an array', function() {
|
||||
it('initializes the array using an array', function () {
|
||||
b.fromArray([1, 2, 3, 4, 5]);
|
||||
expect(b.getArray().length).to.be(5);
|
||||
expect(b.getArray()[0]).to.be(1);
|
||||
@@ -62,7 +60,7 @@ describe('ol.webgl.Buffer', function() {
|
||||
expect(b.getArray()[4]).to.be(5);
|
||||
});
|
||||
|
||||
it('initializes the array using a size', function() {
|
||||
it('initializes the array using a size', function () {
|
||||
const a = Float32Array.of(1, 2, 3, 4, 5);
|
||||
b.fromArrayBuffer(a.buffer);
|
||||
expect(b.getArray().length).to.be(5);
|
||||
@@ -72,24 +70,21 @@ describe('ol.webgl.Buffer', function() {
|
||||
expect(b.getArray()[3]).to.be(4);
|
||||
expect(b.getArray()[4]).to.be(5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getSize', function() {
|
||||
describe('#getSize', function () {
|
||||
let b;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
b = new WebGLArrayBuffer(ARRAY_BUFFER);
|
||||
});
|
||||
|
||||
it('returns 0 when the buffer array is not initialized', function() {
|
||||
it('returns 0 when the buffer array is not initialized', function () {
|
||||
expect(b.getSize()).to.be(0);
|
||||
});
|
||||
|
||||
it('returns the size of the array otherwise', function() {
|
||||
it('returns the size of the array otherwise', function () {
|
||||
b.ofSize(12);
|
||||
expect(b.getSize()).to.be(12);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import WebGLHelper, {DefaultUniform} from '../../../../src/ol/webgl/Helper.js';
|
||||
import {FLOAT} from '../../../../src/ol/webgl.js';
|
||||
import {
|
||||
create as createTransform,
|
||||
rotate as rotateTransform,
|
||||
scale as scaleTransform,
|
||||
translate as translateTransform
|
||||
translate as translateTransform,
|
||||
} from '../../../../src/ol/transform.js';
|
||||
import {FLOAT} from '../../../../src/ol/webgl.js';
|
||||
|
||||
|
||||
const VERTEX_SHADER = `
|
||||
precision mediump float;
|
||||
@@ -47,43 +46,42 @@ const FRAGMENT_SHADER = `
|
||||
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
}`;
|
||||
|
||||
describe('ol.webgl.WebGLHelper', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
describe('without an argument', function() {
|
||||
|
||||
describe('ol.webgl.WebGLHelper', function () {
|
||||
describe('constructor', function () {
|
||||
describe('without an argument', function () {
|
||||
let h;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
});
|
||||
|
||||
it('initialized WebGL context & canvas', function() {
|
||||
it('initialized WebGL context & canvas', function () {
|
||||
expect(h.getGL() instanceof WebGLRenderingContext).to.eql(true);
|
||||
expect(h.getCanvas() instanceof HTMLCanvasElement).to.eql(true);
|
||||
});
|
||||
|
||||
it('has a default rendering pass', function() {
|
||||
it('has a default rendering pass', function () {
|
||||
expect(h.postProcessPasses_.length).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with post process passes', function() {
|
||||
|
||||
describe('with post process passes', function () {
|
||||
let h;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper({
|
||||
postProcesses: [{
|
||||
scaleRatio: 0.5
|
||||
}, {
|
||||
uniforms: {
|
||||
u_test: 4
|
||||
}
|
||||
}]
|
||||
postProcesses: [
|
||||
{
|
||||
scaleRatio: 0.5,
|
||||
},
|
||||
{
|
||||
uniforms: {
|
||||
u_test: 4,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('has instantiated post-processing passes', function() {
|
||||
it('has instantiated post-processing passes', function () {
|
||||
expect(h.postProcessPasses_.length).to.eql(2);
|
||||
expect(h.postProcessPasses_[0].scaleRatio_).to.eql(0.5);
|
||||
expect(h.postProcessPasses_[0].uniforms_.length).to.eql(0);
|
||||
@@ -91,24 +89,20 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
expect(h.postProcessPasses_[1].uniforms_.length).to.eql(1);
|
||||
expect(h.postProcessPasses_[1].uniforms_[0].value).to.eql(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('operations', function() {
|
||||
|
||||
describe('prepare draw', function() {
|
||||
|
||||
describe('operations', function () {
|
||||
describe('prepare draw', function () {
|
||||
let h;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper({
|
||||
uniforms: {
|
||||
u_test1: 42,
|
||||
u_test2: [1, 3],
|
||||
u_test3: document.createElement('canvas'),
|
||||
u_test4: createTransform()
|
||||
}
|
||||
u_test4: createTransform(),
|
||||
},
|
||||
});
|
||||
h.useProgram(h.getProgram(FRAGMENT_SHADER, VERTEX_SHADER));
|
||||
h.prepareDraw({
|
||||
@@ -117,23 +111,27 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
viewState: {
|
||||
rotation: 10,
|
||||
resolution: 10,
|
||||
center: [0, 0]
|
||||
}
|
||||
center: [0, 0],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('has resized the canvas', function() {
|
||||
it('has resized the canvas', function () {
|
||||
expect(h.getCanvas().width).to.eql(100);
|
||||
expect(h.getCanvas().height).to.eql(160);
|
||||
});
|
||||
|
||||
it('has processed default uniforms', function() {
|
||||
expect(h.uniformLocations_[DefaultUniform.OFFSET_ROTATION_MATRIX]).not.to.eql(undefined);
|
||||
expect(h.uniformLocations_[DefaultUniform.OFFSET_SCALE_MATRIX]).not.to.eql(undefined);
|
||||
it('has processed default uniforms', function () {
|
||||
expect(
|
||||
h.uniformLocations_[DefaultUniform.OFFSET_ROTATION_MATRIX]
|
||||
).not.to.eql(undefined);
|
||||
expect(
|
||||
h.uniformLocations_[DefaultUniform.OFFSET_SCALE_MATRIX]
|
||||
).not.to.eql(undefined);
|
||||
expect(h.uniformLocations_[DefaultUniform.TIME]).not.to.eql(undefined);
|
||||
});
|
||||
|
||||
it('has processed uniforms', function() {
|
||||
it('has processed uniforms', function () {
|
||||
expect(h.uniforms_.length).to.eql(4);
|
||||
expect(h.uniforms_[0].name).to.eql('u_test1');
|
||||
expect(h.uniforms_[1].name).to.eql('u_test2');
|
||||
@@ -147,64 +145,64 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('valid shader compiling', function() {
|
||||
describe('valid shader compiling', function () {
|
||||
let h;
|
||||
let p;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
|
||||
p = h.getProgram(FRAGMENT_SHADER, VERTEX_SHADER);
|
||||
h.useProgram(p);
|
||||
});
|
||||
|
||||
it('has saved the program', function() {
|
||||
it('has saved the program', function () {
|
||||
expect(h.currentProgram_).to.eql(p);
|
||||
});
|
||||
|
||||
it('has no shader compilation error', function() {
|
||||
it('has no shader compilation error', function () {
|
||||
expect(h.shaderCompileErrors_).to.eql(null);
|
||||
});
|
||||
|
||||
it('can find the uniform location', function() {
|
||||
it('can find the uniform location', function () {
|
||||
expect(h.getUniformLocation('u_test')).to.not.eql(null);
|
||||
});
|
||||
|
||||
it('can find the attribute location', function() {
|
||||
it('can find the attribute location', function () {
|
||||
expect(h.getAttributeLocation('a_test')).to.not.eql(-1);
|
||||
});
|
||||
|
||||
it('cannot find an unknown attribute location', function() {
|
||||
it('cannot find an unknown attribute location', function () {
|
||||
expect(h.getAttributeLocation('a_test_missing')).to.eql(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid shader compiling', function() {
|
||||
describe('invalid shader compiling', function () {
|
||||
let h;
|
||||
let p;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
|
||||
p = h.getProgram(FRAGMENT_SHADER, INVALID_VERTEX_SHADER);
|
||||
h.useProgram(p);
|
||||
});
|
||||
|
||||
it('has saved the program', function() {
|
||||
it('has saved the program', function () {
|
||||
expect(h.currentProgram_).to.eql(p);
|
||||
});
|
||||
|
||||
it('has shader compilation errors', function() {
|
||||
it('has shader compilation errors', function () {
|
||||
expect(h.shaderCompileErrors_).to.not.eql(null);
|
||||
});
|
||||
|
||||
it('cannot find the uniform location', function() {
|
||||
it('cannot find the uniform location', function () {
|
||||
expect(h.getUniformLocation('u_test')).to.eql(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#makeProjectionTransform', function() {
|
||||
describe('#makeProjectionTransform', function () {
|
||||
let h;
|
||||
let frameState;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
|
||||
frameState = {
|
||||
@@ -212,33 +210,39 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
viewState: {
|
||||
rotation: 0.4,
|
||||
resolution: 2,
|
||||
center: [10, 20]
|
||||
}
|
||||
center: [10, 20],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('gives out the correct transform', function() {
|
||||
it('gives out the correct transform', function () {
|
||||
const scaleX = 2 / frameState.size[0] / frameState.viewState.resolution;
|
||||
const scaleY = 2 / frameState.size[1] / frameState.viewState.resolution;
|
||||
const given = createTransform();
|
||||
const expected = createTransform();
|
||||
scaleTransform(expected, scaleX, scaleY);
|
||||
rotateTransform(expected, -frameState.viewState.rotation);
|
||||
translateTransform(expected, -frameState.viewState.center[0], -frameState.viewState.center[1]);
|
||||
translateTransform(
|
||||
expected,
|
||||
-frameState.viewState.center[0],
|
||||
-frameState.viewState.center[1]
|
||||
);
|
||||
|
||||
h.makeProjectionTransform(frameState, given);
|
||||
|
||||
expect(given.map(val => val.toFixed(15))).to.eql(expected.map(val => val.toFixed(15)));
|
||||
expect(given.map((val) => val.toFixed(15))).to.eql(
|
||||
expected.map((val) => val.toFixed(15))
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createTexture', function() {
|
||||
describe('#createTexture', function () {
|
||||
let h;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
});
|
||||
|
||||
it('creates an empty texture from scratch', function() {
|
||||
it('creates an empty texture from scratch', function () {
|
||||
const width = 4;
|
||||
const height = 4;
|
||||
const t = h.createTexture([width, height]);
|
||||
@@ -246,7 +250,13 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
|
||||
const fb = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t, 0);
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0,
|
||||
gl.TEXTURE_2D,
|
||||
t,
|
||||
0
|
||||
);
|
||||
const data = new Uint8Array(width * height * 4);
|
||||
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
||||
gl.deleteFramebuffer(fb);
|
||||
@@ -261,7 +271,7 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
expect(data[7]).to.eql(0);
|
||||
});
|
||||
|
||||
it('creates a texture from image data', function() {
|
||||
it('creates a texture from image data', function () {
|
||||
const width = 4;
|
||||
const height = 4;
|
||||
const canvas = document.createElement('canvas');
|
||||
@@ -277,7 +287,13 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
|
||||
const fb = gl.createFramebuffer();
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t, 0);
|
||||
gl.framebufferTexture2D(
|
||||
gl.FRAMEBUFFER,
|
||||
gl.COLOR_ATTACHMENT0,
|
||||
gl.TEXTURE_2D,
|
||||
t,
|
||||
0
|
||||
);
|
||||
const data = new Uint8Array(width * height * 4);
|
||||
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
||||
gl.deleteFramebuffer(fb);
|
||||
@@ -292,7 +308,7 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
expect(data[7]).to.eql(250);
|
||||
});
|
||||
|
||||
it('reuses a given texture', function() {
|
||||
it('reuses a given texture', function () {
|
||||
const width = 4;
|
||||
const height = 4;
|
||||
const gl = h.getGL();
|
||||
@@ -303,26 +319,29 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#enableAttributes', function() {
|
||||
describe('#enableAttributes', function () {
|
||||
let baseAttrs, h;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
h = new WebGLHelper();
|
||||
baseAttrs = [
|
||||
{
|
||||
name: 'attr1',
|
||||
size: 3
|
||||
size: 3,
|
||||
},
|
||||
{
|
||||
name: 'attr2',
|
||||
size: 2
|
||||
size: 2,
|
||||
},
|
||||
{
|
||||
name: 'attr3',
|
||||
size: 1
|
||||
}
|
||||
size: 1,
|
||||
},
|
||||
];
|
||||
h.useProgram(h.getProgram(FRAGMENT_SHADER, `
|
||||
h.useProgram(
|
||||
h.getProgram(
|
||||
FRAGMENT_SHADER,
|
||||
`
|
||||
precision mediump float;
|
||||
|
||||
uniform mat4 u_projectionMatrix;
|
||||
@@ -336,10 +355,12 @@ describe('ol.webgl.WebGLHelper', function() {
|
||||
|
||||
void main(void) {
|
||||
gl_Position = vec4(u_test, a_test, 0.0, 1.0);
|
||||
}`));
|
||||
}`
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('enables attributes based on the given array (FLOAT)', function() {
|
||||
it('enables attributes based on the given array (FLOAT)', function () {
|
||||
const spy = sinon.spy(h, 'enableAttributeArray_');
|
||||
h.enableAttributes(baseAttrs);
|
||||
const bytesPerFloat = Float32Array.BYTES_PER_ELEMENT;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import WebGLRenderTarget from '../../../../src/ol/webgl/RenderTarget.js';
|
||||
import WebGLHelper from '../../../../src/ol/webgl/Helper.js';
|
||||
import WebGLRenderTarget from '../../../../src/ol/webgl/RenderTarget.js';
|
||||
|
||||
|
||||
describe('ol.webgl.RenderTarget', function() {
|
||||
describe('ol.webgl.RenderTarget', function () {
|
||||
let helper, testImage_4x4;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
helper = new WebGLHelper();
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
@@ -18,30 +17,27 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
}
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a target of size 1x1', function() {
|
||||
describe('constructor', function () {
|
||||
it('creates a target of size 1x1', function () {
|
||||
const rt = new WebGLRenderTarget(helper);
|
||||
expect(rt.getSize()).to.eql([1, 1]);
|
||||
});
|
||||
|
||||
it('creates a target of specified size', function() {
|
||||
it('creates a target of specified size', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [12, 34]);
|
||||
expect(rt.getSize()).to.eql([12, 34]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setSize', function() {
|
||||
|
||||
it('updates the target size', function() {
|
||||
describe('#setSize', function () {
|
||||
it('updates the target size', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [12, 34]);
|
||||
expect(rt.getSize()).to.eql([12, 34]);
|
||||
rt.setSize([45, 67]);
|
||||
expect(rt.getSize()).to.eql([45, 67]);
|
||||
});
|
||||
|
||||
it('does nothing if the size has not changed', function() {
|
||||
it('does nothing if the size has not changed', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [12, 34]);
|
||||
const spy = sinon.spy(rt, 'updateSize_');
|
||||
rt.setSize([12, 34]);
|
||||
@@ -49,17 +45,15 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
rt.setSize([12, 345]);
|
||||
expect(spy.called).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#readAll', function() {
|
||||
|
||||
it('returns 1-pixel data with the default options', function() {
|
||||
describe('#readAll', function () {
|
||||
it('returns 1-pixel data with the default options', function () {
|
||||
const rt = new WebGLRenderTarget(helper);
|
||||
expect(rt.readAll().length).to.eql(4);
|
||||
});
|
||||
|
||||
it('returns the content of the texture', function() {
|
||||
it('returns the content of the texture', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [4, 4]);
|
||||
helper.createTexture([4, 4], testImage_4x4, rt.getTexture());
|
||||
const data = rt.readAll();
|
||||
@@ -75,7 +69,7 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
expect(data.length).to.eql(4 * 4 * 4);
|
||||
});
|
||||
|
||||
it('does not call gl.readPixels again when #clearCachedData is not called', function() {
|
||||
it('does not call gl.readPixels again when #clearCachedData is not called', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [4, 4]);
|
||||
helper.createTexture([4, 4], testImage_4x4, rt.getTexture());
|
||||
const spy = sinon.spy(rt.helper_.getGL(), 'readPixels');
|
||||
@@ -87,12 +81,10 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
rt.readAll();
|
||||
expect(spy.callCount).to.eql(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#readPixel', function() {
|
||||
|
||||
it('returns the content of one pixel', function() {
|
||||
describe('#readPixel', function () {
|
||||
it('returns the content of one pixel', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [4, 4]);
|
||||
helper.createTexture([4, 4], testImage_4x4, rt.getTexture());
|
||||
|
||||
@@ -110,7 +102,7 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
expect(data.length).to.eql(4);
|
||||
});
|
||||
|
||||
it('does not call gl.readPixels again when #clearCachedData is not called', function() {
|
||||
it('does not call gl.readPixels again when #clearCachedData is not called', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [4, 4]);
|
||||
helper.createTexture([4, 4], testImage_4x4, rt.getTexture());
|
||||
const spy = sinon.spy(rt.helper_.getGL(), 'readPixels');
|
||||
@@ -123,7 +115,7 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
expect(spy.callCount).to.eql(2);
|
||||
});
|
||||
|
||||
it('returns an array filled with 0 if outside of range', function() {
|
||||
it('returns an array filled with 0 if outside of range', function () {
|
||||
const rt = new WebGLRenderTarget(helper, [4, 4]);
|
||||
helper.createTexture([4, 4], testImage_4x4, rt.getTexture());
|
||||
|
||||
@@ -142,7 +134,5 @@ describe('ol.webgl.RenderTarget', function() {
|
||||
data = rt.readPixel(2, 3);
|
||||
expect(data).not.to.eql([0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import {parseLiteralStyle, ShaderBuilder} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
||||
import {arrayToGlsl, colorToGlsl, numberToGlsl} from '../../../../src/ol/style/expressions.js';
|
||||
import {
|
||||
ShaderBuilder,
|
||||
parseLiteralStyle,
|
||||
} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
||||
import {
|
||||
arrayToGlsl,
|
||||
colorToGlsl,
|
||||
numberToGlsl,
|
||||
} from '../../../../src/ol/style/expressions.js';
|
||||
|
||||
describe('ol.webgl.ShaderBuilder', function() {
|
||||
|
||||
describe('getSymbolVertexShader', function() {
|
||||
it('generates a symbol vertex shader (with varying)', function() {
|
||||
describe('ol.webgl.ShaderBuilder', function () {
|
||||
describe('getSymbolVertexShader', function () {
|
||||
it('generates a symbol vertex shader (with varying)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addVarying('v_opacity', 'float', numberToGlsl(0.4));
|
||||
builder.addVarying('v_test', 'vec3', arrayToGlsl([1, 2, 3]));
|
||||
@@ -61,7 +67,7 @@ void main(void) {
|
||||
v_test = vec3(1.0, 2.0, 3.0);
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with uniforms and attributes)', function() {
|
||||
it('generates a symbol vertex shader (with uniforms and attributes)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addUniform('float u_myUniform');
|
||||
builder.addAttribute('vec2 a_myAttr');
|
||||
@@ -116,7 +122,7 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with rotateWithView)', function() {
|
||||
it('generates a symbol vertex shader (with rotateWithView)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.setSizeExpression(`vec2(${numberToGlsl(6)})`);
|
||||
builder.setSymbolOffsetExpression(arrayToGlsl([5, -7]));
|
||||
@@ -170,10 +176,11 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader for hitDetection', function() {
|
||||
it('generates a symbol vertex shader for hitDetection', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
|
||||
expect(builder.getSymbolVertexShader(true)).to.eql(`precision mediump float;
|
||||
expect(builder.getSymbolVertexShader(true)).to
|
||||
.eql(`precision mediump float;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_offsetScaleMatrix;
|
||||
uniform mat4 u_offsetRotateMatrix;
|
||||
@@ -219,7 +226,7 @@ void main(void) {
|
||||
v_hitColor = a_hitColor;
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with a rotation expression)', function() {
|
||||
it('generates a symbol vertex shader (with a rotation expression)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.setSizeExpression(`vec2(${numberToGlsl(6)})`);
|
||||
builder.setSymbolOffsetExpression(arrayToGlsl([5, -7]));
|
||||
@@ -273,8 +280,8 @@ void main(void) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSymbolFragmentShader', function() {
|
||||
it('generates a symbol fragment shader (with varying)', function() {
|
||||
describe('getSymbolFragmentShader', function () {
|
||||
it('generates a symbol fragment shader (with varying)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addVarying('v_opacity', 'float', numberToGlsl(0.4));
|
||||
builder.addVarying('v_test', 'vec3', arrayToGlsl([1, 2, 3]));
|
||||
@@ -299,7 +306,7 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol fragment shader (with uniforms)', function() {
|
||||
it('generates a symbol fragment shader (with uniforms)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addUniform('float u_myUniform');
|
||||
builder.addUniform('vec2 u_myUniform2');
|
||||
@@ -325,10 +332,11 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol fragment shader for hit detection', function() {
|
||||
it('generates a symbol fragment shader for hit detection', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
|
||||
expect(builder.getSymbolFragmentShader(true)).to.eql(`precision mediump float;
|
||||
expect(builder.getSymbolFragmentShader(true)).to
|
||||
.eql(`precision mediump float;
|
||||
uniform float u_time;
|
||||
uniform float u_zoom;
|
||||
uniform float u_resolution;
|
||||
@@ -345,54 +353,74 @@ void main(void) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseSymbolStyle', function() {
|
||||
it('parses a style without expressions', function() {
|
||||
describe('parseSymbolStyle', function () {
|
||||
it('parses a style without expressions', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: [4, 8],
|
||||
color: '#ff0000',
|
||||
rotateWithView: true
|
||||
}
|
||||
rotateWithView: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql([]);
|
||||
expect(result.builder.attributes).to.eql([]);
|
||||
expect(result.builder.varyings).to.eql([]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(1.0, 0.0, 0.0, 1.0).rgb, vec4(1.0, 0.0, 0.0, 1.0).a * 1.0 * 1.0)');
|
||||
'vec4(vec4(1.0, 0.0, 0.0, 1.0).rgb, vec4(1.0, 0.0, 0.0, 1.0).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(vec2(4.0, 8.0))');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(true);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.eql({});
|
||||
});
|
||||
|
||||
it('parses a style with expressions', function() {
|
||||
it('parses a style with expressions', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['get', 'attr1'],
|
||||
color: [255, 127.5, 63.75, 0.25],
|
||||
textureCoord: [0.5, 0.5, 0.5, 1],
|
||||
offset: ['match', ['get', 'attr3'], 'red', [6, 0], 'green', [3, 0], [0, 0]]
|
||||
}
|
||||
offset: [
|
||||
'match',
|
||||
['get', 'attr3'],
|
||||
'red',
|
||||
[6, 0],
|
||||
'green',
|
||||
[3, 0],
|
||||
[0, 0],
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql([]);
|
||||
expect(result.builder.attributes).to.eql(['float a_attr1', 'float a_attr3']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_attr1',
|
||||
type: 'float',
|
||||
expression: 'a_attr1'
|
||||
}]);
|
||||
expect(result.builder.attributes).to.eql([
|
||||
'float a_attr1',
|
||||
'float a_attr3',
|
||||
]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_attr1',
|
||||
type: 'float',
|
||||
expression: 'a_attr1',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(1.0, 0.5, 0.25, 0.25).rgb, vec4(1.0, 0.5, 0.25, 0.25).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(a_attr1)');
|
||||
expect(result.builder.offsetExpression).to.eql('(a_attr3 == 1.0 ? vec2(6.0, 0.0) : (a_attr3 == 0.0 ? vec2(3.0, 0.0) : vec2(0.0, 0.0)))');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.5, 0.5, 0.5, 1.0)');
|
||||
expect(result.builder.offsetExpression).to.eql(
|
||||
'(a_attr3 == 1.0 ? vec2(6.0, 0.0) : (a_attr3 == 0.0 ? vec2(3.0, 0.0) : vec2(0.0, 0.0)))'
|
||||
);
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.5, 0.5, 0.5, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(2);
|
||||
expect(result.attributes[0].name).to.eql('attr1');
|
||||
@@ -400,15 +428,15 @@ void main(void) {
|
||||
expect(result.uniforms).to.eql({});
|
||||
});
|
||||
|
||||
it('parses a style with a uniform (texture)', function() {
|
||||
it('parses a style with a uniform (texture)', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'image',
|
||||
src: '../data/image.png',
|
||||
size: 6,
|
||||
color: '#336699',
|
||||
opacity: 0.5
|
||||
}
|
||||
opacity: 0.5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql(['sampler2D u_texture']);
|
||||
@@ -419,33 +447,48 @@ void main(void) {
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.have.property('u_texture');
|
||||
});
|
||||
|
||||
it('parses a style with variables', function() {
|
||||
it('parses a style with variables', function () {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {
|
||||
lower: 100,
|
||||
higher: 400
|
||||
higher: 400,
|
||||
},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['interpolate', ['linear'], ['get', 'population'], ['var', 'lower'], 4, ['var', 'higher'], 8],
|
||||
size: [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
['get', 'population'],
|
||||
['var', 'lower'],
|
||||
4,
|
||||
['var', 'higher'],
|
||||
8,
|
||||
],
|
||||
color: '#336699',
|
||||
opacity: 0.5
|
||||
}
|
||||
opacity: 0.5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql(['float u_lower', 'float u_higher']);
|
||||
expect(result.builder.uniforms).to.eql([
|
||||
'float u_lower',
|
||||
'float u_higher',
|
||||
]);
|
||||
expect(result.builder.attributes).to.eql(['float a_population']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_population',
|
||||
type: 'float',
|
||||
expression: 'a_population'
|
||||
}]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_population',
|
||||
type: 'float',
|
||||
expression: 'a_population',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(0.2, 0.4, 0.6, 1.0).rgb, vec4(0.2, 0.4, 0.6, 1.0).a * 0.5 * 1.0)'
|
||||
);
|
||||
@@ -453,7 +496,9 @@ void main(void) {
|
||||
'vec2(mix(4.0, 8.0, pow(clamp((a_population - u_lower) / (u_higher - u_lower), 0.0, 1.0), 1.0)))'
|
||||
);
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(1);
|
||||
expect(result.attributes[0].name).to.eql('population');
|
||||
@@ -461,41 +506,55 @@ void main(void) {
|
||||
expect(result.uniforms).to.have.property('u_higher');
|
||||
});
|
||||
|
||||
it('parses a style with a filter', function() {
|
||||
it('parses a style with a filter', function () {
|
||||
const result = parseLiteralStyle({
|
||||
filter: ['between', ['get', 'attr0'], 0, 10],
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
color: '#336699'
|
||||
}
|
||||
color: '#336699',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql(['float a_attr0']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_attr0',
|
||||
type: 'float',
|
||||
expression: 'a_attr0'
|
||||
}]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_attr0',
|
||||
type: 'float',
|
||||
expression: 'a_attr0',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(0.2, 0.4, 0.6, 1.0).rgb, vec4(0.2, 0.4, 0.6, 1.0).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.discardExpression).to.eql('!(v_attr0 >= 0.0 && v_attr0 <= 10.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.discardExpression).to.eql(
|
||||
'!(v_attr0 >= 0.0 && v_attr0 <= 10.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(1);
|
||||
expect(result.attributes[0].name).to.eql('attr0');
|
||||
});
|
||||
|
||||
it('parses a style with a color interpolation', function() {
|
||||
it('parses a style with a color interpolation', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
color: ['interpolate', ['linear'], ['var', 'ratio'], 0, [255, 255, 0], 1, 'red']
|
||||
}
|
||||
color: [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
['var', 'ratio'],
|
||||
0,
|
||||
[255, 255, 0],
|
||||
1,
|
||||
'red',
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql([]);
|
||||
@@ -505,19 +564,21 @@ void main(void) {
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.have.property('u_ratio');
|
||||
});
|
||||
|
||||
it('parses a style with a rotation expression using an attribute', function() {
|
||||
it('parses a style with a rotation expression using an attribute', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
rotation: ['get', 'heading']
|
||||
}
|
||||
rotation: ['get', 'heading'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql(['float a_heading']);
|
||||
@@ -525,29 +586,29 @@ void main(void) {
|
||||
expect(result.builder.rotationExpression).to.eql('a_heading');
|
||||
});
|
||||
|
||||
it('correctly adds string variables to the string literals mapping', function() {
|
||||
it('correctly adds string variables to the string literals mapping', function () {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {
|
||||
mySize: 'abcdef'
|
||||
mySize: 'abcdef',
|
||||
},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['match', ['var', 'mySize'], 'abc', 10, 'def', 20, 30],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.uniforms['u_mySize']()).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it('throws when a variable is requested but not present in the style', function(done) {
|
||||
it('throws when a variable is requested but not present in the style', function (done) {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['var', 'mySize'],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -558,13 +619,13 @@ void main(void) {
|
||||
done(true);
|
||||
});
|
||||
|
||||
it('throws when a variable is requested but the style does not have a variables dict', function(done) {
|
||||
it('throws when a variable is requested but the style does not have a variables dict', function (done) {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['var', 'mySize'],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -575,5 +636,4 @@ void main(void) {
|
||||
done(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user