Kiwi.Renderers.GLTextureManager Class
Manages GL Texture objects, including creation, uploading, destruction and memory management
Constructor
Kiwi.Renderers.GLTextureManager
()
GLTextureManager
Returns:
Item Index
Methods
Methods
_addTextureToCache
-
glTexture
Adds a texture wrapper to the cache
Parameters:
-
glTexture
GLTextureWrapper
_deleteTexture
-
gl
-
idx
Deletes a texture from memory and removes the wrapper from the cache
Parameters:
-
gl
WebGLRenderingContext -
idx
Number
_freeSpace
-
gl
-
numBytesToRemove
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
Uploads a texture to video memory
Parameters:
-
gl
WebGLRenderingContext -
glTextureWrapper
GLTextureWrapper
Returns:
boolean
clearTextures
-
gl
Removes all textures from video memory and clears the wrapper cache
Parameters:
-
gl
WebGLRenderingContext
registerTextureWrapper
-
gl
-
glTextureWrapper
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
Uploads a single texture to video memory
Parameters:
-
gl
WebGLRenderingContext -
textureAtlas
Kiwi.Textures.TextureAtlas
uploadTextureLibrary
-
gl
-
textureLibrary
Uploads a texture library to video memory
Parameters:
-
gl
WebGLRenderingContext -
textureLibrary
Kiwi.Textures.TextureLibrary
useTexture
-
gl
-
glTextureWrapper
-
[textureUnit=0]
Binds the texture ready for use, uploads it if it isn't already
Parameters:
-
gl
WebGLRenderingContext -
glTextureWrapper
GLTextureWrappery -
[textureUnit=0]
Number optionalOptional 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