Class: TextureSource

TextureSource

A TextureSource stores the information that represents an image. All textures have require TextureSource, which contains information about the source. Therefore you can have many textures all using a single TextureSource (eg a sprite sheet)

This is an class is extended depending on the source of the texture. Eg if you are using an an image as your resource, then an ImageSource is used.

new TextureSource (options)

Name Type Description
options TextureSourceOptions<T>

options for creating a new TextureSource

Extends

  • EventEmitter

Implements

Members

defaultOptions TextureSourceOptions static

The default options used when creating a new TextureSource. override these to add your own defaults

from (resource: TextureResourceOrOptions) => TextureSource static

A helper function that creates a new TextureSource based on the resource you provide.

_resourceId

i unique resource id, used by the bind group systems. This can change if the texture is resized or its resource changes

addressMode WRAP_MODE

setting this will set wrapModeU,wrapModeV and wrapModeW all at once!

alphaMode ALPHA_MODES

the alpha mode of the texture

antialias boolean

Only really affects RenderTextures. Should we use antialiasing for this texture. It will look better, but may impact performance as a Blit operation will be required to resolve the texture.

Default Value:
  • false

autoGarbageCollect boolean

If true, the Garbage Collector will unload this texture if it is not used after a period of time

autoGenerateMipmaps boolean

Should we auto generate mipmaps for this texture? This will automatically generate mipmaps for this texture when uploading to the GPU. Mipmapped textures take up more memory, but can look better when scaled down.

For performance reasons, it is recommended to NOT use this with RenderTextures, as they are often updated every frame. If you do, make sure to call updateMipmaps after you update the texture.

Default Value:
  • false

destroyed boolean readonly

Has the source been destroyed?

dimension TEXTURE_DIMENSIONS

how many dimensions does this texture have? currently v8 only supports 2d

Default Value:
  • "2d"

format TEXTURE_FORMATS

the format that the texture data has

Default Value:
  • "rgba8unorm"

height number

the height of this texture source, accounting for resolution eg pixelHeight 200, resolution 2, then height will be 100

Default Value:
  • 1

label string

optional label, can be used for debugging

lodMaxClamp number

Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture.

lodMinClamp number

Specifies the minimum and maximum levels of detail, respectively, used internally when sampling a texture.

magFilter SCALE_MODE

Specifies the sampling behavior when the sample footprint is smaller than or equal to one texel.

minFilter SCALE_MODE

Specifies the sampling behavior when the sample footprint is larger than one texel.

mipLevelCount number

The number of mip levels to generate for this texture. this is overridden if autoGenerateMipmaps is true

Default Value:
  • 1

mipmapFilter SCALE_MODE

Specifies behavior for sampling between mipmap levels.

pixelHeight number

the pixel height of this texture source. This is the REAL pure number, not accounting resolution

Default Value:
  • 1

pixelWidth number

the pixel width of this texture source. This is the REAL pure number, not accounting resolution

Default Value:
  • 1

repeatMode WRAP_MODE

setting this will set wrapModeU,wrapModeV and wrapModeW all at once!

resolution number

the resolution of the texture. Changing this number, will not change the number of pixels in the actual texture but will the size of the texture when rendered.

changing the resolution of this texture to 2 for example will make it appear twice as small when rendered (as pixel density will have increased)

resource T

the resource that will be upladed to the GPU. This is where we get our pixels from eg an ImageBimt / Canvas / Video etc

resourceHeight number

the height of the resource. This is the REAL pure number, not accounting resolution

resourceWidth number

the width of the resource. This is the REAL pure number, not accounting resolution

scaleMode SCALE_MODE

setting this will set magFilter,minFilter and mipmapFilter all at once!

source TextureSource

returns itself

style TextureStyle

the style of the texture

uid readonly

unique id for this Texture source

width number

the width of this texture source, accounting for resolution eg pixelWidth 200, resolution 2, then width will be 100

Default Value:
  • 1

_batchTick number protected

Used by the batcher to build texture batches. faster to have the variable here!

Default Value:
  • -1

_textureBindLocation number protected

A temporary batch location for the texture batching. Here for performance reasons only!

Default Value:
  • -1

_touched number protected

Used by automatic texture Garbage Collection, stores last GC tick when it was bound

Default Value:
  • 0

options protectedreadonly

Methods

destroy ()

Destroys this texture source

resize (width, height, resolution) boolean

Resize the texture, this is handy if you want to use the texture as a render texture

Name Type Attributes Description
width number <optional>

the new width of the texture

height number <optional>

the new height of the texture

resolution number <optional>

the new resolution of the texture

Returns:
Type Description
boolean
  • if the texture was resized

unload ()

This will unload the Texture source from the GPU. This will free up the GPU memory As soon as it is required fore rendering, it will be re-uploaded.

update ()

call this if you have modified the texture outside of the constructor

updateMipmaps ()

Lets the renderer know that this texture has been updated and its mipmaps should be re-generated. This is only important for RenderTexture instances, as standard Texture instances will have their mipmaps generated on upload. You should call this method after you make any change to the texture

The reason for this is is can be quite expensive to update mipmaps for a texture. So by default, We want you, the developer to specify when this action should happen.

Generally you don't want to have mipmaps generated on Render targets that are changed every frame,