deallocateTexture method

void deallocateTexture(
  1. Texture texture
)

Implementation

void deallocateTexture(Texture texture) {
  final textureProperties = properties.get(texture);

  if (textureProperties["__webglInit"] == null) return;

  // check if it's necessary to remove the WebGLTexture object

  final source = texture.source;
  final webglTextures = _sources.get(source);

  if (webglTextures != null) {
    Map webglTexture = webglTextures[textureProperties["__cacheKey"]];
    webglTexture["usedTimes"]--;

    // the WebGLTexture object is not used anymore, remove it

    if (webglTexture["usedTimes"] == 0) {
      deleteTexture(texture);
    }

    // remove the weak map entry if no WebGLTexture uses the source anymore

    if (webglTextures.keys.length == 0) {
      _sources.delete(source);
    }
  }

  properties.remove(texture);
}