Skip to content

ImageTexture

Image texture

Helper class storing image as a WebGL texture. Used by shader classes and renderers as wrapper around images providing convenient interfaces.

Constructors

new ImageTexture()

new ImageTexture(gl, size, grayscale, linear, mipmap): ImageTexture

Constructor

Parameters

gl: WebGL2RenderingContext

Context where texture is allocated

size: Size = ...

Size of the image

grayscale: boolean = false

Whether image is grayscsale or rgb

linear: boolean = false

Whether interpolation is linear or nearest

mipmap: boolean = false

Returns

ImageTexture

Properties

buffer

protected buffer: null | WebGLTexture = null

Input image texture


gl

protected gl: WebGL2RenderingContext

Context where texture is allocated


grayscale

protected grayscale: boolean = false

Whether image is grayscsale or rgb


levels

protected levels: number = 0

Number of mipmap levels


linear

protected linear: boolean = false

Whether interpolation is linear or nearest


mipmap

protected mipmap: boolean = false


size

protected size: Size

Size of the image

Methods

dispose()

dispose(): void

Dispose allocated resources

Returns

void


genLevels()

genLevels(): boolean

Generate mipmap levels if enabled

Returns

boolean


isGrayscale()

isGrayscale(): boolean

Whether texture is grayscale

Returns

boolean

True if texture is grayscale


levelCount()

levelCount(): number

Number of mipmap levels

Returns

number


levelSize()

levelSize(level): Size

Size of the mipmap level

Parameters

level: number

Returns

Size


resize()

resize(size): boolean

Resize texture

Parameters

size: Size

New size of the image

Returns

boolean

True when successfully resized, false otherwise


texture()

texture(): null | WebGLTexture

Texture instance

Returns

null | WebGLTexture

Instance of the texture


textureSize()

textureSize(): Size

Texture size

Returns

Size

Size of the texture


update()

update(image): null | WebGLTexture

Update texture

Parameters

image: ImageSource

Image to upload into texture

Returns

null | WebGLTexture

Updated texture


valid()

valid(): boolean

Whether texture is allocated and valid

Returns

boolean

True if texture is allocated, false otherwise