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:
@@ -273,12 +273,6 @@ class WebGLHelper extends Disposable {
|
||||
listen(this.canvas_, ContextEventType.RESTORED,
|
||||
this.handleWebGLContextRestored, this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
*/
|
||||
this.projectionMatrix_ = createTransform();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../transform.js").Transform}
|
||||
@@ -514,14 +508,6 @@ class WebGLHelper extends Disposable {
|
||||
applyFrameState(frameState) {
|
||||
const size = frameState.size;
|
||||
const rotation = frameState.viewState.rotation;
|
||||
const resolution = frameState.viewState.resolution;
|
||||
const center = frameState.viewState.center;
|
||||
|
||||
// set the "uniform" values (coordinates 0,0 are the center of the view)
|
||||
const projectionMatrix = resetTransform(this.projectionMatrix_);
|
||||
scaleTransform(projectionMatrix, 2 / (resolution * size[0]), 2 / (resolution * size[1]));
|
||||
rotateTransform(projectionMatrix, -rotation);
|
||||
translateTransform(projectionMatrix, -center[0], -center[1]);
|
||||
|
||||
const offsetScaleMatrix = resetTransform(this.offsetScaleMatrix_);
|
||||
scaleTransform(offsetScaleMatrix, 2 / size[0], 2 / size[1]);
|
||||
@@ -531,7 +517,6 @@ class WebGLHelper extends Disposable {
|
||||
rotateTransform(offsetRotateMatrix, -rotation);
|
||||
}
|
||||
|
||||
this.setUniformMatrixValue(DefaultUniform.PROJECTION_MATRIX, fromTransform(this.tmpMat4_, projectionMatrix));
|
||||
this.setUniformMatrixValue(DefaultUniform.OFFSET_SCALE_MATRIX, fromTransform(this.tmpMat4_, offsetScaleMatrix));
|
||||
this.setUniformMatrixValue(DefaultUniform.OFFSET_ROTATION_MATRIX, fromTransform(this.tmpMat4_, offsetRotateMatrix));
|
||||
}
|
||||
@@ -691,6 +676,28 @@ class WebGLHelper extends Disposable {
|
||||
return this.attribLocations_[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the given transform to apply the rotation/translation/scaling of the given frame state.
|
||||
* The resulting transform can be used to convert world space coordinates to view coordinates.
|
||||
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
|
||||
* @param {import("../transform").Transform} transform Transform to update.
|
||||
* @return {import("../transform").Transform} The updated transform object.
|
||||
* @api
|
||||
*/
|
||||
makeProjectionTransform(frameState, transform) {
|
||||
const size = frameState.size;
|
||||
const rotation = frameState.viewState.rotation;
|
||||
const resolution = frameState.viewState.resolution;
|
||||
const center = frameState.viewState.center;
|
||||
|
||||
resetTransform(transform);
|
||||
scaleTransform(transform, 2 / (resolution * size[0]), 2 / (resolution * size[1]));
|
||||
rotateTransform(transform, -rotation);
|
||||
translateTransform(transform, -center[0], -center[1]);
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give a value for a standard float uniform
|
||||
* @param {string} uniform Uniform name
|
||||
|
||||
Reference in New Issue
Block a user