aboutsummaryrefslogtreecommitdiff
path: root/web/pw-visualizer/src/webgl
diff options
context:
space:
mode:
Diffstat (limited to 'web/pw-visualizer/src/webgl')
-rw-r--r--web/pw-visualizer/src/webgl/texture.ts28
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(