diff --git a/src/graphics/graphics-library/texture/distance-texture.ts b/src/graphics/graphics-library/texture/distance-texture.ts index b7ada47..81fa51e 100644 --- a/src/graphics/graphics-library/texture/distance-texture.ts +++ b/src/graphics/graphics-library/texture/distance-texture.ts @@ -1,5 +1,6 @@ import { vec2 } from 'gl-matrix'; -import { enableExtension } from '../helper/enable-extension'; +import { tryEnableExtension } from '../helper/enable-extension'; +import { UniversalRenderingContext } from '../universal-rendering-context'; import { Texture } from './texture'; import { FilteringOptions } from './texture-options'; @@ -7,31 +8,19 @@ import { FilteringOptions } from './texture-options'; export class DistanceTexture extends Texture { public static readonly textureUnitId = 1; - private floatEnabled = false; private floatLinearEnabled = false; - constructor(gl: WebGL2RenderingContext) { + constructor(gl: WebGL2RenderingContext & UniversalRenderingContext) { super(gl, DistanceTexture.textureUnitId, { - minFilter: FilteringOptions.NEAREST, - maxFilter: FilteringOptions.NEAREST, + minFilter: FilteringOptions.LINEAR, + maxFilter: FilteringOptions.LINEAR, }); - try { - enableExtension(gl, 'EXT_color_buffer_float'); - this.floatEnabled = true; + const bufferFloatExtension = tryEnableExtension(gl, 'EXT_color_buffer_float'); + const floatLinearExtension = tryEnableExtension(gl, 'OES_texture_float_linear'); + this.floatLinearEnabled = !!bufferFloatExtension && !!floatLinearExtension; - enableExtension(gl, 'OES_texture_float_linear'); - this.floatLinearEnabled = true; - } catch { - // it's okay - } - - if (this.floatLinearEnabled) { - this.setTextureOptions({ - minFilter: FilteringOptions.LINEAR, - maxFilter: FilteringOptions.LINEAR, - }); - } + gl.insights.floatInterpolationEnabled = this.floatLinearEnabled; } public setSize(size: vec2) { @@ -39,12 +28,12 @@ export class DistanceTexture extends Texture { this.gl.texImage2D( this.gl.TEXTURE_2D, 0, - this.floatEnabled ? (this.gl as WebGL2RenderingContext).R16F : this.gl.RGBA, + this.floatLinearEnabled ? (this.gl as WebGL2RenderingContext).R16F : this.gl.RGBA, size.x, size.y, 0, - this.floatEnabled ? (this.gl as WebGL2RenderingContext).RED : this.gl.RGBA, - this.floatEnabled + this.floatLinearEnabled ? (this.gl as WebGL2RenderingContext).RED : this.gl.RGBA, + this.floatLinearEnabled ? (this.gl as WebGL2RenderingContext).FLOAT : this.gl.UNSIGNED_BYTE, null