Use sRGB color textures where available
This commit is contained in:
parent
2a236319d4
commit
1846ebd861
|
@ -138,9 +138,8 @@ export abstract class ECAAStrategy extends AntialiasingStrategy {
|
|||
}
|
||||
|
||||
protected initDirectFramebuffer(view: MonochromeDemoView) {
|
||||
this.directColorTexture = createFramebufferColorTexture(view.gl, this.destFramebufferSize);
|
||||
this.directPathIDTexture = createFramebufferColorTexture(view.gl,
|
||||
this.destFramebufferSize);
|
||||
this.directColorTexture = createFramebufferColorTexture(view, this.destFramebufferSize);
|
||||
this.directPathIDTexture = createFramebufferColorTexture(view, this.destFramebufferSize);
|
||||
this.directFramebuffer =
|
||||
createFramebuffer(view.gl,
|
||||
view.drawBuffersExt,
|
||||
|
@ -574,9 +573,9 @@ export class ECAAMulticolorStrategy extends ECAAStrategy {
|
|||
}
|
||||
|
||||
protected initEdgeDetectFramebuffer(view: MonochromeDemoView) {
|
||||
this.bgColorTexture = createFramebufferColorTexture(view.gl,
|
||||
this.bgColorTexture = createFramebufferColorTexture(view,
|
||||
this.supersampledFramebufferSize);
|
||||
this.fgColorTexture = createFramebufferColorTexture(view.gl,
|
||||
this.fgColorTexture = createFramebufferColorTexture(view,
|
||||
this.supersampledFramebufferSize);
|
||||
this.edgeDetectFramebuffer = createFramebuffer(view.gl,
|
||||
view.drawBuffersExt,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
import * as glmatrix from 'gl-matrix';
|
||||
|
||||
import {assert, UINT32_SIZE, unwrapNull} from './utils';
|
||||
import { DemoView } from './view';
|
||||
|
||||
export type WebGLVertexArrayObject = any;
|
||||
|
||||
|
@ -24,25 +25,24 @@ export interface UniformMap {
|
|||
|
||||
export const QUAD_ELEMENTS: Uint8Array = new Uint8Array([2, 0, 1, 1, 3, 2]);
|
||||
|
||||
export function createFramebufferColorTexture(gl: WebGLRenderingContext, size: glmatrix.vec2):
|
||||
WebGLTexture {
|
||||
export function createFramebufferColorTexture(view: DemoView, size: glmatrix.vec2): WebGLTexture {
|
||||
// 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
|
||||
// zero data explicitly when initializing the texture.
|
||||
const zeroes = new Uint8Array(size[0] * size[1] * UINT32_SIZE);
|
||||
const texture = unwrapNull(gl.createTexture());
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texImage2D(gl.TEXTURE_2D,
|
||||
const texture = unwrapNull(view.gl.createTexture());
|
||||
view.gl.activeTexture(view.gl.TEXTURE0);
|
||||
view.gl.bindTexture(view.gl.TEXTURE_2D, texture);
|
||||
view.gl.texImage2D(view.gl.TEXTURE_2D,
|
||||
0,
|
||||
gl.RGBA,
|
||||
view.colorAlphaFormat,
|
||||
size[0],
|
||||
size[1],
|
||||
0,
|
||||
gl.RGBA,
|
||||
gl.UNSIGNED_BYTE,
|
||||
view.colorAlphaFormat,
|
||||
view.gl.UNSIGNED_BYTE,
|
||||
zeroes);
|
||||
setTextureParameters(gl, gl.NEAREST);
|
||||
setTextureParameters(view.gl, view.gl.NEAREST);
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,11 +48,11 @@ export default class SSAAStrategy extends AntialiasingStrategy {
|
|||
view.gl.bindTexture(view.gl.TEXTURE_2D, this.supersampledColorTexture);
|
||||
view.gl.texImage2D(view.gl.TEXTURE_2D,
|
||||
0,
|
||||
view.gl.RGBA,
|
||||
view.colorAlphaFormat,
|
||||
this.supersampledFramebufferSize[0],
|
||||
this.supersampledFramebufferSize[1],
|
||||
0,
|
||||
view.gl.RGBA,
|
||||
view.colorAlphaFormat,
|
||||
view.gl.UNSIGNED_BYTE,
|
||||
null);
|
||||
setTextureParameters(view.gl, view.gl.LINEAR);
|
||||
|
|
|
@ -30,7 +30,7 @@ import {calculatePixelDescent, calculatePixelRectForGlyph, PathfinderFont} from
|
|||
import {BUILTIN_FONT_URI, calculatePixelXMin, GlyphStore, Hint, SimpleTextLayout} from "./text";
|
||||
import {assert, expectNotNull, panic, PathfinderError, scaleRect, UINT32_SIZE} from './utils';
|
||||
import {unwrapNull} from './utils';
|
||||
import {MonochromeDemoView, Timings, TIMINGS} from './view';
|
||||
import {DemoView, MonochromeDemoView, Timings, TIMINGS} from './view';
|
||||
|
||||
const DEFAULT_TEXT: string =
|
||||
`’Twas brillig, and the slithy toves
|
||||
|
@ -441,7 +441,7 @@ class TextDemoView extends MonochromeDemoView {
|
|||
// Blit.
|
||||
this.gl.uniformMatrix4fv(blitProgram.uniforms.uTransform, false, transform);
|
||||
this.gl.activeTexture(this.gl.TEXTURE0);
|
||||
this.gl.bindTexture(this.gl.TEXTURE_2D, this.appController.atlas.ensureTexture(this.gl));
|
||||
this.gl.bindTexture(this.gl.TEXTURE_2D, this.appController.atlas.ensureTexture(this));
|
||||
this.gl.uniform1i(blitProgram.uniforms.uSource, 0);
|
||||
this.setIdentityTexScaleUniform(blitProgram.uniforms);
|
||||
this.gl.drawElements(this.gl.TRIANGLES,
|
||||
|
@ -582,7 +582,7 @@ class TextDemoView extends MonochromeDemoView {
|
|||
}
|
||||
|
||||
private createAtlasFramebuffer() {
|
||||
const atlasColorTexture = this.appController.atlas.ensureTexture(this.gl);
|
||||
const atlasColorTexture = this.appController.atlas.ensureTexture(this);
|
||||
this.atlasDepthTexture = createFramebufferDepthTexture(this.gl, ATLAS_SIZE);
|
||||
this.atlasFramebuffer = createFramebuffer(this.gl,
|
||||
this.drawBuffersExt,
|
||||
|
@ -770,23 +770,23 @@ class Atlas {
|
|||
this._usedSize = glmatrix.vec2.clone([ATLAS_SIZE[0], shelfBottom]);
|
||||
}
|
||||
|
||||
ensureTexture(gl: WebGLRenderingContext): WebGLTexture {
|
||||
ensureTexture(view: DemoView): WebGLTexture {
|
||||
if (this._texture != null)
|
||||
return this._texture;
|
||||
|
||||
const texture = unwrapNull(gl.createTexture());
|
||||
const texture = unwrapNull(view.gl.createTexture());
|
||||
this._texture = texture;
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
gl.texImage2D(gl.TEXTURE_2D,
|
||||
view.gl.bindTexture(view.gl.TEXTURE_2D, texture);
|
||||
view.gl.texImage2D(view.gl.TEXTURE_2D,
|
||||
0,
|
||||
gl.RGBA,
|
||||
view.colorAlphaFormat,
|
||||
ATLAS_SIZE[0],
|
||||
ATLAS_SIZE[1],
|
||||
0,
|
||||
gl.RGBA,
|
||||
gl.UNSIGNED_BYTE,
|
||||
view.colorAlphaFormat,
|
||||
view.gl.UNSIGNED_BYTE,
|
||||
null);
|
||||
setTextureParameters(gl, gl.NEAREST);
|
||||
setTextureParameters(view.gl, view.gl.NEAREST);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
|
|
@ -140,6 +140,11 @@ export abstract class DemoView extends PathfinderView {
|
|||
|
||||
pathTransformBufferTextures: PathfinderBufferTexture[];
|
||||
|
||||
get colorAlphaFormat(): number {
|
||||
return this.sRGBExt == null ? this.gl.RGBA : this.sRGBExt.SRGB_ALPHA_EXT;
|
||||
}
|
||||
|
||||
protected sRGBExt: any;
|
||||
protected timerQueryExt: any;
|
||||
|
||||
protected antialiasingStrategy: AntialiasingStrategy | null;
|
||||
|
@ -295,6 +300,7 @@ export abstract class DemoView extends PathfinderView {
|
|||
this.drawBuffersExt = this.gl.getExtension('WEBGL_draw_buffers');
|
||||
this.colorBufferHalfFloatExt = this.gl.getExtension('EXT_color_buffer_half_float');
|
||||
this.instancedArraysExt = this.gl.getExtension('ANGLE_instanced_arrays');
|
||||
this.sRGBExt = this.gl.getExtension('EXT_sRGB');
|
||||
this.textureHalfFloatExt = this.gl.getExtension('OES_texture_half_float');
|
||||
this.timerQueryExt = this.gl.getExtension('EXT_disjoint_timer_query');
|
||||
this.vertexArrayObjectExt = this.gl.getExtension('OES_vertex_array_object');
|
||||
|
|
Loading…
Reference in New Issue