summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/view/MapLoader.ts28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/view/MapLoader.ts b/src/view/MapLoader.ts
index eca8b75..f39700e 100644
--- a/src/view/MapLoader.ts
+++ b/src/view/MapLoader.ts
@@ -22,6 +22,21 @@ function loadTiles(tiles: Map<string, string>): Promise<Map<string, HTMLImageEle
return loadImages(mapValues(t => `resources/sprite/tile/${t}.png`, tiles));
}
+function mkTexture(gl: WebGLRenderingContext, src: HTMLCanvasElement|HTMLImageElement): WebGLTexture {
+ let texture = gl.createTexture();
+ if (!texture)
+ throw new Error('unable to create texture');
+
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+
+ return texture;
+}
+
function mkTileTexture(gl: WebGLRenderingContext, tiles: Map<string, HTMLImageElement>): [WebGLTexture, Map<string, number>] {
let canvas = document.createElement('canvas');
canvas.width = nextPowerOf2(tiles.size) * MapView.tileSize;
@@ -36,18 +51,7 @@ function mkTileTexture(gl: WebGLRenderingContext, tiles: Map<string, HTMLImageEl
ret.set(k, i++);
}
- let texture = gl.createTexture();
- if (!texture)
- throw new Error('unable to create texture');
-
- gl.bindTexture(gl.TEXTURE_2D, texture);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
-
- return [texture, ret];
+ return [mkTexture(gl, canvas), ret];
}