(
gl: WebGL2RenderingContext, inputTexture: WebGLTexture,
inputDims: Dimensions, outputDims: Dimensions, alignCorners: boolean,
useCustomShadersToResize: boolean,
interpolation: 'nearest_neighbor'|'bilinear', rotation: Rotation)
| 176 | } |
| 177 | |
| 178 | export function runResizeProgram( |
| 179 | gl: WebGL2RenderingContext, inputTexture: WebGLTexture, |
| 180 | inputDims: Dimensions, outputDims: Dimensions, alignCorners: boolean, |
| 181 | useCustomShadersToResize: boolean, |
| 182 | interpolation: 'nearest_neighbor'|'bilinear', rotation: Rotation) { |
| 183 | const {program, vao, vertices, uniformLocations} = useCustomShadersToResize ? |
| 184 | resizeProgram(gl, inputDims, outputDims, alignCorners, interpolation) : |
| 185 | drawTextureProgram(gl, false, true, rotation); |
| 186 | gl.useProgram(program); |
| 187 | // Set up geometry |
| 188 | webgl_util.callAndCheck(gl, () => { |
| 189 | gl.bindVertexArray(vao); |
| 190 | }); |
| 191 | |
| 192 | // |
| 193 | // Set up input texture |
| 194 | // |
| 195 | gl.uniform1i(uniformLocations.get('inputTexture'), 1); |
| 196 | gl.activeTexture(gl.TEXTURE0 + 1); |
| 197 | gl.bindTexture(gl.TEXTURE_2D, inputTexture); |
| 198 | if (!useCustomShadersToResize) { |
| 199 | const textureFilter = |
| 200 | interpolation === 'nearest_neighbor' ? gl.NEAREST : gl.LINEAR; |
| 201 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, textureFilter); |
| 202 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, textureFilter); |
| 203 | } |
| 204 | |
| 205 | // |
| 206 | // Set up output texture. |
| 207 | // |
| 208 | if (!resizeTextureCache.has(gl)) { |
| 209 | resizeTextureCache.set(gl, gl.createTexture()); |
| 210 | } |
| 211 | const resizeTexture = resizeTextureCache.get(gl); |
| 212 | |
| 213 | const targetTexture = resizeTexture; |
| 214 | const targetTextureWidth = outputDims.width; |
| 215 | const targetTextureHeight = outputDims.height; |
| 216 | |
| 217 | gl.activeTexture(gl.TEXTURE0 + 2); |
| 218 | gl.bindTexture(gl.TEXTURE_2D, targetTexture); |
| 219 | |
| 220 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 221 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 222 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 223 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 224 | |
| 225 | // Reallocate texture storage if target size has changed. |
| 226 | if (!resizeTextureDimsCache.has(gl)) { |
| 227 | resizeTextureDimsCache.set(gl, {width: -1, height: -1}); |
| 228 | } |
| 229 | const resizeTextureDims = resizeTextureDimsCache.get(gl); |
| 230 | |
| 231 | if (resizeTextureDims == null || |
| 232 | resizeTextureDims.width !== targetTextureWidth || |
| 233 | resizeTextureDims.height !== targetTextureHeight) { |
| 234 | const level = 0; |
| 235 | const format = outputDims.depth === 3 ? gl.RGB : gl.RGBA; |
no test coverage detected
searching dependent graphs…