initRenderTarget method

dynamic initRenderTarget(
  1. WebGLRenderTarget renderTarget
)

Implementation

initRenderTarget(WebGLRenderTarget renderTarget) {
  var properties = this.properties;
  var renderTargetProperties = properties.get(renderTarget);

  if (renderTargetProperties["initialized"] == undefined) {
    var device = this.device;

    int width = renderTarget.width.toInt();
    int height = renderTarget.height.toInt();
    var colorTextureFormat = this._getFormat(renderTarget.texture);

    var colorTextureGPU = device.createTexture(GPUTextureDescriptor(
        size:
            GPUExtent3D(width: width, height: height, depthOrArrayLayers: 1),
        format: colorTextureFormat,
        sampleCount: renderTarget.samples,
        usage: GPUTextureUsage.RenderAttachment |
            GPUTextureUsage.TextureBinding | GPUTextureUsage.CopySrc));

    this.info.memory["textures"]++;

    renderTargetProperties["colorTextureGPU"] = colorTextureGPU;
    renderTargetProperties["colorTextureFormat"] = colorTextureFormat;


    print("renderTarget.samples: ${renderTarget.samples} ");

    // 多重采样 抗锯齿
    var colorTextureGPUWithSamples = device.createTexture(GPUTextureDescriptor(
        size: GPUExtent3D(width: width, height: height, depthOrArrayLayers: 1),
        format: colorTextureFormat,
        sampleCount: renderTarget.samples,
        usage: GPUTextureUsage.RenderAttachment |
            GPUTextureUsage.TextureBinding | GPUTextureUsage.CopySrc));

    renderTargetProperties["colorTextureGPUWithSamples"] = colorTextureGPUWithSamples;

    // When the ".texture" or ".depthTexture" property of a render target is used as a map,
    // the renderer has to find the respective GPUTexture objects to setup the bind groups.
    // Since it's not possible to see just from a texture object whether it belongs to a render
    // target or not, we need the initializedRTT flag.

    var textureProperties = properties.get(renderTarget.texture);
    textureProperties["textureGPU"] = colorTextureGPU;
    textureProperties["initializedRTT"] = false;

    if (renderTarget.depthBuffer == true) {
      var depthTextureFormat =
          GPUTextureFormat.Depth24PlusStencil8; // @TODO: Make configurable

      var depthTextureGPU = device.createTexture(GPUTextureDescriptor(
          size: GPUExtent3D(
              width: width, height: height, depthOrArrayLayers: 1),
          format: depthTextureFormat,
          usage: GPUTextureUsage.RenderAttachment));

      this.info.memory["textures"]++;

      renderTargetProperties["depthTextureGPU"] = depthTextureGPU;
      renderTargetProperties["depthTextureFormat"] = depthTextureFormat;

      if (renderTarget.depthTexture != null) {
        var depthTextureProperties =
            properties.get(renderTarget.depthTexture);
        depthTextureProperties["textureGPU"] = depthTextureGPU;
        depthTextureProperties["initializedRTT"] = false;
      }
    }

    //

    // var disposeCallback = onRenderTargetDispose.bind( this );
    // renderTargetProperties.disposeCallback = disposeCallback;

    // renderTarget.addEventListener( 'dispose', disposeCallback );

    //

    renderTargetProperties["initialized"] = true;
  }
}