Add auto context restoration

This commit is contained in:
schmelczerandras 2020-09-27 16:10:52 +02:00
commit 2e57f090e6

View file

@ -1,9 +1,9 @@
import { mat2d, vec2, vec3 } from 'gl-matrix';
import { mat2d, vec2, vec3, vec4 } from 'gl-matrix';
import { UniversalRenderingContext } from '../graphics-library/universal-rendering-context';
export class UniformsProvider {
public ambientLight = vec3.fromValues(0.25, 0.15, 0.25);
public shadowLength = 400;
public _backgroundColor = vec4.fromValues(1, 1, 1, 1);
private scaleWorldLengthToNDC = 1;
private transformWorldToNDC = mat2d.create();
@ -18,7 +18,7 @@ export class UniformsProvider {
return {
...uniforms,
ambientLight: this.ambientLight,
shadowLength: this.shadowLength,
backgroundColor: this._backgroundColor,
uvToWorld: this.uvToWorld,
worldAreaInView: this.worldAreaInView,
squareToAspectRatio: this.squareToAspectRatio,
@ -28,6 +28,14 @@ export class UniformsProvider {
};
}
public set backgroundColor(value: vec3 | vec4) {
if (value.length === 3) {
this.backgroundColor = vec4.fromValues(value[0], value[1], value[2], 1);
} else {
this._backgroundColor = value as vec4;
}
}
public getViewArea(): vec2 {
return this.worldAreaInView;
}