MCPcopy
hub / github.com/tensorflow/tfjs / uploadDenseMatrixToTexture

Function uploadDenseMatrixToTexture

tfjs-backend-webgl/src/gpgpu_util.ts:181–213  ·  view source on GitHub ↗
(
    gl: WebGLRenderingContext, texture: WebGLTexture, width: number,
    height: number, data: TypedArray, textureConfig: TextureConfig)

Source from the content-addressed store, hash-verified

179}
180
181export 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
215export function uploadPixelDataToTexture(
216 gl: WebGLRenderingContext, texture: WebGLTexture,

Callers

nothing calls this directly

Calls 3

envFunction · 0.90
getNumberMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…