-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Flexible and convenient texture loading #3291
Comments
Maybe these could have overrides as well, for added flexibility. pub fn pending_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self;
pub fn error_ui(self, add_contents: impl FnOnce(&mut Ui, LoadError)) -> Self; But these would have to be evaluated before anything is drawn, so it would probably require having to call a |
Most of the proposal is implemented, but there's work left to do:
|
### What Add Example page to the Welcome Screen. Fixes #3096 <img width="1366" alt="image" src="https://github.com/rerun-io/rerun/assets/49431240/bbe2e84e-9ade-4da8-b095-d7b0f396c26f"> ### TODO - [x] fix layout issues - [x] display tags - [x] have dedicated, short copy for the description: #3201 ### Not included in this PR - **WARNING**: here, we bake in a manifest with hard-coded links to RRDs that were generated within this PR. This will lead to issue down the line, when the RRD format changes. - #3212 - #3213 - download updated manifest - #3190 - load thumbnail from the web - emilk/egui#3291 - provide feedback while downloading a RRD - #3192 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3191) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/3191) - [Docs preview](https://rerun.io/preview/3be107e4cc6aa6758a3f22c27a79233b33f2ea6b/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/3be107e4cc6aa6758a3f22c27a79233b33f2ea6b/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/) --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
When the server sends invalid CORS headers, then the browser will output only an opaque
Browsers may output more information to the developer console or through other means, but they may not expose this information to the page. We can't tell the user it's "likely" a CORS error, because there are a whole bunch of other possible causes for a
I don't know how to improve the situation. We could list all of the possible causes, but that's a lot of stuff to throw at a user. I also don't think it really needs to be improved, because the problem is clear once you look at the devtools console, which you do often anyway. |
We can improve the situations like so:
So, I suggest in |
This is awesome! In my project I'm loading a lot of images so I implemented this with my own image abstraction, but it'd be awesome if I could switch to using the new loader traits in the future. I'd be happy to implement a WgpuWasmTextureLoader, either as part of the egui_wgpu crate or as a separate external crate. |
That's all you would need to implement though, and it would work for any |
It's great! Btw, is it also neccessary/possible that directly passing a grayscale image buffer (like |
@wangxiaochuTHU For now, only |
Intro
Showing images in egui is currently very cumbersome. There is
egui_extras::RetainedImage
, but it requires you to store theRetainedImage
image somewhere and is obviously not very immediate mode.Ideally we want users to be able to write something like:
We also want 3rd party crates like
egui_commonmark
to be able to use the same system, without having to implement their own image loading.Desired features
egui is designed to have minimal dependencies and never doing any system calls, and I'd like to keep it that way. Therefor the solution needs to be some sort of plugin system with callbacks. This is also the best choice for flexibility.
There is three steps to loading an image:
include_bytes!("my_icon.png")
In most cases we want the loaded image to be passed to
egui::Context::load_texture
, which wil hand the image off to whatever rendering backend egui is hooked up to. This will allow the image loaded to work with any egui integration.We should also allow users to have more exotic ways of loading images. At Rerun we have a data store where we store images, and it would be great if we could just reference images in that store with e.g.
ui.image(rerun://data/store/path);
.In some cases however, the user may want to refer to textures that they themselves have uploaded to the GPU, i.e. return a
TextureId::User
. We do this at Rerun.Proposal
I propose we introduce three new traits in
egui
:BytesLoader
ImageLoader
TextureLoaader
The user can then mix-and-match these as they will.
Users can register them with
ctx.add_bytes_loader
,ctx.add_image_loader
,ctx.add_texture_loader
,and use them with
ctx.load_bytes
,ctx.load_image
,ctx.load_texture
.We will supply good default implementations for these traits in
egui_extras
. Most users will never need to look at the details of these.All these traits are designed to be immediate, i.e. callable each frame. It is therefor up to the implementation to cache any results.
They are designed to be able to suppor background loading (e.g. slow downloading of images).
For this they return
Pending
when something is being loaded. When the loading is done, they are responsible for callingctx.request_repaint
so that the now-loaded image will be shown.They can also return an error.
Pending
will be shown in egui usingui.spinner
, and errors with red text.Common code
BytesLoader
ImageLoader
TextureLoader
Common usage
Advanced usage:
Implementation
For version one, let's ignore cache eviction, and lets parse all images inline (on the main thread). We can always improve this in future PRs.
in
egui
We just have the bare traits here, plus:
in
egui_extras
Implementation notes
egui_extras::RetainedImage
, or the above urlThe text was updated successfully, but these errors were encountered: