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)); this.monumentPromise.then(monument => this.layoutMonument(fileData, monument));
} }
protected createView(): ThreeDView { protected createView(gammaLUT: HTMLImageElement,
return new ThreeDView(this, commonShaderSource: string,
unwrapNull(this.gammaLUT), shaderSources: ShaderMap<ShaderProgramSource>):
unwrapNull(this.commonShaderSource), ThreeDView {
unwrapNull(this.shaderSources)); return new ThreeDView(this, gammaLUT, commonShaderSource, shaderSources);
} }
protected get builtinFileURI(): string { protected get builtinFileURI(): string {

View File

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

View File

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

View File

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

View File

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