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

simple wgpu example #191

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

andrew-r-thomas
Copy link

this is a simple example using wgpu of a rainbow triangle that is centered at the mouse position.

it's probably not the cleanest way to do things on the wgpu side but it's a good starter example for people looking to use wgpu in baseview

some things to note:

  • the wgpu version used is 0.18, this is because we needed a version that accepted a window that implements HasRawWindowHandle and HasRawDisplayHandle from rwh
  • the surface size on wgpu should be twice the window size in baseview for the sizes to match up. not sure why this is, but good to note

Copy link
Member

@prokopyl prokopyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! 🙂

The issue of the surface size needing to be twice as big as the window size is a window scaling factor issue. You probably have a High-DPI monitor on your machine, but on my machine everything is off by a factor of 2.

To fix this you need to handle window resize events, which also carry the scaling factor. Currently in baseview there is no way to get the actual window size at creation time, but a resize event will be fired right away which will give you all the information you need.

You can use the render_femtovg example as a reference on how to handle those events and resize your rendering buffers when needed. 🙂

You're also recreating the whole vertex buffer on every mouse move, but I think it would be better to simply write the mouse position into a uniform buffer and handle the translation in the shader instead.

There's also a couple clippy warnings that need fixing, but nothing too bad. Nevermind, seems like you fixed those already! 👍

@andrew-r-thomas
Copy link
Author

@prokopyl not sure what the weird clippy error is for the windows test, looks like its coming from the baseview source. everything else should be fixed though!

@murl-digital
Copy link

fyi @andrew-r-thomas, i was able to get the latest version of wgpu working with your example, basically i remove the lifetime requirements, made Surface 'static, and converted directly between the raw window and display handle types between 05 and 0.6

@andrew-r-thomas
Copy link
Author

fyi @andrew-r-thomas, i was able to get the latest version of wgpu working with your example, basically i remove the lifetime requirements, made Surface 'static, and converted directly between the raw window and display handle types between 05 and 0.6

sweet! I think there are a bunch of refactoring changes for baseview that are in progress that will allow for 0.6 to be more fully supported, but good to know that theres a fix in the meantime!

@andrew-r-thomas andrew-r-thomas requested a review from prokopyl May 22, 2024 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants