init method

  1. @override
Future<void> init(
  1. RenderingContext gl, {
  2. Caps? caps,
})
override

Create GL objects, compile shaders, cache uniform locations.

Implementation

@override
Future<void> init(RenderingContext gl, {Caps? caps}) async {
  var vs = await flutter_services.rootBundle.loadString(vsAsset);
  final fs = await flutter_services.rootBundle.loadString(fsAsset);

  // Add shader define based on texture format support
  if (caps?.hasIntegerTex ?? false) {
    vs = injectAfterVersion(vs, '#define USE_INTEGER_TEXTURE');
  }

  _prog = ShaderFactory.compile(
    gl,
    vertexSource: vs,
    fragmentSource: fs,
    attribBindings: {'position': 0},
  );

  _uProjection = gl.getUniformLocation(_prog!, 'projection');
  _uView = gl.getUniformLocation(_prog!, 'view');
  _uFocal = gl.getUniformLocation(_prog!, 'focal');
  _uViewport = gl.getUniformLocation(_prog!, 'viewport');
  _uSplatCount = gl.getUniformLocation(_prog!, 'splatCount');
  _uOrderTexture = gl.getUniformLocation(_prog!, 'u_orderTexture');
  _uTexture = gl.getUniformLocation(_prog!, 'u_texture');
  _uMaxSplatSize = gl.getUniformLocation(_prog!, 'uMaxSplatSize');
  _cacheAttributeLocations(gl);

  _createQuadBuffers(gl);
  _recomputeInstanceCount();

  // Bind samplers to fixed texture units once (no per-frame cost).
  gl.useProgram(_prog);
  if (_uTexture != null) {
    gl.uniform1i(_uTexture!, 0); // splat atlas -> TEXTURE0
  }
  if (_uOrderTexture != null) {
    gl.uniform1i(_uOrderTexture!, 1); // order map -> TEXTURE1
  }
}