| 45 | } |
| 46 | |
| 47 | function createTexture(gl, filter, data, width, height) { |
| 48 | var texture = gl.createTexture(); |
| 49 | gl.bindTexture(gl.TEXTURE_2D, texture); |
| 50 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 51 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 52 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter); |
| 53 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter); |
| 54 | if (data instanceof Uint8Array) { |
| 55 | gl.texImage2D( |
| 56 | gl.TEXTURE_2D, |
| 57 | 0, |
| 58 | gl.RGBA, |
| 59 | width, |
| 60 | height, |
| 61 | 0, |
| 62 | gl.RGBA, |
| 63 | gl.UNSIGNED_BYTE, |
| 64 | data |
| 65 | ); |
| 66 | } else { |
| 67 | gl.texImage2D( |
| 68 | gl.TEXTURE_2D, |
| 69 | 0, |
| 70 | gl.RGBA, |
| 71 | gl.RGBA, |
| 72 | gl.UNSIGNED_BYTE, |
| 73 | data |
| 74 | ); |
| 75 | } |
| 76 | gl.bindTexture(gl.TEXTURE_2D, null); |
| 77 | return texture; |
| 78 | } |
| 79 | |
| 80 | function bindTexture(gl, texture, unit) { |
| 81 | gl.activeTexture(gl.TEXTURE0 + unit); |