From 338dc6ac63a2292e191099e3424e7d28bc11f31b Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Mon, 18 Jul 2022 21:55:35 +0200 Subject: bugfix: don't cache textures bound to a specific GLContext --- web/pw-visualizer/src/index.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'web/pw-visualizer/src/index.ts') diff --git a/web/pw-visualizer/src/index.ts b/web/pw-visualizer/src/index.ts index bee1bab..4231707 100644 --- a/web/pw-visualizer/src/index.ts +++ b/web/pw-visualizer/src/index.ts @@ -24,7 +24,7 @@ import { VertexBufferLayout, VertexArray } from "./webgl/vertexBufferLayout"; import { defaultLabelFactory, LabelFactory, Align, Label } from "./webgl/text"; import { VoronoiBuilder } from "./voronoi/voronoi"; import * as assets from "./assets"; -import { Texture } from "./webgl/texture"; +import { loadImage, Texture } from "./webgl/texture"; function to_bbox(box: number[]): BBox { @@ -585,16 +585,16 @@ export class GameInstance { } var game_instance: GameInstance; -var textures: Texture[]; +var texture_images: HTMLImageElement[]; var shaders: Dictionary; export async function set_instance(source: string): Promise { - // TODO: embed shader programs - if (!textures || !shaders) { - const texture_promises = [ - Texture.fromImage(GL, assets.fontPng, "font"), - Texture.fromImage(GL, assets.shipPng, "ship"), - Texture.fromImage(GL, assets.earthPng, "earth") + // TODO: this loading code is a mess. Please clean me up! + if (!texture_images || !shaders) { + const image_promises = [ + loadImage(assets.fontPng), + loadImage(assets.shipPng), + loadImage(assets.earthPng), ]; const shader_promies = [ @@ -633,8 +633,8 @@ export async function set_instance(source: string): Promise { ]; let shaders_array: [string, ShaderFactory][]; - [textures, shaders_array] = await Promise.all([ - Promise.all(texture_promises), + [texture_images, shaders_array] = await Promise.all([ + Promise.all(image_promises), Promise.all(shader_promies), ]); @@ -643,12 +643,15 @@ export async function set_instance(source: string): Promise { } resizeCanvasToDisplaySize(CANVAS); + const fontTexture = Texture.fromImage(GL, texture_images[0], "font"); + const shipTexture = Texture.fromImage(GL, texture_images[1], "ship"); + const earthTexture = Texture.fromImage(GL, texture_images[2], "earth"); game_instance = new GameInstance( Game.new(source), - textures.slice(2), - textures[1], - textures[0], + [earthTexture], + shipTexture, + fontTexture, shaders ); -- cgit v1.2.3