Skip to content

Missing type for minFilter and magFilter in createTexture #60

Description

@benbro

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
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions