Webgl points / use the helper ton compute the projection transform

The `WebGLHelper` class now provides a `makeProjectionTransform` method
that updates a transform to match the projection for a given frame state.

This also means that the WebGLHelper does not set the projection matrix
uniform anymore, this is the responsibility of the renderer as
the rendered coordinates will not be in world space from now on.
This commit is contained in:
Olivier Guyot
2019-05-14 18:59:24 +02:00
parent fb455891ce
commit 5d2b7fe4bb
3 changed files with 70 additions and 44 deletions

View File

@@ -1,5 +1,10 @@
import WebGLHelper from '../../../../src/ol/webgl/Helper';
import {create as createTransform} from '../../../../src/ol/transform';
import {
create as createTransform,
multiply,
rotate as rotateTransform,
scale as scaleTransform, translate as translateTransform
} from '../../../../src/ol/transform';
const VERTEX_SHADER = `
@@ -185,5 +190,33 @@ describe('ol.webgl.WebGLHelper', function() {
});
});
describe('#makeProjectionTransform', function() {
let h;
let frameState;
beforeEach(function() {
h = new WebGLHelper();
frameState = {
size: [100, 150],
viewState: {
rotation: 0.4,
resolution: 2,
center: [10, 20]
}
}
});
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]);
expect(h.makeProjectionTransform(frameState, given)).to.eql(expected);
});
});
});
});