| 179 | } |
| 180 | |
| 181 | export function uploadDenseMatrixToTexture( |
| 182 | gl: WebGLRenderingContext, texture: WebGLTexture, width: number, |
| 183 | height: number, data: TypedArray, textureConfig: TextureConfig) { |
| 184 | webgl_util.callAndCheck(gl, () => gl.bindTexture(gl.TEXTURE_2D, texture)); |
| 185 | |
| 186 | let dataForUpload: TypedArray, texelDataType: number, internalFormat: number; |
| 187 | if (data instanceof Uint8Array) { |
| 188 | dataForUpload = new Uint8Array(width * height * 4); |
| 189 | texelDataType = gl.UNSIGNED_BYTE; |
| 190 | internalFormat = gl.RGBA; |
| 191 | } else { |
| 192 | dataForUpload = new Float32Array(width * height * 4); |
| 193 | texelDataType = gl.FLOAT; |
| 194 | internalFormat = textureConfig.internalFormatPackedFloat; |
| 195 | } |
| 196 | |
| 197 | dataForUpload.set(data); |
| 198 | if (env().getNumber('WEBGL_VERSION') === 2) { |
| 199 | webgl_util.callAndCheck( |
| 200 | gl, |
| 201 | () => gl.texSubImage2D( |
| 202 | gl.TEXTURE_2D, 0, 0, 0, width, height, gl.RGBA, texelDataType, |
| 203 | dataForUpload)); |
| 204 | } else { |
| 205 | webgl_util.callAndCheck( |
| 206 | gl, |
| 207 | () => gl.texImage2D( |
| 208 | gl.TEXTURE_2D, 0, internalFormat, width, height, 0, gl.RGBA, |
| 209 | texelDataType, dataForUpload)); |
| 210 | } |
| 211 | |
| 212 | webgl_util.callAndCheck(gl, () => gl.bindTexture(gl.TEXTURE_2D, null)); |
| 213 | } |
| 214 | |
| 215 | export function uploadPixelDataToTexture( |
| 216 | gl: WebGLRenderingContext, texture: WebGLTexture, |