loadTexture method

Texture loadTexture(
  1. String path, [
  2. int textureFlags = TextureFlags.defaultFlags
])

Loads a Texture from the given path.

If the texture at path has already been loaded, a cached version is returned and its reference count is incremented. Otherwise, a new texture is loaded, cached, and returned.

  • path: The path to the texture file.
  • textureFlags: Optional flags to control texture parameters like filtering and wrapping. Defaults to TextureFlags.defaultFlags.

Returns the loaded or cached Texture.

Implementation

Texture loadTexture(String path, [int textureFlags = TextureFlags.defaultFlags]) {
  var texture = _textureCache[path];
  var newTex = texture == null;
  if (newTex) {
    texture = Texture.load(_gl, _loadingInfo, path, textureFlags);
    texture.onDispose((Texture texture) {
      _textureCache.remove(path);
    });
    _textureCache[path] = texture;
  } else {
    texture.retain();
  }

  return texture;
}