Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a pixelgl.Window.SwapBuffers method (that doesn't poll events) #217

Closed
snargleplax opened this issue Feb 10, 2020 · 1 comment
Closed

Comments

@snargleplax
Copy link
Contributor

I'd like to be able to call the part of pixelgl.Window.Update that swaps buffers without calling the part that polls input. Since UpdateInput has already been broken out and exported (cf. #78), this symmetric case seems like a reasonable extension of the same principle.

My use case is an architecture that polls input via UpdateInput and JustPressed in a separate goroutine from the graphics refresh loop. Because the graphics goroutine polls input as a side-effect of its call to Update, the input handling goroutine's call to JustPressed doesn't trigger reliably -- because, I surmise, the two are racing and sometimes the graphics update "swallows" the first-time input. Regular Pressed works, but then I'd have to roll my own edge detection.

I've tested this change locally (since it's trivial to make) and it seems to work fine:

diff --git a/pixelgl/window.go b/pixelgl/window.go
index 10c16ce..14ce2d9 100644
--- a/pixelgl/window.go
+++ b/pixelgl/window.go
@@ -173,6 +173,11 @@ func (w *Window) Destroy() {

 // Update swaps buffers and polls events. Call this method at the end of each frame.
 func (w *Window) Update() {
+       w.SwapBuffers()
+       w.UpdateInput()
+}
+
+func (w *Window) SwapBuffers() {
        mainthread.Call(func() {
                _, _, oldW, oldH := intBounds(w.bounds)
                newW, newH := w.window.GetSize()
@@ -207,8 +212,6 @@ func (w *Window) Update() {
                w.window.SwapBuffers()
                w.end()
        })
-
-       w.UpdateInput()
 }

 // SetClosed sets the closed flag of the Window.

I'll submit a PR with this.

Thanks for this library, been playing with it about a week now and it's been great.

@delp
Copy link
Contributor

delp commented May 2, 2020

Addressed by #219
Thanks for the change!

@delp delp closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants