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/webgl/texture.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'web/pw-visualizer/src/webgl/texture.ts') diff --git a/web/pw-visualizer/src/webgl/texture.ts b/web/pw-visualizer/src/webgl/texture.ts index faafe76..9624489 100644 --- a/web/pw-visualizer/src/webgl/texture.ts +++ b/web/pw-visualizer/src/webgl/texture.ts @@ -1,5 +1,15 @@ import type { Renderer } from "./renderer"; + +export function loadImage(image_url: string): Promise { + return new Promise((resolve, reject) => { + const image = new Image(); + image.onload = () => { resolve(image) } + image.onerror = reject; + image.src = image_url; + }) +} + export class Texture { texture: WebGLTexture; width: number; @@ -9,20 +19,12 @@ export class Texture { static fromImage( gl: WebGLRenderingContext, - path: string, + image: HTMLImageElement, name: string, - ): Promise { - return new Promise((resolve, reject) => { - const out = new Texture(gl, name); - - const image = new Image(); - image.onload = () => { - out.setImage(gl, image); - resolve(out); - } - image.onerror = reject; - image.src = path; - }) + ): Texture { + const tx = new Texture(gl, name); + tx.setImage(gl, image); + return tx; } static fromRenderer( -- cgit v1.2.3