support uniform textures and other compose methods#125
Draft
fisherevans wants to merge 2 commits into
Draft
Conversation
…ional compose methods
4 tasks
- Add doc comments to Canvas.SetUniformTexture and GLShader.SetUniformTexture describing the sampler binding semantics and the unit index constraint. - Drop unnecessary else after early return in GLShader.SetUniformTexture. - Remove dead commented-out clamp-to-[0,1] snippet from ComposeMultiply. - Revert .gitignore to upstream state (.idea/ belongs in a global ignore). - Add tests/compose_test.go with table-driven cases for ComposeMultiply and ComposeScreen covering opaque, black, white, and transparent inputs.
dusk125
requested changes
Apr 22, 2026
| } | ||
| ct.shader.s.SetUniformAttr(loc, u.Value()) | ||
| } | ||
| gl.ActiveTexture(gl.TEXTURE0) |
Contributor
There was a problem hiding this comment.
Maybe cache the active texture before this loop and restore it here (I'm assuming that that's the intention behind this call)
| } | ||
|
|
||
| c.shader = NewGLShader(baseCanvasFragmentShader) | ||
| c.shader = NewGLShader(BaseCanvasFragmentShader) |
Contributor
There was a problem hiding this comment.
Why the change to exporting the base shader?
| case pixel.ComposeMultiply: | ||
| glhf.BlendFunc(glhf.BlendFactor(gl.DST_COLOR), glhf.Zero) | ||
| case pixel.ComposeScreen: | ||
| gl.BlendEquation(gl.FUNC_ADD) |
Contributor
There was a problem hiding this comment.
Could these be added back down to glhf?
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.
Changes
Two independent additions to the opengl backend.
Sampler uniforms (
SetUniformTexture)Canvas.SetUniformTexture(name, tex, unit)binds a*glhf.Textureto a namedsampler2Din the canvas's fragment shader. The texture is activated on the given unit and bound each frame during draw.In the shader:
The two default shader constants are now exported (
BaseCanvasVertexShader,BaseCanvasFragmentShader) so custom shaders can extend the defaults without duplicating the source.Compose methods
Two new Porter-Duff composition modes for
canvas.SetComposeMethod:pixel.ComposeMultiply— multiplies source and destination channels. Useful for lighting masks: https://www.slembcke.net/blog/2DLightingTechniques#screen-space-lightmapspixel.ComposeScreen— inverse of multiply; lightens by1-(1-src)*(1-dst).Both modes have software implementations in
Compose()and hardware blend function registrations in the opengl backend. The hardware path uses rawgo-gl/glcalls forBlendEquationandBlendFuncSeparatesince glhf v2.0.0 does not yet expose those wrappers (the companion glhf PR #8 adds them — once that lands these can be simplified).Test plan
go build ./...unchanged.go test ./...— newtests/compose_test.gocoversComposeMultiplyandComposeScreenwith opaque, transparent, black, and white inputs.