Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing type for minFilter and magFilter in createTexture #60

Open
benbro opened this issue Jun 3, 2023 · 0 comments
Open

Missing type for minFilter and magFilter in createTexture #60

benbro opened this issue Jun 3, 2023 · 0 comments

Comments

@benbro
Copy link

benbro commented Jun 3, 2023

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 benbro changed the title Wrong type for minFilter and magFilter in createTexture Missing type for minFilter and magFilter in createTexture Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant