A DOM form on a quad in a Godot 4 scene
Godot is a game engine. Its web export draws everything into one WebGL canvas, so a login form or a chat box has to be rebuilt from engine controls,
and on a phone the keyboard only opens for a real <input>. Here the form is a real <form> inside Godot's canvas.
The browser paints it into a texture that Godot puts on a quad in a 3D scene. Load the engine, then type in the fields, press Sign in and send a chat line.
A press outside the form goes to Godot and recolours the orbiting objects.
Godot 4.7.2, Compatibility renderer (WebGL2), single-threaded. It isn't loaded until you ask.
The yellow line above the form is a Godot Label3D, drawn with Godot's own font. It changes when the form reports a sign-in or a chat line.
The three small objects orbit the panel and pass in front of the form and behind it. The panel sways less while a field has focus.
Show the code a DOM form as a Godot texture
- Put the form inside the canvas Godot renders into.
- Style it like any other form. It is opaque, because the quad's shader doesn't blend.
- Start the engine when the reader asks.
- Fetch the engine. The 39.5 MB
index.wasmis stored as a 10.1 MB gzip file and inflated in the page. - Start Godot on the canvas with the engine's own
Engineloader and no HTML shell. - GDScript: a quad with an unshaded material.
- GDScript: make a texture and find the WebGLTexture behind it.
texture_get_native_handle()gives the GL name;GL.texturesis reached withJavaScriptBridge.eval()inside the engine's module. - JavaScript: the object GDScript calls.
- JavaScript: note each
paintevent. - GDScript: each frame, upload if the form was repainted.
- JavaScript:
texElementSubImage2D()into Godot's texture. - GDScript: project the quad's corners to the screen.
- JavaScript: four corners to one perspective matrix.
- JavaScript:
updateElementGeometry(). - JavaScript: keep Godot from handling events the form received.
- GDScript: hear from the form, and Godot's own input.
- The route without Emscripten internals, JavaScript side.
- The same route, GDScript side.
- GDScript: which ways reach
GL. - All of main.gd.
- All of bridge.js.
How it works
- The page gives Godot a canvas that already holds the form (
content="drawable",layoutsubtree, anddrawableon the form). Godot makes its WebGL2 context on that canvas. - GDScript makes an
ImageTextureof the sizegetElementImageDefaultSize()reports and asksRenderingServer.texture_get_native_handle()for its GL texture name. Emscripten maps names toWebGLTextureobjects inGL.textures. - After each
paintevent, GDScript's_process()calls the bridge, which binds that texture and callsgl.texElementSubImage2D(), then puts Godot's binding back. - Each frame GDScript projects the quad's four corners with
Camera3D.unproject_position(). The bridge turns them into a homography and passes it tocanvas.updateElementGeometry(). - The form stops mouse, touch and key events from bubbling to the canvas, where Godot listens.
- The route buttons switch how the texture is reached while the scene runs. "createTexture hook" records the texture Godot creates between two calls. "readPixels" uploads into a texture the page owns, reads it back with
readPixels()and gives Godot the bytes.
Live checks
The checks start a second copy of the Godot app in a small frame, so they don't touch the one above. They download the engine (10.4 MB) if it isn't cached and take several seconds.
| Result | Experiment | Detail |
|---|
Findings
Measured in headless Chromium 157 on 2026-11-21 with Godot 4.7.2 and software WebGL2, at 1× and at a 2.625 device scale with touch. Nothing here was run on a phone.
- A stock Godot 4.7.2 web export drew a live DOM form on a quad. No engine change, no GDExtension and no custom export template. The scene is one GDScript file.
GL.texturesis reachable from GDScript and not from the page.JavaScriptBridge.eval(code, false)runs a directevalinside the engine's module function, where Emscripten'sGLis a local variable. The same expression withuse_global_execution_contexttrue finds noGL.get_interface("GL")andget_interface("Module")return null, and the page'sEngineobject doesn't exposeGLeither.RenderingServer.texture_get_native_handle()gave a usable GL name.texElementSubImage2D()wrote into the texture Godot had allocated with its ownglTexImage2D. Row 0 of the element image is the top of the form, which is also Godot's convention, so there's no flip.- The texture can be found without Emscripten. Godot creates exactly one WebGL texture while
ImageTexture.create_from_image()runs, so a wrapper aroundgl.createTexturefor the length of that call identifies it. - The read-back route works and costs a
readPixels()per repaint. It needs neitherGL.texturesnor a hook:JavaScriptBridge.js_buffer_to_packed_byte_array()turns the page'sUint8Arrayinto anImage. The live checks report the time each route spent in its upload call on this device. - The browser's GL can build the mip chain. The
Imageis created with mipmaps so that Godot samples with a mipmap filter, and the bridge callsgenerateMipmap()after each upload. - One perspective matrix placed the hit box on the swaying quad. The check compares the box the browser reports for the form with the corners Godot projected.
- Godot's mouse handler takes focus. Its
mousedownlistener on the canvas callscanvas.focus(). A press on a field bubbles to the canvas. WithoutstopPropagation()at the form, focus was on the canvas after the click and typed text didn't reach the field. Godot also listens formouseupandpasteon the window. - Godot doesn't know the form is there and the browser doesn't know what Godot draws over it. An orbiting object that passes in front of a field hides it, and a press on that spot still reaches the field. Hit testing follows the geometry only.
- The wasm file is over Cloudflare's 25 MiB limit for one static asset.
index.wasmis 39.5 MB. It's stored asindex.wasm.gz(10.1 MB), inflated withDecompressionStream, and handed to the engine by answering itsfetch()with aResponseof typeapplication/wasm, which still compiles while streaming. get_interface()on a missing name prints an engine error to the console as well as returning null.- Not verified on a phone: the on-screen keyboard, IME composition, autofill, password managers, touch selection handles, screen readers, frame rate on a real GPU and the deployed site. The live checks run on the device that opens the page.