Fix rendering for WebGL2 GPU-s lacking OES_texture_float_linear

This commit is contained in:
schmelczerandras 2020-10-19 11:59:09 +02:00
parent 258529b039
commit f2a7107a67

View file

@ -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