drawBuffers method

void drawBuffers(
  1. dynamic renderTarget,
  2. Framebuffer? framebuffer
)

Implementation

void drawBuffers(renderTarget, Framebuffer? framebuffer) {
  dynamic drawBuffers = defaultDrawbuffers;

  bool needsUpdate = false;

  if (renderTarget != null) {
    drawBuffers = currentDrawbuffers.get(framebuffer);

    if (drawBuffers == null) {
      drawBuffers = [];
      currentDrawbuffers.set(framebuffer, drawBuffers);
    }

    if (renderTarget is WebGLMultipleRenderTargets) {
      final textures = (renderTarget.texture as GroupTexture).children;

      if (drawBuffers.length != textures.length || drawBuffers[0] != WebGL.COLOR_ATTACHMENT0) {
        for (int i = 0, il = textures.length; i < il; i++) {
          if(drawBuffers.length <= i){
            drawBuffers.add(WebGL.COLOR_ATTACHMENT0 + i);
          }
          else{
            drawBuffers[i] = WebGL.COLOR_ATTACHMENT0 + i;
          }
        }

        drawBuffers.length = textures.length;

        needsUpdate = true;
      }
    }
    else {
      if (drawBuffers.length == 0 || drawBuffers[0] != WebGL.COLOR_ATTACHMENT0) {
        if (drawBuffers.length == 0) {
          drawBuffers.add(WebGL.COLOR_ATTACHMENT0);
        }
        else {
          drawBuffers[0] = WebGL.COLOR_ATTACHMENT0;
        }

        drawBuffers.length = 1;

        needsUpdate = true;
      }
    }
  } else {
    if (drawBuffers.length == 0 || drawBuffers[0] != WebGL.BACK) {
      if (drawBuffers.length == 0) {
        drawBuffers.add(WebGL.BACK);
      } else {
        drawBuffers[0] = WebGL.BACK;
      }

      drawBuffers.length = 1;

      needsUpdate = true;
    }
  }

  if (needsUpdate) {
    if (capabilities.isWebGL2) {
      Uint32Array buf = Uint32Array.fromList(List<int>.from(drawBuffers));
      gl.drawBuffers(buf);
      buf.dispose();
    }
    else {
      extensions.get('WEBGL_draw_buffers').drawBuffersWEBGL(List<int>.from(drawBuffers));
    }
  }
}