(
shape: [number, number], physicalTexType: PhysicalTextureType,
gl: WebGLRenderingContext, textureConfig: TextureConfig,
isPacked: boolean)
| 205 | } |
| 206 | |
| 207 | export function computeBytes( |
| 208 | shape: [number, number], physicalTexType: PhysicalTextureType, |
| 209 | gl: WebGLRenderingContext, textureConfig: TextureConfig, |
| 210 | isPacked: boolean): number { |
| 211 | // It is not possible to infer packed status from the texture type because |
| 212 | // depending on the textureConfig, different texture types may resolve to the |
| 213 | // same internal format (e.g. in WebGL1, the internal format for |
| 214 | // UNPACKED_FLOAT16 textures is gl.RGBA). Therefore we pass in `isPacked` |
| 215 | // explicitly. |
| 216 | const internalFormat = |
| 217 | internalFormatForPhysicalTexType(physicalTexType, textureConfig); |
| 218 | |
| 219 | let numElements: number; |
| 220 | if (isPacked) { |
| 221 | const [packedWidth, packedHeight] = |
| 222 | getPackedMatrixTextureShapeWidthHeight(shape[0], shape[1]); |
| 223 | numElements = packedWidth * packedHeight; |
| 224 | |
| 225 | } else { |
| 226 | const [width, height] = |
| 227 | getUnpackedMatrixTextureShapeWidthHeight(shape[0], shape[1]); |
| 228 | numElements = width * height; |
| 229 | } |
| 230 | |
| 231 | const bytesPerElement = numBytesForInternalFormat(gl, internalFormat); |
| 232 | return numElements * bytesPerElement; |
| 233 | } |
| 234 | |
| 235 | function internalFormatForPhysicalTexType( |
| 236 | physicalTexType: PhysicalTextureType, |
no test coverage detected
searching dependent graphs…