Skip to content

Commit

Permalink
Merge pull request cocos#69 from GengineJS/develop-merge-1020
Browse files Browse the repository at this point in the history
Fix the problem that the camera preview window does not display the picture
  • Loading branch information
star-e committed Oct 24, 2022
2 parents 2b72c01 + ff7612d commit 08f4a48
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export function buildPostprocessPass (camera: Camera,
ppl.addRenderTexture(postprocessPassRTName, Format.RGBA8, width, height, camera.window);
ppl.addDepthStencil(postprocessPassDS, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
}
ppl.updateRenderWindow(postprocessPassRTName, camera.window);
const postprocessPass = ppl.addRasterPass(width, height, 'Postprocess', `CameraPostprocessPass${cameraID}`);
postprocessPass.setViewport(new Viewport(area.x, area.y, area.width, area.height));
if (ppl.containsResource(inputTex)) {
Expand Down Expand Up @@ -414,6 +415,9 @@ export function buildForwardPass (camera: Camera,
}
ppl.addDepthStencil(forwardPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED);
}
if (!isOffScreen) {
ppl.updateRenderWindow(forwardPassRTName, camera.window);
}
const forwardPass = ppl.addRasterPass(width, height, 'default', `CameraForwardPass${cameraID}`);
forwardPass.setViewport(new Viewport(area.x, area.y, width, height));
for (const dirShadowName of cameraInfo.mainLightShadowNames) {
Expand All @@ -437,7 +441,7 @@ export function buildForwardPass (camera: Camera,
const passDSView = new RasterView('_',
AccessType.WRITE, AttachmentType.DEPTH_STENCIL,
isOffScreen ? LoadOp.CLEAR : getLoadOpOfClearFlag(camera.clearFlag, AttachmentType.DEPTH_STENCIL),
StoreOp.DISCARD,
StoreOp.STORE,
camera.clearFlag,
new Color(camera.clearDepth, camera.clearStencil, 0, 0));
forwardPass.addRasterView(forwardPassRTName, passView);
Expand Down
23 changes: 20 additions & 3 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class DeviceTexture extends DeviceResource {
protected _desc: ResourceDesc | null = null;
protected _trait: ResourceTraits | null = null;
get texture () { return this._texture; }
set framebuffer (val: Framebuffer | null) { this._framebuffer = val; }
get framebuffer () { return this._framebuffer; }
get description () { return this._desc; }
get trait () { return this._trait; }
Expand Down Expand Up @@ -566,6 +567,13 @@ class DeviceRenderPass {
const resourceVisitor = new ResourceVisitor(resName, context);
resourceGraph.visitVertex(resourceVisitor, vertId);
resTex = context.deviceTextures.get(resName)!;
} else {
const resGraph = this.context.resourceGraph;
const resId = resGraph.vertex(resName);
const resFbo = resGraph._vertices[resId]._object;
if (resTex.framebuffer && resFbo instanceof Framebuffer && resTex.framebuffer !== resFbo) {
resTex.framebuffer = resFbo;
}
}
if (!swapchain) swapchain = resTex.swapchain;
if (!framebuffer) framebuffer = resTex.framebuffer;
Expand Down Expand Up @@ -759,9 +767,18 @@ class DeviceRenderPass {
queue.postRecord();
}
}
resetQueues (id: number, pass: RasterPass) {
resetResource (id: number, pass: RasterPass) {
this._rasterInfo.applyInfo(id, pass);
this._deviceQueues.length = 0;
for (const [resName, rasterV] of this._rasterInfo.pass.rasterViews) {
const deviceTex = this.context.deviceTextures.get(resName);
const resGraph = this.context.resourceGraph;
const resId = resGraph.vertex(resName);
const resFbo = resGraph._vertices[resId]._object;
if (deviceTex!.framebuffer && resFbo instanceof Framebuffer && deviceTex!.framebuffer !== resFbo) {
this._framebuffer = deviceTex!.framebuffer = resFbo;
}
}
}
}

Expand Down Expand Up @@ -1444,7 +1461,7 @@ export class Executor {
}
this._context.deviceTextures.clear();
}
private readonly _context: ExecutorContext;
readonly _context: ExecutorContext;
}

class BaseRenderVisitor {
Expand Down Expand Up @@ -1497,7 +1514,7 @@ class PreRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor {
this.currPass = new DeviceRenderPass(this.context, new RasterPassInfo(this.passID, pass));
devicePasses.set(passHash, this.currPass);
} else {
this.currPass.resetQueues(this.passID, pass);
this.currPass.resetResource(this.passID, pass);
}
}
compute (value: ComputePass) {}
Expand Down
10 changes: 7 additions & 3 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ function isManaged (residency: ResourceResidency): boolean {
}

export class WebPipeline implements Pipeline {
updateRenderWindow (name: string, renderWindow: RenderWindow): void {
const resId = this.resourceGraph.vertex(name);
const currFbo = this.resourceGraph._vertices[resId]._object;
if (currFbo !== renderWindow.framebuffer) {
this.resourceGraph._vertices[resId]._object = renderWindow.framebuffer;
}
}
public containsResource (name: string): boolean {
return this._resourceGraph.contains(name);
}
Expand Down Expand Up @@ -1002,9 +1009,6 @@ export class WebPipeline implements Pipeline {
new ResourceStates(),
new SamplerInfo(Filter.POINT, Filter.POINT, Filter.NONE),
);
}
updateRenderWindow (name: string, renderWindow: RenderWindow): void {

}
beginFrame () {
// noop
Expand Down

0 comments on commit 08f4a48

Please sign in to comment.