mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-20 15:03:25 +00:00
wg_engine: Improve resizing mechanics
In case of resizing recreate only render targets, but not all compositor handles
This commit is contained in:
parent
f017bb84c1
commit
482bd50157
3 changed files with 72 additions and 34 deletions
|
@ -28,40 +28,59 @@ void WgCompositor::initialize(WgContext& context, uint32_t width, uint32_t heigh
|
||||||
// pipelines (external handle, do not release)
|
// pipelines (external handle, do not release)
|
||||||
pipelines.initialize(context);
|
pipelines.initialize(context);
|
||||||
// initialize opacity pool
|
// initialize opacity pool
|
||||||
|
initPools(context);
|
||||||
|
// allocate global view matrix handles
|
||||||
|
WgShaderTypeMat4x4f viewMat(width, height);
|
||||||
|
context.allocateBufferUniform(bufferViewMat, &viewMat, sizeof(viewMat));
|
||||||
|
bindGroupViewMat = context.layouts.createBindGroupBuffer1Un(bufferViewMat);
|
||||||
|
// create render targets handles
|
||||||
|
resize(context, width, height);
|
||||||
|
// composition and blend geometries
|
||||||
|
meshData.blitBox(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WgCompositor::initPools(WgContext& context)
|
||||||
|
{
|
||||||
for (uint32_t i = 0; i < 256; i++) {
|
for (uint32_t i = 0; i < 256; i++) {
|
||||||
float opacity = i / 255.0f;
|
float opacity = i / 255.0f;
|
||||||
context.allocateBufferUniform(bufferOpacities[i], &opacity, sizeof(float));
|
context.allocateBufferUniform(bufferOpacities[i], &opacity, sizeof(float));
|
||||||
bindGroupOpacities[i] = context.layouts.createBindGroupBuffer1Un(bufferOpacities[i]);
|
bindGroupOpacities[i] = context.layouts.createBindGroupBuffer1Un(bufferOpacities[i]);
|
||||||
}
|
}
|
||||||
// create render targets handles
|
|
||||||
resize(context, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::release(WgContext& context)
|
void WgCompositor::release(WgContext& context)
|
||||||
{
|
{
|
||||||
|
// composition and blend geometries
|
||||||
|
meshData.release(context);
|
||||||
// release render targets habdles
|
// release render targets habdles
|
||||||
resize(context, 0, 0);
|
resize(context, 0, 0);
|
||||||
|
// release opacity pool
|
||||||
|
releasePools(context);
|
||||||
|
// release global view matrix handles
|
||||||
|
context.layouts.releaseBindGroup(bindGroupViewMat);
|
||||||
|
context.releaseBuffer(bufferViewMat);
|
||||||
|
// release pipelines
|
||||||
|
pipelines.release(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WgCompositor::releasePools(WgContext& context)
|
||||||
|
{
|
||||||
// release opacity pool
|
// release opacity pool
|
||||||
for (uint32_t i = 0; i < 256; i++) {
|
for (uint32_t i = 0; i < 256; i++) {
|
||||||
context.layouts.releaseBindGroup(bindGroupOpacities[i]);
|
context.layouts.releaseBindGroup(bindGroupOpacities[i]);
|
||||||
context.releaseBuffer(bufferOpacities[i]);
|
context.releaseBuffer(bufferOpacities[i]);
|
||||||
}
|
}
|
||||||
// release pipelines
|
|
||||||
pipelines.release(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WgCompositor::resize(WgContext& context, uint32_t width, uint32_t height) {
|
void WgCompositor::resize(WgContext& context, uint32_t width, uint32_t height) {
|
||||||
// release existig handles
|
// release existig handles
|
||||||
if ((this->width != width) || (this->height != height)) {
|
if ((this->width != width) || (this->height != height)) {
|
||||||
// composition and blend geometries
|
|
||||||
meshData.release(context);
|
|
||||||
// release intermediate render storages
|
// release intermediate render storages
|
||||||
storageDstCopy.release(context);
|
storageDstCopy.release(context);
|
||||||
// release global view matrix handles
|
|
||||||
context.layouts.releaseBindGroup(bindGroupViewMat);
|
|
||||||
context.releaseBuffer(bufferViewMat);
|
|
||||||
// release global stencil buffer handles
|
// release global stencil buffer handles
|
||||||
context.releaseTextureView(texViewDepthStencilMS);
|
context.releaseTextureView(texViewDepthStencilMS);
|
||||||
context.releaseTexture(texDepthStencilMS);
|
context.releaseTexture(texDepthStencilMS);
|
||||||
|
@ -77,19 +96,16 @@ void WgCompositor::resize(WgContext& context, uint32_t width, uint32_t height) {
|
||||||
// store render target dimensions
|
// store render target dimensions
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
|
// reallocate global view matrix handles
|
||||||
|
WgShaderTypeMat4x4f viewMat(width, height);
|
||||||
|
context.allocateBufferUniform(bufferViewMat, &viewMat, sizeof(viewMat));
|
||||||
// allocate global stencil buffer handles
|
// allocate global stencil buffer handles
|
||||||
texDepthStencil = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 1);
|
texDepthStencil = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 1);
|
||||||
texViewDepthStencil = context.createTextureView(texDepthStencil);
|
texViewDepthStencil = context.createTextureView(texDepthStencil);
|
||||||
texDepthStencilMS = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 4);
|
texDepthStencilMS = context.createTexAttachement(width, height, WGPUTextureFormat_Depth24PlusStencil8, 4);
|
||||||
texViewDepthStencilMS = context.createTextureView(texDepthStencilMS);
|
texViewDepthStencilMS = context.createTextureView(texDepthStencilMS);
|
||||||
// allocate global view matrix handles
|
|
||||||
WgShaderTypeMat4x4f viewMat(width, height);
|
|
||||||
context.allocateBufferUniform(bufferViewMat, &viewMat, sizeof(viewMat));
|
|
||||||
bindGroupViewMat = context.layouts.createBindGroupBuffer1Un(bufferViewMat);
|
|
||||||
// initialize intermediate render storages
|
// initialize intermediate render storages
|
||||||
storageDstCopy.initialize(context, width, height);
|
storageDstCopy.initialize(context, width, height);
|
||||||
// composition and blend geometries
|
|
||||||
meshData.blitBox(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ private:
|
||||||
RenderRegion shrinkRenderRegion(RenderRegion& rect);
|
RenderRegion shrinkRenderRegion(RenderRegion& rect);
|
||||||
public:
|
public:
|
||||||
void initialize(WgContext& context, uint32_t width, uint32_t height);
|
void initialize(WgContext& context, uint32_t width, uint32_t height);
|
||||||
|
void initPools(WgContext& context);
|
||||||
void release(WgContext& context);
|
void release(WgContext& context);
|
||||||
|
void releasePools(WgContext& context);
|
||||||
void resize(WgContext& context, uint32_t width, uint32_t height);
|
void resize(WgContext& context, uint32_t width, uint32_t height);
|
||||||
|
|
||||||
// render passes workflow
|
// render passes workflow
|
||||||
|
|
|
@ -308,31 +308,51 @@ bool WgRenderer::target(WGPUDevice device, WGPUInstance instance, void* target,
|
||||||
if ((mContext.device != device) || (mContext.instance != instance)) {
|
if ((mContext.device != device) || (mContext.instance != instance)) {
|
||||||
// release all handles
|
// release all handles
|
||||||
release();
|
release();
|
||||||
|
|
||||||
// initialize base rendering handles
|
// initialize base rendering handles
|
||||||
mContext.initialize(instance, device);
|
mContext.initialize(instance, device);
|
||||||
// release render targets only
|
|
||||||
} else if (mRenderStorageRoot.texView) {
|
// initialize render tree instances
|
||||||
mRenderStoragePool.release(mContext);
|
mRenderStoragePool.initialize(mContext, width, height);
|
||||||
mRenderStorageRoot.release(mContext);
|
mRenderStorageRoot.initialize(mContext, width, height);
|
||||||
mCompositor.release(mContext);
|
mCompositor.initialize(mContext, width, height);
|
||||||
clearTargets();
|
|
||||||
|
// store target properties
|
||||||
|
mTargetSurface.stride = width;
|
||||||
|
mTargetSurface.w = width;
|
||||||
|
mTargetSurface.h = height;
|
||||||
|
|
||||||
|
// configure surface (must be called after context creation)
|
||||||
|
if (type == 0) {
|
||||||
|
surface = (WGPUSurface)target;
|
||||||
|
surfaceConfigure(surface, mContext, width, height);
|
||||||
|
} else targetTexture = (WGPUTexture)target;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize render tree instances
|
// update retnder targets dimentions
|
||||||
mRenderStoragePool.initialize(mContext, width, height);
|
if ((mTargetSurface.w != width) || (mTargetSurface.h != height)) {
|
||||||
mRenderStorageRoot.initialize(mContext, width, height);
|
// release render tagets
|
||||||
mCompositor.initialize(mContext, width, height);
|
mRenderStoragePool.release(mContext);
|
||||||
|
mRenderStorageRoot.release(mContext);
|
||||||
|
clearTargets();
|
||||||
|
|
||||||
// store target properties
|
mRenderStoragePool.initialize(mContext, width, height);
|
||||||
mTargetSurface.stride = width;
|
mRenderStorageRoot.initialize(mContext, width, height);
|
||||||
mTargetSurface.w = width;
|
mCompositor.resize(mContext, width, height);
|
||||||
mTargetSurface.h = height;
|
|
||||||
|
|
||||||
// configure surface (must be called after context creation)
|
// store target properties
|
||||||
if (type == 0) {
|
mTargetSurface.stride = width;
|
||||||
surface = (WGPUSurface)target;
|
mTargetSurface.w = width;
|
||||||
surfaceConfigure(surface, mContext, width, height);
|
mTargetSurface.h = height;
|
||||||
} else targetTexture = (WGPUTexture)target;
|
|
||||||
|
// configure surface (must be called after context creation)
|
||||||
|
if (type == 0) {
|
||||||
|
surface = (WGPUSurface)target;
|
||||||
|
surfaceConfigure(surface, mContext, width, height);
|
||||||
|
} else targetTexture = (WGPUTexture)target;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue