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

Would it make sense to have some kind of "view" or "renderable" handle? #123

Open
madsmtm opened this issue Jun 10, 2023 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@madsmtm
Copy link
Member

madsmtm commented Jun 10, 2023

I'm only really familiar with macOS and iOS, but on those platforms it would make sense to split the window and the view handles in two.

That way, users could make some sort of interface in the native toolkit, and just provide the NSView handle to wgpu to render into. With the current design, we're assuming that the whole window's content is what should be rendered into.

I think this is roughly how it already works on web, e.g. you can lay out the page in a certain way, and then just create a canvas that you pass on to the renderer to do its thing. (Though arguably winit shouldn't be creating a canvas, perhaps instead it should provide a div that the graphics library itself can insert the canvas into?)

Would this sort of thing work on other platforms?

@madsmtm madsmtm added the enhancement New feature or request label Jun 10, 2023
@MarijnS95
Copy link
Member

I think this is roughly how it already works on web

And on android, where NativeWindow is just a silly name for the native wrapper around a Surface and could be any part of the view layout, not necessarily the whole "window surface".

https://github.com/MarijnS95/AndroidNativeSurface

@madsmtm
Copy link
Member Author

madsmtm commented Jun 10, 2023

Basically, I want better cooperation with the existing layout systems (if they exist).

I'm especially unsure what the best approach is for building a "native" user interface on Linux? GTK? Or would it be best to do it "raw", and provide something like struct XcbViewHandle { visual_id: u32, position: (u32, u32), size: (u32, u32) }?

@kchibisov
Copy link
Member

Wayland's wl_surface can be used for anything as well, but that's how the handle is done.

I wonder whether on macOS you don't need to have a reference to a window to perform some requests on it? Also, the user could simply omit the window, fields are not required to be set, so setting just NSView is absolutely fine.

and provide something like struct XcbViewHandle { visual_id: u32, position: (u32, u32), size: (u32, u32) }?

visual has nothing to do with windows on X11, it's a pixel format. Everything is a XID, which is window as it's said in the structs.

@madsmtm
Copy link
Member Author

madsmtm commented Jun 10, 2023

The window field is entirely redundant on macOS, it can always be gotten from the view.

So maybe it would actually make sense to rename the [Raw]WindowHandle to [Raw]ViewHandle (or similar)?

@MarijnS95
Copy link
Member

to [Raw]ViewHandle (or similar)?

The common name for this thing on e.g. Android and in graphics APIs like (E)GL and Vulkan is a "surface", I'd name it that.

OTOH it's not that in Vulkan/GL yet, you still have to create a Surface from a Surface which may sound weird?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants