get method

dynamic get(
  1. dynamic object
)

Implementation

get(object) {
  var device = this.device;
  var material = object.material;

  Map<String, dynamic> cache = this._getCache(object);

  var currentPipeline;

  if (this._needsUpdate(object, cache)) {
    // release previous cache

    if (cache["currentPipeline"] != undefined) {
      this._releaseObject(object);
    }

    // get shader

    WebGPUNodeBuilder nodeBuilder = this.nodes.get(object);

    // programmable stages

    var stageVertex = this.stages.vertex.get(nodeBuilder.vertexShader);

    if (stageVertex == undefined) {
      stageVertex = new WebGPUProgrammableStage(
          device, nodeBuilder.vertexShader, 'vertex');
      this.stages.vertex.set(nodeBuilder.vertexShader, stageVertex);
    }

    var stageFragment = this.stages.fragment.get(nodeBuilder.fragmentShader);

    if (stageFragment == undefined) {
      stageFragment = new WebGPUProgrammableStage(
          device, nodeBuilder.fragmentShader, 'fragment');
      this.stages.fragment.set(nodeBuilder.fragmentShader, stageFragment);
    }

    // determine render pipeline

    currentPipeline = this
        ._acquirePipeline(stageVertex, stageFragment, object, nodeBuilder);

    cache["currentPipeline"] = currentPipeline;

    // keep track of all used times

    currentPipeline.usedTimes++;
    stageVertex.usedTimes++;
    stageFragment.usedTimes++;

    // events

    material.addEventListener('dispose', cache["dispose"]);
  } else {
    currentPipeline = cache["currentPipeline"];
  }

  return currentPipeline;
}