Add js/wasm (WebGL2) backend#8
Open
fisherevans wants to merge 2 commits into
Open
Conversation
Parallel WebGL2 implementation of Shader, Texture, VertexSlice, Frame, and VertexArray under the `js && wasm` build tag; existing files now tagged `!js` so desktop builds are untouched. Includes a GLSL 330 core to 300 es preprocessor so consumers can run their existing shaders in the browser unchanged. Also adds `BlendFuncSeparate` and `BlendEquation` helpers needed by downstream pixel consumers. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
… test - examples/demo imports GLFW and broke GOOS=js GOARCH=wasm go build ./... (the advertised build test). Tag it !js so the example is desktop-only. - Document the SetContext / shader-preprocessor behavior under WebGL2 in the README and package doc so users building for the browser know the required init order and the GLSL 330 -> 300 es adaptation. - Add a unit test for preprocessShaderForES300. The rest of the WebGL2 backend still needs a real context to exercise, but the preprocessor is pure Go and worth pinning down. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
4 tasks
dusk125
requested changes
Apr 22, 2026
Contributor
There was a problem hiding this comment.
Do you mind breaking this file out into its component files (shader_wasm, frame_wasm, etc)? I appreciate trying to keep the wasm stuff contained, but I think it'll be easier to review/maintain going forward (and more easily shows why the frame.go, etc have the !js build flag
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 implementation of the glhf primitives so consumers can build for
GOOS=js GOARCH=wasmwithout changing call-sites. Everything is keyed on thejs && wasmbuild tag; existing files gain//go:build !jsso desktop behavior is untouched.gl_wasm.go— thin wrappers around thesyscall/jsWebGL2 context and enum map.glhf_wasm.go— WebGL2 implementations ofShader,Texture,VertexSlice,VertexArray,Frame, state setters (Clear,Bounds, blend funcs), plus a#version 330 core→#version 300 espreprocessor so consumers can compile their existing shader source unchanged. The preprocessor is covered byglhf_wasm_test.go.orphan.go(desktop build) grows additional helpers downstream consumers were reaching past glhf for:BlendFuncSeparate,BlendEquation— needed by pixel'sComposeScreenpath.ActiveTexture(unit int)— needed by pixel's sampler-uniform path.SrcColor,DstColor,OneMinusSrcColor,OneMinusDstColor— needed byComposeMultiplyand friends.doc.goandREADME.mdhave a new section describing the WASM backend (SetContextusage, GLSL adaptation,CLAMP_TO_BORDER→CLAMP_TO_EDGEsubstitution).examples/demo/main.gois tagged!jssince it imports GLFW.Related PRs
Test plan
go build ./...).GOOS=js GOARCH=wasm go build ./...succeeds;go test -ccompiles the new test file cleanly.