Add per-attachment clear colors for multiple render targets - #9142
Merged
Conversation
Build size reportThis PR changes the size of the minified bundles.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the engine’s render-pass clearing semantics to support per-color-attachment clear colors and clear enable flags for MRT (multiple render targets), bringing WebGL behavior in line with WebGPU and avoiding unnecessary per-frame allocations.
Changes:
- Extends
RenderPass#setClearColor(color, index)with an optional attachment index; omitting the index preserves the prior “apply to all attachments” behavior. - Updates the WebGL render-pass start path to clear MRT color attachments individually via
gl.clearBufferfv, honoring per-attachment clear colors/flags while preserving attachments that are not cleared. - Adds unit tests validating
setClearColorbehavior across multiple attachments, and updates theindependent-blendingexample to demonstrate per-attachment clears.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/platform/graphics/render-pass.test.mjs | Adds unit tests for per-attachment clear-color API behavior on RenderPass. |
| src/platform/graphics/webgl/webgl-graphics-device.js | Implements per-attachment MRT clearing on WebGL using clearBufferfv and removes per-frame clear-options allocations. |
| src/platform/graphics/render-pass.js | Extends setClearColor to accept an optional attachment index and updates clear ops accordingly. |
| examples/src/examples/test/independent-blending.example.mjs | Demonstrates per-attachment clear colors using a standalone clear-only render pass. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows each color attachment of a multiple-render-target render pass to use its own clear color and clear flag. Previously WebGL cleared all attachments using a single gl.clear call, which applied attachment 0's clear color to every attachment, and ignored the per-attachment clear flags. WebGPU already supported this.
Changes:
RenderPass#setClearColoraccepts an optional attachment index. When not specified, all attachments are modified as before.API Changes:
RenderPass#setClearColor(color, index)- new optional index parameter, in 0 to 7 range, selecting the color attachment to modify.Note that clearing integer format color attachments is not supported and asserts in debug builds - this can be added using clearBufferiv/clearBufferuiv when needed.
Examples:
test/independent-blendingexample now also demonstrates per-attachment clear colors - a standalone clear-only render pass clears each attachment to a different color, visible as the border around each panel, and the camera renders on top without clearing.