(
imageData: Uint8Array, gl: WebGL2RenderingContext, dims: Dimensions,
texture?: WebGLTexture)
| 106 | * texture will be returned |
| 107 | */ |
| 108 | export function uploadTextureData( |
| 109 | imageData: Uint8Array, gl: WebGL2RenderingContext, dims: Dimensions, |
| 110 | texture?: WebGLTexture): WebGLTexture { |
| 111 | const targetTextureWidth = dims.width; |
| 112 | const targetTextureHeight = dims.height; |
| 113 | |
| 114 | tf.util.assert( |
| 115 | targetTextureWidth * targetTextureHeight * dims.depth === |
| 116 | imageData.length, |
| 117 | () => 'uploadTextureData Error: imageData length must match w * h * d'); |
| 118 | |
| 119 | const targetTexture = texture || gl.createTexture(); |
| 120 | gl.activeTexture(gl.TEXTURE0); |
| 121 | gl.bindTexture(gl.TEXTURE_2D, targetTexture); |
| 122 | |
| 123 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 124 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 125 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 126 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 127 | |
| 128 | const level = 0; |
| 129 | const format = dims.depth === 3 ? gl.RGB : gl.RGBA; |
| 130 | const internalFormat = format; |
| 131 | const border = 0; |
| 132 | const type = gl.UNSIGNED_BYTE; |
| 133 | |
| 134 | webgl_util.callAndCheck(gl, () => { |
| 135 | gl.texImage2D( |
| 136 | gl.TEXTURE_2D, level, internalFormat, targetTextureWidth, |
| 137 | targetTextureHeight, border, format, type, imageData); |
| 138 | }); |
| 139 | |
| 140 | gl.bindTexture(gl.TEXTURE_2D, null); |
| 141 | return targetTexture; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Render a texture to the default framebuffer (i.e. screen) |
no outgoing calls
no test coverage detected
searching dependent graphs…