Make sure the gamma LUT loads before the initial render

This commit is contained in:
Patrick Walton 2017-11-20 16:47:52 -08:00
parent 5a1e4d4e60
commit 8c89ef9938
6 changed files with 36 additions and 35 deletions

View File

@ -155,11 +155,11 @@ class ThreeDController extends DemoAppController<ThreeDView> {
this.monumentPromise.then(monument => this.layoutMonument(fileData, monument));
}
protected createView(): ThreeDView {
return new ThreeDView(this,
unwrapNull(this.gammaLUT),
unwrapNull(this.commonShaderSource),
unwrapNull(this.shaderSources));
protected createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
ThreeDView {
return new ThreeDView(this, gammaLUT, commonShaderSource, shaderSources);
}
protected get builtinFileURI(): string {

View File

@ -116,10 +116,6 @@ export abstract class DemoAppController<View extends DemoView> extends AppContro
protected filePickerView: FilePickerView | null;
protected commonShaderSource: string | null;
protected shaderSources: ShaderMap<ShaderProgramSource> | null;
protected gammaLUT: HTMLImageElement;
protected aaLevelSelect: HTMLSelectElement | null;
private fpsLabel: HTMLElement | null;
@ -195,10 +191,7 @@ export abstract class DemoAppController<View extends DemoView> extends AppContro
const promises: any[] = [gammaLUTPromise, shaderLoader.common, shaderLoader.shaders];
this.view = Promise.all(promises).then(assets => {
this.gammaLUT = assets[0];
this.commonShaderSource = assets[1];
this.shaderSources = assets[2];
return this.createView();
return this.createView(assets[0], assets[1], assets[2]);
});
this.aaLevelSelect = document.getElementById('pf-aa-level-select') as
@ -252,7 +245,10 @@ export abstract class DemoAppController<View extends DemoView> extends AppContro
this.fpsLabel.classList.remove('invisible');
}
protected abstract createView(): View;
protected abstract createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
View;
protected updateAALevel(): Promise<void> {
let aaType: AntialiasingStrategyName, aaLevel: number;
@ -322,7 +318,12 @@ export abstract class DemoAppController<View extends DemoView> extends AppContro
.then(blob => {
const imgElement = document.createElement('img');
imgElement.src = URL.createObjectURL(blob);
return imgElement;
const promise: Promise<HTMLImageElement> = new Promise(resolve => {
imgElement.addEventListener('load', () => {
resolve(imgElement);
}, false);
});
return promise;
});
}

View File

@ -133,11 +133,11 @@ class BenchmarkAppController extends DemoAppController<BenchmarkTestView> {
});
}
protected createView(): BenchmarkTestView {
return new BenchmarkTestView(this,
unwrapNull(this.gammaLUT),
unwrapNull(this.commonShaderSource),
unwrapNull(this.shaderSources));
protected createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
BenchmarkTestView {
return new BenchmarkTestView(this, gammaLUT, commonShaderSource, shaderSources);
}
private reset(): void {

View File

@ -231,11 +231,11 @@ class IntegrationTestAppController extends DemoAppController<IntegrationTestView
context.putImageData(imageData, 0, 0);
}
protected createView(): IntegrationTestView {
return new IntegrationTestView(this,
unwrapNull(this.gammaLUT),
unwrapNull(this.commonShaderSource),
unwrapNull(this.shaderSources));
protected createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
IntegrationTestView {
return new IntegrationTestView(this, gammaLUT, commonShaderSource, shaderSources);
}
protected fileLoaded(fileData: ArrayBuffer, builtinName: string | null): void {

View File

@ -68,11 +68,11 @@ class SVGDemoController extends DemoAppController<SVGDemoView> {
});
}
protected createView() {
return new SVGDemoView(this,
unwrapNull(this.gammaLUT),
unwrapNull(this.commonShaderSource),
unwrapNull(this.shaderSources));
protected createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
SVGDemoView {
return new SVGDemoView(this, gammaLUT, commonShaderSource, shaderSources);
}
protected get defaultFile(): string {

View File

@ -165,11 +165,11 @@ class TextDemoController extends DemoAppController<TextDemoView> {
window.jQuery(this.editTextModal).modal();
}
protected createView() {
return new TextDemoView(this,
unwrapNull(this.gammaLUT),
unwrapNull(this.commonShaderSource),
unwrapNull(this.shaderSources));
protected createView(gammaLUT: HTMLImageElement,
commonShaderSource: string,
shaderSources: ShaderMap<ShaderProgramSource>):
TextDemoView {
return new TextDemoView(this, gammaLUT, commonShaderSource, shaderSources);
}
protected fileLoaded(fileData: ArrayBuffer, builtinName: string | null) {