Add motion blur and better interpolation when OES_texture_float_linear is not available

This commit is contained in:
schmelczerandras 2020-10-31 11:15:45 +01:00
parent 2889fd54db
commit 7803bbeaee
7 changed files with 50 additions and 8 deletions

View file

@ -18,8 +18,8 @@ export class DistanceTexture extends Texture {
const bufferFloatExtension = tryEnableExtension(gl, 'EXT_color_buffer_float');
const floatLinearExtension = tryEnableExtension(gl, 'OES_texture_float_linear');
this.floatLinearEnabled = !!bufferFloatExtension && !!floatLinearExtension;
this.floatLinearEnabled = !!bufferFloatExtension && !!floatLinearExtension;
gl.insights.floatInterpolationEnabled = this.floatLinearEnabled;
}

View file

@ -11,9 +11,18 @@ export const getUniversalRenderingContext = (
canvas: HTMLCanvasElement,
ignoreWebGL2 = false
): UniversalRenderingContext => {
const contextAttributes: WebGLContextAttributes = {
alpha: true,
antialias: false,
depth: false,
desynchronized: true,
preserveDrawingBuffer: true,
powerPreference: 'high-performance',
};
const context: WebGL2RenderingContext | WebGLRenderingContext | null = ignoreWebGL2
? null
: canvas.getContext('webgl2');
: canvas.getContext('webgl2', contextAttributes);
let result = context as UniversalRenderingContext;
@ -23,10 +32,13 @@ export const getUniversalRenderingContext = (
}
} else {
result = (canvas.getContext('webgl') ||
canvas.getContext('experimental-webgl')) as UniversalRenderingContext;
canvas.getContext('experimental-webgl', {
...contextAttributes,
alpha: false,
})) as UniversalRenderingContext;
if (!result) {
throw new Error('Neither WebGL or WebGL2 is supported');
throw new Error('Neither WebGL nor WebGL2 is supported');
}
result.isWebGL2 = false;