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

Add RenderTarget|null typing + remove dead code #5704

Merged
merged 6 commits into from
Oct 4, 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
4 changes: 2 additions & 2 deletions src/framework/components/camera/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ class CameraComponent extends Component {
/**
* Calculates aspect ratio value for a given render target.
*
* @param {import('../../../platform/graphics/render-target.js').RenderTarget} [rt] - Optional
* @param {import('../../../platform/graphics/render-target.js').RenderTarget|null} [rt] - Optional
* render target. If unspecified, the backbuffer is used.
* @returns {number} The aspect ratio of the render target (or backbuffer).
*/
Expand All @@ -905,7 +905,7 @@ class CameraComponent extends Component {
/**
* Prepare the camera for frame rendering.
*
* @param {import('../../../platform/graphics/render-target.js').RenderTarget} rt - Render
* @param {import('../../../platform/graphics/render-target.js').RenderTarget|null} rt - Render
* target to which rendering will be performed. Will affect camera's aspect ratio, if
* aspectRatioMode is {@link ASPECT_AUTO}.
* @ignore
Expand Down
14 changes: 10 additions & 4 deletions src/platform/graphics/render-pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ class RenderPass {
/** @type {string} */
name;

/** @type {import('../graphics/render-target.js').RenderTarget} */
/**
* The render target for this render pass:
* - `undefined`: render pass does not render to any render target
* - `null`: render pass renders to the backbuffer
* - Otherwise, renders to the provided RT.
* @type {import('../graphics/render-target.js').RenderTarget|null|undefined}
*/
renderTarget;

/**
Expand Down Expand Up @@ -186,15 +192,15 @@ class RenderPass {
}

/**
* @param {import('../graphics/render-target.js').RenderTarget} renderTarget - The render
* @param {import('../graphics/render-target.js').RenderTarget|null} [renderTarget] - The render
* target to render into (output). This function should be called only for render passes which
* use render target, or passes which render directly into the default framebuffer, in which
* case a null or undefined render target is expected.
*/
init(renderTarget) {
init(renderTarget = null) {

// null represents the default framebuffer
this.renderTarget = renderTarget || null;
this.renderTarget = renderTarget;

// defaults depend on multisampling
this.samples = Math.max(this.renderTarget ? this.renderTarget.samples : this.device.samples, 1);
Expand Down
8 changes: 4 additions & 4 deletions src/scene/graphics/post-effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class PostEffect {
/**
* Draw a screen-space rectangle in a render target, using a specified shader.
*
* @param {import('../../platform/graphics/render-target.js').RenderTarget} target - The output
* render target.
* @param {import('../../platform/graphics/shader.js').Shader} shader - The shader to be used for
* drawing the rectangle.
* @param {import('../../platform/graphics/render-target.js').RenderTarget|null} target - The
* output render target.
* @param {import('../../platform/graphics/shader.js').Shader} shader - The shader to be used
* for drawing the rectangle.
* @param {import('../../core/math/vec4.js').Vec4} [rect] - The normalized screen-space position
* (rect.x, rect.y) and size (rect.z, rect.w) of the rectangle. Default is [0, 0, 1, 1].
*/
Expand Down
8 changes: 3 additions & 5 deletions src/scene/graphics/quad-render-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const _tempRect = new Vec4();
*
* @param {import('../../platform/graphics/graphics-device.js').GraphicsDevice} device - The graphics device used to draw
* the quad.
* @param {import('../../platform/graphics/render-target.js').RenderTarget|undefined} target - The destination render
* @param {import('../../platform/graphics/render-target.js').RenderTarget|null} target - The destination render
* target. If undefined, target is the frame buffer.
* @param {import('../../platform/graphics/shader.js').Shader} shader - The shader used for rendering the quad. Vertex
* shader should contain `attribute vec2 vertex_position`.
Expand Down Expand Up @@ -67,10 +67,8 @@ function drawQuadWithShader(device, target, shader, rect, scissorRect) {
// in a separate render pass B (e.g. rendering UI). Those two render passes need to be merged into one, as they both render into
// the same framebuffer. The workaround here is to store multi-sampled color buffer, instead of only resolving it, which is wasted
// memory bandwidth. Without this we end up with a black result (or just UI), as multi-sampled color buffer is never written to.
if (device.isWebGPU && target === null) {
const samples = target?.samples ?? device.samples;
if (samples > 1)
renderPass.colorOps.store = true;
if (device.isWebGPU && target === null && device.samples > 1) {
renderPass.colorOps.store = true;
}

renderPass.render();
Expand Down