wg_engine: fix scene blending

In a case of scenes without masking white clear color used, instead of black color

Issue https://github.com/thorvg/thorvg/issues/2592
Issue https://github.com/thorvg/thorvg/issues/2921
This commit is contained in:
Sergii Liebodkin 2024-11-04 14:12:46 +00:00 committed by Hermet Park
parent 2ad6753680
commit 52356b023d
3 changed files with 6 additions and 3 deletions

View file

@ -88,7 +88,7 @@ RenderRegion WgCompositor::shrinkRenderRegion(RenderRegion& rect)
}
void WgCompositor::beginRenderPass(WGPUCommandEncoder commandEncoder, WgRenderStorage* target, bool clear)
void WgCompositor::beginRenderPass(WGPUCommandEncoder commandEncoder, WgRenderStorage* target, bool clear, WGPUColor clearColor)
{
assert(commandEncoder);
assert(target);
@ -105,6 +105,7 @@ void WgCompositor::beginRenderPass(WGPUCommandEncoder commandEncoder, WgRenderSt
colorAttachment.loadOp = clear ? WGPULoadOp_Clear : WGPULoadOp_Load,
colorAttachment.storeOp = WGPUStoreOp_Store;
colorAttachment.resolveTarget = target->texView;
colorAttachment.clearValue = clearColor;
#ifdef __EMSCRIPTEN__
colorAttachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
#endif

View file

@ -67,7 +67,7 @@ public:
void release(WgContext& context);
// render passes workflow
void beginRenderPass(WGPUCommandEncoder encoder, WgRenderStorage* target, bool clear);
void beginRenderPass(WGPUCommandEncoder encoder, WgRenderStorage* target, bool clear, WGPUColor clearColor = { 0.0, 0.0, 0.0, 0.0 });
void endRenderPass();
// render shapes, images and scenes

View file

@ -368,7 +368,9 @@ bool WgRenderer::beginComposite(RenderCompositor* cmp, MaskMethod method, uint8_
WgRenderStorage* storage = mRenderStoragePool.allocate(mContext);
mRenderStorageStack.push(storage);
// begin newly added render pass
mCompositor.beginRenderPass(mCommandEncoder, mRenderStorageStack.last(), true);
WGPUColor color{};
if ((method == MaskMethod::None) && (opacity != 255)) color = { 1.0, 1.0, 1.0, 0.0 };
mCompositor.beginRenderPass(mCommandEncoder, mRenderStorageStack.last(), true, color);
return true;
}