Use RGB5_A1 on macOS to work around driver stalls with RGBA
This commit is contained in:
parent
00433d418a
commit
1102965f6d
|
@ -82,19 +82,20 @@ export class Atlas {
|
||||||
if (this._texture != null)
|
if (this._texture != null)
|
||||||
return this._texture;
|
return this._texture;
|
||||||
|
|
||||||
const texture = unwrapNull(renderContext.gl.createTexture());
|
const gl = renderContext.gl;
|
||||||
|
const texture = unwrapNull(gl.createTexture());
|
||||||
this._texture = texture;
|
this._texture = texture;
|
||||||
renderContext.gl.bindTexture(renderContext.gl.TEXTURE_2D, texture);
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
renderContext.gl.texImage2D(renderContext.gl.TEXTURE_2D,
|
gl.texImage2D(gl.TEXTURE_2D,
|
||||||
0,
|
0,
|
||||||
renderContext.colorAlphaFormat,
|
gl.RGBA,
|
||||||
ATLAS_SIZE[0],
|
ATLAS_SIZE[0],
|
||||||
ATLAS_SIZE[1],
|
ATLAS_SIZE[1],
|
||||||
0,
|
0,
|
||||||
renderContext.colorAlphaFormat,
|
gl.RGBA,
|
||||||
renderContext.gl.UNSIGNED_BYTE,
|
gl.UNSIGNED_BYTE,
|
||||||
null);
|
null);
|
||||||
setTextureParameters(renderContext.gl, renderContext.gl.NEAREST);
|
setTextureParameters(gl, gl.NEAREST);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,10 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
import * as glmatrix from 'gl-matrix';
|
import * as glmatrix from 'gl-matrix';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import {assert, UINT32_SIZE, unwrapNull} from './utils';
|
import {assert, UINT32_SIZE, unwrapNull} from './utils';
|
||||||
import {DemoView} from './view';
|
import {ColorAlphaFormat, DemoView} from './view';
|
||||||
|
|
||||||
export type WebGLVertexArrayObject = any;
|
export type WebGLVertexArrayObject = any;
|
||||||
|
|
||||||
|
@ -47,25 +48,30 @@ export const QUAD_ELEMENTS: Uint8Array = new Uint8Array([2, 0, 1, 1, 3, 2]);
|
||||||
|
|
||||||
export function createFramebufferColorTexture(gl: WebGLRenderingContext,
|
export function createFramebufferColorTexture(gl: WebGLRenderingContext,
|
||||||
size: glmatrix.vec2,
|
size: glmatrix.vec2,
|
||||||
colorAlphaFormat: GLenum):
|
colorAlphaFormat: ColorAlphaFormat,
|
||||||
|
filter?: number):
|
||||||
WebGLTexture {
|
WebGLTexture {
|
||||||
// Firefox seems to have a bug whereby textures don't get marked as initialized when cleared
|
// Firefox seems to have a bug whereby textures don't get marked as initialized when cleared
|
||||||
// if they're anything other than the first attachment of an FBO. To work around this, supply
|
// if they're anything other than the first attachment of an FBO. To work around this, supply
|
||||||
// zero data explicitly when initializing the texture.
|
// zero data explicitly when initializing the texture.
|
||||||
const zeroes = new Uint8Array(size[0] * size[1] * UINT32_SIZE);
|
let format, type, internalFormat, bitDepth, zeroes;
|
||||||
|
if (colorAlphaFormat === 'RGBA8') {
|
||||||
|
format = internalFormat = gl.RGBA;
|
||||||
|
type = gl.UNSIGNED_BYTE;
|
||||||
|
bitDepth = 32;
|
||||||
|
zeroes = new Uint8Array(size[0] * size[1] * 4);
|
||||||
|
} else {
|
||||||
|
format = internalFormat = gl.RGBA;
|
||||||
|
type = gl.UNSIGNED_SHORT_5_5_5_1;
|
||||||
|
bitDepth = 16;
|
||||||
|
zeroes = new Uint16Array(size[0] * size[1] * 4);
|
||||||
|
}
|
||||||
|
|
||||||
const texture = unwrapNull(gl.createTexture());
|
const texture = unwrapNull(gl.createTexture());
|
||||||
gl.activeTexture(gl.TEXTURE0);
|
gl.activeTexture(gl.TEXTURE0);
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
gl.texImage2D(gl.TEXTURE_2D,
|
gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, size[0], size[1], 0, format, type, zeroes);
|
||||||
0,
|
setTextureParameters(gl, _.defaultTo(filter, gl.NEAREST));
|
||||||
colorAlphaFormat,
|
|
||||||
size[0],
|
|
||||||
size[1],
|
|
||||||
0,
|
|
||||||
colorAlphaFormat,
|
|
||||||
gl.UNSIGNED_BYTE,
|
|
||||||
zeroes);
|
|
||||||
setTextureParameters(gl, gl.NEAREST);
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,19 +56,11 @@ export default class SSAAStrategy extends AntialiasingStrategy {
|
||||||
this.destFramebufferSize,
|
this.destFramebufferSize,
|
||||||
this.supersampleScale);
|
this.supersampleScale);
|
||||||
|
|
||||||
this.supersampledColorTexture = unwrapNull(gl.createTexture());
|
this.supersampledColorTexture =
|
||||||
gl.activeTexture(gl.TEXTURE0);
|
createFramebufferColorTexture(gl,
|
||||||
gl.bindTexture(gl.TEXTURE_2D, this.supersampledColorTexture);
|
this.supersampledFramebufferSize,
|
||||||
gl.texImage2D(gl.TEXTURE_2D,
|
renderContext.colorAlphaFormat,
|
||||||
0,
|
gl.LINEAR);
|
||||||
renderContext.colorAlphaFormat,
|
|
||||||
this.supersampledFramebufferSize[0],
|
|
||||||
this.supersampledFramebufferSize[1],
|
|
||||||
0,
|
|
||||||
renderContext.colorAlphaFormat,
|
|
||||||
gl.UNSIGNED_BYTE,
|
|
||||||
null);
|
|
||||||
setTextureParameters(gl, gl.LINEAR);
|
|
||||||
|
|
||||||
this.supersampledDepthTexture =
|
this.supersampledDepthTexture =
|
||||||
createFramebufferDepthTexture(gl, this.supersampledFramebufferSize);
|
createFramebufferDepthTexture(gl, this.supersampledFramebufferSize);
|
||||||
|
|
|
@ -46,6 +46,8 @@ export interface Timings {
|
||||||
rendering: number;
|
rendering: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ColorAlphaFormat = 'RGBA8' | 'RGB5_A1';
|
||||||
|
|
||||||
declare class WebGLQuery {}
|
declare class WebGLQuery {}
|
||||||
|
|
||||||
export abstract class PathfinderView {
|
export abstract class PathfinderView {
|
||||||
|
@ -157,8 +159,10 @@ export abstract class DemoView extends PathfinderView implements RenderContext {
|
||||||
meshes: PathfinderMeshBuffers[];
|
meshes: PathfinderMeshBuffers[];
|
||||||
meshData: PathfinderMeshData[];
|
meshData: PathfinderMeshData[];
|
||||||
|
|
||||||
get colorAlphaFormat(): GLenum {
|
get colorAlphaFormat(): ColorAlphaFormat {
|
||||||
return this.gl.RGBA;
|
// On macOS, RGBA framebuffers seem to cause driver stalls when switching between rendering
|
||||||
|
// and texturing. Work around this by using RGB5A1 instead.
|
||||||
|
return navigator.platform === 'MacIntel' ? 'RGB5_A1' : 'RGBA8';
|
||||||
}
|
}
|
||||||
|
|
||||||
get renderContext(): RenderContext {
|
get renderContext(): RenderContext {
|
||||||
|
@ -360,7 +364,7 @@ export interface RenderContext {
|
||||||
readonly timerQueryExt: EXTDisjointTimerQuery;
|
readonly timerQueryExt: EXTDisjointTimerQuery;
|
||||||
readonly vertexArrayObjectExt: OESVertexArrayObject;
|
readonly vertexArrayObjectExt: OESVertexArrayObject;
|
||||||
|
|
||||||
readonly colorAlphaFormat: GLenum;
|
readonly colorAlphaFormat: ColorAlphaFormat;
|
||||||
|
|
||||||
readonly shaderPrograms: ShaderMap<PathfinderShaderProgram>;
|
readonly shaderPrograms: ShaderMap<PathfinderShaderProgram>;
|
||||||
readonly gammaLUT: HTMLImageElement;
|
readonly gammaLUT: HTMLImageElement;
|
||||||
|
|
Loading…
Reference in New Issue