mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
CompositeMethod::ClipPath will be replaced with the Scene::clip()
wg_engine needs to refactor to remove the enum value usage before proceeding with its removal
This commit is contained in:
parent
ff2cacd25d
commit
b66ff36502
4 changed files with 48 additions and 29 deletions
|
@ -161,11 +161,11 @@ void WgCompositor::renderShape(WgContext& context, WgRenderDataShape* renderData
|
||||||
if (renderData->clips.count != 0) {
|
if (renderData->clips.count != 0) {
|
||||||
renderClipPath(context, renderData, &storageClipPath);
|
renderClipPath(context, renderData, &storageClipPath);
|
||||||
if (renderData->strokeFirst) {
|
if (renderData->strokeFirst) {
|
||||||
composeStrokes(context, renderData, &storageClipPath, CompositeMethod::ClipPath);
|
drawStrokesClipped(context, renderData, &storageClipPath);
|
||||||
composeShape(context, renderData, &storageClipPath, CompositeMethod::ClipPath);
|
drawShapeClipped(context, renderData, &storageClipPath);
|
||||||
} else {
|
} else {
|
||||||
composeShape(context, renderData, &storageClipPath, CompositeMethod::ClipPath);
|
drawShapeClipped(context, renderData, &storageClipPath);
|
||||||
composeStrokes(context, renderData, &storageClipPath, CompositeMethod::ClipPath);
|
drawStrokesClipped(context, renderData, &storageClipPath);
|
||||||
}
|
}
|
||||||
// use custom blending
|
// use custom blending
|
||||||
} else if (blentType == WgPipelineBlendType::Custom) {
|
} else if (blentType == WgPipelineBlendType::Custom) {
|
||||||
|
@ -197,7 +197,7 @@ void WgCompositor::renderImage(WgContext& context, WgRenderDataPicture* renderDa
|
||||||
// apply clip path if neccessary
|
// apply clip path if neccessary
|
||||||
if (renderData->clips.count != 0) {
|
if (renderData->clips.count != 0) {
|
||||||
renderClipPath(context, renderData, &storageClipPath);
|
renderClipPath(context, renderData, &storageClipPath);
|
||||||
composeImage(context, renderData, &storageClipPath, CompositeMethod::ClipPath);
|
drawImageClipped(context, renderData, &storageClipPath);
|
||||||
// use custom blending
|
// use custom blending
|
||||||
} else if (blentType == WgPipelineBlendType::Custom)
|
} else if (blentType == WgPipelineBlendType::Custom)
|
||||||
blendImage(context, renderData, blendMethod);
|
blendImage(context, renderData, blendMethod);
|
||||||
|
@ -281,7 +281,7 @@ void WgCompositor::blendScene(WgContext& context, WgRenderStorage* src, WgCompos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::composeShape(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask, CompositeMethod composeMethod)
|
void WgCompositor::drawShapeClipped(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask)
|
||||||
{
|
{
|
||||||
assert(mask);
|
assert(mask);
|
||||||
assert(renderData);
|
assert(renderData);
|
||||||
|
@ -299,12 +299,12 @@ void WgCompositor::composeShape(WgContext& context, WgRenderDataShape* renderDat
|
||||||
endRenderPass();
|
endRenderPass();
|
||||||
// restore current render pass
|
// restore current render pass
|
||||||
beginRenderPass(commandEncoder, target, false);
|
beginRenderPass(commandEncoder, target, false);
|
||||||
RenderRegion rect { 0, 0,(int32_t)width, (int32_t)height };
|
RenderRegion rect = shrinkRenderRegion(renderData->aabb);
|
||||||
composeRegion(context, &storageInterm, mask, composeMethod, rect);
|
clipRegion(context, &storageInterm, mask, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::composeStrokes(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask, CompositeMethod composeMethod)
|
void WgCompositor::drawStrokesClipped(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask)
|
||||||
{
|
{
|
||||||
assert(mask);
|
assert(mask);
|
||||||
assert(renderData);
|
assert(renderData);
|
||||||
|
@ -322,12 +322,12 @@ void WgCompositor::composeStrokes(WgContext& context, WgRenderDataShape* renderD
|
||||||
endRenderPass();
|
endRenderPass();
|
||||||
// restore current render pass
|
// restore current render pass
|
||||||
beginRenderPass(commandEncoder, target, false);
|
beginRenderPass(commandEncoder, target, false);
|
||||||
RenderRegion rect { 0, 0, (int32_t)width, (int32_t)height };
|
RenderRegion rect = shrinkRenderRegion(renderData->aabb);
|
||||||
composeRegion(context, &storageInterm, mask, composeMethod, rect);
|
clipRegion(context, &storageInterm, mask, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::composeImage(WgContext& context, WgRenderDataPicture* renderData, WgRenderStorage* mask, CompositeMethod composeMethod)
|
void WgCompositor::drawImageClipped(WgContext& context, WgRenderDataPicture* renderData, WgRenderStorage* mask)
|
||||||
{
|
{
|
||||||
assert(mask);
|
assert(mask);
|
||||||
assert(renderData);
|
assert(renderData);
|
||||||
|
@ -343,7 +343,18 @@ void WgCompositor::composeImage(WgContext& context, WgRenderDataPicture* renderD
|
||||||
// restore current render pass
|
// restore current render pass
|
||||||
beginRenderPass(commandEncoder, target, false);
|
beginRenderPass(commandEncoder, target, false);
|
||||||
RenderRegion rect { 0, 0, (int32_t)width, (int32_t)height };
|
RenderRegion rect { 0, 0, (int32_t)width, (int32_t)height };
|
||||||
composeRegion(context, &storageInterm, mask, composeMethod, rect);
|
clipRegion(context, &storageInterm, mask, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WgCompositor::clipRegion(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, RenderRegion& rect)
|
||||||
|
{
|
||||||
|
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x, rect.y, rect.w, rect.h);
|
||||||
|
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
|
||||||
|
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, storageInterm.bindGroupTexure, 0, nullptr);
|
||||||
|
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, mask->bindGroupTexure, 0, nullptr);
|
||||||
|
wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines->sceneClip);
|
||||||
|
meshData.drawImage(context, renderPassEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -354,21 +365,14 @@ void WgCompositor::composeScene(WgContext& context, WgRenderStorage* src, WgRend
|
||||||
assert(mask);
|
assert(mask);
|
||||||
assert(renderPassEncoder);
|
assert(renderPassEncoder);
|
||||||
RenderRegion rect = shrinkRenderRegion(cmp->aabb);
|
RenderRegion rect = shrinkRenderRegion(cmp->aabb);
|
||||||
composeRegion(context, src, mask, cmp->method, rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::composeRegion(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, CompositeMethod composeMethod, RenderRegion& rect)
|
|
||||||
{
|
|
||||||
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x, rect.y, rect.w, rect.h);
|
wgpuRenderPassEncoderSetScissorRect(renderPassEncoder, rect.x, rect.y, rect.w, rect.h);
|
||||||
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
|
wgpuRenderPassEncoderSetStencilReference(renderPassEncoder, 0);
|
||||||
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, src->bindGroupTexure, 0, nullptr);
|
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 0, src->bindGroupTexure, 0, nullptr);
|
||||||
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, mask->bindGroupTexure, 0, nullptr);
|
wgpuRenderPassEncoderSetBindGroup(renderPassEncoder, 1, mask->bindGroupTexure, 0, nullptr);
|
||||||
wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines->sceneComp[(uint32_t)composeMethod]);
|
wgpuRenderPassEncoderSetPipeline(renderPassEncoder, pipelines->sceneComp[(uint32_t)cmp->method]);
|
||||||
meshData.drawImage(context, renderPassEncoder);
|
meshData.drawImage(context, renderPassEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::drawClipPath(WgContext& context, WgRenderDataShape* renderData)
|
void WgCompositor::drawClipPath(WgContext& context, WgRenderDataShape* renderData)
|
||||||
{
|
{
|
||||||
assert(renderData);
|
assert(renderData);
|
||||||
|
|
|
@ -59,7 +59,7 @@ private:
|
||||||
|
|
||||||
static WgPipelineBlendType blendMethodToBlendType(BlendMethod blendMethod);
|
static WgPipelineBlendType blendMethodToBlendType(BlendMethod blendMethod);
|
||||||
|
|
||||||
void composeRegion(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, CompositeMethod composeMethod, RenderRegion& rect);
|
void clipRegion(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, RenderRegion& rect);
|
||||||
RenderRegion shrinkRenderRegion(RenderRegion& rect);
|
RenderRegion shrinkRenderRegion(RenderRegion& rect);
|
||||||
public:
|
public:
|
||||||
// render target dimensions
|
// render target dimensions
|
||||||
|
@ -82,9 +82,10 @@ public:
|
||||||
void blendImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod);
|
void blendImage(WgContext& context, WgRenderDataPicture* renderData, BlendMethod blendMethod);
|
||||||
void blendScene(WgContext& context, WgRenderStorage* src, WgCompose* cmp);
|
void blendScene(WgContext& context, WgRenderStorage* src, WgCompose* cmp);
|
||||||
|
|
||||||
void composeShape(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask, CompositeMethod composeMethod);
|
void drawShapeClipped(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask);
|
||||||
void composeStrokes(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask, CompositeMethod composeMethod);
|
void drawStrokesClipped(WgContext& context, WgRenderDataShape* renderData, WgRenderStorage* mask);
|
||||||
void composeImage(WgContext& context, WgRenderDataPicture* renderData, WgRenderStorage* mask, CompositeMethod composeMethod);
|
void drawImageClipped(WgContext& context, WgRenderDataPicture* renderData, WgRenderStorage* mask);
|
||||||
|
|
||||||
void composeScene(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, WgCompose* cmp);
|
void composeScene(WgContext& context, WgRenderStorage* src, WgRenderStorage* mask, WgCompose* cmp);
|
||||||
|
|
||||||
void drawClipPath(WgContext& context, WgRenderDataShape* renderData);
|
void drawClipPath(WgContext& context, WgRenderDataShape* renderData);
|
||||||
|
|
|
@ -324,7 +324,7 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
||||||
primitiveState, multisampleState, blendStateSrc);
|
primitiveState, multisampleState, blendStateSrc);
|
||||||
|
|
||||||
// render pipeline blit
|
// render pipeline blend
|
||||||
sceneBlend = createRenderPipeline(context.device, "The render pipeline scene blend",
|
sceneBlend = createRenderPipeline(context.device, "The render pipeline scene blend",
|
||||||
shaderSceneBlend, "vs_main", "fs_main", layoutSceneBlend,
|
shaderSceneBlend, "vs_main", "fs_main", layoutSceneBlend,
|
||||||
vertexBufferLayoutsImage, 2,
|
vertexBufferLayoutsImage, 2,
|
||||||
|
@ -333,10 +333,21 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
||||||
primitiveState, multisampleState, blendStateNrm);
|
primitiveState, multisampleState, blendStateNrm);
|
||||||
|
|
||||||
|
// render pipeline scene clip path
|
||||||
|
sceneClip = createRenderPipeline(
|
||||||
|
context.device, "The render pipeline scene clip path",
|
||||||
|
shaderSceneComp, "vs_main", "fs_main_ClipPath", layoutSceneComp,
|
||||||
|
vertexBufferLayoutsImage, 2,
|
||||||
|
WGPUColorWriteMask_All, offscreenTargetFormat,
|
||||||
|
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
||||||
|
WGPUCompareFunction_Always, WGPUStencilOperation_Zero,
|
||||||
|
primitiveState, multisampleState, blendStateNrm);
|
||||||
|
|
||||||
|
// TODO: remove fs_main_ClipPath shader from list after removing CompositeMethod::ClipPath value
|
||||||
// compose shader names
|
// compose shader names
|
||||||
const char* shaderComposeNames[] {
|
const char* shaderComposeNames[] {
|
||||||
"fs_main_None",
|
"fs_main_None",
|
||||||
"fs_main_ClipPath",
|
"fs_main_ClipPath", // TODO: remove after CompositeMethod updated
|
||||||
"fs_main_AlphaMask",
|
"fs_main_AlphaMask",
|
||||||
"fs_main_InvAlphaMask",
|
"fs_main_InvAlphaMask",
|
||||||
"fs_main_LumaMask",
|
"fs_main_LumaMask",
|
||||||
|
@ -349,10 +360,11 @@ void WgPipelines::initialize(WgContext& context)
|
||||||
"fs_main_DarkenMask"
|
"fs_main_DarkenMask"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: remove fs_main_ClipPath shader from list after removing CompositeMethod::ClipPath value
|
||||||
// compose shader blend states
|
// compose shader blend states
|
||||||
const WGPUBlendState composeBlends[] {
|
const WGPUBlendState composeBlends[] {
|
||||||
blendStateNrm, // None
|
blendStateNrm, // None
|
||||||
blendStateNrm, // ClipPath
|
blendStateNrm, // ClipPath // TODO: remove after CompositeMethod updated
|
||||||
blendStateNrm, // AlphaMask
|
blendStateNrm, // AlphaMask
|
||||||
blendStateNrm, // InvAlphaMask
|
blendStateNrm, // InvAlphaMask
|
||||||
blendStateNrm, // LumaMask
|
blendStateNrm, // LumaMask
|
||||||
|
@ -429,6 +441,7 @@ void WgPipelines::releaseGraphicHandles(WgContext& context)
|
||||||
releaseRenderPipeline(blit);
|
releaseRenderPipeline(blit);
|
||||||
releaseRenderPipeline(clipPath);
|
releaseRenderPipeline(clipPath);
|
||||||
releaseRenderPipeline(sceneBlend);
|
releaseRenderPipeline(sceneBlend);
|
||||||
|
releaseRenderPipeline(sceneClip);
|
||||||
size_t pipesSceneCompCnt = sizeof(sceneComp) / sizeof(sceneComp[0]);
|
size_t pipesSceneCompCnt = sizeof(sceneComp) / sizeof(sceneComp[0]);
|
||||||
for (uint32_t i = 0; i < pipesSceneCompCnt; i++)
|
for (uint32_t i = 0; i < pipesSceneCompCnt; i++)
|
||||||
releaseRenderPipeline(sceneComp[i]);
|
releaseRenderPipeline(sceneComp[i]);
|
||||||
|
|
|
@ -65,7 +65,8 @@ public:
|
||||||
WGPURenderPipeline radial[2]{};
|
WGPURenderPipeline radial[2]{};
|
||||||
WGPURenderPipeline linear[2]{};
|
WGPURenderPipeline linear[2]{};
|
||||||
WGPURenderPipeline image[2]{};
|
WGPURenderPipeline image[2]{};
|
||||||
WGPURenderPipeline sceneComp[12];
|
WGPURenderPipeline sceneClip;
|
||||||
|
WGPURenderPipeline sceneComp[12]; // TODO: update to 11 after removing CompositeMethod::ClipPath enum value
|
||||||
WGPURenderPipeline sceneBlend;
|
WGPURenderPipeline sceneBlend;
|
||||||
WGPURenderPipeline blit{};
|
WGPURenderPipeline blit{};
|
||||||
WGPURenderPipeline clipPath{};
|
WGPURenderPipeline clipPath{};
|
||||||
|
|
Loading…
Add table
Reference in a new issue