setImageFromAsset method
Loads the skydome texture from a Flutter asset and prepares mipmaps.
The shader program is ensured (compiled/linked) in the background; drawing safely no-ops until both the program and texture are available.
Implementation
Future<void> setImageFromAsset(String assetPath) async {
// Intentionally don't await; draw() will early-return until ready.
unawaited(_ensureProgram());
_tex ??= _gl.createTexture();
_gl
..bindTexture(WebGL.TEXTURE_2D, _tex)
..texParameteri(
WebGL.TEXTURE_2D,
WebGL.TEXTURE_WRAP_S,
WebGL.CLAMP_TO_EDGE,
)
..texParameteri(
WebGL.TEXTURE_2D,
WebGL.TEXTURE_WRAP_T,
WebGL.CLAMP_TO_EDGE,
)
..texParameteri(
WebGL.TEXTURE_2D,
WebGL.TEXTURE_MIN_FILTER,
WebGL.LINEAR_MIPMAP_LINEAR,
)
..texParameteri(WebGL.TEXTURE_2D, WebGL.TEXTURE_MAG_FILTER, WebGL.LINEAR)
..pixelStorei(WebGL.UNPACK_ALIGNMENT, 1);
await _gl.texImage2DfromAsset(
WebGL.TEXTURE_2D,
assetPath,
internalformat: WebGL.RGBA,
type: WebGL.UNSIGNED_BYTE,
);
_gl.generateMipmap(WebGL.TEXTURE_2D);
_ready = true;
}