virtual-background icon indicating copy to clipboard operation
virtual-background copied to clipboard

Missing type for minFilter and magFilter in createTexture

Open benbro opened this issue 2 years ago • 0 comments

When compiling a project with typescript 5.0.2 I'm getting the following error in three places:

Argument of type '9729' is not assignable to parameter of type '9728'

https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/backgroundBlurStage.ts#L125 https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/backgroundBlurStage.ts#L133 https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/webgl2/backgroundImageStage.ts#L155

The function createTexture is defined without types for magFilter and minFilter: https://github.com/Volcomix/virtual-background/blob/main/src/pipelines/helpers/webglHelper.ts#L67

Allowed values for magFilter https://github.com/KhronosGroup/glTF/blob/main/specification/1.0/README.md#samplermagfilter

Allowed values for MinFilter https://github.com/KhronosGroup/glTF/blob/main/specification/1.0/README.md#samplerminfilter

Fix:

export function createTexture(
  gl: WebGL2RenderingContext,
  internalformat: number,
  width: number,
  height: number,
  minFilter: number = gl.NEAREST,
  magFilter: number = gl.NEAREST
) {
  const texture = gl.createTexture()
  gl.bindTexture(gl.TEXTURE_2D, texture)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter)
  gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height)
  return texture
}

Or

export function createTexture(
  gl: WebGL2RenderingContext,
  internalformat: number,
  width: number,
  height: number,
  minFilter: (WebGLRenderingContextBase['NEAREST']|WebGLRenderingContextBase['LINEAR']) = gl.NEAREST,
  magFilter: (WebGLRenderingContextBase['NEAREST']|WebGLRenderingContextBase['LINEAR']|WebGLRenderingContextBase['NEAREST_MIPMAP_NEAREST']|WebGLRenderingContextBase['LINEAR_MIPMAP_NEAREST']|WebGLRenderingContextBase['NEAREST_MIPMAP_LINEAR']|WebGLRenderingContextBase['LINEAR_MIPMAP_LINEAR']) = gl.NEAREST
) {
  const texture = gl.createTexture()
  gl.bindTexture(gl.TEXTURE_2D, texture)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter)
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter)
  gl.texStorage2D(gl.TEXTURE_2D, 1, internalformat, width, height)
  return texture
}

benbro avatar Jun 03 '23 06:06 benbro