createDepth static method

GpuTexture createDepth({
  1. required int width,
  2. required int height,
  3. int samples = 1,
})

Implementation

static GpuTexture createDepth({required int width, required int height, int samples = 1}) {
  final wgpu = WebgpuRend.instance.wgpu;
  return using((arena) {
    final desc = arena<WGPUTextureDescriptor>();
    desc.ref.label.data = nullptr;
    desc.ref.label.length = 0;
    desc.ref.usage = WGPUTextureUsage_RenderAttachment;
    desc.ref.dimension = WGPUTextureDimension.WGPUTextureDimension_2D;
    desc.ref.size.width = width;
    desc.ref.size.height = height;
    desc.ref.size.depthOrArrayLayers = 1;
    desc.ref.format = WGPUTextureFormat.WGPUTextureFormat_Depth24Plus;
    desc.ref.mipLevelCount = 1;
    desc.ref.sampleCount = samples;
    desc.ref.viewFormatCount = 0;
    desc.ref.viewFormats = nullptr;

    final texHandle =
        wgpu.wgpuDeviceCreateTexture(WebgpuRend.instance.device, desc);

    final viewDesc = arena<WGPUTextureViewDescriptor>();
    viewDesc.ref.label.data = nullptr;
    viewDesc.ref.label.length = 0;
    viewDesc.ref.format = WGPUTextureFormat.WGPUTextureFormat_Depth24Plus;
    viewDesc.ref.dimension =
        WGPUTextureViewDimension.WGPUTextureViewDimension_2D;
    viewDesc.ref.baseMipLevel = 0;
    viewDesc.ref.mipLevelCount = 1;
    viewDesc.ref.baseArrayLayer = 0;
    viewDesc.ref.arrayLayerCount = 1;
    viewDesc.ref.aspect = WGPUTextureAspect.WGPUTextureAspect_DepthOnly;

    final viewHandle = wgpu.wgpuTextureCreateView(texHandle, viewDesc);

    return GpuTexture._(
        texHandle.cast(), -1, texHandle, viewHandle, width, height, false);
  });
}