Repository navigation
fix(rendering): use the default clear color for window letterbox margins - #336
Conversation
There was a problem hiding this comment.
Review: Use project background color for uncovered window regions
This is a small, well-scoped fix. Both call sites replace the hardcoded black clear color with texture_storage->get_default_clear_color() (alpha forced to 1.0) so letterbox/uncovered window regions match the project's background color instead of always being black.
No issues found. The change is correct, safe, and consistent with existing usage.
- Correctness & consistency — The new usage matches how
get_default_clear_color()is already used for related purposes elsewhere (window border/letterbox fill indisplay_server_windows.cpp, early-window clear indisplay_server.cpp, viewport background inrenderer_viewport.cpp). Both paths correctly force alpha to1.0to keep regions opaque. The RD call is placed once outside the per-target loop; the GLES3 call stays guarded behind thep_first+ letterbox-region check. - Performance —
get_default_clear_color()is a trivial accessor returning a cachedColorfield (no allocation, no lock, no settings lookup), so per-frame cost is negligible. - Thread safety — Reading the cached clear color on the render thread follows the established pattern already used by several per-frame render-thread call sites; no new concern is introduced. The existing comment about avoiding a
DisplayServerwindow-size query (deadlock in separate-render-thread mode) still holds. - Memory safety —
texture_storageis created in each constructor and already dereferenced unconditionally in both functions, so the added call introduces no new null-dereference risk. - Comments — Both updated/added comments accurately describe the code.
Optional (testing note, not a blocker): get_default_clear_color() returns the raw rendering/environment/defaults/default_clear_color value and is passed directly without an sRGB↔linear conversion — matching the sibling usages. Worth a quick visual confirmation that the letterbox fill matches the actual rendered viewport background across both renderers (and in HDR mode), since scene-render paths may apply the color in linear/sRGB framebuffer contexts. This is an existing engine-wide consideration, not introduced by this PR.
Clear uncovered window regions with the existing default clear color in both GLES3 and RenderingDevice compositors, while keeping margins opaque. Projects can control their margins through default_clear_color or RenderingServer.set_default_clear_color without a new API or changes to viewport layout and input coordinates.
Base:
spx4.4.1. This is the engine-side prerequisite for the SPX stage-letterbox branch.Prior build and runtime validation: Matching Native and Web builds passed. Eight macOS OpenGL3/Metal window scenarios checked white and runtime color changes, horizontal/vertical margins and transparent input colors; Web DPR 1/2 resize samples stayed opaque white with unchanged visible-world bounds.