begin method

void begin(
  1. Size size, {
  2. BlendState blendState = BlendState.alphaBlend,
  3. DepthStencilState depthStencilState = DepthStencilState.depthRead,
  4. Matrix4? transformMatrix,
})

Begin a new rendering batch.

After begin is called the graphics device can be used to bind resources like Meshs, Materials and Textures.

Once you have executed all your bindings you can submit the batch to the GPU with end.

Implementation

void begin(
  Size size, {
  // TODO(wolfen): unused at the moment
  BlendState blendState = BlendState.alphaBlend,
  // TODO(wolfen): used incorrectly
  DepthStencilState depthStencilState = DepthStencilState.depthRead,
  Matrix4? transformMatrix,
}) {
  _commandBuffer = gpu.gpuContext.createCommandBuffer();
  _hostBuffer = gpu.gpuContext.createHostBuffer();
  _renderPass = _commandBuffer.createRenderPass(_getRenderTarget(size))
    ..setColorBlendEnable(true)
    ..setColorBlendEquation(
      gpu.ColorBlendEquation(
        sourceAlphaBlendFactor: blendState == BlendState.alphaBlend
            ? gpu.BlendFactor.oneMinusSourceAlpha
            : gpu.BlendFactor.one,
      ),
    )
    ..setDepthWriteEnable(depthStencilState == DepthStencilState.depthRead)
    ..setDepthCompareOperation(
      // TODO(wolfen): this is not correctly implemented AT all.
      switch (depthStencilState) {
        DepthStencilState.none => gpu.CompareFunction.never,
        DepthStencilState.standard => gpu.CompareFunction.always,
        DepthStencilState.depthRead => gpu.CompareFunction.less,
      },
    );
  _transformMatrix.setFrom(transformMatrix ?? Matrix4.identity());
}