-
Notifications
You must be signed in to change notification settings - Fork 182
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
GLFW v3.4 #400
base: master
Are you sure you want to change the base?
GLFW v3.4 #400
Conversation
Thanks for working on this.
It's not much, but there are two small example programs in https://github.com/go-gl/example. Out of the box, it fails to link on GOOS=darwin GOARCH=arm64 with:
That doesn't happen if this line is added to #include "glfw/src/cocoa_time.c"
+#include "glfw/src/posix_module.c"
#include "glfw/src/posix_thread.c" And with that at least basic functionality seems to work okay on macOS. |
I'll go ahead and try these then.
Cool I'll add this in. By the way, does this fix #272 for you? I think the upstream fix is included in GLFW v3.4. |
Forgot to mention, @dmitshur can you test with |
Without the changes in #399 (and also defining I can replicate the same gles1 and gles3 failures on Fedora 40 (Wayland and X11) but I get the same error on v3.3 so that's fine? Compiling with Isn't Glfw v3.4 supposed to be able to switch between Wayland and X11 at runtime? If that is the case, should we enable that by default? Maybe have x11 and wayland tags for when you only want a single backend? |
I can define
I think it's fine too. To my understanding, GLES v1 & v3 are just different implementations of the OpenGL spec. So, it's probably good keeping them in, but they might be hard to test on bleeding edge distros like Arch and Fedora. Also, I believe
I think it's best to keep X11 as the default to make the transition easier from v3.3 to v3.4, but if GLFW can now choose Wayland or X11 at runtime, maybe we can add support for this when both |
I just pushed support for applying both X11 & Wayland on Linux with (-tags x11,wayland). I will add to BSD later, but I want to get the build working standalone on BSD first. |
That won't make any difference as I was building on FreeBSD. The GOOS value for the native operating system is always added automatically and the same goes for GOARCH. If you build your app on Linux for example, you don't need to pass |
No, it is not an error in Fedora. It is a drawback of the solution. See #359, we need a better solution but right now that is better than not being able to compile. Implicit declarations are emitted (which is treated as an error on Fedora 40 due to stricter security settings) if your don't force _GNU_SOURCE to on but if you do, you get a warning that it is defined twice.
I'm not personally of doing that approach. Wayland is the future and I think we should enable the runtime switching support if we can. However, it is up to @dmitshur at the end of the day. |
Yes, this is a warning due to the manual definition inside GLFW source code. I don't understand why it's defined without a |
// GLFW Options: | ||
#cgo linux,!wayland CFLAGS: -D_GLFW_X11 | ||
#cgo linux,x11 CFLAGS: -D_GLFW_X11 | ||
#cgo linux,wayland CFLAGS: -D_GLFW_WAYLAND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on top, is it OK that _GNU_SOURCE
is now globally set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want it set but I couldn't compile at all without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no response to #400 (comment), I'll just mark this as resolved.
package glfw | ||
|
||
/* | ||
#cgo CFLAGS: -Iglfw/include -D_GNU_SOURCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then, _GNU_SOURCE
is now globally set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no response to #400 (comment), I'll just mark this as resolved.
@metal3d I think |
@Jacalz I completely agree, but this isn't about ideologies. This is about what is best for the users of this library.
I have added support for this on Linux like I said previously ( |
My point has nothing to do with ideologies. You are taking things out of context and I don't agree that being X11-only would be helpful in the long run. Enabling Wayland-only by default would be stupid but supporting dynamic switching between the two is a good compromise that we should try to make use of now that we can. Enabling runtime switching by default is the best path forward given how quickly Wayland is getting adopted and some distros like Fedora are even disabling Xorg support (XWayland works yes, but you see the direction we are heading). Making the switch to enable Wayland support by default now is going to be the better option as a future-proof setting and that switch will be much harder to make down the line. Remember that v3.4 is an entirely new module import and it would be problematic to suddenly enable Wayland support and require an extra dependency when compiling later in the lifecycle of that existing in the repository. If we are to stay up to date with the times, that support needs to be enabled from the start. If you still want to have X11-only, I see no reason why people can't still use v3.3 given that it still will be maintained some time forward. We have seen in Fyne that the community cares very much for Wayland support to be enabled and Flathub even marks an X11-only application as unsafe nowadays (https://flathub.org/apps/io.github.jacalz.rymdport). Having dynamic runtime switching gets us both X11 and Wayland support and a lot more people will actually use it instead of having to enable an obscure build tag combination. |
Hey @Geo25rey, given that Mac --> opengl32 is checked here, I tried building on an M3 with:
And then running I had to comment out:
in v3.4/glfw/testdata/customcursor/main.go:36, as it was complaining about Cocoa:
Given the above being commented out, the mouse passthrough I was looking for worked (with floating), after adding the Hint to |
@J7mbo Thx for testing this out according to LWJGL/lwjgl3#695, this commit glfw/glfw@9a87c2a introduced 2 new errors affecting macOS and Wayland, so I think we should pass both |
@J7mbo I just looked at your issue #375 (comment) and it looks like all the hints are out of date or have out of date descriptions so I will add them from here https://www.glfw.org/docs/3.4/window_guide.html#window_hints_wnd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting it this far. I've been using this locally on macOS and haven't spotted any more issues on this platform and in my usage.
Forgot to mention, @dmitshur can you test with
-tags darwin,gles2
as well?
I gave it a try:
$ go run -tags=gles2 .
# github.com/go-gl/example/trygles2
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: ignoring duplicate libraries: '-lGLESv2'
ld: library 'GLESv2' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It's the same error as I get with glfw/v3.3. I've never tried to use OpenGL ES on macOS, and I don't think it's supported. Maybe it is on iOS, but I don't think go-gl/glfw (or upstream GLFW) tries to support iOS at this time.
https://www.glfw.org/docs/latest/window_guide.html#GLFW_CONTEXT_VERSION_MAJOR_hint includes:
macOS: The OS only supports core profile contexts for OpenGL versions 3.2 and later.
I have added support for this on Linux like I said previously (
-tags x11,wayland
). Right now, I just have it setup as an opt-in feature rather than replacing the X11 default.
Thanks for working on this and getting this work at all, that's great. There was a question of what would be preferred default behavior.
My general approach to answering these kinds of questions is to try to follow the upstream GLFW decisions whenever viable, with a balance of satisfying constraints on the Go side. Since GLFW v3.4 changed its default compared to GLFW v3.3 from X11 (with Wayland selected at compile-time) to X11+Wayland selected at runtime, if we can make that the default for glfw/v3.4, that seems optimal to me. That is, based on my current understanding, having what is currently selected with -tags=x11,wayland
be selected with -tags=
(no custom tags) instead seems optimal for the eventual glfw/v3.4 version. I'm certainly open to being convinced otherwise if there are reasons this doesn't work well.
If we think more discussion is needed, I also think it's fine to leave it as is and make it a follow up issue instead of trying to resolve it as part of this PR.
@@ -0,0 +1,6 @@ | |||
//go:build !((linux && wayland) || (freebsd && wayland) || (netbsd && wayland) || (openbsd && wayland)) | |||
// -build linux,wayland freebsd,wayland netbsd,wayland openbsd,wayland |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I thought I left this review comment before, but it doesn't seem to show up. Trying it again.)
This line seems to be malformed. Maybe it was intended to be // +build
. I think it'd be fine not to include it at all, since all versions of Go since Go 1.17 can handle build constraints specified via just the //go:build
lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I'll go ahead and fix this. I'll look at the docs. Do you have a link to the relevant docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build constraints are documented at https://pkg.go.dev/cmd/go#hdr-Build_constraints.
Are there any extra steps or requirements for building in Windows? I have tried to build in both Windows 10 and 11 with different results, but failing in both. I tried the same steps in my Arch Linux machine and it worked first try. |
Thx for testing on Windows @DownloadableFox Please share the build errors you have found so they can be fixed. |
@dmitshur I have added a TODO list for items I'd like to get done before merging this in the PR description #400 (comment)
I agree. We should probably pull in someone from the Fyne team, as well. I'm sure they'd have some useful insights on this. |
I don't have my Windows 11 computer with me at the moment, but this is the output from Windows 10: It appears to be several lines of linker problems. If you want the full log I'd be happy to share it with you, though it's pretty big. I tried building v3.3 and it built with no problems under the same environment. Currently using Go 1.22.1 and MINGW64 through MSYS2. |
I am part of the Fyne team. That's where my insights and opinions on Wayland come from |
@DownloadableFox please provide the full plain text output either here in a < summary > < details > HTML tag or in a public gist. |
@Jacalz How about we discuss in a voice call in the Fyne Discord server? Do you have availability this weekend? Also, I'd like to include someone from the Fyne team that is not opinionated about Wayland itself to hopefully prevent any stalemates, if that is alright with you. |
Voice call sounds like a good plan. I won't be available this weekend unfortunately but the next one or next week should hopefully be a better option.
Sure. If you say so. |
@Jacalz how about 1pm EDT on Monday, May 3? |
That works well for me. Should we check on Discord if someone more from our team is available? |
Yeah sounds good. @Jacalz Can you ask around? |
As a correction to my previous comment, both Windows 11 and 10 share the same output. I might have not looked at it correctly last time I tried to build. Here's the log: https://gist.github.com/DownloadableFox/33c16e3e26566a1eb1252454a0b1e87d EDIT: Ended up making it a Gist instead due to formatting issues. |
I was actually able to fix this after a couple of hours tampering with the code. I was able to build and run in both Windows 10 and 11 by adding this line to
|
Absolutely. Andrew ( |
Did this happen in the end? Any update? |
The meeting on the third of June hasn't happened yet |
Any updates on this? |
We had a discussion and came to the conclusion that X11 + Wayland is the way to go. It is the default upstream and what the whole ecosystem is pushing for. It is a change that will be harder to implement in the future. |
Checking in on the status. @Geo25rey, would you like to keep pushing this forward? If so, there are some unresolved review comments that need to be addressed, otherwise this seems close. I've been using this locally for a while without uncovering new issues. |
@dmitshur I can work on it tomorrow. I have a patch for Windows support to finish and I need to update the Linux default build tags. |
Overview
This is a rough implementation of go-glfw using GLFW v3.4. I have done some basic testing on Linux Wayland and XWayland. I highly recommend reviewing by commit considering the nature and size of this PR.
I am also looking for people to test the builds and functionality on the various platforms listed below. I can personally continue testing on Linux and if I have extra time, MacOS Arm.
Closes: #393
Potentially fixes: #272 @dmitshur
Requesting Review from: @Jacalz
Rundown by commit
C.glfwSetWindowIcon()
under a Wayland environment because it's not supportedTesting
Preamble
I used the short Custom Cursor program for testing. It would probably be a good idea to test with other programs, as well. Does anyone have such test programs?
It is especially important to get more test programs for Wayland since more features than just setting the window icon are not supported by GLFW and/or the Wayland protocols yet, and I'm not sure of other implications of the SIGABRT behavior previously mentioned. For example, I could dynamically add some element to my window at runtime, which could crash my program with a cryptic abort message with no other context. At best, developers using go-glfw can report it here, and at worst a subset of users will report the issue to downstream projects that use go-glfw and the downstream developers may not know what to do with the error message.
cd v3.4/glfw; go run
testdata/customcursor/main.go
-tags linux,wayland
)-tags linux,wayland,gles1
)-tags linux,wayland,gles2
)-tags linux,wayland,gles3
)-tags linux,wayland,vulkan
)-tags linux
)-tags linux,gles1
)-tags linux,gles2
)-tags linux,gles3
)-tags linux,vulkan
)-tags freebsd,wayland
)-tags freebsd
)-tags netbsd,wayland
)-tags netbsd
)-tags openbsd
)-tags darwin
)-tags darwin,gles2
)-tags darwin
)-tags darwin,gles2
)-tags windows
)-tags windows,gles2
)-tags windows
)-tags windows,gles2
)TODO before merge