Skip to content

Any examples of using Glutin to create a single context that may be used with multiple windows over its lifetime. #1442

@rib

Description

@rib

Hi, I'm trying to update egui/eframe to better support Android by lazily creating graphics state when applications first resume and on android it would destroy and recreate surface state when the application is Paused and Resumed.

I've been able to get egui/eframe working like this on Android when running with wgpu and the same should be possible with gles + egl but I'm currently not really clear on how I can do this with the Glutin API.

My impression is that Glutin tightly couples GL contexts with windows which seems surprising to me, and I'm unsure at the moment how to practically create a context that's initially not associated with any windows/surfaces and then separately be able to create and destroy windows to use with that context. It would also be OK if the context is initially created with an associated window but I'd still like to be able to freely destroy and create other windows later that would be used with the original context that shouldn't need to be destroyed.

Ideally I'm also looking for an approach that will work consistently across platforms; avoiding the need to handle Android as a special case. (So if possible I'd like to avoid needing to create a RawContext type of escape hatch just for Android)

A few things I have seen:

I've seen that a window can be "split" from a glutin context but also saw the surprising safety warning that if the window is destroyed then the context should be destroyed first which I found counter intuitive. I also haven't seen how you can do the opposite and attach a window to a context. I think I would have expected that Context::make_current() would have taken some form of WindowSurface argument that would allow contexts and window surfaces to be managed separately.

I've seen the multiwindow example which isn't quite what I'm looking for here since that seems to create a separate context for each window which shouldn't be necessary here (and also implies re-creating GL state, such as uploading textures which isn't desirable).

I've also seen the rawcontext type that represents a context that's associated with a window that was created externally which doesn't seem applicable. In this case I'd still like Glutin to handle creating window surfaces.

In the Context docs I see it says "however Contexts can be shared between multiple windows" which does suggest that it is possible to do what I'm looking for so maybe I'm currently just missing a trick somewhere?

Maybe there's even some example app somewhere that shows how this kind of use case can be handled?

Any pointers would be much appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions