API Docs for: 1.4.0
Show:

Kiwi.Renderers.GLTextureManager Class

Module: Renderers
Parent Module: Kiwi

Manages GL Texture objects, including creation, uploading, destruction and memory management

Constructor

Kiwi.Renderers.GLTextureManager

() GLTextureManager

Returns:

GLTextureManager:

Methods

_addTextureToCache

(
  • glTexture
)
private

Adds a texture wrapper to the cache

Parameters:

  • glTexture GLTextureWrapper

_deleteTexture

(
  • gl
  • idx
)
private

Deletes a texture from memory and removes the wrapper from the cache

Parameters:

  • gl WebGLRenderingContext
  • idx Number

_freeSpace

(
  • gl
  • numBytesToRemove
)
private

Attempts to free space in video memory.

This removes textures sequentially, starting from the first cached texture. This may remove textures that are in use. These should automatically re-upload into the last position. After a few frames, this will push in-use textures to the safe end of the queue.

If there are too many textures in use to fit in memory, they will all be cycled every frame, even if it would be more efficient to swap out one or two very large textures and preserve several smaller ones. This is an issue with this implementation and should be fixed.

This behaviour was changed in v1.1.0. Previous versions used a different memory freeing algorithm.

Parameters:

  • gl WebGLRenderingContext
  • numBytesToRemove Number

Returns:

boolean

_uploadTexture

(
  • gl
  • glTextureWrapper
)
private

Uploads a texture to video memory

Parameters:

  • gl WebGLRenderingContext
  • glTextureWrapper GLTextureWrapper

Returns:

boolean

clearTextures

(
  • gl
)
public

Removes all textures from video memory and clears the wrapper cache

Parameters:

  • gl WebGLRenderingContext

registerTextureWrapper

(
  • gl
  • glTextureWrapper
)
public

Defined in src\render\GLTextureManager.ts:154

Available since 1.1.0

Adds a texture wrapper to the manager. This both adds the wrapper to the manager cache, and attempts to upload the attached texture to video memory.

Parameters:

  • gl WebGLRenderingContext
  • glTextureWrapper GLTextureWrapper

uploadTexture

(
  • gl
  • textureAtlas
)
public

Uploads a single texture to video memory

Parameters:

uploadTextureLibrary

(
  • gl
  • textureLibrary
)
public

Uploads a texture library to video memory

Parameters:

useTexture

(
  • gl
  • glTextureWrapper
  • [textureUnit=0]
)
public

Binds the texture ready for use, uploads it if it isn't already

Parameters:

  • gl WebGLRenderingContext
  • glTextureWrapper GLTextureWrappery
  • [textureUnit=0] Number optional

    Optional parameter for multitexturing. You can have up to 32 textures available to a shader at one time, in the range 0-31. If you don't need multiple textures, this is perfectly safe to ignore.

Returns:

boolean

Properties

_textureWrapperCache

GLTextureWrapper private

An array of references to all texture wrappers

DEFAULT_MAX_TEX_MEM_MB

Number public static

The default maximum amount of texture memory to use before swapping textures

maxTextureMem

Number public

The maximum amount of texture memory to use before swapping textures, initialised from DEFAULT_MAX_TEX_MEM_MB

numTextureWrites

Number public

The number of textures uploads in the last frame

usedTextureMem

Number public

The amount of texture memory currently uplaoded

usedTextureMem

Number public

The number of textures currently uplaoded