parseUniform function

void parseUniform(
  1. ActiveInfo activeInfo,
  2. UniformLocation addr,
  3. WebGLUniform container
)

Implementation

void parseUniform(ActiveInfo activeInfo, UniformLocation addr, WebGLUniform container) {
  final path = activeInfo.name;
  final pathLength = path.length;

  //console.info("WebGLUniformsHelper.parseUniform path: $path addr: ${addr.id} ");

  // reset RegExp object, because of the early exit of a previous run
  // RePathPart.lastIndex = 0;

  final matches = rePathPart.allMatches(path);

  for (final match in matches) {
    dynamic id = match.group(1);
    final idIsIndex = match.group(2) == ']';
    final subscript = match.group(3);

    if (idIsIndex) id = int.parse(id); // convert to integer

    final matchEnd = match.end;

    if (subscript == null || subscript == '[' && matchEnd + 2 == pathLength) {
      // bare name or "pure" bottom-level array "[0]" suffix
      addUniform(container, subscript == null ? SingleUniform(id, activeInfo, addr) : PureArrayUniform(id, activeInfo, addr));
      break;
    }
    else {
      // step into inner node / create it in case it doesn't exist

      final map = container.map;
      StructuredUniform? next = map[id];

      if (next == null) {
        next = StructuredUniform(id);
        addUniform(container, next);
      }

      container = next;
    }
  }
}