beginRenderPass method
RenderPassEncoder
beginRenderPass(
- GpuTexture texture, {
- Color? clearColor,
- int sampleCount = 1,
- GpuTexture? msaaTexture,
- GpuTexture? depthTexture,
- WGPULoadOp loadOp = WGPULoadOp.WGPULoadOp_Load,
- WGPUStoreOp storeOp = WGPUStoreOp.WGPUStoreOp_Store,
Implementation
RenderPassEncoder beginRenderPass(
GpuTexture texture, {
Color? clearColor,
int sampleCount = 1,
GpuTexture? msaaTexture,
GpuTexture? depthTexture,
WGPULoadOp loadOp = WGPULoadOp.WGPULoadOp_Load,
WGPUStoreOp storeOp = WGPUStoreOp.WGPUStoreOp_Store,
}) {
final scratch = _Scratchpad.instance;
final colorAttr = scratch.colorAttachment;
if (sampleCount > 1) {
if (msaaTexture == null) {
throw ArgumentError("If sampleCount > 1, msaaTexture must be provided");
}
colorAttr.ref.view = msaaTexture.view;
colorAttr.ref.resolveTarget = texture.view;
colorAttr.ref.storeOp = WGPUStoreOp.WGPUStoreOp_Discard;
} else {
// Standard 1x rendering
colorAttr.ref.view = texture.view;
colorAttr.ref.resolveTarget = nullptr;
colorAttr.ref.storeOp = WGPUStoreOp.WGPUStoreOp_Store;
}
colorAttr.ref.loadOp =
clearColor != null ? WGPULoadOp.WGPULoadOp_Clear : loadOp;
colorAttr.ref.depthSlice = 0xFFFFFFFF;
if (clearColor != null) {
colorAttr.ref.clearValue.r = clearColor.red / 255.0;
colorAttr.ref.clearValue.g = clearColor.green / 255.0;
colorAttr.ref.clearValue.b = clearColor.blue / 255.0;
colorAttr.ref.clearValue.a = clearColor.opacity;
}
final desc = scratch.renderPassDesc;
desc.ref.label.data = nullptr;
desc.ref.label.length = 0;
desc.ref.colorAttachmentCount = 1;
desc.ref.colorAttachments = colorAttr;
if (depthTexture != null) {
final depthAttr = scratch.depthStencilAttachment;
depthAttr.ref.view = depthTexture.view;
depthAttr.ref.depthClearValue = 1.0;
depthAttr.ref.depthLoadOp = WGPULoadOp.WGPULoadOp_Clear;
depthAttr.ref.depthStoreOp = WGPUStoreOp.WGPUStoreOp_Store;
depthAttr.ref.stencilLoadOp = WGPULoadOp.WGPULoadOp_Undefined;
depthAttr.ref.stencilStoreOp = WGPUStoreOp.WGPUStoreOp_Undefined;
desc.ref.depthStencilAttachment = depthAttr;
} else {
desc.ref.depthStencilAttachment = nullptr;
}
desc.ref.timestampWrites = nullptr;
desc.ref.occlusionQuerySet = nullptr;
final passHandle = _wgpu.wgpuCommandEncoderBeginRenderPass(_handle, desc);
return RenderPassEncoder(passHandle);
}