Skip to content

Commit

Permalink
feat: adopt promise.all in examples for faster image loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 16, 2020
1 parent d2e39c8 commit 0e7bb2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/examples/cubemaps/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import vertexSourceCode from "./vertex.glsl";
async function init(): Promise<null> {
const geometry = icosahedronGeometry(0.75, 2);
const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode);
const cubeTexture = new CubeMapTexture([
await fetchImage("/assets/textures/cube/pisa/px.png"),
await fetchImage("/assets/textures/cube/pisa/nx.png"),
await fetchImage("/assets/textures/cube/pisa/py.png"),
await fetchImage("/assets/textures/cube/pisa/ny.png"),
await fetchImage("/assets/textures/cube/pisa/pz.png"),
await fetchImage("/assets/textures/cube/pisa/nz.png"),
]);
const cubeTexture = new CubeMapTexture(
await Promise.all([
fetchImage("/assets/textures/cube/pisa/px.png"),
fetchImage("/assets/textures/cube/pisa/nx.png"),
fetchImage("/assets/textures/cube/pisa/py.png"),
fetchImage("/assets/textures/cube/pisa/ny.png"),
fetchImage("/assets/textures/cube/pisa/pz.png"),
fetchImage("/assets/textures/cube/pisa/nz.png"),
]),
);

const context = new RenderingContext(document.getElementById("framebuffer") as HTMLCanvasElement);
const canvasFramebuffer = context.canvasFramebuffer;
Expand Down
18 changes: 10 additions & 8 deletions src/examples/cubemaps/hdr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import vertexSourceCode from "./vertex.glsl";
async function init(): Promise<null> {
const geometry = convertToInterleavedGeometry(icosahedronGeometry(0.75, 2));
const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode);
const cubeTexture = new CubeMapTexture([
await fetchHDR("/assets/textures/cube/pisaHDR/px.hdr"),
await fetchHDR("/assets/textures/cube/pisaHDR/nx.hdr"),
await fetchHDR("/assets/textures/cube/pisaHDR/py.hdr"),
await fetchHDR("/assets/textures/cube/pisaHDR/ny.hdr"),
await fetchHDR("/assets/textures/cube/pisaHDR/pz.hdr"),
await fetchHDR("/assets/textures/cube/pisaHDR/nz.hdr"),
]);
const cubeTexture = new CubeMapTexture(
await Promise.all([
fetchHDR("/assets/textures/cube/pisaHDR/px.hdr"),
fetchHDR("/assets/textures/cube/pisaHDR/nx.hdr"),
fetchHDR("/assets/textures/cube/pisaHDR/py.hdr"),
fetchHDR("/assets/textures/cube/pisaHDR/ny.hdr"),
fetchHDR("/assets/textures/cube/pisaHDR/pz.hdr"),
fetchHDR("/assets/textures/cube/pisaHDR/nz.hdr"),
]),
);

const context = new RenderingContext(document.getElementById("framebuffer") as HTMLCanvasElement);
const canvasFramebuffer = context.canvasFramebuffer;
Expand Down
18 changes: 10 additions & 8 deletions src/examples/cubemaps/lod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import vertexSourceCode from "./vertex.glsl";
async function init(): Promise<null> {
const geometry = convertToInterleavedGeometry(icosahedronGeometry(0.75, 2));
const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode);
const cubeTexture = new CubeMapTexture([
await fetchImage("/assets/textures/cube/pisa/px.png"),
await fetchImage("/assets/textures/cube/pisa/nx.png"),
await fetchImage("/assets/textures/cube/pisa/py.png"),
await fetchImage("/assets/textures/cube/pisa/ny.png"),
await fetchImage("/assets/textures/cube/pisa/pz.png"),
await fetchImage("/assets/textures/cube/pisa/nz.png"),
]);
const cubeTexture = new CubeMapTexture(
await Promise.all([
fetchImage("/assets/textures/cube/pisa/px.png"),
fetchImage("/assets/textures/cube/pisa/nx.png"),
fetchImage("/assets/textures/cube/pisa/py.png"),
fetchImage("/assets/textures/cube/pisa/ny.png"),
fetchImage("/assets/textures/cube/pisa/pz.png"),
fetchImage("/assets/textures/cube/pisa/nz.png"),
]),
);

const context = new RenderingContext(document.getElementById("framebuffer") as HTMLCanvasElement);
const canvasFramebuffer = context.canvasFramebuffer;
Expand Down

0 comments on commit 0e7bb2d

Please sign in to comment.