diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-18 21:55:35 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-18 21:55:35 +0200 |
commit | 338dc6ac63a2292e191099e3424e7d28bc11f31b (patch) | |
tree | dfba3887e01b64b03d8349b3afb4538cc4e4ce04 /web/pw-visualizer/src/webgl | |
parent | 7daf8f643798ce76733006f8469890bf1a3fd05e (diff) | |
download | planetwars.dev-338dc6ac63a2292e191099e3424e7d28bc11f31b.tar.xz planetwars.dev-338dc6ac63a2292e191099e3424e7d28bc11f31b.zip |
bugfix: don't cache textures bound to a specific GLContext
Diffstat (limited to 'web/pw-visualizer/src/webgl')
-rw-r--r-- | web/pw-visualizer/src/webgl/texture.ts | 28 |
1 files changed, 15 insertions, 13 deletions
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<HTMLImageElement> { + 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<Texture> { - 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( |