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
texElement2D
functionality 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 sourcestexElement2D
API support viasupportsTexElement2D
propertytexElement2D
when available, with graceful fallback to existing texture upload methodssetSource()
method to accept HTML elements with proper dimension handling viagetBoundingClientRect()
New Example
html-texture.example.mjs
demonstrating:texElement2D
texElement2D
is not supportedTechnical Details
HTML-in-Canvas Requirements
layoutsubtree
attribute for feature enablementFallback Strategy
When
texElement2D
is not supported or fails, the implementation automatically falls back to:Browser Support
--enable-experimental-web-platform-features
Files Modified
src/platform/graphics/graphics-device.js
src/platform/graphics/webgl/webgl-graphics-device.js
src/platform/graphics/webgl/webgl-texture.js
src/platform/graphics/texture.js
examples/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