Fix rendering for WebGL2 GPU-s lacking OES_texture_float_linear
This commit is contained in:
parent
258529b039
commit
f2a7107a67
1 changed files with 12 additions and 23 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { vec2 } from 'gl-matrix';
|
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 { Texture } from './texture';
|
||||||
import { FilteringOptions } from './texture-options';
|
import { FilteringOptions } from './texture-options';
|
||||||
|
|
||||||
|
|
@ -7,31 +8,19 @@ import { FilteringOptions } from './texture-options';
|
||||||
export class DistanceTexture extends Texture {
|
export class DistanceTexture extends Texture {
|
||||||
public static readonly textureUnitId = 1;
|
public static readonly textureUnitId = 1;
|
||||||
|
|
||||||
private floatEnabled = false;
|
|
||||||
private floatLinearEnabled = false;
|
private floatLinearEnabled = false;
|
||||||
|
|
||||||
constructor(gl: WebGL2RenderingContext) {
|
constructor(gl: WebGL2RenderingContext & UniversalRenderingContext) {
|
||||||
super(gl, DistanceTexture.textureUnitId, {
|
super(gl, DistanceTexture.textureUnitId, {
|
||||||
minFilter: FilteringOptions.NEAREST,
|
minFilter: FilteringOptions.LINEAR,
|
||||||
maxFilter: FilteringOptions.NEAREST,
|
maxFilter: FilteringOptions.LINEAR,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const bufferFloatExtension = tryEnableExtension(gl, 'EXT_color_buffer_float');
|
||||||
enableExtension(gl, 'EXT_color_buffer_float');
|
const floatLinearExtension = tryEnableExtension(gl, 'OES_texture_float_linear');
|
||||||
this.floatEnabled = true;
|
this.floatLinearEnabled = !!bufferFloatExtension && !!floatLinearExtension;
|
||||||
|
|
||||||
enableExtension(gl, 'OES_texture_float_linear');
|
gl.insights.floatInterpolationEnabled = this.floatLinearEnabled;
|
||||||
this.floatLinearEnabled = true;
|
|
||||||
} catch {
|
|
||||||
// it's okay
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.floatLinearEnabled) {
|
|
||||||
this.setTextureOptions({
|
|
||||||
minFilter: FilteringOptions.LINEAR,
|
|
||||||
maxFilter: FilteringOptions.LINEAR,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setSize(size: vec2) {
|
public setSize(size: vec2) {
|
||||||
|
|
@ -39,12 +28,12 @@ export class DistanceTexture extends Texture {
|
||||||
this.gl.texImage2D(
|
this.gl.texImage2D(
|
||||||
this.gl.TEXTURE_2D,
|
this.gl.TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
this.floatEnabled ? (this.gl as WebGL2RenderingContext).R16F : this.gl.RGBA,
|
this.floatLinearEnabled ? (this.gl as WebGL2RenderingContext).R16F : this.gl.RGBA,
|
||||||
size.x,
|
size.x,
|
||||||
size.y,
|
size.y,
|
||||||
0,
|
0,
|
||||||
this.floatEnabled ? (this.gl as WebGL2RenderingContext).RED : this.gl.RGBA,
|
this.floatLinearEnabled ? (this.gl as WebGL2RenderingContext).RED : this.gl.RGBA,
|
||||||
this.floatEnabled
|
this.floatLinearEnabled
|
||||||
? (this.gl as WebGL2RenderingContext).FLOAT
|
? (this.gl as WebGL2RenderingContext).FLOAT
|
||||||
: this.gl.UNSIGNED_BYTE,
|
: this.gl.UNSIGNED_BYTE,
|
||||||
null
|
null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue