-
Notifications
You must be signed in to change notification settings - Fork 26
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
gl.Init called without a current context on Windows backend, and fails. #6
Comments
I see two possible ways of fixing this.
So it's a question of Note that the So with second choice, user code to initialize a program would be: err := glfw.Init(gl.ContextSwitcher)
if err != nil {
log.Fatalln("glfw.Init:", err)
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Test", nil, nil)
if err != nil {
log.Fatalln(err)
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
log.Fatalln("Failed to initialize gl bindings: %v", err)
}
... With the first choice, user doesn't need to call I also wonder, if a context is detached, window closed, then a new window is opened, new context is created, then |
I am leaning towards making |
The part I really don't like with the implicit approach (my suggested fix) is that there's no contract on the type handed to ContextSwitcher.MakeContextCurrent. Have you considered just merging the two goxjs packages? |
On the other hand, "context switching" and "initializing gl bindings" do feel like two slightly separate concerns, maybe. I am not completely confident on when
I'm actually working on making that contract more typed than just a single multi-purpose
When I started out,
That lead me to trying to decouple them, and this I wanted the exact |
That's a good question. Really, the go package should have a function table per GL context - see the wglGetProcAddress Remarks section, but I think it only has a single set of globals. In which case, I'd also side with explicit over implicit. |
All right, let me try bringing back |
Actually, it became quite a bit better when I decided to reduce the responsibility of That way it can be a bit cleaner, see https://gist.github.com/shurcooL/bb5eb9d0bf14ec71fdfc. I'll still try the approach of having |
Ok, I think I'll stay with keeping I'd like to start off with this simpler solution that does not require API additions on the user side (i.e., they don't need to start adding If there are any issues with the current fix, then we can revisit this. I think by the time there's a usage case where there are multiple windows, multiple contexts being made current and running Since I have absolutely no code that uses multiple windows/contexts, I don't want to try to solve a problem which I cannot test or see how well it works. So I'll start simple, and move forward from there.
That's a great point, and I agree that'd be a more correct, efficient long term solution. But I don't want to rush into it right away, I'd rather make it an optional future enhancement, driven by a testable use case. |
I've been following along, perhaps a bit silently -- but @shurcooL I highly agree with your last comment and think it is the right way to approach this. |
Reduce its responsibility from "switch context" and "initialize gl bindings" to just "initialize gl bindings". Actual context switching now happens within glfw library itself. Trying to switch context on desktop side brought in too much responsibility for something that is already being done in glfw. Needed for goxjs/gl#6.
This issue is now resolved via goxjs/glfw@c2e5c56 and a52900d. |
…atures Framebuffer features
Originally reported in google/gxui#86 (comment).
The text was updated successfully, but these errors were encountered: