diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-18 21:02:27 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-18 21:02:27 +0200 |
commit | d092f5d89c0fda5cc67349d5489b4ef1b294e053 (patch) | |
tree | c630cd90c358101e700fcf76011d84a63957aa31 /web/pw-visualizer/src/webgl/texture.ts | |
parent | 6e494aca463b8632fe2b78ee89b8651187f8061a (diff) | |
download | planetwars.dev-d092f5d89c0fda5cc67349d5489b4ef1b294e053.tar.xz planetwars.dev-d092f5d89c0fda5cc67349d5489b4ef1b294e053.zip |
use texture for rendering ships
Diffstat (limited to 'web/pw-visualizer/src/webgl/texture.ts')
-rw-r--r-- | web/pw-visualizer/src/webgl/texture.ts | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/web/pw-visualizer/src/webgl/texture.ts b/web/pw-visualizer/src/webgl/texture.ts index 9d6adcf..faafe76 100644 --- a/web/pw-visualizer/src/webgl/texture.ts +++ b/web/pw-visualizer/src/webgl/texture.ts @@ -11,15 +11,18 @@ export class Texture { gl: WebGLRenderingContext, path: string, name: string, - ): Texture { - const out = new Texture(gl, name); - - const image = new Image(); - image.onload = out.setImage.bind(out, gl, image); - image.onerror = error; - image.src = path; - - return out; + ): 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; + }) } static fromRenderer( @@ -99,8 +102,3 @@ export class Texture { return this.height; } } - -function error(e: any) { - console.error("IMAGE LOAD ERROR"); - console.error(e); -} |