Skip to content

fix(3dgl): Render GLCanvasElement on WebAssembly - #25158

Merged
ramezgerges merged 2 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/wasm-glcanvas-readback
Oct 15, 2026
Merged

ramezgerges merged 2 commits into
unoplatform:masterfrom
ramezgerges:dev/rara/wasm-glcanvas-readback

Conversation

@ramezgerges

@ramezgerges ramezgerges commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24497

PR Type:

🐞 Bugfix

What changed? 🚀

GLCanvasElement rendered nothing on WebAssembly. Its first frame failed with The framebuffer readback failed with InvalidEnum, and the element then disabled itself, leaving a blank area.

Cause. The element copies its framebuffer into a BGRA WriteableBitmap with glReadPixels. GLES drivers don't all support BGRA reads, so NeedsRgbaReadbackSwap probes with a 1×1 BGRA read and falls back to RGBA plus an R/B swap. On the browser it skipped the probe, assuming the JS shim translated BGRA reads. That stopped being true when GL entry points started resolving to emscripten's native GL first (7482315): glReadPixels now reaches WebGL with GL_BGRA, which WebGL 2.0 always rejects with INVALID_ENUM. The probe and its stale assumption landed three days after that change (eb66ce7).

Fix:

  • The probe now runs on WebAssembly too. Emscripten reports a WebGL 2 context as OpenGL ES 3.0 (…); I checked its GL library for the .NET 10 (3.1.56) and .NET 11 (6.0.3) emsdks. So the existing GLES path applies: the probe fails and the element reads RGBA and swaps R/B.
  • The probe runs once per process instead of once per element. Every element gets its context from the same platform logic. On the browser, each failing probe also logs a WebGL readPixels: invalid format warning, so this keeps it to one per page.

Test. Given_GLCanvasElement.When_Cleared_Then_Shows_Clear_Color clears a GLCanvasElement to pure red and checks the screenshot. It catches a blank canvas and a red/blue mix-up. It's inconclusive when no OpenGL context is available (OnGLUnavailable). These are the first GLCanvasElement runtime tests.

  • The runtime tests now reference Uno.WinUI.Graphics3DGL.
  • That reference brings Uno.Core.Extensions.Logging.Singleton, whose Uno.Extensions.LogExtensionPoint makes existing Log() calls in the tests ambiguous. The test project references it with ExcludeAssets="compile", leaving Graphics3DGL's own dependencies untouched.

Backports: #25159 (6.8) and #25160 (6.7). WebAssembly GLCanvasElement support first shipped in 6.7 together with this bug, so no stable release has rendered it.

Validation:

  • Runtime, WASM SamplesApp (net11.0-browserwasm, headless Edge):
    • The new test fails without the fix, with IsGLInitialized false after the InvalidEnum readback error, and passes with it.
    • The GLCanvasElement_Cube sample shows a blank area before and the rotating cube after.
  • WebGL check: the issue's standalone page, in the same browser. A BGRA readPixels fails with 0x500 and leaves the buffer all zero; an RGBA read returns the right pixel.
  • Runtime, Skia desktop: the new test is inconclusive on my machine, which has no usable desktop OpenGL over RDP. That's the intended path.
  • Compile: Uno.WinUI.Graphics3DGL builds with analyzers on.

PR Checklist ✅

🤖 Generated with Claude Code

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 238608 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 1158

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • DropDownButtonPage.png-dark
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DynamicFont.png-dark
    • DynamicFont.png
    • Examples.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
  • skia-windows-screenshots: 1158 changed over 2474

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBarButtonWithIconTest.png
    • AppWindowFeatures.png-dark
    • AutomationProperties_Relations.png-dark
    • AutoSuggestBox_Keyboard.png-dark
    • AutoSuggestBox_Keyboard.png
    • BorderCenteredwithmargins.png-dark
    • BorderCenteredwithmargins.png
    • BorderLeftwithmargins.png-dark
    • BorderLeftwithmargins.png
    • BorderVersusPanelClipping.png-dark
    • BorderVersusPanelClipping.png
    • Border_CornerRadius_Alignments.png-dark
    • Border_CornerRadius_Alignments.png
    • Border_Simple.png-dark
    • Border_Simple.png
    • Button_IsEnabled_Automated.png-dark
    • Button_IsEnabled_Automated.png
    • Button_Opacity_Automated.png-dark
    • Button_Opacity_Automated.png

ramezgerges and others added 2 commits October 15, 2026 07:00
GLCanvasElement skipped its BGRA readback probe on the browser, on the
premise that the JS shim translated BGRA reads. GL entry points now
resolve to emscripten's native GL first, so glReadPixels reaches WebGL
with GL_BGRA, which WebGL 2.0 rejects with INVALID_ENUM. The first
readback failed and the element stopped rendering, leaving it blank.

WebGL reports itself as OpenGL ES, so the existing GLES probe now runs
there and selects the RGBA read with the red/blue swap. Every element
gets its context from the same platform logic, so the probe now runs once
per process instead of per element, which also keeps the browser from
logging a WebGL warning for each element.

Fixes unoplatform#24497

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Renders a GLCanvasElement cleared to pure red and checks the readback
shows red, which fails for a blank canvas and for a red/blue mix-up.
Inconclusive where no OpenGL context is available.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@ramezgerges
ramezgerges force-pushed the dev/rara/wasm-glcanvas-readback branch from 3d210f7 to 01c412e Compare October 15, 2026 11:02
@ramezgerges
ramezgerges enabled auto-merge October 15, 2026 11:19
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239689 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DisplayInformation.png-dark
    • DynamicFont.png-dark
    • DynamicFont.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_ScreenReader.png-dark
    • AppBar_KeyBoard.png
    • Application_DispatcherShutdownMode.png
    • AppWindowTitleBar Properties.png
    • Arrange_Performance01.png-dark
    • AuthenticationBroker_Cancel.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutomationProperties_Landmark.png
    • AutoSuggestBox_BitmapIcon.png-dark
    • AutoSuggestBox_BitmapIcon.png
    • BadgeNotificationTests.png-dark
    • BadgeNotificationTests.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Sizing.png-dark
    • BitmapIcon_Sizing.png
    • Border_AntiAlias.png-dark
    • Border_AntiAlias.png

@mergify

mergify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@ramezgerges
ramezgerges merged commit 9e17b82 into unoplatform:master Oct 15, 2026
53 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/wasm-glcanvas-readback branch October 21, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM] Regression: GLCanvasElement renders blank — BGRA glReadPixels rejected by WebGL 2.0

4 participants