Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small internal refator to RenderPass to allow simpler override implementation #5652

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/platform/graphics/render-pass.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Debug } from '../../core/debug.js';
import { Debug, DebugHelper } from '../../core/debug.js';
import { Tracing } from '../../core/tracing.js';
import { Color } from '../../core/math/color.js';
import { TRACEID_RENDER_PASS, TRACEID_RENDER_PASS_DETAIL } from '../../core/constants.js';
Expand Down Expand Up @@ -143,23 +143,23 @@ class RenderPass {
/**
* Custom function that is called to render the pass.
*
* @type {Function}
* @type {Function|undefined}
*/
execute;
_execute;

/**
* Custom function that is called before the pass has started.
*
* @type {Function}
* @type {Function|undefined}
*/
before;
_before;

/**
* Custom function that is called after the pass has fnished.
*
* @type {Function}
* @type {Function|undefined}
*/
after;
_after;

/**
* Creates an instance of the RenderPass.
Expand All @@ -169,11 +169,11 @@ class RenderPass {
* @param {Function} [execute] - Custom function that is called to render the pass.
*/
constructor(graphicsDevice, execute) {
DebugHelper.setName(this, this.constructor.name);
Debug.assert(graphicsDevice);
this.device = graphicsDevice;

/** @type {Function} */
this.execute = execute;
this._execute = execute;
}

/**
Expand Down Expand Up @@ -211,6 +211,18 @@ class RenderPass {
}
}

before() {
this._before?.();
}

execute() {
this._execute?.();
}

after() {
this._after?.();
}

/**
* Mark render pass as clearing the full color buffer.
*
Expand Down Expand Up @@ -261,19 +273,19 @@ class RenderPass {
this.log(device, device.renderPassIndex);
});

this.before?.();
this.before();

if (realPass) {
device.startPass(this);
}

this.execute?.();
this.execute();

if (realPass) {
device.endPass(this);
}

this.after?.();
this.after();

device.renderPassIndex++;

Expand Down
6 changes: 3 additions & 3 deletions src/scene/renderer/forward-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ class ForwardRenderer extends Renderer {
}

// update clusters all the time
renderPass.after = () => {
renderPass._after = () => {
this.updateClusters(layerComposition);
};
}
Expand Down Expand Up @@ -863,14 +863,14 @@ class ForwardRenderer extends Renderer {

// callback on the camera component before rendering with this camera for the first time
if (startRenderAction.firstCameraUse && camera.onPreRender) {
renderPass.before = () => {
renderPass._before = () => {
camera.onPreRender();
};
}

// callback on the camera component when we're done rendering with this camera
if (endRenderAction.lastCameraUse && camera.onPostRender) {
renderPass.after = () => {
renderPass._after = () => {
camera.onPostRender();
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/scene/renderer/shadow-renderer-directional.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ShadowRendererDirectional {
}
});

renderPass.after = () => {
renderPass._after = () => {
// after the pass is done, apply VSM blur if needed
this.shadowRenderer.renderVsm(light, camera);
};
Expand Down
4 changes: 2 additions & 2 deletions src/scene/renderer/shadow-renderer-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ShadowRendererLocal {
this.shadowRenderer.setupRenderPass(renderPass, shadowCamera, false);

// render shadows inside the pass
renderPass.execute = () => {
renderPass._execute = () => {

for (let i = 0; i < count; i++) {
const light = shadowLights[i];
Expand All @@ -154,7 +154,7 @@ class ShadowRendererLocal {

// apply vsm
if (applyVsm) {
renderPass.after = () => {
renderPass._after = () => {
// after the pass is done, apply VSM blur if needed
this.shadowRenderer.renderVsm(light, shadowCamera);
};
Expand Down