uploadFull method

void uploadFull(
  1. RenderingContext gl,
  2. List<int> indices, {
  3. Caps? caps,
})

Uploads a complete array of splat indices to the texture.

The indices array contains the rendering order of splats, stored in row-major order within the 2D texture. If the required texture size exceeds the current allocation, the texture will be resized with additional headroom to minimize future reallocations.

Returns immediately if indices is empty.

Implementation

void uploadFull(RenderingContext gl, List<int> indices, {Caps? caps}) {
  if (indices.isEmpty) return;
  if (texture == null) {
    // decide once when we first allocate
    _useR32UI = caps?.hasIntegerTex ?? false;
  }
  final neededRows = (indices.length + width - 1) ~/ width;
  if (texture == null || _allocHeight < neededRows) {
    _allocHeight = (neededRows * 5) ~/ 4 + 1;
    _createOrResize(gl, _allocHeight);
  } else {
    gl.bindTexture(WebGL.TEXTURE_2D, texture);
  }

  final totalTexels = neededRows * width;
  if (_useR32UI) {
    final u32 = Uint32Array(totalTexels); // zero-initialized
    for (var i = 0; i < indices.length; ++i) {
      u32[i] = indices[i];
    }
    gl.texSubImage2D(WebGL.TEXTURE_2D, 0, 0, 0, width, neededRows,
        WebGL.RED_INTEGER, WebGL.UNSIGNED_INT, u32,);
  } else {
    // pack into R channel of RGBA32F
    final f32 = Float32Array(totalTexels * 4); // zero-initialized
    for (var i = 0; i < indices.length; ++i) {
      f32[i * 4] = indices[i].toDouble();
    }
    gl.texSubImage2D(WebGL.TEXTURE_2D, 0, 0, 0, width, neededRows, WebGL.RGBA,
        WebGL.FLOAT, f32,);
  }
  height = neededRows;
}