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

UI with pixels #90

Closed
teevik opened this issue Jun 23, 2020 · 9 comments · Fixed by #116
Closed

UI with pixels #90

teevik opened this issue Jun 23, 2020 · 9 comments · Fixed by #116
Labels
question Usability question

Comments

@teevik
Copy link

teevik commented Jun 23, 2020

Hey, I'm pretty new to graphics programming and wgpu. I was wondering how you'd go about adding UI while using pixels?

Would a library like Iced work, since it has wgpu support?

Is this where you'd use render passes?

@parasyte parasyte added the question Usability question label Jun 23, 2020
@parasyte
Copy link
Owner

parasyte commented Jun 23, 2020

There is no need for a render pass to draw a GUI. iced has a mode of operation allowing it to integrate with any wgpu-based application (instead of taking over the event loop and windowing system, as the normal App-based examples do.)

I haven't tried this yet, but I will see about getting an example written. It will just be based on the "integration" example from the iced repo: https://github.com/hecrj/iced/tree/master/examples/integration

@SpyrosRoum
Copy link

I'll to make it work myself but in the meantime I'd also love to see an example like that from as it will probably be better haha
Thanks for all the work as well :D

@JMS55
Copy link
Contributor

JMS55 commented Jul 27, 2020

I'm using imgui, imgui-wgpu, and imgui-winit-support along with Pixels::render_with() for my UI and it works great. The only gotcha is that you have to modify Pixels::render_with() to take &Device, and make Pixels's device and queue fields pub, so that you can pass them both to imgui_wgpu::Renderer::new().

@parasyte
Copy link
Owner

For anyone else following the conversation, there is an experimental branch which makes those changes, providing a struct with many of the necessary references:

pixels/src/lib.rs

Lines 49 to 63 in 00d1255

#[derive(Debug)]
pub struct PixelsContext {
// WGPU state
pub device: wgpu::Device,
pub queue: wgpu::Queue,
swap_chain: wgpu::SwapChain,
// Texture state for the source
pub texture: wgpu::Texture,
pub texture_extent: wgpu::Extent3d,
pub texture_format_size: u32,
// A default renderer to scale the input texture to the screen size
pub scaling_renderer: ScalingRenderer,
}

@JMS55
Copy link
Contributor

JMS55 commented Jul 27, 2020

There's currently no way to get a PixelContext outside of render_with(), which is needed to setup imgui-wgpu (need to borrow &Device and &mut Queue at the same time).

@parasyte
Copy link
Owner

parasyte commented Jul 27, 2020

That's why these were originally stored as Rc<Device>, and Rc<RefCell<Queue>> (to provide shared ownership with interior mutability). I think a slightly more intricate design can provide access to these without runtime overhead, as discussed in #107

@teevik
Copy link
Author

teevik commented Sep 7, 2020

Is UI with pixels now possible since #112 got merged?

parasyte added a commit that referenced this issue Sep 8, 2020
@parasyte
Copy link
Owner

parasyte commented Sep 8, 2020

@teevik I added an example that incorporates imgui. #116 Have a look and provide any feedback on that PR! I also want to do an example for iced. Just haven't gotten around to it.

@teevik
Copy link
Author

teevik commented Sep 8, 2020

Thanks so much for this, I'll try it out! I'm planning on making some sort of 2d shooter with pixel simulation, really hyped for trying this out now 😄

parasyte added a commit that referenced this issue Sep 18, 2020
* Add Dear ImGui example

- Closes #90

* Change argument order to match `render_with`

* Remove unnecessary borrow

* Refactor error messages

* Add a space

* Refactor Gui field privacy

* Add a menu bar and allow the about window to be closed

- The local bool is necessary because the menu bar closures are not allowed to borrow `self` for mutable access while `imgui::Ui<'ui>` is alive.
- The token-based menu bar lifetime is even more verbose than this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants