-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Image constructor specialised for rendering to a texture #17209
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
base: main
Are you sure you want to change the base?
Conversation
@BenjaminBrienen I've "rebased" this |
Shouldn't hard code to default the texture format. HDR cameras need a different format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update headless_renderer, gpu_readback, and compute_shader_game_of_life
I think those are all the examples that use this pattern.
(Sorry, that wasn't an approve, just a comment)
Yeah, this should either take a |
So to clarify, the suggestion is to either:
|
In the discord there were a few comments:
if (hdr) {
ViewTarget::TEXTURE_FORMAT_HDR
} else {
TextureFormat::bevy_default()
} For now I have left the constructor in |
I've done this but the discrepancies make me think maybe these should have their own helper constructors, possibly with guidance in the doc comment.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, sorry for forgetting about this PR. After looking at the change again, I think I'm almost happy with everything, but I realize now that maybe we should just have the texture format be a direct parameter to the function instead of an HDR flag. That way it can easily be used in other contexts and people can inline the if hdr
pattern if they need it and if they don't it's pretty easy to just provide the right texture format.
I think it's fine if more advanced use cases just modify the resulting image like you did in the examples. It's still nicer to have the constructor as a starting point for that boilerplate.
07396cc
to
21dda3c
Compare
I've updated I've improved the documentation. Also fixed a bug in the The examples I've updated are:
Since example |
This looks good, but could you make the changes to add the TEXTURE_FORMAT consts to bevy_image in a separate PR? I think it's a worthwhile change, but I'd prefer if it wasn't bundled with a feature PR. |
Approved, but I would still like the texture format changes in bevy_image to be in a separate PR |
4926025
to
146fd1b
Compare
Dropped the constants out of this PR. |
Co-authored-by: Antony <antony.m.3012@gmail.com>
ad3905a
to
0ba5fb2
Compare
Objective
Fixes #7358
Redo of #7360
Ergonomics. There's a bunch of enigmatic boilerplate for constructing a texture for rendering to, which could be greatly simplified for the external user-facing API.
Solution
Image
, with minimal changes beyond theDefault
implementation.Strictly speaking, there are two small differences between the constructor and the example:
1. The example sets thesize
when initially constructing theImage
, thenresize
s, butresize
sets thesize
anyway so we don't need to do this extra step.2. The example setsImage.texture_descriptor.format
toTextureFormat::Bgra8UnormSrgb
, but the default impl sets this toTextureFormat::Rgba8UnormSrgb
viawgpu::TextureFormat::bevy_default()
. I don't know what sort of impact this has, but it works on my machine.I've deliberately chosen to only include
width
andheight
as parameters, but maybe it makes sense for some of the other properties to be exposed as parameters.Changelog
Added
Added
Image::new_target_texture
constructor for simpler creation of render target textures.Notes:
Image
constructor specialised for rendering to a texture #7360 - there's some relevant discussion on code style there.bevy_render::camera::Camera
andbevy_render::camera::RenderTarget::Image
.bevy_image
used to be part ofbevy_render
and was split out in the past, andbevy_image
doesn't depend onbevy_render
. What's the recommendation here?