From 236151ba9cefca6196004b03a6c06220fb84057c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 11 Nov 2018 13:58:22 +0100 Subject: view: do not split multi-frame sprites into multiple textures --- src/view/util/image.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'src/view/util/image.ts') diff --git a/src/view/util/image.ts b/src/view/util/image.ts index 4c5e386..0ad5d16 100644 --- a/src/view/util/image.ts +++ b/src/view/util/image.ts @@ -1,4 +1,3 @@ -import { nextPowerOf2 } from '../../util'; import { Renderer } from '../renderer/renderer'; import { SpriteCoords } from '../sprite'; @@ -14,33 +13,22 @@ export function loadImage(url: string): Promise { export function mkTexture( r: Renderer, src: HTMLCanvasElement|HTMLImageElement, - frame: number = 0, - total: number = 1, -): [WebGLTexture, SpriteCoords] { +): [WebGLTexture, [number, number]] { const gl = r.getContext(); const texture = gl.createTexture(); if (!texture) throw new Error('unable to create texture'); - const w = src.width, h = src.height / total; - - const canvas = document.createElement('canvas'); - canvas.width = w; - canvas.height = h; - - const ctx = canvas.getContext('2d') as CanvasRenderingContext2D; - ctx.drawImage(src, 0, frame * h, w, h, 0, 0, w, h); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas); + 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); - const coords: SpriteCoords = [ - 0, 0, w / r.coordScale, h / r.coordScale, + const size: [number, number] = [ + src.width / r.coordScale, src.height / r.coordScale, ]; - return [texture, coords]; + return [texture, size]; } -- cgit v1.2.3