setup method

void setup(
  1. Object3D object,
  2. Material material,
  3. WebGLProgram program,
  4. BufferGeometry geometry,
  5. BufferAttribute<NativeArray<num>>? index,
)

Implementation

void setup(
  Object3D object,
  Material material,
  WebGLProgram program,
  BufferGeometry geometry,
  BufferAttribute? index,
) {
  bool updateBuffers = false;

  if (vaoAvailable) {
    final state = getBindingState(geometry, program, material);

    if (currentState != state) {
      currentState = state;
      bindVertexArrayObject(currentState["object"]);
    }

    updateBuffers = needsUpdate(object, geometry, program, index);
    // print("WebGLBindingStates.dart setup object: ${object}  updateBuffers: ${updateBuffers}  ");

    if (updateBuffers) saveCache(object, geometry, program, index);
  }
  else {
    final wireframe = (material.wireframe == true);

    if (
      currentState["geometry"] != geometry.id ||
      currentState["program"] != program.id ||
      currentState["wireframe"] != wireframe
    ) {
      currentState["geometry"] = geometry.id;
      currentState["program"] = program.id;
      currentState["wireframe"] = wireframe;

      updateBuffers = true;
    }
  }

  if (index != null) {
    attributes.update(index, WebGL.ELEMENT_ARRAY_BUFFER);
  }

  if (updateBuffers || forceUpdate) {
    forceUpdate = false;

    setupVertexAttributes(object, material, program, geometry);

    if (index != null) {
      final buf = attributes.get(index)["buffer"];
      gl.bindBuffer(WebGL.ELEMENT_ARRAY_BUFFER, buf);
    }
  }
}