Add js/wasm (WebGL2) backend for the opengl package#127
Closed
fisherevans wants to merge 3 commits into
Closed
Conversation
Adds a parallel WebGL2 backend under the `js && wasm` build tag so pixel can target the browser without touching desktop code paths. The existing GLFW + go-gl files are tagged `!js`; new `*_wasm.go` siblings implement Window, Canvas, input (keyboard/mouse via DOM events), and stubs for cursor/joystick/monitor. Also refactors a few desktop call sites off the raw `go-gl/gl` package and onto glhf wrappers (`BlendFuncSeparate`, `BlendEquation`, `ActiveTexture`) so the same source compiles for both targets. Two of pixel's internal shaders gained explicit float literals (`0.0`, `2.0`) so GLSL ES 300 — which is stricter about int->float conversion than 330 core — accepts them unchanged. Depends on companion WASM branches of glhf and mainthread. Desktop behavior is unchanged. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The PR description claimed mouse input was wired through DOM events,
but input_dom_wasm.go only installed keyboard listeners. Add mousedown /
mouseup / mousemove / mouseenter / mouseleave / wheel / contextmenu
handlers, map MouseEvent.button to pixel.MouseButtonN, and fire all
user-registered callbacks (button, char, mouse moved/entered, scroll)
so game code that sets them sees the same events as on desktop.
Also drop the unused internal.InputHandler{} shim and its stale "not
wired up yet" comment, and add a WebAssembly section to the top-level
README describing how to load the canvas, which features are stubbed,
and the required build command. Adjust the "Missing features" list so
the HTML5 backend isn't still called out as missing.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Polls navigator.getGamepads() once per UpdateInput and feeds the results through the same internal.JoystickState machinery the desktop backend uses. Standard-layout pads are remapped so button / axis order matches the GLFW backend (including promoting LT/RT from analog buttons to the trigger axes); non-standard pads pass through as raw indices so applications can still address them.
2264bd3 to
399d77d
Compare
This was referenced Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a parallel WebGL2 backend to the `opengl` package under the `js && wasm` build tag so pixel can target the browser. The existing GLFW + go-gl files gain `//go:build !js`; new `*_wasm.go` siblings implement:
The only desktop-visible change is explicit float literals (`0.0`, `2.0`) added to two of pixel's internal shaders — GLSL ES 300 is stricter about int→float conversion than 330 core, so the change lets the same source compile for both targets.
Dependencies
Depends on companion WASM branches of glhf and mainthread:
Test plan