From 8c89ef993888c6f797aab559b997240d270ead97 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 20 Nov 2017 16:47:52 -0800 Subject: [PATCH] Make sure the gamma LUT loads before the initial render --- demo/client/src/3d-demo.ts | 10 +++++----- demo/client/src/app-controller.ts | 21 +++++++++++---------- demo/client/src/benchmark.ts | 10 +++++----- demo/client/src/integration-test.ts | 10 +++++----- demo/client/src/svg-demo.ts | 10 +++++----- demo/client/src/text-demo.ts | 10 +++++----- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/demo/client/src/3d-demo.ts b/demo/client/src/3d-demo.ts index 8b84254e..22efbd24 100644 --- a/demo/client/src/3d-demo.ts +++ b/demo/client/src/3d-demo.ts @@ -155,11 +155,11 @@ class ThreeDController extends DemoAppController { 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): + ThreeDView { + return new ThreeDView(this, gammaLUT, commonShaderSource, shaderSources); } protected get builtinFileURI(): string { diff --git a/demo/client/src/app-controller.ts b/demo/client/src/app-controller.ts index e80dcfa7..97147d4a 100644 --- a/demo/client/src/app-controller.ts +++ b/demo/client/src/app-controller.ts @@ -116,10 +116,6 @@ export abstract class DemoAppController extends AppContro protected filePickerView: FilePickerView | null; - protected commonShaderSource: string | null; - protected shaderSources: ShaderMap | null; - protected gammaLUT: HTMLImageElement; - protected aaLevelSelect: HTMLSelectElement | null; private fpsLabel: HTMLElement | null; @@ -195,10 +191,7 @@ export abstract class DemoAppController 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 extends AppContro this.fpsLabel.classList.remove('invisible'); } - protected abstract createView(): View; + protected abstract createView(gammaLUT: HTMLImageElement, + commonShaderSource: string, + shaderSources: ShaderMap): + View; protected updateAALevel(): Promise { let aaType: AntialiasingStrategyName, aaLevel: number; @@ -322,7 +318,12 @@ export abstract class DemoAppController extends AppContro .then(blob => { const imgElement = document.createElement('img'); imgElement.src = URL.createObjectURL(blob); - return imgElement; + const promise: Promise = new Promise(resolve => { + imgElement.addEventListener('load', () => { + resolve(imgElement); + }, false); + }); + return promise; }); } diff --git a/demo/client/src/benchmark.ts b/demo/client/src/benchmark.ts index 1b57543d..967ca19b 100644 --- a/demo/client/src/benchmark.ts +++ b/demo/client/src/benchmark.ts @@ -133,11 +133,11 @@ class BenchmarkAppController extends DemoAppController { }); } - protected createView(): BenchmarkTestView { - return new BenchmarkTestView(this, - unwrapNull(this.gammaLUT), - unwrapNull(this.commonShaderSource), - unwrapNull(this.shaderSources)); + protected createView(gammaLUT: HTMLImageElement, + commonShaderSource: string, + shaderSources: ShaderMap): + BenchmarkTestView { + return new BenchmarkTestView(this, gammaLUT, commonShaderSource, shaderSources); } private reset(): void { diff --git a/demo/client/src/integration-test.ts b/demo/client/src/integration-test.ts index fc3aefa1..b55985a1 100644 --- a/demo/client/src/integration-test.ts +++ b/demo/client/src/integration-test.ts @@ -231,11 +231,11 @@ class IntegrationTestAppController extends DemoAppController): + IntegrationTestView { + return new IntegrationTestView(this, gammaLUT, commonShaderSource, shaderSources); } protected fileLoaded(fileData: ArrayBuffer, builtinName: string | null): void { diff --git a/demo/client/src/svg-demo.ts b/demo/client/src/svg-demo.ts index 6853fb13..d946fda9 100644 --- a/demo/client/src/svg-demo.ts +++ b/demo/client/src/svg-demo.ts @@ -68,11 +68,11 @@ class SVGDemoController extends DemoAppController { }); } - protected createView() { - return new SVGDemoView(this, - unwrapNull(this.gammaLUT), - unwrapNull(this.commonShaderSource), - unwrapNull(this.shaderSources)); + protected createView(gammaLUT: HTMLImageElement, + commonShaderSource: string, + shaderSources: ShaderMap): + SVGDemoView { + return new SVGDemoView(this, gammaLUT, commonShaderSource, shaderSources); } protected get defaultFile(): string { diff --git a/demo/client/src/text-demo.ts b/demo/client/src/text-demo.ts index d03c5255..1ee51521 100644 --- a/demo/client/src/text-demo.ts +++ b/demo/client/src/text-demo.ts @@ -165,11 +165,11 @@ class TextDemoController extends DemoAppController { 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): + TextDemoView { + return new TextDemoView(this, gammaLUT, commonShaderSource, shaderSources); } protected fileLoaded(fileData: ArrayBuffer, builtinName: string | null) {