Add HTML-in-Canvas support with texElement2D API #7897
Draft
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.
Add HTML-in-Canvas support with texElement2D API
This PR implements support for the HTML-in-Canvas proposal by adding
texElement2Dfunctionality to the PlayCanvas engine.This PR is set to Draft mode, it's merge is conditional on the proposed feature being approved / supported by the browsers.
Live example: https://engine-r6jsc97gk-playcanvas.vercel.app/#/misc/html-texture
(check message in Console to confirm new feature vs fallback being used)
What's Changed
Core Engine Changes
_isHTMLElementInterface()method to detect HTML elements as valid texture sourcestexElement2DAPI support viasupportsTexElement2DpropertytexElement2Dwhen available, with graceful fallback to existing texture upload methodssetSource()method to accept HTML elements with proper dimension handling viagetBoundingClientRect()New Example
html-texture.example.mjsdemonstrating:texElement2DtexElement2Dis not supportedTechnical Details
HTML-in-Canvas Requirements
layoutsubtreeattribute for feature enablementFallback Strategy
When
texElement2Dis not supported or fails, the implementation automatically falls back to:Browser Support
--enable-experimental-web-platform-featuresFiles Modified
src/platform/graphics/graphics-device.jssrc/platform/graphics/webgl/webgl-graphics-device.jssrc/platform/graphics/webgl/webgl-texture.jssrc/platform/graphics/texture.jsexamples/src/examples/misc/html-texture.example.mjs(new)Testing
This implementation provides a foundation for future HTML-in-Canvas adoption while maintaining backward compatibility.
Screen.Recording.2025-08-11.at.11.37.05.mov