init method
Create GL objects, compile shaders, cache uniform locations.
Implementation
@override
Future<void> init(RenderingContext gl, {Caps? caps}) async {
// Intentionally don't await; draw() will early-return until ready.
unawaited(_ensureProgram(gl));
// 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.
_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);
}